|
1 | 1 | use predicates::prelude::predicate;
|
| 2 | +use soroban_cli::xdr::{Limited, Limits, ReadXdr, ScMetaEntry, ScMetaV0}; |
| 3 | +use soroban_spec_tools::contract::Spec; |
2 | 4 | use soroban_test::TestEnv;
|
| 5 | +use std::io::Cursor; |
3 | 6 |
|
4 | 7 | #[test]
|
5 | 8 | fn build_all() {
|
@@ -135,18 +138,50 @@ fn build_with_metadata() {
|
135 | 138 | .assert()
|
136 | 139 | .success();
|
137 | 140 |
|
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"); |
141 | 141 | sandbox
|
142 | 142 | .new_assert_cmd("contract")
|
143 | 143 | .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) |
148 | 149 | .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); |
152 | 187 | }
|
0 commit comments