PocketIc Test - call to canister_info fails. CanisterInfo SubnetNotFound

I’m calling update method using pocketIc.
The update method internally calls canister_info
Here is the brief code of test.

Code:

    let pocket_ic = PocketIcBuilder::new()
        .with_nns_subnet()
        .with_application_subnet()
        .with_application_subnet()
        .with_system_subnet()
        .build();
.
.
    pocket_ic
                .update_call(
            canister_id_1,
            principal_id_1,
            "update_which_calls_canister_info",
            candid::encode_one(principal_id_1).unwrap(),
        )...

Here is the brief code inside my update method. Here I check for canister_response.0.controllers and compare them to one of my expected values for further processing.

    match canister_info(CanisterInfoRequest {
        canister_id,
        num_requested_changes: None,
    })
    .await
    {
        Ok(canister_response) => {
// check canister_response.0.controllers
        }
        Err(error) => {}
    }

Here it fails when called from pocket_ic integration test. With below error.

DestinationInvalid : Unable to route management canister request canister_info: SubnetNotFound(CanisterId(2syes-usqll-dfpna-aiuxj-milj3-czoql-2wr3g-oy5nk-f6fvk-wvej2-mae), CanisterInfo)

How do I enable pocket ic to call canister_info from management canister?
Do i need to load management canister from wasm? If so, where to download from?
Is there any better way to run/test this in integration tests?

2 Likes

In the error message, I see

CanisterId(2syes-usqll-dfpna-aiuxj-milj3-czoql-2wr3g-oy5nk-f6fvk-wvej2-mae)

which is not a canister ID, but rather a user ID. So you’re calling canister_info on a user ID which causes the failure.

How do I enable pocket ic to call canister_info from management canister?

It is enabled by default, no specific action is needed. Please note that canister_info can only be invoked as an inter-canister call (not via an ingress message).

3 Likes

Thanks @mraszyk for pointing out the issue.

With my call to canister_info I was not passing canister id! I was passing user principal which was causing the issue.