// Tests canister stopping, starting, and checking the status
// by sending ingress messages to ic:00.
Tests canister stopping, starting, and checking the status
by sending ingress messages to ic:00.
Tests canister stopping starting and checking the status by sending ingress messages to ic : 00 .
fn full_canister_lifecycle_ingress() {
    utils::canister_test(|test| {
        let canister = test.create_universal_canister();
        // Create a new canister
        let expected_canister_id = CanisterId::from(1);
        let canister_id_record = Encode!(&CanisterIdRecord::from(expected_canister_id)).unwrap();
        let num_cycles = 1 << 40;
        // Create a new canister from within a canister.
        assert_eq!(
            test.ingress(
                canister,
                "update",
                wasm().call_with_cycles(
                    ic00::IC_00,
                    Method::CreateCanister,
                    call_args().other_side(EmptyBlob::encode()),
                    num_cycles,
                )
            ),
            Ok(WasmResult::Reply(canister_id_record.clone(),)),
        );
        // Set the controller to the anonymous user that's used in tests.
        test.ingress(
            canister,
            "update",
            wasm().call_with_cycles(
                ic00::IC_00,
                Method::SetController,
                call_args().other_side(
                    SetControllerArgs::new(expected_canister_id, PrincipalId::new_anonymous())
                        .encode(),
                ),
                num_cycles,
            ),
        )
        .unwrap();
        // Verify that the newly created canister is running.
        assert_matches!(
            test.ingress(IC_00, Method::CanisterStatus, canister_id_record.clone()),
            Ok(WasmResult::Reply(res)) if CanisterStatusResultV2::decode(&res).unwrap().status() == CanisterStatusType::Running
        );
        // Let ic:00 stop the newly created canister.
        assert_eq!(
            test.ingress(IC_00, Method::StopCanister, canister_id_record.clone()),
            Ok(WasmResult::Reply(EmptyBlob::encode()))
        );
        // Verify that the newly created canister is now stopped.
        assert_matches!(
            test.ingress(IC_00, Method::CanisterStatus, canister_id_record.clone()),
            Ok(WasmResult::Reply(res)) if CanisterStatusResultV2::decode(&res).unwrap().status() == CanisterStatusType::Stopped
        );
        // Start the canister again.
        assert_eq!(
            test.ingress(IC_00, Method::StartCanister, canister_id_record.clone()),
            Ok(WasmResult::Reply(EmptyBlob::encode()))
        );
        // Verify that the newly created canister is running.
        assert_matches!(
            test.ingress(IC_00, Method::CanisterStatus, canister_id_record),
            Ok(WasmResult::Reply(res)) if CanisterStatusResultV2::decode(&res).unwrap().status() == CanisterStatusType::Running
        );
    })
}
fn full_canister_lifecycle_ingress ( ) { utils :: canister_test ( | test | { let canister = test . create_universal_canister ( ) ; // Create a new canister let expected_canister_id = CanisterId :: from ( 1 ) ; let canister_id_record = Encode ! ( CanisterIdRecord from ( expected_canister_id ) ) . unwrap ( ) ; let num_cycles = 1 << 40 ; // Create a new canister from within a canister. assert_eq ! ( test ingress ( canister " " wasm ( ) call_with_cycles ( ic00 IC_00 Method CreateCanister call_args ( ) other_side ( EmptyBlob encode ( ) ) num_cycles ) ) Ok ( WasmResult Reply ( canister_id_record clone ( ) ) ) ) ; // Set the controller to the anonymous user that's used in tests. test . ingress ( canister , " " , wasm ( ) . call_with_cycles ( ic00 :: IC_00 , Method :: SetController , call_args ( ) . other_side ( SetControllerArgs :: new ( expected_canister_id , PrincipalId :: new_anonymous ( ) ) . encode ( ) , ) , num_cycles , ) , ) . unwrap ( ) ; // Verify that the newly created canister is running. assert_matches ! ( test ingress ( IC_00 Method CanisterStatus canister_id_record clone ( ) ) Ok ( WasmResult Reply ( res ) ) if CanisterStatusResultV2 decode ( res ) unwrap ( ) status ( ) CanisterStatusType Running ) ; // Let ic:00 stop the newly created canister. assert_eq ! ( test ingress ( IC_00 Method StopCanister canister_id_record clone ( ) ) Ok ( WasmResult Reply ( EmptyBlob encode ( ) ) ) ) ; // Verify that the newly created canister is now stopped. assert_matches ! ( test ingress ( IC_00 Method CanisterStatus canister_id_record clone ( ) ) Ok ( WasmResult Reply ( res ) ) if CanisterStatusResultV2 decode ( res ) unwrap ( ) status ( ) CanisterStatusType Stopped ) ; // Start the canister again. assert_eq ! ( test ingress ( IC_00 Method StartCanister canister_id_record clone ( ) ) Ok ( WasmResult Reply ( EmptyBlob encode ( ) ) ) ) ; // Verify that the newly created canister is running. assert_matches ! ( test ingress ( IC_00 Method CanisterStatus canister_id_record ) Ok ( WasmResult Reply ( res ) ) if CanisterStatusResultV2 decode ( res ) unwrap ( ) status ( ) CanisterStatusType Running ) ; } ) }
Tests canister stopping, starting, and checking the status
by sending ingress messages to ic:00.
Tests canister stopping starting and checking the status by sending ingress messages to ic : 00 .