pub fn total_compute_allocation_cannot_be_exceeded(
    handle: IcHandle,
    ctx: &ic_fondue::pot::Context,
) {
    let mut rng = ctx.rng.clone();
    let rt = tokio::runtime::Runtime::new().expect("Could not create tokio runtime.");
    let app_sched_cores =
        ic_config::subnet_config::SchedulerConfig::application_subnet().scheduler_cores;
    const MAX_COMP_ALLOC: Option<u64> = Some(99);
    rt.block_on(async move {
        let mut canister_principals = Vec::new();
        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 cans = join_all(
            (0..app_sched_cores)
                .map(|_| UniversalCanister::new_with_comp_alloc(&agent, MAX_COMP_ALLOC, None)),
        )
        .await;
        for can in cans {
            let can_id = can
                .expect("Could not install universal canister.")
                .canister_id();
            canister_principals.push(can_id);
        }

        // Installing the app_sched_cores + 1st canister should fail.
        let can = UniversalCanister::new_with_comp_alloc(&agent, MAX_COMP_ALLOC, None).await;
        assert!(can.is_err());

        let mgr = ManagementCanister::create(&agent);
        // Stop and delete all canisters.

        let res = join_all(
            canister_principals
                .iter()
                .map(|c_id| mgr.stop_canister(c_id).call_and_wait(delay())),
        )
        .await;
        res.into_iter()
            .for_each(|x| x.expect("Could not stop canister."));

        let res = join_all(
            canister_principals
                .iter()
                .map(|c_id| mgr.delete_canister(c_id).call_and_wait(delay())),
        )
        .await;
        res.into_iter()
            .for_each(|x| x.expect("Could not delete canister."));

        // Create universal canister with 'best effort' compute allocation of `0`.
        let uni_can = UniversalCanister::new_with_comp_alloc(&agent, Some(0), Some(std::u64::MAX))
            .await
            .expect("Could not create and install universal canister.");
        let arbitrary_bytes = b";ioapusdvzn,x";

        async fn install_canister(
            universal_canister: &UniversalCanister<'_>,
            reply_data: &[u8],
        ) -> Result<(Principal, Vec<u8>), AgentError> {
            let created_canister = universal_canister
                .update(wasm().call(management::create_canister(100_000_000_000_000)))
                .await
                .map(|res| {
                    Decode!(res.as_slice(), CreateCanisterResult)
                        .unwrap()
                        .canister_id
                })
                .expect("Could not create canister.");
            let res = universal_canister
                .update(
                    wasm().call(
                        management::install_code(
                            created_canister,
                            UNIVERSAL_CANISTER_WASM.to_vec(),
                        )
                        .with_compute_allocation(MAX_COMP_ALLOC.unwrap())
                        .on_reply(wasm().inter_update(
                            created_canister,
                            call_args().other_side(wasm().reply_data(reply_data)),
                        )),
                    ),
                )
                .await;
            res.map(|r| (created_canister, r))
        }

        let results =
            join_all((0..app_sched_cores).map(|_| install_canister(&uni_can, arbitrary_bytes)))
                .await;
        for r in results {
            assert_eq!(r.unwrap().1, arbitrary_bytes);
        }

        let res = install_canister(&uni_can, arbitrary_bytes).await;
        assert_reject(res, RejectCode::CanisterReject);
    })
}
/// This tests expects to be run on a clean slate, i.e. requires it's own Pot
/// with one subnet of type Application.
/// Tests whether the compute allocation limits are enforced on an app subnet
/// both when creating canisters via the provisional API and via another
/// canister (which acts as the wallet canister).
This tests expects to be run on a clean slate, i.e. requires it's own Pot
with one subnet of type Application.
Tests whether the compute allocation limits are enforced on an app subnet
both when creating canisters via the provisional API and via another
canister (which acts as the wallet canister).
This tests expects to be run on a clean slate i . e . requires it ' s own Pot with one subnet of type Application . Tests whether the compute allocation limits are enforced on an app subnet both when creating canisters via the provisional API and via another canister ( which acts as the wallet canister ) .
pub fn total_compute_allocation_cannot_be_exceeded(
    handle: IcHandle,
    ctx: &ic_fondue::pot::Context,
) {
    let mut rng = ctx.rng.clone();
    let rt = tokio::runtime::Runtime::new().expect("Could not create tokio runtime.");
    let app_sched_cores =
        ic_config::subnet_config::SchedulerConfig::application_subnet().scheduler_cores;
    const MAX_COMP_ALLOC: Option<u64> = Some(99);
    rt.block_on(async move {
        let mut canister_principals = Vec::new();
        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 cans = join_all(
            (0..app_sched_cores)
                .map(|_| UniversalCanister::new_with_comp_alloc(&agent, MAX_COMP_ALLOC, None)),
        )
        .await;
        for can in cans {
            let can_id = can
                .expect("Could not install universal canister.")
                .canister_id();
            canister_principals.push(can_id);
        }
        // Installing the app_sched_cores + 1st canister should fail.
        let can = UniversalCanister::new_with_comp_alloc(&agent, MAX_COMP_ALLOC, None).await;
        assert!(can.is_err());
        let mgr = ManagementCanister::create(&agent);
        // Stop and delete all canisters.
        let res = join_all(
            canister_principals
                .iter()
                .map(|c_id| mgr.stop_canister(c_id).call_and_wait(delay())),
        )
        .await;
        res.into_iter()
            .for_each(|x| x.expect("Could not stop canister."));
        let res = join_all(
            canister_principals
                .iter()
                .map(|c_id| mgr.delete_canister(c_id).call_and_wait(delay())),
        )
        .await;
        res.into_iter()
            .for_each(|x| x.expect("Could not delete canister."));
        // Create universal canister with 'best effort' compute allocation of `0`.
        let uni_can = UniversalCanister::new_with_comp_alloc(&agent, Some(0), Some(std::u64::MAX))
            .await
            .expect("Could not create and install universal canister.");
        let arbitrary_bytes = b";ioapusdvzn,x";
        async fn install_canister(
            universal_canister: &UniversalCanister<'_>,
            reply_data: &[u8],
        ) -> Result<(Principal, Vec<u8>), AgentError> {
            let created_canister = universal_canister
                .update(wasm().call(management::create_canister(100_000_000_000_000)))
                .await
                .map(|res| {
                    Decode!(res.as_slice(), CreateCanisterResult)
                        .unwrap()
                        .canister_id
                })
                .expect("Could not create canister.");
            let res = universal_canister
                .update(
                    wasm().call(
                        management::install_code(
                            created_canister,
                            UNIVERSAL_CANISTER_WASM.to_vec(),
                        )
                        .with_compute_allocation(MAX_COMP_ALLOC.unwrap())
                        .on_reply(wasm().inter_update(
                            created_canister,
                            call_args().other_side(wasm().reply_data(reply_data)),
                        )),
                    ),
                )
                .await;
            res.map(|r| (created_canister, r))
        }
        let results =
            join_all((0..app_sched_cores).map(|_| install_canister(&uni_can, arbitrary_bytes)))
                .await;
        for r in results {
            assert_eq!(r.unwrap().1, arbitrary_bytes);
        }
        let res = install_canister(&uni_can, arbitrary_bytes).await;
        assert_reject(res, RejectCode::CanisterReject);
    })
}
pub fn total_compute_allocation_cannot_be_exceeded ( handle : IcHandle , ctx : & ic_fondue :: pot :: Context , ) { let mut rng = ctx . rng . clone ( ) ; let rt = tokio :: runtime :: Runtime :: new ( ) . expect ( " " ) ; let app_sched_cores = ic_config :: subnet_config :: SchedulerConfig :: application_subnet ( ) . scheduler_cores ; const MAX_COMP_ALLOC : Option < u64 > = Some ( 99 ) ; rt . block_on ( async move { let mut canister_principals = Vec :: new ( ) ; 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 cans = join_all ( ( 0 .. app_sched_cores ) . map ( | _ | UniversalCanister :: new_with_comp_alloc ( & agent , MAX_COMP_ALLOC , None ) ) , ) . await ; for can in cans { let can_id = can . expect ( " " ) . canister_id ( ) ; canister_principals . push ( can_id ) ; } // Installing the app_sched_cores + 1st canister should fail. let can = UniversalCanister :: new_with_comp_alloc ( & agent , MAX_COMP_ALLOC , None ) . await ; assert ! ( can is_err ( ) ) ; let mgr = ManagementCanister :: create ( & agent ) ; // Stop and delete all canisters. let res = join_all ( canister_principals . iter ( ) . map ( | c_id | mgr . stop_canister ( c_id ) . call_and_wait ( delay ( ) ) ) , ) . await ; res . into_iter ( ) . for_each ( | x | x . expect ( " " ) ) ; let res = join_all ( canister_principals . iter ( ) . map ( | c_id | mgr . delete_canister ( c_id ) . call_and_wait ( delay ( ) ) ) , ) . await ; res . into_iter ( ) . for_each ( | x | x . expect ( " " ) ) ; // Create universal canister with 'best effort' compute allocation of `0`. let uni_can = UniversalCanister :: new_with_comp_alloc ( & agent , Some ( 0 ) , Some ( std :: u64 :: MAX ) ) . await . expect ( " " ) ; let arbitrary_bytes = b" " ; async fn install_canister ( universal_canister : & UniversalCanister < ' _ > , reply_data : & [ u8 ] , ) -> Result < ( Principal , Vec < u8 > ) , AgentError > { let created_canister = universal_canister . update ( wasm ( ) . call ( management :: create_canister ( 100_000_000_000_000 ) ) ) . await . map ( | res | { Decode ! ( res as_slice ( ) CreateCanisterResult ) . unwrap ( ) . canister_id } ) . expect ( " " ) ; let res = universal_canister . update ( wasm ( ) . call ( management :: install_code ( created_canister , UNIVERSAL_CANISTER_WASM . to_vec ( ) , ) . with_compute_allocation ( MAX_COMP_ALLOC . unwrap ( ) ) . on_reply ( wasm ( ) . inter_update ( created_canister , call_args ( ) . other_side ( wasm ( ) . reply_data ( reply_data ) ) , ) ) , ) , ) . await ; res . map ( | r | ( created_canister , r ) ) } let results = join_all ( ( 0 .. app_sched_cores ) . map ( | _ | install_canister ( & uni_can , arbitrary_bytes ) ) ) . await ; for r in results { assert_eq ! ( r unwrap ( ) 1 arbitrary_bytes ) ; } let res = install_canister ( & uni_can , arbitrary_bytes ) . await ; assert_reject ( res , RejectCode :: CanisterReject ) ; } ) }
This tests expects to be run on a clean slate, i.e.
This tests expects to be run on a clean slate i . e .
handle
IcHandle
ctx
&ic_fondue::pot::Context
handle
IcHandle
ctx
&ic_fondue::pot::Context