From f8f12eb1816bfa173eec530dc9a27f66fd4f8872 Mon Sep 17 00:00:00 2001 From: Gleb Date: Wed, 6 Nov 2024 21:12:07 -0800 Subject: [PATCH] Add test to reproduce the bug --- Cargo.lock | 1 + cmd/crates/soroban-test/Cargo.toml | 1 + .../tests/fixtures/workspace/Cargo.lock | 89 ++++++++++++------- cmd/crates/soroban-test/tests/it/build.rs | 61 ++++++++++--- 4 files changed, 110 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d3cc0c78..cb4a0b3c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4915,6 +4915,7 @@ dependencies = [ "soroban-spec-tools", "stellar-rpc-client", "stellar-strkey 0.0.11", + "stellar-xdr 22.0.0-rc.1.1", "thiserror", "tokio", "toml 0.8.19", diff --git a/cmd/crates/soroban-test/Cargo.toml b/cmd/crates/soroban-test/Cargo.toml index d9eb31bdd..44fceeb87 100644 --- a/cmd/crates/soroban-test/Cargo.toml +++ b/cmd/crates/soroban-test/Cargo.toml @@ -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 } diff --git a/cmd/crates/soroban-test/tests/fixtures/workspace/Cargo.lock b/cmd/crates/soroban-test/tests/fixtures/workspace/Cargo.lock index cc4bfbb58..ec70d9ccb 100644 --- a/cmd/crates/soroban-test/tests/fixtures/workspace/Cargo.lock +++ b/cmd/crates/soroban-test/tests/fixtures/workspace/Cargo.lock @@ -355,7 +355,6 @@ dependencies = [ "elliptic-curve", "rfc6979", "signature", - "spki", ] [[package]] @@ -370,15 +369,16 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", "rand_core", "serde", "sha2", + "subtle", "zeroize", ] @@ -400,7 +400,6 @@ dependencies = [ "ff", "generic-array", "group", - "pkcs8", "rand_core", "sec1", "subtle", @@ -614,9 +613,7 @@ dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", - "once_cell", "sha2", - "signature", ] [[package]] @@ -717,6 +714,18 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2", +] + [[package]] name = "paste" version = "1.0.14" @@ -761,6 +770,15 @@ dependencies = [ "syn", ] +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro2" version = "1.0.69" @@ -849,7 +867,6 @@ dependencies = [ "base16ct", "der", "generic-array", - "pkcs8", "subtle", "zeroize", ] @@ -959,9 +976,9 @@ checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "soroban-builtin-sdk-macros" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc32c6e817f3ca269764ec0d7d14da6210b74a5bf14d4e745aa3ee860558900" +checksum = "2f57a68ef8777e28e274de0f3a88ad9a5a41d9a2eb461b4dd800b086f0e83b80" dependencies = [ "itertools", "proc-macro2", @@ -971,9 +988,9 @@ dependencies = [ [[package]] name = "soroban-env-common" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c14e18d879c520ff82612eaae0590acaf6a7f3b977407e1abb1c9e31f94c7814" +checksum = "2fd1c89463835fe6da996318156d39f424b4f167c725ec692e5a7a2d4e694b3d" dependencies = [ "arbitrary", "crate-git-revision", @@ -985,13 +1002,14 @@ dependencies = [ "soroban-wasmi", "static_assertions", "stellar-xdr", + "wasmparser", ] [[package]] name = "soroban-env-guest" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5122ca2abd5ebcc1e876a96b9b44f87ce0a0e06df8f7c09772ddb58b159b7454" +checksum = "6bfb2536811045d5cd0c656a324cbe9ce4467eb734c7946b74410d90dea5d0ce" dependencies = [ "soroban-env-common", "static_assertions", @@ -999,13 +1017,16 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "114a0fa0d0cc39d0be16b1ee35b6e5f4ee0592ddcf459bde69391c02b03cf520" +checksum = "2b7a32c28f281c423189f1298960194f0e0fc4eeb72378028171e556d8cd6160" dependencies = [ "backtrace", "curve25519-dalek", + "ecdsa", "ed25519-dalek", + "elliptic-curve", + "generic-array", "getrandom", "hex-literal", "hmac", @@ -1013,8 +1034,10 @@ dependencies = [ "num-derive", "num-integer", "num-traits", + "p256", "rand", "rand_chacha", + "sec1", "sha2", "sha3", "soroban-builtin-sdk-macros", @@ -1022,13 +1045,14 @@ dependencies = [ "soroban-wasmi", "static_assertions", "stellar-strkey", + "wasmparser", ] [[package]] name = "soroban-env-macros" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b13e3f8c86f812e0669e78fcb3eae40c385c6a9dd1a4886a1de733230b4fcf27" +checksum = "242926fe5e0d922f12d3796cd7cd02dd824e5ef1caa088f45fce20b618309f64" dependencies = [ "itertools", "proc-macro2", @@ -1041,9 +1065,9 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "20.5.0" +version = "21.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a54708f44890e0546180db6b4f530e2a88d83b05a9b38a131caa21d005e25a" +checksum = "43793d5deb5fc27c3e14e036e24cb3afcf7d1e2a172d9166e37f3d174b928749" dependencies = [ "serde", "serde_json", @@ -1055,9 +1079,9 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "20.5.0" +version = "21.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84fc8be9068dd4e0212d8b13ad61089ea87e69ac212c262914503a961c8dc3a3" +checksum = "69e39bf9e8ab05579c836e8e5be5f2f4c5ba75e7337ece20e975e82fc3a9d41e" dependencies = [ "arbitrary", "bytes-lit", @@ -1075,9 +1099,9 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "20.5.0" +version = "21.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db20def4ead836663633f58d817d0ed8e1af052c9650a04adf730525af85b964" +checksum = "a9ad528a770ec7adb524635d855b424ae2fd4fef04fb702bb0ab466a4c354d78" dependencies = [ "crate-git-revision", "darling", @@ -1095,9 +1119,9 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "20.5.0" +version = "21.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eefeb5d373b43f6828145d00f0c5cc35e96db56a6671ae9614f84beb2711cab" +checksum = "5b262c82d840552f71ee9254f2e928622fd803bd4df4815e65f73f73efc2fa9c" dependencies = [ "base64 0.13.1", "stellar-xdr", @@ -1107,9 +1131,9 @@ dependencies = [ [[package]] name = "soroban-spec-rust" -version = "20.5.0" +version = "21.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3152bca4737ef734ac37fe47b225ee58765c9095970c481a18516a2b287c7a33" +checksum = "85a061820c2dd0bd3ece9411e0dd3aeb6ed9ca2b7d64270eda9e798c3b6dec5f" dependencies = [ "prettyplease", "proc-macro2", @@ -1169,9 +1193,9 @@ dependencies = [ [[package]] name = "stellar-xdr" -version = "20.1.0" +version = "21.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e59cdf3eb4467fb5a4b00b52e7de6dca72f67fac6f9b700f55c95a5d86f09c9d" +checksum = "2675a71212ed39a806e415b0dbf4702879ff288ec7f5ee996dda42a135512b50" dependencies = [ "arbitrary", "base64 0.13.1", @@ -1353,11 +1377,12 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.88.0" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8cf7dd82407fe68161bedcd57fde15596f32ebf6e9b3bdbf3ae1da20e38e5e" +checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50" dependencies = [ - "indexmap 1.9.3", + "indexmap 2.1.0", + "semver", ] [[package]] diff --git a/cmd/crates/soroban-test/tests/it/build.rs b/cmd/crates/soroban-test/tests/it/build.rs index 925d88df1..2a6d3d467 100644 --- a/cmd/crates/soroban-test/tests/it/build.rs +++ b/cmd/crates/soroban-test/tests/it/build.rs @@ -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() { @@ -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:?}", + ); }