diff --git a/.github/workflows/motoko-canister-logs-example.yml b/.github/workflows/motoko-canister-logs-example.yml index 08fdf554f..dd657e4c8 100644 --- a/.github/workflows/motoko-canister-logs-example.yml +++ b/.github/workflows/motoko-canister-logs-example.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Provision Darwin - run: bash .github/workflows/provision-darwin.sh + run: DFX_VERSION="0.21.0-beta.0" bash .github/workflows/provision-darwin.sh - name: Motoko Canister Logs Darwin run: | dfx start --background @@ -31,7 +31,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Provision Linux - run: bash .github/workflows/provision-linux.sh + run: DFX_VERSION="0.21.0-beta.0" bash .github/workflows/provision-linux.sh - name: Motoko Canister Logs Linux run: | dfx start --background diff --git a/.github/workflows/rust-canister-logs-example.yml b/.github/workflows/rust-canister-logs-example.yml index f274fa5fe..41f502a56 100644 --- a/.github/workflows/rust-canister-logs-example.yml +++ b/.github/workflows/rust-canister-logs-example.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Provision Darwin - run: bash .github/workflows/provision-darwin.sh + run: DFX_VERSION="0.21.0-beta.0" bash .github/workflows/provision-darwin.sh - name: Rust Canister Logs Darwin run: | dfx start --background @@ -31,7 +31,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Provision Linux - run: bash .github/workflows/provision-linux.sh + run: DFX_VERSION="0.21.0-beta.0" bash .github/workflows/provision-linux.sh - name: Rust Canister Logs Linux run: | dfx start --background diff --git a/motoko/canister_logs/Makefile b/motoko/canister_logs/Makefile index 25ad614a0..b499582fb 100644 --- a/motoko/canister_logs/Makefile +++ b/motoko/canister_logs/Makefile @@ -66,6 +66,11 @@ test: install dfx canister logs CanisterLogs \ | grep 'timer trap' && echo 'PASS' + # Test raw_rand. + dfx canister call CanisterLogs raw_rand + dfx canister logs CanisterLogs \ + | grep 'ic.raw_rand() call succeeded' && echo 'PASS' + .PHONY: clean .SILENT: clean clean: diff --git a/motoko/canister_logs/src/Main.mo b/motoko/canister_logs/src/Main.mo index 11961646a..9ec2aef07 100644 --- a/motoko/canister_logs/src/Main.mo +++ b/motoko/canister_logs/src/Main.mo @@ -8,6 +8,7 @@ actor CanisterLogs { let timerDelaySeconds = 5; let second = 1_000_000_000; + let ic00_raw_rand = (actor "aaaaa-aa" : actor { raw_rand : () -> async Blob }).raw_rand; private func execute_timer() : async () { Debug.print("right before timer trap"); @@ -45,4 +46,11 @@ actor CanisterLogs { let _blob = StableMemory.loadBlob(offset, value); // Expect reading outside of memory bounds to trap. }; + public func raw_rand() : async Blob { + Debug.print("pre ic.raw_rand() call"); + let bytes = await ic00_raw_rand(); + Debug.print("ic.raw_rand() call succeeded"); + bytes; + }; + }; diff --git a/rust/canister_logs/Makefile b/rust/canister_logs/Makefile index 74a1fb96b..8076bdd18 100644 --- a/rust/canister_logs/Makefile +++ b/rust/canister_logs/Makefile @@ -78,6 +78,11 @@ test: install dfx canister logs canister_logs \ | grep 'timer trap' && echo 'PASS' + # Test raw_rand. + dfx canister call canister_logs raw_rand + dfx canister logs canister_logs \ + | grep 'ic.raw_rand() call succeeded' && echo 'PASS' + .PHONY: clean .SILENT: clean clean: diff --git a/rust/canister_logs/canister_logs.did b/rust/canister_logs/canister_logs.did index 7f24793a6..167e4e747 100644 --- a/rust/canister_logs/canister_logs.did +++ b/rust/canister_logs/canister_logs.did @@ -6,4 +6,5 @@ service : { "panic" : (text) -> (); "memory_oob" : () -> (); "failed_unwrap" : () -> (); + "raw_rand" : () -> (blob); }; diff --git a/rust/canister_logs/src/lib.rs b/rust/canister_logs/src/lib.rs index d680cd1be..c2e04d957 100644 --- a/rust/canister_logs/src/lib.rs +++ b/rust/canister_logs/src/lib.rs @@ -1,4 +1,6 @@ -use ic_cdk::{init, post_upgrade, query, update}; +use ic_cdk::{ + api::management_canister::main::raw_rand as ic00_raw_rand, init, post_upgrade, query, update, +}; use std::time::Duration; const TIMER_INTERVAL_SEC: u64 = 5; @@ -61,3 +63,18 @@ fn failed_unwrap() { ic_cdk::print("right before failed unwrap"); String::from_utf8(vec![0xc0, 0xff, 0xee]).unwrap(); // Invalid utf8 should panic. } + +#[update] +async fn raw_rand() -> Vec { + ic_cdk::println!("pre ic.raw_rand() call"); + match ic00_raw_rand().await { + Ok((bytes,)) => { + ic_cdk::println!("ic.raw_rand() call succeeded"); + bytes + } + Err(err) => { + ic_cdk::println!("ic.raw_rand() call failed: {:?}", err); + vec![] + } + } +}