-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor management_canister tests (#438)
* move main/provisonal tests to e2e * refactor management example * use stable rust in examples * periodically run CI to keep cache available * fmt * single quote in yml * 0 for Sunday
- Loading branch information
Showing
11 changed files
with
130 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use ic_cdk::*; | ||
|
||
mod main { | ||
use super::*; | ||
use ic_cdk::api::management_canister::main::*; | ||
#[update] | ||
async fn execute_main_methods() { | ||
let arg = CreateCanisterArgument { | ||
settings: Some(CanisterSettings { | ||
controllers: Some(vec![ic_cdk::id()]), | ||
compute_allocation: Some(0.into()), | ||
memory_allocation: Some(10000.into()), | ||
freezing_threshold: Some(10000.into()), | ||
}), | ||
}; | ||
let canister_id = create_canister(arg, 100_000_000_000u128 / 13) | ||
.await | ||
.unwrap() | ||
.0 | ||
.canister_id; | ||
|
||
let arg = UpdateSettingsArgument { | ||
canister_id, | ||
settings: CanisterSettings::default(), | ||
}; | ||
update_settings(arg).await.unwrap(); | ||
|
||
let arg = InstallCodeArgument { | ||
mode: CanisterInstallMode::Install, | ||
canister_id, | ||
// A minimal valid wasm module | ||
// wat2wasm "(module)" | ||
wasm_module: b"\x00asm\x01\x00\x00\x00".to_vec(), | ||
arg: vec![], | ||
}; | ||
install_code(arg).await.unwrap(); | ||
let arg = CanisterIdRecord { canister_id }; | ||
uninstall_code(arg).await.unwrap(); | ||
start_canister(arg).await.unwrap(); | ||
stop_canister(arg).await.unwrap(); | ||
let response = canister_status(arg).await.unwrap().0; | ||
assert_eq!(response.status, CanisterStatusType::Stopped); | ||
deposit_cycles(arg, 1_000_000_000_000u128).await.unwrap(); | ||
delete_canister(arg).await.unwrap(); | ||
let response = raw_rand().await.unwrap().0; | ||
assert_eq!(response.len(), 32); | ||
} | ||
} | ||
|
||
mod provisional { | ||
use super::*; | ||
use ic_cdk::api::management_canister::provisional::*; | ||
|
||
#[update] | ||
async fn execute_provisional_methods() { | ||
let settings = CanisterSettings { | ||
controllers: Some(vec![ic_cdk::caller()]), | ||
compute_allocation: Some(50.into()), | ||
memory_allocation: Some(10000.into()), | ||
freezing_threshold: Some(10000.into()), | ||
}; | ||
let arg = ProvisionalCreateCanisterWithCyclesArgument { | ||
amount: Some(1_000_000_000.into()), | ||
settings: Some(settings), | ||
}; | ||
let canister_id = provisional_create_canister_with_cycles(arg) | ||
.await | ||
.unwrap() | ||
.0 | ||
.canister_id; | ||
|
||
let arg = ProvisionalTopUpCanisterArgument { | ||
canister_id, | ||
amount: 1_000_000_000.into(), | ||
}; | ||
provisional_top_up_canister(arg).await.unwrap(); | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
# Executed before each test. | ||
setup() { | ||
cd examples/management_canister | ||
bitcoind -regtest -daemonwait | ||
# Make sure the directory is clean. | ||
dfx start --clean --background | ||
} | ||
|
||
# executed after each test | ||
teardown() { | ||
dfx stop | ||
bitcoin-cli -regtest stop | ||
} | ||
|
||
@test "All management canister methods succeed" { | ||
@test "http_request example succeed" { | ||
dfx start --clean --background --enable-canister-http | ||
dfx deploy | ||
dfx canister call caller http_request_example | ||
} | ||
|
||
@test "ecdsa methods succeed" { | ||
dfx start --clean --background | ||
dfx deploy | ||
dfx canister call caller execute_ecdsa_methods | ||
} | ||
|
||
@test "bitcoin methods succeed" { | ||
bitcoind -regtest -daemonwait | ||
dfx start --clean --background --enable-bitcoin | ||
dfx deploy | ||
run dfx canister call caller execute_main_methods | ||
run dfx canister call caller execute_provisional_methods | ||
run dfx canister call caller http_request_example | ||
run dfx canister call caller execute_ecdsa_methods | ||
run dfx canister call caller execute_bitcoin_methods | ||
dfx canister call caller execute_bitcoin_methods | ||
bitcoin-cli -regtest stop | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[toolchain] | ||
channel = "stable" # sync with rust-version in root Cargo.toml | ||
targets = ["wasm32-unknown-unknown"] | ||
components = ["rustfmt", "clippy"] |