/// Try to install a canister with a wasm that asks for a large memory but a
/// small memory allocation. It should be rejected.
Try to install a canister with a wasm that asks for a large memory but a
small memory allocation. It should be rejected.
Try to install a canister with a wasm that asks for a large memory but a small memory allocation . It should be rejected .
pub fn canister_large_initial_memory_small_memory_allocation(
    handle: IcHandle,
    ctx: &ic_fondue::pot::Context,
) {
    // A wasm module that asks for 2GiB of initial memory.
    let wasm = wabt::wat2wasm(
        r#"(module
              (func $hi)
              (memory $memory 32768)
              (export "memory" (memory $memory))
              (export "canister_query hi" (func $hi)))"#,
    )
    .unwrap();
    let mut rng = ctx.rng.clone();
    let rt = tokio::runtime::Runtime::new().expect("Could not create tokio runtime.");
    rt.block_on({
        async move {
            let endpoint = get_random_application_node_endpoint(&handle, &mut rng);
            endpoint.assert_ready(ctx).await;
            let agent = assert_create_agent(endpoint.url.as_str()).await;
            let mgr = ManagementCanister::create(&agent);
            let canister_id = mgr
                .create_canister()
                .as_provisional_create_with_amount(None)
                .call_and_wait(delay())
                .await
                .expect("Couldn't create canister with provisional API.")
                .0;
            // Install the wasm with no memory allocation, it should succeed.
            mgr.install_code(&canister_id, &wasm)
                .call_and_wait(delay())
                .await
                .unwrap();
            // Attempt to set 1GB memory allocation for the canister, it should fail.
            let res = mgr
                .update_settings(&canister_id)
                .with_memory_allocation(1_u64 << 30)
                .call_and_wait(delay())
                .await;
            assert_reject(res, RejectCode::CanisterReject);
            // Install the wasm with 3GiB memory alloction, it should succeed.
            mgr.update_settings(&canister_id)
                .with_memory_allocation(3_u64 << 30)
                .call_and_wait(delay())
                .await
                .unwrap();
            mgr.install_code(&canister_id, &wasm)
                .with_mode(InstallMode::Reinstall)
                .call_and_wait(delay())
                .await
                .unwrap();
        }
    })
}
pub fn canister_large_initial_memory_small_memory_allocation ( handle : IcHandle , ctx : & ic_fondue :: pot :: Context , ) { // A wasm module that asks for 2GiB of initial memory. let wasm = wabt :: wat2wasm ( r#"(module
              (func $hi)
              (memory $memory 32768)
              (export "memory" (memory $memory))
              (export "canister_query hi" (func $hi)))"# , ) . unwrap ( ) ; let mut rng = ctx . rng . clone ( ) ; let rt = tokio :: runtime :: Runtime :: new ( ) . expect ( " " ) ; rt . block_on ( { async move { let endpoint = get_random_application_node_endpoint ( & handle , & mut rng ) ; endpoint . assert_ready ( ctx ) . await ; let agent = assert_create_agent ( endpoint . url . as_str ( ) ) . await ; let mgr = ManagementCanister :: create ( & agent ) ; let canister_id = mgr . create_canister ( ) . as_provisional_create_with_amount ( None ) . call_and_wait ( delay ( ) ) . await . expect ( " " ) . 0 ; // Install the wasm with no memory allocation, it should succeed. mgr . install_code ( & canister_id , & wasm ) . call_and_wait ( delay ( ) ) . await . unwrap ( ) ; // Attempt to set 1GB memory allocation for the canister, it should fail. let res = mgr . update_settings ( & canister_id ) . with_memory_allocation ( 1_u64 << 30 ) . call_and_wait ( delay ( ) ) . await ; assert_reject ( res , RejectCode :: CanisterReject ) ; // Install the wasm with 3GiB memory alloction, it should succeed. mgr . update_settings ( & canister_id ) . with_memory_allocation ( 3_u64 << 30 ) . call_and_wait ( delay ( ) ) . await . unwrap ( ) ; mgr . install_code ( & canister_id , & wasm ) . with_mode ( InstallMode :: Reinstall ) . call_and_wait ( delay ( ) ) . await . unwrap ( ) ; } } ) }
Try to install a canister with a wasm that asks for a large memory but a
small memory allocation.
Try to install a canister with a wasm that asks for a large memory but a small memory allocation .
handle
IcHandle
ctx
&ic_fondue::pot::Context