Skip to content

Commit

Permalink
Add test to reproduce #1694 (#1727)
Browse files Browse the repository at this point in the history
Co-authored-by: Leigh McCulloch <[email protected]>
  • Loading branch information
Ifropc and leighmcculloch authored Nov 25, 2024
1 parent 506cf2e commit a0d3fa4
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 42 deletions.
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.

55 changes: 45 additions & 10 deletions cmd/crates/soroban-test/tests/it/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use predicates::prelude::predicate;
use soroban_cli::xdr::{Limited, Limits, ReadXdr, ScMetaEntry, ScMetaV0};
use soroban_spec_tools::contract::Spec;
use soroban_test::TestEnv;
use std::io::Cursor;

#[test]
fn build_all() {
Expand Down Expand Up @@ -135,18 +138,50 @@ 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 = std::fs::read(wasm_path).unwrap();
let spec = Spec::new(&wasm).unwrap();
let meta = spec.meta_base64.unwrap();
let entries = ScMetaEntry::read_xdr_base64_iter(&mut Limited::new(
Cursor::new(meta.as_bytes()),
Limits::none(),
))
.filter(|entry| match entry {
// Ignore the meta entries that the SDK embeds that capture the SDK and
// Rust version, since these will change often and are not really
// relevant to this test.
Ok(ScMetaEntry::ScMetaV0(ScMetaV0 { key, .. })) => {
let key = key.to_string();
!matches!(key.as_str(), "rsver" | "rssdkver")
}
_ => true,
})
.collect::<Result<Vec<_>, _>>()
.unwrap();

let expected_entries = vec![
ScMetaEntry::ScMetaV0(ScMetaV0 {
key: "Description".try_into().unwrap(),
val: "A test add contract".try_into().unwrap(),
}),
ScMetaEntry::ScMetaV0(ScMetaV0 {
key: "meta_replaced".try_into().unwrap(),
val: "some_new_meta".try_into().unwrap(),
}),
];

assert_eq!(entries, expected_entries);
}

0 comments on commit a0d3fa4

Please sign in to comment.