Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: next generation of Rust CDK #521

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ path = "canisters/management_caller.rs"
name = "chunk"
path = "canisters/chunk.rs"

[[bin]]
name = "call_struct"
path = "canisters/call_struct.rs"

[dev-dependencies]
hex.workspace = true
pocket-ic = "4"
17 changes: 17 additions & 0 deletions e2e-tests/canisters/call_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use candid::Principal;
use ic_cdk::api::management_canister::main::{CanisterIdRecord, CreateCanisterArgument};
use ic_cdk::prelude::*;

#[update]
async fn create_canister_via_struct() -> Principal {
let res: (CanisterIdRecord,) = Call::new(Principal::management_canister(), "create_canister")
.with_args((CreateCanisterArgument::default(),))
.with_cycles(200_000_000_000)
.with_guaranteed_response()
.call()
.await
.unwrap();
res.0.canister_id
}

fn main() {}
11 changes: 11 additions & 0 deletions e2e-tests/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,14 @@ fn test_chunk() {
)
.expect("Error calling call_install_chunked_code");
}

#[test]
fn call_struct() {
let pic = PocketIc::new();
let wasm = cargo_build_canister("call_struct");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 100_000_000_000_000);
pic.install_canister(canister_id, wasm, vec![], None);
let _: (Principal,) = call_candid(&pic, canister_id, "create_canister_via_struct", ())
.expect("Error calling execute_main_methods");
}
1 change: 1 addition & 0 deletions examples/counter/tests/basic.bats
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load ../../bats/bats-support/load.bash
load ../../bats/bats-assert/load.bash

# Executed before each test.
Expand Down
1 change: 1 addition & 0 deletions examples/profile/tests/basic.bats
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load ../../bats/bats-support/load.bash
load ../../bats/bats-assert/load.bash

# Executed before each test.
Expand Down
126 changes: 55 additions & 71 deletions ic0.txt
Original file line number Diff line number Diff line change
@@ -1,71 +1,55 @@
ic0.msg_arg_data_size : () -> i32; // I U Q CQ Ry CRy F
ic0.msg_arg_data_copy : (dst : i32, offset : i32, size : i32) -> (); // I U Q CQ Ry CRy F
ic0.msg_caller_size : () -> i32; // *
ic0.msg_caller_copy : (dst : i32, offset: i32, size : i32) -> (); // *
ic0.msg_reject_code : () -> i32; // Ry Rt CRy CRt
ic0.msg_reject_msg_size : () -> i32; // Rt CRt
ic0.msg_reject_msg_copy : (dst : i32, offset : i32, size : i32) -> (); // Rt CRt

ic0.msg_reply_data_append : (src : i32, size : i32) -> (); // U Q CQ Ry Rt CRy CRt
ic0.msg_reply : () -> (); // U Q CQ Ry Rt CRy CRt
ic0.msg_reject : (src : i32, size : i32) -> (); // U Q CQ Ry Rt CRy CRt

ic0.msg_cycles_available : () -> i64; // U Rt Ry
ic0.msg_cycles_available128 : (dst : i32) -> (); // U Rt Ry
ic0.msg_cycles_refunded : () -> i64; // Rt Ry
ic0.msg_cycles_refunded128 : (dst : i32) -> (); // Rt Ry
ic0.msg_cycles_accept : (max_amount : i64) -> (amount : i64); // U Rt Ry
ic0.msg_cycles_accept128 : (max_amount_high : i64, max_amount_low: i64, dst : i32)
-> (); // U Rt Ry

ic0.cycles_burn128 : (amount_high : i64, amount_low : i64, dst : i32) -> (); // I G U Ry Rt C T

ic0.canister_self_size : () -> i32; // *
ic0.canister_self_copy : (dst : i32, offset : i32, size : i32) -> (); // *
ic0.canister_cycle_balance : () -> i64; // *
ic0.canister_cycle_balance128 : (dst : i32) -> (); // *
ic0.canister_status : () -> i32; // *
ic0.canister_version : () -> i64; // *

