Skip to content

Commit

Permalink
Multichain tests no longer require prebuilding (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoticTempest authored Nov 14, 2023
1 parent 175a7b8 commit 65612f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
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

0 comments on commit 65612f3

Please sign in to comment.