Skip to content

Commit

Permalink
rewrite deployer test in new style
Browse files Browse the repository at this point in the history
  • Loading branch information
chadoh committed Mar 29, 2023
1 parent d8c2f00 commit 27cacd6
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions test/doc-tests/tests/it/deployer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tests CLI commands from https://soroban.stellar.org/docs/how-to-guides/deployer

use soroban_cli::commands::contract::{deploy, install};
use soroban_test::{AssertExt, TestEnv, Wasm};
use soroban_cli::commands::contract::install;
use soroban_test::{TestEnv, Wasm};

const WASM_DEPLOYER_TEST: &Wasm = &Wasm::Release("soroban_deployer_test_contract");
const WASM_DEPLOYER: &Wasm = &Wasm::Release("soroban_deployer_contract");
Expand All @@ -12,42 +12,41 @@ const INIT_VALUE: &str = "5";
fn invoke() {
TestEnv::with_default(|workspace| {
let hash = WASM_DEPLOYER_TEST.hash().unwrap();
workspace

// install (aka upload) the bytes
let install_ret = workspace
.cmd_arr::<install::Cmd>(&["--wasm", &WASM_DEPLOYER_TEST.path().to_string_lossy()])
.run_in_sandbox(WASM_DEPLOYER_TEST.bytes())
.unwrap();
let derived_hash = workspace
.cmd_arr::<deploy::Cmd>(&["--wasm-hash", &format!("{hash}")])
.run_in_sandbox(hash)
.unwrap();
assert_eq!(hash, install_ret);

// now invoke a 2nd contract, which deploys an instance of the previously-uploaded bytes
let new_contract_info_array = workspace
.new_assert_cmd("contract")
.arg("invoke")
.arg("--wasm")
.arg(&WASM_DEPLOYER.path())
.args(["--id", "0"])
.arg("--")
.arg("deploy")
.args([
.invoke(&[
"--wasm",
&WASM_DEPLOYER.path().to_string_lossy(),
"--id",
"0",
"--",
"deploy",
"--salt",
"0000000000000000000000000000000000000000000000000000000000000000",
"--wasm_hash",
&hash.to_string(),
"--init_fn",
"init",
"--init_args",
&format!("[{{\"u32\":{INIT_VALUE}}}]"),
])
.args(["--wasm_hash", &derived_hash])
.args(["--init_fn", "init"])
.args(["--init_args", &format!("[{{\"u32\":{INIT_VALUE}}}]")])
.assert()
.stderr("")
.stdout_as_str();
.unwrap();

let contract_id = new_contract_info_array.split('"').nth(1).unwrap();

e.new_assert_cmd("contract")
.arg("invoke")
.args(["--id", contract_id])
.args(["--", "value"])
.assert()
.stderr("")
.stdout(format!("{INIT_VALUE}\n"));
assert_eq!(
format!("{INIT_VALUE}"),
workspace
.invoke(&["--id", contract_id, "--", "value",])
.unwrap()
);
});
}

0 comments on commit 27cacd6

Please sign in to comment.