Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Multichain tests no longer require prebuilding #360

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions integration-tests/src/mpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use mpc_recovery::Cli;

const PACKAGE: &str = "mpc-recovery";
const PACKAGE_MULTICHAIN: &str = "mpc-recovery-node";
const PACKAGE_CONTRACT: &str = "mpc-contract";
const TARGET_CONTRACT: &str = "wasm32-unknown-unknown";

/// NodeProcess holds onto the respective handles such that on drop, it will clean
/// the running process, task, or thread.
Expand Down Expand Up @@ -37,11 +39,15 @@ fn target_dir() -> Option<PathBuf> {
}
}

pub async fn build(release: bool) -> anyhow::Result<ExitStatus> {
async fn build_package(
release: bool,
package: &str,
target: Option<&str>,
) -> anyhow::Result<ExitStatus> {
let mut cmd = Command::new("cargo");
cmd.arg("build")
.arg("--package")
.arg(PACKAGE)
.arg(package)
.envs(std::env::vars())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());
Expand All @@ -50,9 +56,25 @@ pub async fn build(release: bool) -> anyhow::Result<ExitStatus> {
cmd.arg("--release");
}

if let Some(target) = target {
cmd.arg("--target").arg(target);
}

Ok(cmd.spawn()?.status().await?)
}

pub async fn build(release: bool) -> anyhow::Result<ExitStatus> {
build_package(release, PACKAGE, None).await
}

pub async fn build_multichain(release: bool) -> anyhow::Result<ExitStatus> {
build_package(release, PACKAGE_MULTICHAIN, None).await
}

pub async fn build_multichain_contract() -> anyhow::Result<ExitStatus> {
build_package(true, PACKAGE_CONTRACT, Some(TARGET_CONTRACT)).await
}

pub async fn spawn(release: bool, node: &str, cli: Cli) -> anyhow::Result<NodeProcess> {
if cfg!(feature = "flamegraph") {
let handle: std::thread::JoinHandle<anyhow::Result<()>> = std::thread::spawn(|| {
Expand Down
17 changes: 13 additions & 4 deletions integration-tests/src/multichain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,31 @@ pub struct Context<'a> {
}

pub async fn setup(docker_client: &DockerClient) -> anyhow::Result<Context<'_>> {
if !crate::mpc::build_multichain_contract().await?.success() {
anyhow::bail!("failed to prebuild multichain contract");
}

let release = true;
if !crate::mpc::build_multichain(release).await?.success() {
anyhow::bail!("failed to prebuild multichain node service");
}

let docker_network = NETWORK;
docker_client.create_network(docker_network).await?;

let SandboxCtx { sandbox, worker } = initialize_sandbox(docker_client, NETWORK).await?;

let mpc_contract = worker
.dev_deploy(include_bytes!(
"../../../target/wasm32-unknown-unknown/release/mpc_contract.wasm"
))
.dev_deploy(&std::fs::read(
"../target/wasm32-unknown-unknown/release/mpc_contract.wasm",
)?)
.await?;
tracing::info!(contract_id = %mpc_contract.id(), "deployed mpc contract");

Ok(Context {
docker_client,
docker_network: docker_network.to_string(),
release: true,
release,
sandbox,
worker,
mpc_contract,
Expand Down
Loading