diff --git a/.github/workflows/ic-ref.yml b/.github/workflows/ic-ref.yml index fa699f93..eb94f4ef 100644 --- a/.github/workflows/ic-ref.yml +++ b/.github/workflows/ic-ref.yml @@ -12,6 +12,7 @@ jobs: strategy: matrix: build: [linux-stable] + pocket-ic: ["replica", "pocketic"] include: - build: linux-stable ic-hs-ref: "3d71032e" @@ -28,7 +29,7 @@ jobs: - name: Install dfx uses: dfinity/setup-dfx@main with: - dfx-version: "0.22.0-beta.0" + dfx-version: "0.24.2" - name: Cargo cache uses: actions/cache@v4 @@ -53,11 +54,20 @@ jobs: - name: Run Integration Tests run: | set -ex - dfx start --background --clean + if [[ "${{ matrix.pocket-ic }}" == "replica" ]] + then + dfx start --background --clean + else + dfx start --background --clean --pocketic + fi sleep 1 - export IC_REF_PORT=$(dfx info replica-port) + export IC_REF_PORT=$(dfx info webserver-port) export IC_UNIVERSAL_CANISTER_PATH=$HOME/canister.wasm export IC_WALLET_CANISTER_PATH=$HOME/wallet.wasm + if [[ "${{ matrix.pocket-ic }}" == "pocketic" ]] + then + export POCKET_IC="http://localhost:${IC_REF_PORT}" + fi cargo test --all-features -- --ignored dfx stop env: @@ -79,11 +89,20 @@ jobs: # create key: pkcs11-tool -k --module $HSM_PKCS11_LIBRARY_PATH --login --slot-index $HSM_SLOT_INDEX -d $HSM_KEY_ID --key-type EC:prime256v1 --pin $HSM_PIN - dfx start --background --clean + if [[ "${{ matrix.pocket-ic }}" == "replica" ]] + then + dfx start --background --clean + else + dfx start --background --clean --pocketic + fi sleep 1 - export IC_REF_PORT=$(dfx info replica-port) + export IC_REF_PORT=$(dfx info webserver-port) export IC_UNIVERSAL_CANISTER_PATH=$HOME/canister.wasm export IC_WALLET_CANISTER_PATH=$HOME/wallet.wasm + if [[ "${{ matrix.pocket-ic }}" == "pocketic" ]] + then + export POCKET_IC="http://localhost:${IC_REF_PORT}" + fi cd ref-tests cargo test --all-features -- --ignored --nocapture --test-threads=1 dfx stop @@ -98,9 +117,18 @@ jobs: - name: Run Doc Tests run: | set -ex - dfx start --background --clean + if [[ "${{ matrix.pocket-ic }}" == "replica" ]] + then + dfx start --background --clean + else + dfx start --background --clean --pocketic + fi sleep 1 - export IC_REF_PORT=$(dfx info replica-port) + export IC_REF_PORT=$(dfx info webserver-port) + if [[ "${{ matrix.pocket-ic }}" == "pocketic" ]] + then + export POCKET_IC="http://localhost:${IC_REF_PORT}" + fi cargo test --all-features --doc -- --ignored dfx stop env: diff --git a/Cargo.lock b/Cargo.lock index 5bdda798..011cedf0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -225,6 +225,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.22.1" @@ -505,6 +511,22 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.13" @@ -523,6 +545,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" @@ -638,6 +669,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + [[package]] name = "ecdsa" version = "0.16.9" @@ -708,6 +745,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "erased-serde" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c138974f9d5e7fe373eb04df7cae98833802ae4b11c24ac7039a21d5af4b26c" +dependencies = [ + "serde", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -921,6 +967,9 @@ name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] [[package]] name = "hmac" @@ -1015,6 +1064,7 @@ dependencies = [ "hyper", "hyper-util", "rustls", + "rustls-native-certs", "rustls-pki-types", "tokio", "tokio-rustls", @@ -1064,7 +1114,7 @@ dependencies = [ "http", "http-body", "ic-certification", - "ic-transport-types", + "ic-transport-types 0.39.1", "ic-verify-bls-signature", "js-sys", "k256", @@ -1123,6 +1173,23 @@ dependencies = [ "thiserror", ] +[[package]] +name = "ic-transport-types" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875dc4704780383112e8e8b5063a1b98de114321d0c7d3e7f635dcf360a57fba" +dependencies = [ + "candid", + "hex", + "ic-certification", + "leb128", + "serde", + "serde_bytes", + "serde_repr", + "sha2 0.10.8", + "thiserror", +] + [[package]] name = "ic-transport-types" version = "0.39.1" @@ -1150,6 +1217,7 @@ dependencies = [ "futures-util", "ic-agent", "once_cell", + "pocket-ic", "rand", "semver", "serde", @@ -1217,6 +1285,7 @@ dependencies = [ "humantime", "ic-agent", "ic-utils", + "pocket-ic", "rand", "serde", "serde_json", @@ -1228,7 +1297,7 @@ name = "icx-cert" version = "0.39.1" dependencies = [ "anyhow", - "base64", + "base64 0.22.1", "clap", "hex", "ic-certification", @@ -1351,7 +1420,7 @@ version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" dependencies = [ - "regex-automata", + "regex-automata 0.4.7", ] [[package]] @@ -1440,6 +1509,15 @@ dependencies = [ "logos-codegen", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.7.4" @@ -1452,6 +1530,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minicov" version = "0.3.5" @@ -1590,6 +1678,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + [[package]] name = "overload" version = "0.1.1" @@ -1658,7 +1752,7 @@ version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" dependencies = [ - "base64", + "base64 0.22.1", "serde", ] @@ -1754,6 +1848,35 @@ dependencies = [ "spki", ] +[[package]] +name = "pocket-ic" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "124a2380ca6f557adf8b02517cbfd2f564113230e14cda6f6aadd3dfe156293c" +dependencies = [ + "base64 0.13.1", + "candid", + "hex", + "ic-certification", + "ic-transport-types 0.37.1", + "reqwest", + "schemars", + "serde", + "serde_bytes", + "serde_cbor", + "serde_json", + "sha2 0.10.8", + "slog", + "strum", + "strum_macros", + "thiserror", + "tokio", + "tracing", + "tracing-appender", + "tracing-subscriber", + "wslpath", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -1938,6 +2061,7 @@ dependencies = [ "ic-utils", "k256", "p256", + "pocket-ic", "rand", "serde", "serde_cbor", @@ -1953,10 +2077,19 @@ checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", - "regex-automata", + "regex-automata 0.4.7", "regex-syntax 0.8.4", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + [[package]] name = "regex-automata" version = "0.4.7" @@ -1982,15 +2115,16 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "reqwest" -version = "0.12.7" +version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ - "base64", + "base64 0.22.1", "bytes", "futures-channel", "futures-core", "futures-util", + "h2", "http", "http-body", "http-body-util", @@ -2001,11 +2135,13 @@ dependencies = [ "js-sys", "log", "mime", + "mime_guess", "once_cell", "percent-encoding", "pin-project-lite", "quinn", "rustls", + "rustls-native-certs", "rustls-pemfile", "rustls-pki-types", "serde", @@ -2014,6 +2150,7 @@ dependencies = [ "sync_wrapper", "tokio", "tokio-rustls", + "tokio-socks", "tokio-util", "tower-service", "url", @@ -2076,13 +2213,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcaf18a4f2be7326cd874a5fa579fae794320a0f388d365dca7e480e55f83f8a" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" dependencies = [ - "base64", + "base64 0.22.1", "rustls-pki-types", ] @@ -2124,6 +2274,39 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.76", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -2150,6 +2333,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.23" @@ -2195,6 +2401,17 @@ dependencies = [ "syn 2.0.76", ] +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "serde_json" version = "1.0.127" @@ -2321,6 +2538,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slog" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" +dependencies = [ + "erased-serde", +] + [[package]] name = "smallvec" version = "1.13.2" @@ -2402,6 +2628,9 @@ name = "strum" version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] [[package]] name = "strum_macros" @@ -2567,9 +2796,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.39.3" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", @@ -2605,6 +2834,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-socks" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f" +dependencies = [ + "either", + "futures-util", + "thiserror", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.11" @@ -2656,6 +2897,18 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" +dependencies = [ + "crossbeam-channel", + "thiserror", + "time", + "tracing-subscriber", +] + [[package]] name = "tracing-attributes" version = "0.1.27" @@ -2688,18 +2941,35 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", + "serde", + "serde_json", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", + "tracing-serde", ] [[package]] @@ -2720,6 +2990,12 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "unicase" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -3196,6 +3472,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wslpath" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04a2ecdf2cc4d33a6a93d71bcfbc00bb1f635cdb8029a2cc0709204a045ec7a3" + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index 0de99756..e2e9cffa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ futures-util = "0.3.21" hex = "0.4.3" k256 = "0.13.4" leb128 = "0.2.5" +pocket-ic = "6.0.0" p256 = "0.13.2" rand = "0.8.5" reqwest = { version = "0.12", default-features = false } diff --git a/ic-utils/Cargo.toml b/ic-utils/Cargo.toml index 4ae5f8f5..91f314af 100644 --- a/ic-utils/Cargo.toml +++ b/ic-utils/Cargo.toml @@ -33,6 +33,7 @@ once_cell = "1.10.0" [dev-dependencies] ed25519-consensus = { workspace = true } ic-agent = { workspace = true, default-features = true } +pocket-ic = { workspace = true } rand = { workspace = true } tokio = { workspace = true, features = ["full"] } diff --git a/ic-utils/src/canister.rs b/ic-utils/src/canister.rs index ed19dca2..e4f8bfd6 100644 --- a/ic-utils/src/canister.rs +++ b/ic-utils/src/canister.rs @@ -392,8 +392,18 @@ mod tests { use ic_agent::identity::BasicIdentity; use rand::thread_rng; - fn get_effective_canister_id() -> Principal { - Principal::from_text("rwlgt-iiaaa-aaaaa-aaaaa-cai").unwrap() + const POCKET_IC: &str = "POCKET_IC"; + + async fn get_effective_canister_id() -> Principal { + let default_effective_canister_id = + Principal::from_text("rwlgt-iiaaa-aaaaa-aaaaa-cai").unwrap(); + if let Ok(pocket_ic_url) = std::env::var(POCKET_IC) { + pocket_ic::nonblocking::get_default_effective_canister_id(pocket_ic_url) + .await + .unwrap_or(default_effective_canister_id) + } else { + default_effective_canister_id + } } #[ignore] @@ -423,7 +433,7 @@ mod tests { let (new_canister_id,) = management_canister .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .call_and_wait() .await .unwrap(); diff --git a/icx/Cargo.toml b/icx/Cargo.toml index db8f197f..13e813dd 100644 --- a/icx/Cargo.toml +++ b/icx/Cargo.toml @@ -28,6 +28,7 @@ hex = { workspace = true } humantime = "2.0.1" ic-agent = { workspace = true, default-features = true } ic-utils = { workspace = true } +pocket-ic = { workspace = true } rand = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } diff --git a/icx/src/main.rs b/icx/src/main.rs index d6ab7c3f..db1d1ba1 100644 --- a/icx/src/main.rs +++ b/icx/src/main.rs @@ -261,7 +261,7 @@ pub fn get_effective_canister_id( method_name: &str, arg_value: &[u8], canister_id: Principal, -) -> Result { +) -> Result> { if is_management_canister { let method_name = MgmtMethod::from_str(method_name).with_context(|| { format!("Attempted to call an unsupported management canister method: {method_name}") @@ -274,7 +274,7 @@ pub fn get_effective_canister_id( MgmtMethod::InstallCode => { let install_args = Decode!(arg_value, CanisterInstall) .context("Argument is not valid for CanisterInstall")?; - Ok(install_args.canister_id) + Ok(Some(install_args.canister_id)) } MgmtMethod::StartCanister | MgmtMethod::StopCanister @@ -297,9 +297,9 @@ pub fn get_effective_canister_id( } let in_args = Decode!(arg_value, In).context("Argument is not a valid Principal")?; - Ok(in_args.canister_id) + Ok(Some(in_args.canister_id)) } - MgmtMethod::ProvisionalCreateCanisterWithCycles => Ok(Principal::management_canister()), + MgmtMethod::ProvisionalCreateCanisterWithCycles => Ok(None), MgmtMethod::UpdateSettings => { #[derive(CandidType, Deserialize)] struct In { @@ -308,7 +308,7 @@ pub fn get_effective_canister_id( } let in_args = Decode!(arg_value, In).context("Argument is not valid for UpdateSettings")?; - Ok(in_args.canister_id) + Ok(Some(in_args.canister_id)) } MgmtMethod::InstallChunkedCode => { #[derive(CandidType, Deserialize)] @@ -317,7 +317,7 @@ pub fn get_effective_canister_id( } let in_args = Decode!(arg_value, In) .context("Argument is not valid for InstallChunkedCode")?; - Ok(in_args.target_canister) + Ok(Some(in_args.target_canister)) } MgmtMethod::BitcoinGetBalance | MgmtMethod::BitcoinGetUtxos @@ -331,7 +331,7 @@ pub fn get_effective_canister_id( } } } else { - Ok(canister_id) + Ok(Some(canister_id)) } } @@ -353,6 +353,11 @@ async fn main() -> Result<()> { .build() .context("Failed to build the Agent")?; + let default_effective_canister_id = + pocket_ic::nonblocking::get_default_effective_canister_id(opts.replica.clone()) + .await + .unwrap_or(Principal::management_canister()); + // You can handle information about subcommands by requesting their matches by name // (as below), requesting just the name used, or both at the same time match &opts.subcommand { @@ -375,7 +380,8 @@ async fn main() -> Result<()> { &arg, t.canister_id, ) - .context("Failed to get effective_canister_id for this call")?; + .context("Failed to get effective_canister_id for this call")? + .unwrap_or(default_effective_canister_id); if t.serialize { match &opts.subcommand { diff --git a/ref-tests/Cargo.toml b/ref-tests/Cargo.toml index 6a568013..07cc0629 100644 --- a/ref-tests/Cargo.toml +++ b/ref-tests/Cargo.toml @@ -14,6 +14,7 @@ ic-identity-hsm = { path = "../ic-identity-hsm" } ic-utils = { path = "../ic-utils", features = ["raw"] } k256 = { workspace = true } p256 = { workspace = true } +pocket-ic = { workspace = true } rand = { workspace = true } serde = { workspace = true, features = ["derive"] } sha2 = { workspace = true } diff --git a/ref-tests/src/utils.rs b/ref-tests/src/utils.rs index 186e7c29..254d4025 100644 --- a/ref-tests/src/utils.rs +++ b/ref-tests/src/utils.rs @@ -10,9 +10,18 @@ const HSM_PKCS11_LIBRARY_PATH: &str = "HSM_PKCS11_LIBRARY_PATH"; const HSM_SLOT_INDEX: &str = "HSM_SLOT_INDEX"; const HSM_KEY_ID: &str = "HSM_KEY_ID"; const HSM_PIN: &str = "HSM_PIN"; +const POCKET_IC: &str = "POCKET_IC"; -pub fn get_effective_canister_id() -> Principal { - Principal::from_text("rwlgt-iiaaa-aaaaa-aaaaa-cai").unwrap() +pub async fn get_effective_canister_id() -> Principal { + let default_effective_canister_id = + Principal::from_text("rwlgt-iiaaa-aaaaa-aaaaa-cai").unwrap(); + if let Ok(pocket_ic_url) = std::env::var(POCKET_IC) { + pocket_ic::nonblocking::get_default_effective_canister_id(pocket_ic_url) + .await + .unwrap_or(default_effective_canister_id) + } else { + default_effective_canister_id + } } pub fn create_identity() -> Result, String> { @@ -149,7 +158,7 @@ pub async fn create_universal_canister(agent: &Agent) -> Result 0_u64 && result.cycles < creation_fee, + result.cycles > 0_u64 && result.cycles < creation_fee + canister_initial_balance, "expected 0..{creation_fee}, got {}", result.cycles ); @@ -771,7 +775,7 @@ mod management_canister { let (canister_id_1,) = ic00 .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .call_and_wait() .await?; let result = ic00.canister_status(&canister_id_1).call_and_wait().await?; @@ -786,7 +790,7 @@ mod management_canister { let (canister_id_2,) = ic00 .create_canister() .as_provisional_create_with_amount(Some(amount)) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .call_and_wait() .await?; let result = ic00.canister_status(&canister_id_2).call_and_wait().await?; @@ -856,7 +860,7 @@ mod management_canister { let (canister_id,) = mgmt .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .call_and_wait() .await?; let (pt1,) = mgmt @@ -890,13 +894,25 @@ mod management_canister { #[ignore] #[test] fn subnet_metrics() { - with_universal_canister(|agent, _| async move { + with_agent(|agent| async move { + let ic00 = ManagementCanister::create(&agent); + + // create a canister on the root subnet + let registry_canister_id = Principal::from_text("rwlgt-iiaaa-aaaaa-aaaaa-cai").unwrap(); + let _ = ic00 + .create_canister() + .as_provisional_create_with_amount(None) + .with_effective_canister_id(registry_canister_id) + .call_and_wait() + .await?; + + // fetch root subnet metrics let metrics = agent .read_state_subnet_metrics(Principal::self_authenticating(agent.read_root_key())) .await?; assert!( metrics.num_canisters >= 1, - "expected universal canister in num_canisters" + "expected a canister on the root subnet" ); Ok(()) }) @@ -1028,7 +1044,7 @@ mod extras { let (canister_id,) = ic00 .create_canister() .as_provisional_create_with_amount(Some(20_000_000_000_000_u128)) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_compute_allocation(1_u64) .with_memory_allocation(1024 * 1024_u64) .with_freezing_threshold(1_000_000_u64) @@ -1064,7 +1080,7 @@ mod extras { let result = ic00 .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_memory_allocation(1u64 << 50) .call_and_wait() .await; @@ -1076,7 +1092,7 @@ mod extras { let (_,) = ic00 .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_memory_allocation(10 * 1024 * 1024u64) .call_and_wait() .await?; @@ -1096,8 +1112,8 @@ mod extras { let (_,) = ic00 .create_canister() - .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .as_provisional_create_with_amount(Some(1_000_000_000_000_000)) + .with_effective_canister_id(get_effective_canister_id().await) .with_compute_allocation(ca) .call_and_wait() .await?; @@ -1114,7 +1130,7 @@ mod extras { let result = ic00 .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_freezing_threshold(2u128.pow(70)) .call_and_wait() .await; @@ -1136,7 +1152,7 @@ mod extras { let (canister_id,) = ic00 .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_reserved_cycles_limit(2u128.pow(70)) .call_and_wait() .await @@ -1161,7 +1177,7 @@ mod extras { let (canister_id,) = ic00 .create_canister() .as_provisional_create_with_amount(Some(20_000_000_000_000_u128)) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_reserved_cycles_limit(2_500_800_000_000u128) .call_and_wait() .await?; @@ -1208,7 +1224,7 @@ mod extras { assert_eq!( ic00.create_canister() .as_provisional_create_with_specified_id(specified_id) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(specified_id) .call_and_wait() .await .unwrap() @@ -1220,7 +1236,7 @@ mod extras { let result = ic00 .create_canister() .as_provisional_create_with_specified_id(specified_id) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(specified_id) .call_and_wait() .await; @@ -1258,7 +1274,7 @@ mod extras { let (canister_id,) = ic00 .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_wasm_memory_limit(1_000_000_000) .call_and_wait() .await @@ -1283,7 +1299,7 @@ mod extras { let (canister_id,) = ic00 .create_canister() .as_provisional_create_with_amount(Some(20_000_000_000_000_u128)) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_wasm_memory_limit(1_000_000_000) .call_and_wait() .await?; @@ -1330,7 +1346,7 @@ mod extras { let (canister_id,) = ic00 .create_canister() .as_provisional_create_with_amount(None) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_log_visibility(LogVisibility::Public) .call_and_wait() .await @@ -1353,7 +1369,7 @@ mod extras { let (canister_id,) = ic00 .create_canister() .as_provisional_create_with_amount(Some(20_000_000_000_000_u128)) - .with_effective_canister_id(get_effective_canister_id()) + .with_effective_canister_id(get_effective_canister_id().await) .with_log_visibility(LogVisibility::Controllers) .call_and_wait() .await?; diff --git a/ref-tests/tests/integration.rs b/ref-tests/tests/integration.rs index 4288ff19..b026c206 100644 --- a/ref-tests/tests/integration.rs +++ b/ref-tests/tests/integration.rs @@ -236,11 +236,11 @@ fn wallet_canister_forward() { #[ignore] #[test] fn wallet_canister_create_and_install() { - with_wallet_canister(None, |agent, wallet_id| async move { + with_wallet_canister(Some(1_000_000_000_000_000), |agent, wallet_id| async move { let wallet = WalletCanister::create(&agent, wallet_id).await?; let create_result = wallet - .wallet_create_canister(100_000_000_000, None, None, None, None) + .wallet_create_canister(200_000_000_000_000, None, None, None, None) .await?; #[derive(CandidType)] @@ -460,7 +460,7 @@ fn wallet_create_wallet() { #[ignore] #[test] fn wallet_canister_funds() { - let provisional_amount = 1 << 40; + let provisional_amount = 1_000_000_000_000_000; with_wallet_canister(Some(provisional_amount), |agent, wallet_id| async move { let alice = WalletCanister::create(&agent, wallet_id).await?; let bob = WalletCanister::create(