Skip to content

Working with the NNS

If your canister interacts with NNS canisters, such as the ICP ledger, governance or the cycles minting canister, PocketIC can deploy them when the instance is created. Enable them with icpFeatures:

import { IcpFeaturesConfig, PocketIc } from '@dfinity/pic';
const pic = await PocketIc.create(process.env.PIC_URL, {
icpFeatures: {
icpToken: IcpFeaturesConfig.DefaultConfig,
nnsGovernance: IcpFeaturesConfig.DefaultConfig,
},
});

IcpFeaturesConfig.DefaultConfig configures each feature to resemble mainnet as closely as possible. The available features are:

FeatureDeploys
registryThe NNS registry canister, kept in sync with PocketIC’s internal registry
cyclesMintingThe cycles minting canister, with the ICP/XDR conversion rate set
icpTokenThe ICP ledger and index canisters; the anonymous principal starts with 1,000,000,000 ICP
cyclesTokenThe cycles ledger and index canisters; the anonymous principal starts with 2^127 - 1 cycles
nnsGovernanceThe NNS governance and root canisters, with a 1 ICP neuron controlled by the anonymous principal
snsThe SNS-W and aggregator canisters, with the SNS canister WASMs uploaded
iiThe Internet Identity backend and frontend canisters
nnsUiThe NNS dapp; requires cyclesMinting, icpToken, nnsGovernance, sns and ii

ii and nnsUi also deploy frontends, which PocketIC serves through an HTTP gateway created together with the instance. Set the httpGateway option, then make the instance live to serve them:

const pic = await PocketIc.create(process.env.PIC_URL, {
httpGateway: {},
icpFeatures: { ii: IcpFeaturesConfig.DefaultConfig },
});
const gatewayPort = await pic.makeLive();
const iiUrl = `http://uqzsh-gqaaa-aaaaq-qaada-cai.localhost:${gatewayPort}`;

Without httpGateway, creating an instance with either feature throws an error.

The subnets that host these canisters must be empty: leave them unconfigured or use SubnetStateType.New, as PocketIC rejects state loaded with SubnetStateType.FromPath. Enabling cyclesMinting also moves the instance’s default time to 10 May 2021, to match the cycles minting canister’s state.

Check out the NNS Proxy example for a full test that creates neurons and proposals against NNS governance.