Skip to content

Commit a0d3fa4

Browse files
Add test to reproduce #1694 (#1727)
Co-authored-by: Leigh McCulloch <[email protected]>
1 parent 506cf2e commit a0d3fa4

File tree

2 files changed

+102
-42
lines changed

2 files changed

+102
-42
lines changed

cmd/crates/soroban-test/tests/fixtures/workspace/Cargo.lock

+57-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/crates/soroban-test/tests/it/build.rs

+45-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use predicates::prelude::predicate;
2+
use soroban_cli::xdr::{Limited, Limits, ReadXdr, ScMetaEntry, ScMetaV0};
3+
use soroban_spec_tools::contract::Spec;
24
use soroban_test::TestEnv;
5+
use std::io::Cursor;
36

47
#[test]
58
fn build_all() {
@@ -135,18 +138,50 @@ fn build_with_metadata() {
135138
.assert()
136139
.success();
137140

138-
// verify that the metadata added in the contract code via contractmetadata! macro is present
139-
// as well as the meta that is included on build
140-
let wasm_path = fixture_path.join(&outdir).join("add.wasm");
141141
sandbox
142142
.new_assert_cmd("contract")
143143
.current_dir(&fixture_path)
144-
.arg("info")
145-
.arg("meta")
146-
.arg("--wasm")
147-
.arg(wasm_path)
144+
.arg("build")
145+
.arg("--meta")
146+
.arg("meta_replaced=some_new_meta")
147+
.arg("--out-dir")
148+
.arg(&outdir)
148149
.assert()
149-
.success()
150-
.stdout(predicate::str::contains("Description: A test add contract"))
151-
.stdout(predicate::str::contains("contract meta: added on build"));
150+
.success();
151+
152+
// verify that the metadata added in the contract code via contractmetadata! macro is present
153+
// as well as the meta that is included on build
154+
let wasm_path = fixture_path.join(&outdir).join("add.wasm");
155+
let wasm = std::fs::read(wasm_path).unwrap();
156+
let spec = Spec::new(&wasm).unwrap();
157+
let meta = spec.meta_base64.unwrap();
158+
let entries = ScMetaEntry::read_xdr_base64_iter(&mut Limited::new(
159+
Cursor::new(meta.as_bytes()),
160+
Limits::none(),
161+
))
162+
.filter(|entry| match entry {
163+
// Ignore the meta entries that the SDK embeds that capture the SDK and
164+
// Rust version, since these will change often and are not really
165+
// relevant to this test.
166+
Ok(ScMetaEntry::ScMetaV0(ScMetaV0 { key, .. })) => {
167+
let key = key.to_string();
168+
!matches!(key.as_str(), "rsver" | "rssdkver")
169+
}
170+
_ => true,
171+
})
172+
.collect::<Result<Vec<_>, _>>()
173+
.unwrap();
174+
175+
let expected_entries = vec![
176+
ScMetaEntry::ScMetaV0(ScMetaV0 {
177+
key: "Description".try_into().unwrap(),
178+
val: "A test add contract".try_into().unwrap(),
179+
}),
180+
ScMetaEntry::ScMetaV0(ScMetaV0 {
181+
key: "meta_replaced".try_into().unwrap(),
182+
val: "some_new_meta".try_into().unwrap(),
183+
}),
184+
];
185+
186+
assert_eq!(entries, expected_entries);
152187
}

0 commit comments

Comments
 (0)