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

Add test to reproduce #1694 #1727

Merged
merged 5 commits into from
Nov 25, 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
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);
}
Loading