Skip to content

Commit

Permalink
Fix init test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Nov 18, 2024
1 parent 2b58f20 commit 36a1daf
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 69 deletions.
79 changes: 11 additions & 68 deletions cmd/crates/soroban-test/tests/it/init.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use assert_fs::prelude::*;
use predicates::prelude::predicate;
use soroban_test::{AssertExt, TestEnv};
use soroban_test::TestEnv;

#[test]
fn init() {
let sandbox = TestEnv::default();
let major = soroban_cli::commands::version::pkg()
.split('.')
.next()
.unwrap();
let cli_version = soroban_cli::commands::version::pkg();
let major = cli_version.split('.').next().unwrap();
let is_rc = cli_version.contains("rc");
sandbox
.new_assert_cmd("contract")
.arg("init")
Expand All @@ -20,68 +19,12 @@ fn init() {
.child("Cargo.toml")
.assert(predicate::function(|c: &str| {
let table = toml::from_str::<toml::Table>(c).unwrap();
table["workspace"]["dependencies"]["soroban-sdk"].as_str()
== Some(&format!("{major}.0.0"))
let sdk_version = table["workspace"]["dependencies"]["soroban-sdk"].as_str();
println!("Check expected version {major}.0.0 matches template's {sdk_version:?}");
if is_rc {
sdk_version.map(|x| x.split('-').next()).flatten() == Some(&format!("{major}.0.0"))
} else {
sdk_version == Some(&format!("{major}.0.0"))
}
}));
}

#[test]
fn init_and_deploy() {
let name = "hello_world";
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("contract")
.arg("init")
.arg("--name")
.arg(name)
.arg("project")
.assert()
.success();

let manifest_path = sandbox
.dir()
.join(format!("project/contracts/{name}/Cargo.toml"));
assert!(manifest_path.exists());

sandbox
.new_assert_cmd("contract")
.arg("build")
.arg("--manifest-path")
.arg(manifest_path)
.assert()
.success();

let target_dir = sandbox
.dir()
.join("project/target/wasm32-unknown-unknown/release");
assert!(target_dir.exists());

let assert = sandbox
.new_assert_cmd("contract")
.arg("deploy")
.arg("--wasm")
.arg(target_dir.join(format!("{name}.wasm")))
.assert();

let contract = assert.stdout_as_str();

assert.success();

let assert = sandbox
.new_assert_cmd("contract")
.arg("invoke")
.arg("--id")
.arg(contract)
.arg("--")
.arg("hello")
.arg("--to")
.arg("bar")
.assert();

let output = assert.stdout_as_str();

assert_eq!(output, r#"["Hello","bar"]"#);

assert.success();
}
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod cookbook;
mod custom_types;
mod dotenv;
mod hello_world;
mod init;
mod keys;
mod snapshot;
mod tx;
Expand Down
62 changes: 62 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use soroban_test::{AssertExt, TestEnv};

#[test]
fn init_and_deploy() {
let name = "hello_world";
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("contract")
.arg("init")
.arg("--name")
.arg(name)
.arg("project")
.assert()
.success();

let manifest_path = sandbox
.dir()
.join(format!("project/contracts/{name}/Cargo.toml"));
assert!(manifest_path.exists());

sandbox
.new_assert_cmd("contract")
.arg("build")
.arg("--manifest-path")
.arg(manifest_path)
.assert()
.success();

let target_dir = sandbox
.dir()
.join("project/target/wasm32-unknown-unknown/release");
assert!(target_dir.exists());

let assert = sandbox
.new_assert_cmd("contract")
.arg("deploy")
.arg("--wasm")
.arg(target_dir.join(format!("{name}.wasm")))
.assert();

let contract = assert.stdout_as_str();

assert.success();

let assert = sandbox
.new_assert_cmd("contract")
.arg("invoke")
.arg("--id")
.arg(contract)
.arg("--")
.arg("hello")
.arg("--to")
.arg("bar")
.assert();

let output = assert.stdout_as_str();

assert_eq!(output, r#"["Hello","bar"]"#);

assert.success();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
]

[workspace.dependencies]
soroban-sdk = "21.0.0"
soroban-sdk = "22.0.0-rc.3"

[profile.release]
opt-level = "z"
Expand Down

0 comments on commit 36a1daf

Please sign in to comment.