Skip to content

Commit

Permalink
Add test to reproduce the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Nov 13, 2024
1 parent 02c9c8e commit f8f12eb
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 42 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ crate-type = ["rlib", "cdylib"]


[dependencies]
stellar-xdr = { workspace = true, features = ["cli"] }
soroban-spec = { workspace = true }
soroban-spec-tools = { workspace = true }
soroban-ledger-snapshot = { workspace = true }
Expand Down
89 changes: 57 additions & 32 deletions cmd/crates/soroban-test/tests/fixtures/workspace/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 51 additions & 10 deletions cmd/crates/soroban-test/tests/it/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use predicates::prelude::predicate;
use soroban_cli::wasm;
use soroban_spec_tools::contract::Spec;
use soroban_test::TestEnv;
use std::collections::HashMap;
use stellar_xdr::curr::{ScMetaEntry, ScMetaV0};

#[test]
fn build_all() {
Expand Down Expand Up @@ -135,18 +139,55 @@ fn build_with_metadata() {
.assert()
.success();

// verify that the metadata added in the contract code via contractmetadata! macro is present
// as well as the meta that is included on build
let wasm_path = fixture_path.join(&outdir).join("add.wasm");
sandbox
.new_assert_cmd("contract")
.current_dir(&fixture_path)
.arg("info")
.arg("meta")
.arg("--wasm")
.arg(wasm_path)
.arg("build")
.arg("--meta")
.arg("meta_replaced=some_new_meta")
.arg("--out-dir")
.arg(&outdir)
.assert()
.success()
.stdout(predicate::str::contains("Description: A test add contract"))
.stdout(predicate::str::contains("contract meta: added on build"));
.success();

// verify that the metadata added in the contract code via contractmetadata! macro is present
// as well as the meta that is included on build
let wasm_path = fixture_path.join(&outdir).join("add.wasm");

let wasm_bytes = wasm::Args {
wasm: wasm_path.clone(),
}
.read()
.unwrap();
let spec = Spec::new(&wasm_bytes).unwrap();
let mut expected_entries = HashMap::new();

expected_entries.insert("Description".to_string(), None);
expected_entries.insert("rsver".to_string(), None);
expected_entries.insert("rssdkver".to_string(), None);
expected_entries.insert("meta_replaced".to_string(), Some("some_new_meta"));

for meta_entry in &spec.meta {
match meta_entry {
ScMetaEntry::ScMetaV0(ScMetaV0 { key, val }) => {
let key = key.to_string();
if let Some(entry) = expected_entries.remove(&key) {
if let Some(str) = entry {
assert_eq!(
str,
val.to_string(),
"Unexpected value ${val} for key ${key} (expecting ${str})"
);
}
} else {
panic!("Unexpected key {key}");
}
}
}
}

assert!(
expected_entries.is_empty(),
"Some entries were not found in the metadata: {expected_entries:?}",
);
}

0 comments on commit f8f12eb

Please sign in to comment.