// Tests canister creation, stopping, starting, and checking the status.
Tests canister creation, stopping, starting, and checking the status.
Tests canister creation stopping starting and checking the status .
fn full_canister_lifecycle_from_another_canister() {
    utils::simple_canister_test(|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!(
            canister.update(wasm().call(management::create_canister(num_cycles))),
            Ok(WasmResult::Reply(canister_id_record,)),
        );
        // Verify that the newly created canister is running.
        assert_matches!(
            canister.update(wasm().call(
                management::canister_status(expected_canister_id))
            ),
            Ok(WasmResult::Reply(res)) if CanisterStatusResultV2::decode(&res).unwrap().status() == CanisterStatusType::Running
        );
        // Let the canister stop the newly created canister.
        assert_eq!(
            canister.update(wasm().call(management::stop_canister(expected_canister_id))),
            Ok(WasmResult::Reply(EmptyBlob::encode())),
        );
        // Verify that the newly created canister is now stopped.
        assert_matches!(
            canister.update(wasm().call(
                management::canister_status(expected_canister_id))
            ),
            Ok(WasmResult::Reply(res)) if CanisterStatusResultV2::decode(&res).unwrap().status() == CanisterStatusType::Stopped
        );
        // Start the canister again.
        assert_eq!(
            canister.update(wasm().call(management::start_canister(expected_canister_id))),
            Ok(WasmResult::Reply(EmptyBlob::encode())),
        );
        // Verify that the canister is running again.
        assert_matches!(
            canister.update(wasm().call(
                    management::canister_status(expected_canister_id))
            ),
            Ok(WasmResult::Reply(res)) if CanisterStatusResultV2::decode(&res).unwrap().status() == CanisterStatusType::Running
        );
    });
}
fn full_canister_lifecycle_from_another_canister ( ) { utils :: simple_canister_test ( | 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 ! ( canister update ( wasm ( ) call ( management create_canister ( num_cycles ) ) ) Ok ( WasmResult Reply ( canister_id_record ) ) ) ; // Verify that the newly created canister is running. assert_matches ! ( canister update ( wasm ( ) call ( management canister_status ( expected_canister_id ) ) ) Ok ( WasmResult Reply ( res ) ) if CanisterStatusResultV2 decode ( res ) unwrap ( ) status ( ) CanisterStatusType Running ) ; // Let the canister stop the newly created canister. assert_eq ! ( canister update ( wasm ( ) call ( management stop_canister ( expected_canister_id ) ) ) Ok ( WasmResult Reply ( EmptyBlob encode ( ) ) ) ) ; // Verify that the newly created canister is now stopped. assert_matches ! ( canister update ( wasm ( ) call ( management canister_status ( expected_canister_id ) ) ) Ok ( WasmResult Reply ( res ) ) if CanisterStatusResultV2 decode ( res ) unwrap ( ) status ( ) CanisterStatusType Stopped ) ; // Start the canister again. assert_eq ! ( canister update ( wasm ( ) call ( management start_canister ( expected_canister_id ) ) ) Ok ( WasmResult Reply ( EmptyBlob encode ( ) ) ) ) ; // Verify that the canister is running again. assert_matches ! ( canister update ( wasm ( ) call ( management canister_status ( expected_canister_id ) ) ) Ok ( WasmResult Reply ( res ) ) if CanisterStatusResultV2 decode ( res ) unwrap ( ) status ( ) CanisterStatusType Running ) ; } ) ; }
Tests canister creation, stopping, starting, and checking the status.
Tests canister creation stopping starting and checking the status .