ic0.msg_method_name_size : () -> i32; // F
ic0.msg_method_name_copy : (dst : i32, offset : i32, size : i32) -> (); // F
ic0.accept_message : () -> (); // F

ic0.call_new : // U CQ Ry Rt CRy CRt T
( callee_src : i32,
callee_size : i32,
name_src : i32,
name_size : i32,
reply_fun : i32,
reply_env : i32,
reject_fun : i32,
reject_env : i32
) -> ();
ic0.call_on_cleanup : (fun : i32, env : i32) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_data_append : (src : i32, size : i32) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_cycles_add : (amount : i64) -> (); // U Ry Rt T
ic0.call_cycles_add128 : (amount_high : i64, amount_low: i64) -> (); // U Ry Rt T
ic0.call_perform : () -> ( err_code : i32 ); // U CQ Ry Rt CRy CRt T

ic0.stable_size : () -> (page_count : i32); // * s
ic0.stable_grow : (new_pages : i32) -> (old_page_count : i32); // * s
ic0.stable_write : (offset : i32, src : i32, size : i32) -> (); // * s
ic0.stable_read : (dst : i32, offset : i32, size : i32) -> (); // * s
ic0.stable64_size : () -> (page_count : i64); // * s
ic0.stable64_grow : (new_pages : i64) -> (old_page_count : i64); // * s
ic0.stable64_write : (offset : i64, src : i64, size : i64) -> (); // * s
ic0.stable64_read : (dst : i64, offset : i64, size : i64) -> (); // * s

ic0.certified_data_set : (src: i32, size: i32) -> (); // I G U Ry Rt T
ic0.data_certificate_present : () -> i32; // *
ic0.data_certificate_size : () -> i32; // Q CQ
ic0.data_certificate_copy : (dst: i32, offset: i32, size: i32) -> (); // Q CQ

ic0.time : () -> (timestamp : i64); // *
ic0.global_timer_set : (timestamp : i64) -> i64; // I G U Ry Rt C T
ic0.performance_counter : (counter_type : i32) -> (counter : i64); // * s
ic0.is_controller: (src: i32, size: i32) -> ( result: i32); // * s
ic0.in_replicated_execution: () -> (result: i32); // * s

