/// Tests whether creating a canister on a subnet other than self fails when not
/// on the NNS subnet.
Tests whether creating a canister on a subnet other than self fails when not
on the NNS subnet.
Tests whether creating a canister on a subnet other than self fails when not on the NNS subnet .
pub fn non_nns_canister_attempt_to_create_canister_on_another_subnet_fails(
    handle: IcHandle,
    ctx: &ic_fondue::pot::Context,
) {
    let rt = tokio::runtime::Runtime::new().expect("Could not create tokio runtime.");
    let mut rng = ctx.rng.clone();
    rt.block_on(async move {
        // Check that canisters on verified app subnets cannot create canisters on other
        // subnets.
        let verified_app_endpoint = get_random_verified_app_node_endpoint(&handle, &mut rng);
        verified_app_endpoint.assert_ready(ctx).await;
        let agent = assert_create_agent(verified_app_endpoint.url.as_str()).await;
        let uni_can = UniversalCanister::new_with_cycles(&agent, 900_000_000_000_000_u64).await;
        let other_subnet = get_random_application_node_endpoint(&handle, &mut rng)
            .subnet_id()
            .unwrap();
        let res = uni_can
            .forward_with_cycles_to(
                &other_subnet.get().into(),
                "create_canister",
                Encode!().unwrap(),
                100_000_000_000_000,
            )
            .await
            .map(|res| {
                Decode!(res.as_slice(), CreateCanisterResult)
                    .unwrap()
                    .canister_id
            });
        assert_reject(res, RejectCode::CanisterReject);
        let other_subnet = get_random_system_node_endpoint(&handle, &mut rng)
            .subnet_id()
            .unwrap();
        let res = uni_can
            .forward_with_cycles_to(
                &other_subnet.get().into(),
                "create_canister",
                Encode!().unwrap(),
                100_000_000_000_000,
            )
            .await
            .map(|res| {
                Decode!(res.as_slice(), CreateCanisterResult)
                    .unwrap()
                    .canister_id
            });
        assert_reject(res, RejectCode::CanisterReject);
        // Check that canisters on app subnets cannot create canisters on other subnets.
        let app_endpoint = get_random_application_node_endpoint(&handle, &mut rng);
        app_endpoint.assert_ready(ctx).await;
        let agent = assert_create_agent(app_endpoint.url.as_str()).await;
        let uni_can = UniversalCanister::new_with_cycles(&agent, 900_000_000_000_000_u64).await;
        let other_subnet = get_random_verified_app_node_endpoint(&handle, &mut rng)
            .subnet_id()
            .unwrap();
        let res = uni_can
            .forward_with_cycles_to(
                &other_subnet.get().into(),
                "create_canister",
                Encode!().unwrap(),
                0,
            )
            .await
            .map(|res| {
                Decode!(res.as_slice(), CreateCanisterResult)
                    .unwrap()
                    .canister_id
            });
        assert_reject(res, RejectCode::CanisterReject);
        let other_subnet = get_random_system_node_endpoint(&handle, &mut rng)
            .subnet_id()
            .unwrap();
        let res = uni_can
            .forward_with_cycles_to(
                &other_subnet.get().into(),
                "create_canister",
                Encode!().unwrap(),
                0,
            )
            .await
            .map(|res| {
                Decode!(res.as_slice(), CreateCanisterResult)
                    .unwrap()
                    .canister_id
            });
        assert_reject(res, RejectCode::CanisterReject);
        // Check that canisters on system subnets excluding NNS cannot create canisters
        // on other subnets.
        let app_endpoint = get_random_system_but_not_nns_node_endpoint(&handle, &mut rng);
        app_endpoint.assert_ready(ctx).await;
        let agent = assert_create_agent(app_endpoint.url.as_str()).await;
        let uni_can = UniversalCanister::new_with_cycles(&agent, 900_000_000_000_000_u64).await;
        let other_subnet = get_random_verified_app_node_endpoint(&handle, &mut rng)
            .subnet_id()
            .unwrap();
        let res = uni_can
            .forward_with_cycles_to(
                &other_subnet.get().into(),
                "create_canister",
                Encode!().unwrap(),
                50_000_000_000_000,
            )
            .await
            .map(|res| {
                Decode!(res.as_slice(), CreateCanisterResult)
                    .unwrap()
                    .canister_id
            });
        assert_reject(res, RejectCode::CanisterReject);
        let other_subnet = get_random_application_node_endpoint(&handle, &mut rng)
            .subnet_id()
            .unwrap();
        let res = uni_can
            .forward_with_cycles_to(
                &other_subnet.get().into(),
                "create_canister",
                Encode!().unwrap(),
                50_000_000_000_000,
            )
            .await
            .map(|res| {
                Decode!(res.as_slice(), CreateCanisterResult)
                    .unwrap()
                    .canister_id
            });
        assert_reject(res, RejectCode::CanisterReject);
    });
}
pub fn non_nns_canister_attempt_to_create_canister_on_another_subnet_fails ( handle : IcHandle , ctx : & ic_fondue :: pot :: Context , ) { let rt = tokio :: runtime :: Runtime :: new ( ) . expect ( " " ) ; let mut rng = ctx . rng . clone ( ) ; rt . block_on ( async move { // Check that canisters on verified app subnets cannot create canisters on other // subnets. let verified_app_endpoint = get_random_verified_app_node_endpoint ( & handle , & mut rng ) ; verified_app_endpoint . assert_ready ( ctx ) . await ; let agent = assert_create_agent ( verified_app_endpoint . url . as_str ( ) ) . await ; let uni_can = UniversalCanister :: new_with_cycles ( & agent , 900_000_000_000_000_u64 ) . await ; let other_subnet = get_random_application_node_endpoint ( & handle , & mut rng ) . subnet_id ( ) . unwrap ( ) ; let res = uni_can . forward_with_cycles_to ( & other_subnet . get ( ) . into ( ) , " " , Encode ! ( ) . unwrap ( ) , 100_000_000_000_000 , ) . await . map ( | res | { Decode ! ( res as_slice ( ) CreateCanisterResult ) . unwrap ( ) . canister_id } ) ; assert_reject ( res , RejectCode :: CanisterReject ) ; let other_subnet = get_random_system_node_endpoint ( & handle , & mut rng ) . subnet_id ( ) . unwrap ( ) ; let res = uni_can . forward_with_cycles_to ( & other_subnet . get ( ) . into ( ) , " " , Encode ! ( ) . unwrap ( ) , 100_000_000_000_000 , ) . await . map ( | res | { Decode ! ( res as_slice ( ) CreateCanisterResult ) . unwrap ( ) . canister_id } ) ; assert_reject ( res , RejectCode :: CanisterReject ) ; // Check that canisters on app subnets cannot create canisters on other subnets. let app_endpoint = get_random_application_node_endpoint ( & handle , & mut rng ) ; app_endpoint . assert_ready ( ctx ) . await ; let agent = assert_create_agent ( app_endpoint . url . as_str ( ) ) . await ; let uni_can = UniversalCanister :: new_with_cycles ( & agent , 900_000_000_000_000_u64 ) . await ; let other_subnet = get_random_verified_app_node_endpoint ( & handle , & mut rng ) . subnet_id ( ) . unwrap ( ) ; let res = uni_can . forward_with_cycles_to ( & other_subnet . get ( ) . into ( ) , " " , Encode ! ( ) . unwrap ( ) , 0 , ) . await . map ( | res | { Decode ! ( res as_slice ( ) CreateCanisterResult ) . unwrap ( ) . canister_id } ) ; assert_reject ( res , RejectCode :: CanisterReject ) ; let other_subnet = get_random_system_node_endpoint ( & handle , & mut rng ) . subnet_id ( ) . unwrap ( ) ; let res = uni_can . forward_with_cycles_to ( & other_subnet . get ( ) . into ( ) , " " , Encode ! ( ) . unwrap ( ) , 0 , ) . await . map ( | res | { Decode ! ( res as_slice ( ) CreateCanisterResult ) . unwrap ( ) . canister_id } ) ; assert_reject ( res , RejectCode :: CanisterReject ) ; // Check that canisters on system subnets excluding NNS cannot create canisters // on other subnets. let app_endpoint = get_random_system_but_not_nns_node_endpoint ( & handle , & mut rng ) ; app_endpoint . assert_ready ( ctx ) . await ; let agent = assert_create_agent ( app_endpoint . url . as_str ( ) ) . await ; let uni_can = UniversalCanister :: new_with_cycles ( & agent , 900_000_000_000_000_u64 ) . await ; let other_subnet = get_random_verified_app_node_endpoint ( & handle , & mut rng ) . subnet_id ( ) . unwrap ( ) ; let res = uni_can . forward_with_cycles_to ( & other_subnet . get ( ) . into ( ) , " " , Encode ! ( ) . unwrap ( ) , 50_000_000_000_000 , ) . await . map ( | res | { Decode ! ( res as_slice ( ) CreateCanisterResult ) . unwrap ( ) . canister_id } ) ; assert_reject ( res , RejectCode :: CanisterReject ) ; let other_subnet = get_random_application_node_endpoint ( & handle , & mut rng ) . subnet_id ( ) . unwrap ( ) ; let res = uni_can . forward_with_cycles_to ( & other_subnet . get ( ) . into ( ) , " " , Encode ! ( ) . unwrap ( ) , 50_000_000_000_000 , ) . await . map ( | res | { Decode ! ( res as_slice ( ) CreateCanisterResult ) . unwrap ( ) . canister_id } ) ; assert_reject ( res , RejectCode :: CanisterReject ) ; } ) ; }
Tests whether creating a canister on a subnet other than self fails when not
on the NNS subnet.
Tests whether creating a canister on a subnet other than self fails when not on the NNS subnet .
handle
IcHandle
ctx
&ic_fondue::pot::Context