Skip to content

Commit 56579e0

Browse files
committed
test(ckerc20): stop ckETH minter before upgrading it in state machine tests
1 parent 0c29296 commit 56579e0

File tree

6 files changed

+62
-1
lines changed

6 files changed

+62
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rs/ethereum/cketh/minter/tests/ckerc20.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use candid::{Nat, Principal};
33
use ic_cketh_minter::endpoints::events::EventPayload;
44
use ic_cketh_minter::endpoints::AddCkErc20Token;
55
use ic_cketh_test_utils::ckerc20::CkErc20Setup;
6+
use ic_cketh_test_utils::flow::DepositParams;
67
use ic_cketh_test_utils::CkEthSetup;
78
use ic_ethereum_types::Address;
89
use ic_ledger_suite_orchestrator_test_utils::supported_erc20_tokens;
@@ -60,6 +61,14 @@ fn should_add_ckusdc_and_ckusdt_to_minter_via_orchestrator() {
6061
}
6162
}
6263

64+
#[test]
65+
fn should_mint_with_ckerc20_setup() {
66+
CkErc20Setup::default()
67+
.cketh
68+
.deposit(DepositParams::default())
69+
.expect_mint();
70+
}
71+
6372
fn format_ethereum_address_to_eip_55(address: &str) -> String {
6473
use std::str::FromStr;
6574
Address::from_str(address).unwrap().to_string()

rs/ethereum/cketh/test_utils/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rust_library(
2323
"//rs/state_machine_tests",
2424
"//rs/test_utilities/load_wasm",
2525
"//rs/types/base_types",
26+
"@crate_index//:assert_matches",
2627
"@crate_index//:candid",
2728
"@crate_index//:ethers-core",
2829
"@crate_index//:hex",

rs/ethereum/cketh/test_utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition.workspace = true
77
documentation.workspace = true
88

99
[dependencies]
10+
assert_matches = "1.5.0"
1011
candid = { workspace = true }
1112
ethers-core = "2.0.8"
1213
hex = "0.4"

rs/ethereum/cketh/test_utils/src/lib.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::flow::{
22
ApprovalFlow, DepositFlow, DepositParams, LedgerTransactionAssert, WithdrawalFlow,
33
};
44
use crate::mock::JsonRpcMethod;
5+
use assert_matches::assert_matches;
56
use candid::{Decode, Encode, Nat, Principal};
67
use ic_canisters_http_types::{HttpRequest, HttpResponse};
78
use ic_cketh_minter::endpoints::events::{Event, EventPayload, GetEventsResult};
@@ -15,7 +16,8 @@ use ic_cketh_minter::{
1516
use ic_ethereum_types::Address;
1617
use ic_icrc1_ledger::{InitArgsBuilder as LedgerInitArgsBuilder, LedgerArgument};
1718
use ic_state_machine_tests::{
18-
CanisterId, Cycles, PrincipalId, StateMachine, StateMachineBuilder, UserError, WasmResult,
19+
CanisterHttpResponsePayload, CanisterId, Cycles, PayloadBuilder, PrincipalId, StateMachine,
20+
StateMachineBuilder, UserError, WasmResult,
1921
};
2022
use ic_test_utilities_load_wasm::load_wasm;
2123
use icrc_ledger_types::icrc1::account::Account;
@@ -425,13 +427,45 @@ impl CkEthSetup {
425427
}
426428

427429
fn upgrade_minter(&self, upgrade_arg: UpgradeArg) {
430+
self.stop_minter();
428431
self.env
429432
.upgrade_canister(
430433
self.minter_id,
431434
minter_wasm(),
432435
Encode!(&MinterArg::UpgradeArg(upgrade_arg)).unwrap(),
433436
)
434437
.unwrap();
438+
self.start_minter();
439+
}
440+
441+
fn stop_minter(&self) {
442+
let stop_msg_id = self.env.stop_canister_non_blocking(self.minter_id);
443+
self.stop_ongoing_https_outcalls();
444+
let stop_res = self.env.await_ingress(stop_msg_id, 100);
445+
assert_matches!(stop_res, Ok(WasmResult::Reply(_)));
446+
}
447+
448+
fn stop_ongoing_https_outcalls(&self) {
449+
let server_error_response = CanisterHttpResponsePayload {
450+
status: 500_u128,
451+
headers: vec![],
452+
body: vec![],
453+
};
454+
let ongoing_https_outcalls: Vec<_> = self
455+
.env
456+
.canister_http_request_contexts()
457+
.into_keys()
458+
.collect();
459+
let mut payload = PayloadBuilder::new();
460+
for callback_id in ongoing_https_outcalls {
461+
payload = payload.http_response(callback_id, &server_error_response);
462+
}
463+
self.env.execute_payload(payload);
464+
}
465+
466+
fn start_minter(&self) {
467+
let start_res = self.env.start_canister(self.minter_id);
468+
assert_matches!(start_res, Ok(WasmResult::Reply(_)));
435469
}
436470

437471
pub fn upgrade_minter_to_add_orchestrator_id(self, orchestrator_id: Principal) -> Self {

rs/state_machine_tests/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,21 @@ impl StateMachine {
22592259
)
22602260
}
22612261

2262+
/// Stops the canister with the specified ID in a non-blocking way.
2263+
///
2264+
/// This function is asynchronous. It returns the ID of the ingress message
2265+
/// that can be awaited later with [await_ingress].
2266+
/// This allows to do some clean-up between the time the canister is in the stopping state
2267+
/// and the time it is actually stopped.
2268+
pub fn stop_canister_non_blocking(&self, canister_id: CanisterId) -> MessageId {
2269+
self.send_ingress(
2270+
PrincipalId::new_anonymous(),
2271+
CanisterId::ic_00(),
2272+
"stop_canister",
2273+
(CanisterIdRecord::from(canister_id)).encode(),
2274+
)
2275+
}
2276+
22622277
/// Calls the `canister_status` endpoint on the management canister.
22632278
pub fn canister_status(
22642279
&self,

0 commit comments

Comments
 (0)