Skip to content

Commit decfb65

Browse files
authored
chore: add inter-canister call use case to canister logging examples (#906)
1 parent 3a1efa7 commit decfb65

File tree

7 files changed

+41
-5
lines changed

7 files changed

+41
-5
lines changed

.github/workflows/motoko-canister-logs-example.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v1
2121
- name: Provision Darwin
22-
run: bash .github/workflows/provision-darwin.sh
22+
run: DFX_VERSION="0.21.0-beta.0" bash .github/workflows/provision-darwin.sh
2323
- name: Motoko Canister Logs Darwin
2424
run: |
2525
dfx start --background
@@ -31,7 +31,7 @@ jobs:
3131
steps:
3232
- uses: actions/checkout@v1
3333
- name: Provision Linux
34-
run: bash .github/workflows/provision-linux.sh
34+
run: DFX_VERSION="0.21.0-beta.0" bash .github/workflows/provision-linux.sh
3535
- name: Motoko Canister Logs Linux
3636
run: |
3737
dfx start --background

.github/workflows/rust-canister-logs-example.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v1
2121
- name: Provision Darwin
22-
run: bash .github/workflows/provision-darwin.sh
22+
run: DFX_VERSION="0.21.0-beta.0" bash .github/workflows/provision-darwin.sh
2323
- name: Rust Canister Logs Darwin
2424
run: |
2525
dfx start --background
@@ -31,7 +31,7 @@ jobs:
3131
steps:
3232
- uses: actions/checkout@v1
3333
- name: Provision Linux
34-
run: bash .github/workflows/provision-linux.sh
34+
run: DFX_VERSION="0.21.0-beta.0" bash .github/workflows/provision-linux.sh
3535
- name: Rust Canister Logs Linux
3636
run: |
3737
dfx start --background

motoko/canister_logs/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ test: install
6666
dfx canister logs CanisterLogs \
6767
| grep 'timer trap' && echo 'PASS'
6868

69+
# Test raw_rand.
70+
dfx canister call CanisterLogs raw_rand
71+
dfx canister logs CanisterLogs \
72+
| grep 'ic.raw_rand() call succeeded' && echo 'PASS'
73+
6974
.PHONY: clean
7075
.SILENT: clean
7176
clean:

motoko/canister_logs/src/Main.mo

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ actor CanisterLogs {
88

99
let timerDelaySeconds = 5;
1010
let second = 1_000_000_000;
11+
let ic00_raw_rand = (actor "aaaaa-aa" : actor { raw_rand : () -> async Blob }).raw_rand;
1112

1213
private func execute_timer() : async () {
1314
Debug.print("right before timer trap");
@@ -45,4 +46,11 @@ actor CanisterLogs {
4546
let _blob = StableMemory.loadBlob(offset, value); // Expect reading outside of memory bounds to trap.
4647
};
4748

49+
public func raw_rand() : async Blob {
50+
Debug.print("pre ic.raw_rand() call");
51+
let bytes = await ic00_raw_rand();
52+
Debug.print("ic.raw_rand() call succeeded");
53+
bytes;
54+
};
55+
4856
};

rust/canister_logs/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ test: install
7878
dfx canister logs canister_logs \
7979
| grep 'timer trap' && echo 'PASS'
8080

81+
# Test raw_rand.
82+
dfx canister call canister_logs raw_rand
83+
dfx canister logs canister_logs \
84+
| grep 'ic.raw_rand() call succeeded' && echo 'PASS'
85+
8186
.PHONY: clean
8287
.SILENT: clean
8388
clean:

rust/canister_logs/canister_logs.did

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ service : {
66
"panic" : (text) -> ();
77
"memory_oob" : () -> ();
88
"failed_unwrap" : () -> ();
9+
"raw_rand" : () -> (blob);
910
};

rust/canister_logs/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use ic_cdk::{init, post_upgrade, query, update};
1+
use ic_cdk::{
2+
api::management_canister::main::raw_rand as ic00_raw_rand, init, post_upgrade, query, update,
3+
};
24
use std::time::Duration;
35

46
const TIMER_INTERVAL_SEC: u64 = 5;
@@ -61,3 +63,18 @@ fn failed_unwrap() {
6163
ic_cdk::print("right before failed unwrap");
6264
String::from_utf8(vec![0xc0, 0xff, 0xee]).unwrap(); // Invalid utf8 should panic.
6365
}
66+
67+
#[update]
68+
async fn raw_rand() -> Vec<u8> {
69+
ic_cdk::println!("pre ic.raw_rand() call");
70+
match ic00_raw_rand().await {
71+
Ok((bytes,)) => {
72+
ic_cdk::println!("ic.raw_rand() call succeeded");
73+
bytes
74+
}
75+
Err(err) => {
76+
ic_cdk::println!("ic.raw_rand() call failed: {:?}", err);
77+
vec![]
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)