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

1682 fix init test #1738

Merged
merged 4 commits into from
Dec 20, 2024
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
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.and_then(|x| x.split('-').next()) == Some(&format!("{major}.0.0"))
} else {
sdk_version == Some(&format!("{major}.0.0"))
Comment on lines +24 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should write an assertion that the generated template is always a stable, non-rc version. See other comment.

}
}));
}

#[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"

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