ic0.debug_print : (src : i32, size : i32) -> (); // * s
ic0.trap : (src : i32, size : i32) -> (); // * s
ic0.msg_arg_data_size : () -> I; // I U RQ NRQ CQ Ry CRy F
ic0.msg_arg_data_copy : (dst : I, offset : I, size : I) -> (); // I U RQ NRQ CQ Ry CRy F
ic0.msg_caller_size : () -> I; // *
ic0.msg_caller_copy : (dst : I, offset : I, size : I) -> (); // *
ic0.msg_reject_code : () -> i32; // Ry Rt CRy CRt
ic0.msg_reject_msg_size : () -> I ; // Rt CRt
ic0.msg_reject_msg_copy : (dst : I, offset : I, size : I) -> (); // Rt CRt
ic0.msg_deadline : () -> i64; // U Q CQ Ry Rt CRy CRt
ic0.msg_reply_data_append : (src : I, size : I) -> (); // U RQ NRQ CQ Ry Rt CRy CRt
ic0.msg_reply : () -> (); // U RQ NRQ CQ Ry Rt CRy CRt
ic0.msg_reject : (src : I, size : I) -> (); // U RQ NRQ CQ Ry Rt CRy CRt
ic0.msg_cycles_available128 : (dst : I) -> (); // U Rt Ry
ic0.msg_cycles_refunded128 : (dst : I) -> (); // Rt Ry
ic0.msg_cycles_accept128 : (max_amount_high : i64, max_amount_low: i64, dst : I)
-> (); // U Rt Ry
ic0.cycles_burn128 : (amount_high : i64, amount_low : i64, dst : I)
-> (); // I G U Ry Rt C T
ic0.canister_self_size : () -> I; // *
ic0.canister_self_copy : (dst : I, offset : I, size : I) -> (); // *
ic0.canister_cycle_balance128 : (dst : I) -> (); // *
ic0.canister_status : () -> i32; // *
ic0.canister_version : () -> i64; // *
ic0.msg_method_name_size : () -> I; // F
ic0.msg_method_name_copy : (dst : I, offset : I, size : I) -> (); // F
ic0.accept_message : () -> (); // F
ic0.call_new :
( callee_src : I,
callee_size : I,
name_src : I,
name_size : I,
reply_fun : I,
reply_env : I,
reject_fun : I,
reject_env : I
) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_on_cleanup : (fun : I, env : I) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_data_append : (src : I, size : I) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_with_best_effort_response : (timeout_seconds : i32) -> (); // U CQ Ry Rt CRy CRt T
ic0.call_cycles_add128 : (amount_high : i64, amount_low: i64) -> (); // U Ry Rt T
ic0.call_perform : () -> ( err_code : i32 ); // U CQ Ry Rt CRy CRt T
ic0.stable64_size : () -> (page_count : i64); // * s
ic0.stable64_grow : (new_pages : i64) -> (old_page_count : i64); // * s
ic0.stable64_write : (offset : i64, src : i64, size : i64) -> (); // * s
ic0.stable64_read : (dst : i64, offset : i64, size : i64) -> (); // * s
ic0.certified_data_set : (src : I, size : I) -> (); // I G U Ry Rt T
ic0.data_certificate_present : () -> i32; // *
ic0.data_certificate_size : () -> I; // NRQ CQ
ic0.data_certificate_copy : (dst : I, offset : I, size : I) -> (); // NRQ CQ
ic0.time : () -> (timestamp : i64); // *
ic0.global_timer_set : (timestamp : i64) -> i64; // I G U Ry Rt C T
ic0.performance_counter : (counter_type : i32) -> (counter : i64); // * s
ic0.is_controller: (src : I, size : I) -> ( result: i32); // * s
ic0.in_replicated_execution: () -> (result: i32); // * s
ic0.debug_print : (src : I, size : I) -> (); // * s
ic0.trap : (src : I, size : I) -> (); // * s
2 changes: 2 additions & 0 deletions src/candid-extractor/ic_mock.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(func (export "msg_reject_code") (result i32) i32.const 0)
(func (export "msg_reject_msg_size") (result i32) i32.const 0)
(func (export "msg_reject_msg_copy") (param i32 i32 i32) )
(func (export "msg_deadline") (result i64) i64.const 0)
(func (export "msg_reply_data_append") (param i32 i32) )
(func (export "msg_reply") )
(func (export "msg_reject") (param i32 i32) )
Expand All @@ -30,6 +31,7 @@
(func (export "call_new") (param i32 i32 i32 i32 i32 i32 i32 i32) )
(func (export "call_on_cleanup") (param i32 i32) )
(func (export "call_data_append") (param i32 i32) )
(func (export "call_with_best_effort_response") (param i32) )
(func (export "call_cycles_add") (param i64) )
(func (export "call_cycles_add128") (param i64 i64) )
(func (export "call_perform") (result i32) i32.const 0)
Expand Down
3 changes: 2 additions & 1 deletion src/ic-cdk-timers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ extern "C" fn global_timer() {
| RejectionCode::DestinationInvalid
| RejectionCode::CanisterReject
| RejectionCode::CanisterError
| RejectionCode::SysUnknown
| RejectionCode::Unknown => {}
}
}
Expand Down Expand Up @@ -254,7 +255,7 @@ fn update_ic0_timer() {
};
if should_change {
// SAFETY: ic0::global_timer_set is always a safe call
unsafe { ic0::global_timer_set(soonest_timer.unwrap() as i64) };
unsafe { ic0::global_timer_set(soonest_timer.unwrap()) };
MOST_RECENT.with(|recent| recent.set(soonest_timer));
}
});
Expand Down
Loading
Loading