# Testing Creation of Canister on a subnet using Cycle Minting Canister with PocketIC

**URL:** <https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906>\
**Category:** Rust\
**Tags:** nns\
**Created:** [January 23, 2024, 4:39am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906 "2024-01-23T04:39:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [January 23, 2024, 4:39am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/1 "2024-01-23T04:39:35Z")

</div>

We are trying to create canisters on a specific subnet using cycle minting canister. I am testing this scenario using pocket-ic.

Getting Error on creation of canisters using CMC canister:

`Error: value: Refunded { refund_amount: 99900000000, create_error: \"Creating canister in subnet fbysm-3acaa-aaaaa-aaaap-yai failed with code 3: Unable to route management canister request create_canister: AlreadyResolved(fbysm-3acaa-aaaaa-aaaap-yai)\" }' `

```rust
pub async fn provision_subnet_orchestrator_canister(subnet: Principal, user_index_wasm: Vec<u8>) -> Principal {

    let create_canister_arg = CreateCanisterCmcArgument {
        subnet_selection: Some(SubnetType::Subnet(Subnet {
            subnet
        })),
        canister_settings: Some(CanisterSettings {
            controllers: Some(vec![api::id()]),
            compute_allocation: None,
            memory_allocation: None,
            freezing_threshold: None,
        }),
        subnet_type: None
    };

  // Creates Canister using CMC Canister
    let (res, ): (Result<Principal, CmcCreateCanisterError>, ) = call::call_with_payment(
        Principal::from_str(NNS_CYCLE_MINTING_CANISTER).unwrap(), 
        "create_canister",
       (create_canister_arg,),
       INDIVIDUAL_USER_CANISTER_RECHARGE_AMOUNT as u64
    )
    .await
    .unwrap();

    let subnet_orchestrator_canister_id = res.unwrap();

   // ... Rest of the Code

}

```

Test

```rust
 let pocket_ic = PocketIcBuilder::new()
        .with_nns_subnet()
        .with_application_subnet()
        .with_system_subnet()
        .build();

   
    let super_admin = get_global_super_admin_principal_id();

    let application_subnets = pocket_ic.topology().get_app_subnets();

    let platform_canister_id = pocket_ic.create_canister_with_settings(Some(super_admin), Some(CanisterSettings {controllers: Some(vec![super_admin]), compute_allocation: None, memory_allocation: None, freezing_threshold: None}));
    pocket_ic.add_cycles(platform_canister_id, CANISTER_INITIAL_CYCLES_FOR_SPAWNING_CANISTERS);
    let platform_orchestrator_wasm = include_bytes!("../../../../../target/wasm32-unknown-unknown/release/platform_orchestrator.wasm.gz");
    let subnet_orchestrator_canister_wasm = include_bytes!("../../../../../target/wasm32-unknown-unknown/release/user_index.wasm.gz");
    let platform_orchestrator_init_args = PlatformOrchestratorInitArgs {
        version: "v1.0.0".into()
    };
    pocket_ic.install_canister(platform_canister_id, platform_orchestrator_wasm.into(), candid::encode_one(platform_orchestrator_init_args).unwrap(), Some(super_admin));
    pocket_ic.add_cycles(platform_canister_id, CANISTER_INITIAL_CYCLES_FOR_SPAWNING_CANISTERS);

    //Ledger Canister
    let minting_account = AccountIdentifier::new(&super_admin, &DEFAULT_SUBACCOUNT);
    let ledger_canister_wasm = include_bytes!("../../ledger-canister.wasm");
    let ledger_canister_id = pocket_ic.create_canister_with_id(Some(super_admin), None, Principal::from_text(NNS_LEDGER_CANISTER_ID).unwrap()).unwrap();
    let icp_ledger_init_args = NnsLedgerCanisterInitPayload {
        minting_account: minting_account.to_string(),
        initial_values: HashMap::new(),
        send_whitelist: HashSet::new(),
        transfer_fee: Some(Tokens::from_e8s(10_000)),
    };
    pocket_ic.install_canister(ledger_canister_id, ledger_canister_wasm.into(), candid::encode_one(icp_ledger_init_args).unwrap(), Some(super_admin));
    

    //Cycle Minting Canister
    let cycle_minting_canister_wasm = include_bytes!("../../cycles-minting-canister.wasm");
    let cycle_minting_canister_id = pocket_ic.create_canister_with_id(Some(super_admin), None, Principal::from_text(NNS_CYCLE_MINTING_CANISTER).unwrap()).unwrap();
    pocket_ic.add_cycles(cycle_minting_canister_id, CANISTER_INITIAL_CYCLES_FOR_SPAWNING_CANISTERS);
    let cycles_minting_canister_init_args = CyclesMintingCanisterInitPayload {
        ledger_canister_id: ledger_canister_id,
        governance_canister_id: CanisterId::anonymous(),
        minting_account_id: Some(minting_account.to_string()),
        last_purged_notification: Some(0),
    };

    pocket_ic.install_canister(
        cycle_minting_canister_id,
        cycle_minting_canister_wasm.into(),
        candid::encode_one(cycles_minting_canister_init_args).unwrap(),
        Some(super_admin)
    );
    

    let authorized_subnetwork_list_args = AuthorizedSubnetWorks {
        who: Some(platform_canister_id),
        subnets: application_subnets.clone()
    };
    pocket_ic.update_call(
        cycle_minting_canister_id,
        CanisterId::anonymous(),
        "set_authorized_subnetwork_list",
        candid::encode_one(authorized_subnetwork_list_args).unwrap()
    ).unwrap();

    for i in 0..50 {
        pocket_ic.tick();
    }

    let subnet_orchestrator_canister_id: Principal = pocket_ic.update_call(
        platform_canister_id,
        super_admin,
        "provision_subnet_orchestrator_canister",
        candid::encode_args((application_subnets[0], subnet_orchestrator_canister_wasm)).unwrap()
    )
    .map(|res| {
        let canister_id: Principal = match res {
            WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(),
            _ => panic!("Canister call failed")
        };
        canister_id
    })
    .unwrap();

```

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [January 23, 2024, 7:52am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/2 "2024-01-23T07:52:00Z")

</div>

I don’t have a solution handy, but if you only use `create_canister` as a workaround I can offer a [CMC mock](https://github.com/dfinity/cycles-ledger/releases) we use for the cycles ledger. It has the same `create_canister` function as the real CMC, but it doesn’t use the subnet targeting logic so this error would not appear. In addition, you can check that the call was properly made using `last_create_canister_args` or you can say that it should fail the next creation call using `fail_next_create_canister_with`

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [January 23, 2024, 9:07am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/3 "2024-01-23T09:07:44Z")

</div>

Thanks @Vivienne. I think for now I will use the fake cmc mock for testing this scenario.

---

<div class="post-metadata">

**Author:** ![mraszyk](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mraszyk/32/7945_2.png) [@mraszyk](https://forum.dfinity.org/u/mraszyk)\
**Post date:** [January 23, 2024, 9:09am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/4 "2024-01-23T09:09:34Z")

</div>

Did you deploy the CMC canister to the NNS subnet of PocketIC? The error suggests the canister was deployed to a non-NNS subnet.

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [January 23, 2024, 9:18am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/5 "2024-01-23T09:18:28Z")

</div>

@mraszyk I just used pocketic method `create_canister_with_id` to create canister.

```rust
 let cycle_minting_canister_wasm = include_bytes!("../../cycles-minting-canister.wasm");
    let cycle_minting_canister_id = pocket_ic.create_canister_with_id(Some(super_admin), None, Principal::from_text(NNS_CYCLE_MINTING_CANISTER).unwrap()).unwrap();
    pocket_ic.add_cycles(cycle_minting_canister_id, CANISTER_INITIAL_CYCLES_FOR_SPAWNING_CANISTERS);
    let cycles_minting_canister_init_args = CyclesMintingCanisterInitPayload {
        ledger_canister_id: ledger_canister_id,
        governance_canister_id: CanisterId::anonymous(),
        minting_account_id: Some(minting_account.to_string()),
        last_purged_notification: Some(0),
    };

```

---

<div class="post-metadata">

**Author:** ![michael-weigelt](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@michael-weigelt](https://forum.dfinity.org/u/michael-weigelt)\
**Post date:** [January 23, 2024, 9:22am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/6 "2024-01-23T09:22:08Z")

</div>

But what is the constant NNS\_CYCLE\_MINTING\_CANISTER? Is it exactly the mainnet CMC id?

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [January 23, 2024, 9:22am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/7 "2024-01-23T09:22:44Z")

</div>

Yes.  
`NNS_LEDGER_CANISTER_ID = "ryjl3-tyaaa-aaaaa-aaaba-cai";`

`NNS_CYCLE_MINTING_CANISTER = "rkp4c-7iaaa-aaaaa-aaaca-cai"`

---

<div class="post-metadata">

**Author:** ![michael-weigelt](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@michael-weigelt](https://forum.dfinity.org/u/michael-weigelt)\
**Post date:** [January 23, 2024, 5:03pm UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/8 "2024-01-23T17:03:34Z")

</div>

We are investigating. Thanks for the report!

---

<div class="post-metadata">

**Author:** ![michael-weigelt](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@michael-weigelt](https://forum.dfinity.org/u/michael-weigelt)\
**Post date:** [January 24, 2024, 10:49am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/9 "2024-01-24T10:49:39Z")

</div>

I was able to reproduce the problem using your exact setup.

Next, in order to debug, I made cargo.toml point to my local repo containing the pocket-ic library. This lead to many version incompatibilities in crates like candid, ic-cdk, serde etc. So I very dirtily changed most crates to use “\*”, because I just wanted to be able to compile and run the test. When it finally compiled, **your test succeeded** until the very last line.

This indicates that there is a dependency version mismatch between pocket-ic and your local dependencies. Can you try upgrading your dependencies starting with candid, ic-cdk, serde (one at a time) and report back?

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [January 24, 2024, 12:51pm UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/10 "2024-01-24T12:51:29Z")

</div>

Thanks @michael-weigelt. One issue with upgrading candid and ic-cdk version is pocket-ic 2.0.1 (latest version) still relies on older versions of candid and ic-cdk.

---

<div class="post-metadata">

**Author:** ![michael-weigelt](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@michael-weigelt](https://forum.dfinity.org/u/michael-weigelt)\
**Post date:** [January 24, 2024, 1:42pm UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/11 "2024-01-24T13:42:35Z")

</div>

I see. I looked into the git logs and I think the pocket-ic server 2.0.1 was built with candid 0.9.x, so perhaps _downgrading_ your candid might do the trick. Perhaps that’s acceptable for now, considering that integration tests use dev-dependencies?

We plan to have a 2.1.0 version out soon, which hopefully addresses the problem fully.

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [January 24, 2024, 2:03pm UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/12 "2024-01-24T14:03:29Z")

</div>

We were using candid version `0.9.3` even downgrading it to `v9.0.0` results into same error.

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [January 24, 2024, 2:04pm UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/13 "2024-01-24T14:04:54Z")

</div>

I tried using older Wasm for cycle minting canister and ledger canister but no luck 🙁

---

<div class="post-metadata">

**Author:** ![michael-weigelt](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@michael-weigelt](https://forum.dfinity.org/u/michael-weigelt)\
**Post date:** [January 26, 2024, 3:48pm UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/14 "2024-01-26T15:48:11Z")

</div>

Hey gravity\_vi, we have identified and fixed the bug that’s causing this. Thank you for the report and helpful information! I will ping you when we have a release with the fix.

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [January 28, 2024, 5:08am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/15 "2024-01-28T05:08:53Z")

</div>

Thank you @michael-weigelt for all the help here 🙂

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [February 5, 2024, 7:18am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/16 "2024-02-05T07:18:29Z")

</div>

@michael-weigelt any updates over here. We are kind of blocked from testing our features with multi subnet architecture.

---

<div class="post-metadata">

**Author:** ![michael-weigelt](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@michael-weigelt](https://forum.dfinity.org/u/michael-weigelt)\
**Post date:** [February 5, 2024, 7:33am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/17 "2024-02-05T07:33:39Z")

</div>

I expect a release today.

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [February 5, 2024, 7:34am UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/18 "2024-02-05T07:34:40Z")

</div>

oh great 🎉 . Thank you

---

<div class="post-metadata">

**Author:** ![michael-weigelt](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@michael-weigelt](https://forum.dfinity.org/u/michael-weigelt)\
**Post date:** [February 7, 2024, 5:28pm UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/19 "2024-02-07T17:28:33Z")

</div>

Hi gravity\_vi, please try out the PocketIC server v3.0.0

> **[Releases · dfinity/pocketic](https://github.com/dfinity/pocketic/releases)**
>
> A canister smart contract testing solution for the Internet Computer. - dfinity/pocketic

Don’t forget to also update your rust PocketIC library to version 2.1.0

---

<div class="post-metadata">

**Author:** ![gravity\_vi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gravity_vi/32/35810_2.png) [@gravity\_vi](https://forum.dfinity.org/u/gravity_vi)\
**Post date:** [February 8, 2024, 2:54pm UTC](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906/20 "2024-02-08T14:54:09Z")

</div>

Thank you so much @michael-weigelt

[Next page](https://forum.dfinity.org/t/testing-creation-of-canister-on-a-subnet-using-cycle-minting-canister-with-pocketic/26906.md?page=2)
