Skip to content

Commit

Permalink
chore: update nns Candid Files (#838)
Browse files Browse the repository at this point in the history
# Motivation

#837 is currently blocked because a new field in the `list_neurons`
requests is breaking our tests. This PR unblocks it by updating the
tests and exposing this new parameter.

This PR addresses just the issues in the nns package.

# Changes

- Checkout ic at `14c8f44`
- Ran `./scripts/import-candid ../ic` from ic-js root folder 
- Ran `./scripts/compile-idl-js` from ic-js root folder 
- Revert changes not related to the `nns` package
- Fix `fromListNeurons` type 
- Exposed `neuron_subaccounts` through `listNeurons`
- Updated expectations for tests based on the new API

# Tests

- Should pass as before

# Todos

- [x] Add entry to changelog (if necessary).

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
yhabib and github-actions[bot] authored Feb 10, 2025
1 parent ffedd0e commit d484d70
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

- Support `NervousSystemParameters.automatically_advance_target_version` in `@dfinity/sns`.
- Add converters to encode or decode base64 string into Uint8Array.
- Support `neuron_subaccounts` in `list_neurons` from `@dfinity/nns`.

# 2025.01.20-1800Z

Expand Down
74 changes: 37 additions & 37 deletions packages/nns/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/nns/candid/genesis_token.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from IC repo commit fb16293 (2025-01-22 tags: release-2025-01-30_03-03-hashes-in-blocks) 'rs/nns/gtc/canister/gtc.did' by import-candid
// Generated from IC repo commit 14c8f44cd6 (2025-02-07 tags: release-2025-02-06_12-26-revert-hashes-in-blocks) 'rs/nns/gtc/canister/gtc.did' by import-candid
type AccountState = record {
authenticated_principal_id : opt principal;
successfully_transferred_neurons : vec TransferredNeuron;
Expand Down
2 changes: 2 additions & 0 deletions packages/nns/candid/governance.certified.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,14 @@ export const idlFactory = ({ IDL }) => {
const ListKnownNeuronsResponse = IDL.Record({
'known_neurons' : IDL.Vec(KnownNeuron),
});
const NeuronSubaccount = IDL.Record({ 'subaccount' : IDL.Vec(IDL.Nat8) });
const ListNeurons = IDL.Record({
'page_size' : IDL.Opt(IDL.Nat64),
'include_public_neurons_in_full_neurons' : IDL.Opt(IDL.Bool),
'neuron_ids' : IDL.Vec(IDL.Nat64),
'page_number' : IDL.Opt(IDL.Nat64),
'include_empty_neurons_readable_by_caller' : IDL.Opt(IDL.Bool),
'neuron_subaccounts' : IDL.Opt(IDL.Vec(NeuronSubaccount)),
'include_neurons_readable_by_caller' : IDL.Bool,
});
const ListNeuronsResponse = IDL.Record({
Expand Down
4 changes: 4 additions & 0 deletions packages/nns/candid/governance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export interface ListNeurons {
neuron_ids: BigUint64Array | bigint[];
page_number: [] | [bigint];
include_empty_neurons_readable_by_caller: [] | [boolean];
neuron_subaccounts: [] | [Array<NeuronSubaccount>];
include_neurons_readable_by_caller: boolean;
}
export interface ListNeuronsResponse {
Expand Down Expand Up @@ -554,6 +555,9 @@ export interface NeuronStakeTransfer {
transfer_timestamp: bigint;
block_height: bigint;
}
export interface NeuronSubaccount {
subaccount: Uint8Array | number[];
}
export interface NeuronSubsetMetrics {
total_maturity_e8s_equivalent: [] | [bigint];
maturity_e8s_equivalent_buckets: Array<[bigint, bigint]>;
Expand Down
7 changes: 6 additions & 1 deletion packages/nns/candid/governance.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from IC repo commit fb16293 (2025-01-22 tags: release-2025-01-30_03-03-hashes-in-blocks) 'rs/nns/governance/canister/governance.did' by import-candid
// Generated from IC repo commit 14c8f44cd6 (2025-02-07 tags: release-2025-02-06_12-26-revert-hashes-in-blocks) 'rs/nns/governance/canister/governance.did' by import-candid
type AccountIdentifier = record {
hash : blob;
};
Expand Down Expand Up @@ -451,6 +451,11 @@ type ListNeurons = record {

page_number: opt nat64;
page_size: opt nat64;
neuron_subaccounts: opt vec NeuronSubaccount;
};

type NeuronSubaccount = record {
subaccount : blob;
};

// Output of the list_neurons method.
Expand Down
2 changes: 2 additions & 0 deletions packages/nns/candid/governance.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,14 @@ export const idlFactory = ({ IDL }) => {
const ListKnownNeuronsResponse = IDL.Record({
'known_neurons' : IDL.Vec(KnownNeuron),
});
const NeuronSubaccount = IDL.Record({ 'subaccount' : IDL.Vec(IDL.Nat8) });
const ListNeurons = IDL.Record({
'page_size' : IDL.Opt(IDL.Nat64),
'include_public_neurons_in_full_neurons' : IDL.Opt(IDL.Bool),
'neuron_ids' : IDL.Vec(IDL.Nat64),
'page_number' : IDL.Opt(IDL.Nat64),
'include_empty_neurons_readable_by_caller' : IDL.Opt(IDL.Bool),
'neuron_subaccounts' : IDL.Opt(IDL.Vec(NeuronSubaccount)),
'include_neurons_readable_by_caller' : IDL.Bool,
});
const ListNeuronsResponse = IDL.Record({
Expand Down
2 changes: 2 additions & 0 deletions packages/nns/candid/governance_test.certified.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,14 @@ export const idlFactory = ({ IDL }) => {
const ListKnownNeuronsResponse = IDL.Record({
'known_neurons' : IDL.Vec(KnownNeuron),
});
const NeuronSubaccount = IDL.Record({ 'subaccount' : IDL.Vec(IDL.Nat8) });
const ListNeurons = IDL.Record({
'page_size' : IDL.Opt(IDL.Nat64),
'include_public_neurons_in_full_neurons' : IDL.Opt(IDL.Bool),
'neuron_ids' : IDL.Vec(IDL.Nat64),
'page_number' : IDL.Opt(IDL.Nat64),
'include_empty_neurons_readable_by_caller' : IDL.Opt(IDL.Bool),
'neuron_subaccounts' : IDL.Opt(IDL.Vec(NeuronSubaccount)),
'include_neurons_readable_by_caller' : IDL.Bool,
});
const ListNeuronsResponse = IDL.Record({
Expand Down
4 changes: 4 additions & 0 deletions packages/nns/candid/governance_test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export interface ListNeurons {
neuron_ids: BigUint64Array | bigint[];
page_number: [] | [bigint];
include_empty_neurons_readable_by_caller: [] | [boolean];
neuron_subaccounts: [] | [Array<NeuronSubaccount>];
include_neurons_readable_by_caller: boolean;
}
export interface ListNeuronsResponse {
Expand Down Expand Up @@ -554,6 +555,9 @@ export interface NeuronStakeTransfer {
transfer_timestamp: bigint;
block_height: bigint;
}
export interface NeuronSubaccount {
subaccount: Uint8Array | number[];
}
export interface NeuronSubsetMetrics {
total_maturity_e8s_equivalent: [] | [bigint];
maturity_e8s_equivalent_buckets: Array<[bigint, bigint]>;
Expand Down
7 changes: 6 additions & 1 deletion packages/nns/candid/governance_test.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from IC repo commit fb16293 (2025-01-22 tags: release-2025-01-30_03-03-hashes-in-blocks) 'rs/nns/governance/canister/governance_test.did' by import-candid
// Generated from IC repo commit 14c8f44cd6 (2025-02-07 tags: release-2025-02-06_12-26-revert-hashes-in-blocks) 'rs/nns/governance/canister/governance_test.did' by import-candid
type AccountIdentifier = record {
hash : blob;
};
Expand Down Expand Up @@ -441,6 +441,11 @@ type ListNeurons = record {
include_neurons_readable_by_caller : bool;
page_number: opt nat64;
page_size: opt nat64;
neuron_subaccounts: opt vec NeuronSubaccount;
};

type NeuronSubaccount = record {
subaccount : blob;
};

type ListNeuronsResponse = record {
Expand Down
2 changes: 2 additions & 0 deletions packages/nns/candid/governance_test.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,14 @@ export const idlFactory = ({ IDL }) => {
const ListKnownNeuronsResponse = IDL.Record({
'known_neurons' : IDL.Vec(KnownNeuron),
});
const NeuronSubaccount = IDL.Record({ 'subaccount' : IDL.Vec(IDL.Nat8) });
const ListNeurons = IDL.Record({
'page_size' : IDL.Opt(IDL.Nat64),
'include_public_neurons_in_full_neurons' : IDL.Opt(IDL.Bool),
'neuron_ids' : IDL.Vec(IDL.Nat64),
'page_number' : IDL.Opt(IDL.Nat64),
'include_empty_neurons_readable_by_caller' : IDL.Opt(IDL.Bool),
'neuron_subaccounts' : IDL.Opt(IDL.Vec(NeuronSubaccount)),
'include_neurons_readable_by_caller' : IDL.Bool,
});
const ListNeuronsResponse = IDL.Record({
Expand Down
2 changes: 1 addition & 1 deletion packages/nns/candid/sns_wasm.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from IC repo commit fb16293 (2025-01-22 tags: release-2025-01-30_03-03-hashes-in-blocks) 'rs/nns/sns-wasm/canister/sns-wasm.did' by import-candid
// Generated from IC repo commit 14c8f44cd6 (2025-02-07 tags: release-2025-02-06_12-26-revert-hashes-in-blocks) 'rs/nns/sns-wasm/canister/sns-wasm.did' by import-candid
type AddWasmRequest = record {
hash : blob;
wasm : opt SnsWasm;
Expand Down
4 changes: 4 additions & 0 deletions packages/nns/src/canisters/governance/request.converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import type {
Amount,
ListProposalInfo,
NeuronSubaccount,
AccountIdentifier as RawAccountIdentifier,
ProposalActionRequest as RawAction,
By as RawBy,
Expand Down Expand Up @@ -1017,17 +1018,20 @@ export const fromListNeurons = ({
neuronIds,
includeEmptyNeurons,
includePublicNeurons,
neuronSubaccounts,
}: {
neuronIds?: NeuronId[];
includeEmptyNeurons?: boolean;
includePublicNeurons?: boolean;
neuronSubaccounts?: NeuronSubaccount[];
}): RawListNeurons => ({
neuron_ids: BigUint64Array.from(neuronIds ?? []),
include_neurons_readable_by_caller: neuronIds ? false : true,
include_empty_neurons_readable_by_caller: toNullable(includeEmptyNeurons),
include_public_neurons_in_full_neurons: toNullable(includePublicNeurons),
page_number: [],
page_size: [],
neuron_subaccounts: toNullable(neuronSubaccounts),
});

export const fromManageNeuron = ({
Expand Down
43 changes: 43 additions & 0 deletions packages/nns/src/governance.canister.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ describe("GovernanceCanister", () => {
include_public_neurons_in_full_neurons: [true],
page_number: [],
page_size: [],
neuron_subaccounts: [],
});
expect(certifiedService.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand Down Expand Up @@ -479,6 +480,7 @@ describe("GovernanceCanister", () => {
include_public_neurons_in_full_neurons: [],
page_number: [],
page_size: [],
neuron_subaccounts: [],
});
expect(service.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand All @@ -505,6 +507,44 @@ describe("GovernanceCanister", () => {
include_public_neurons_in_full_neurons: [false],
page_number: [],
page_size: [],
neuron_subaccounts: [],
});
expect(service.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
});

it("list user neurons by neurons sub-account", async () => {
const service = mock<ActorSubclass<GovernanceService>>();
const oldService = mock<ActorSubclass<GovernanceService>>();
service.list_neurons.mockResolvedValue(mockListNeuronsResponse);

const governance = GovernanceCanister.create({
certifiedServiceOverride: service,
serviceOverride: service,
oldListNeuronsServiceOverride: oldService,
});
const neurons = await governance.listNeurons({
certified: true,
includeEmptyNeurons: true,
includePublicNeurons: true,
neuronSubaccounts: [
{ subaccount: new Uint8Array([1, 2, 3]) },
{ subaccount: new Uint8Array([4, 5, 6]) },
],
});
expect(service.list_neurons).toBeCalledWith({
neuron_ids: new BigUint64Array(),
include_neurons_readable_by_caller: true,
include_empty_neurons_readable_by_caller: [true],
include_public_neurons_in_full_neurons: [true],
page_number: [],
page_size: [],
neuron_subaccounts: [
[
{ subaccount: new Uint8Array([1, 2, 3]) },
{ subaccount: new Uint8Array([4, 5, 6]) },
],
],
});
expect(service.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand Down Expand Up @@ -534,6 +574,8 @@ describe("GovernanceCanister", () => {
page_number: [],
// The field is present in the argument but ignored by the old service.
page_size: [],
// The field is present in the argument but ignored by the old service.
neuron_subaccounts: [],
});
expect(oldService.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand Down Expand Up @@ -561,6 +603,7 @@ describe("GovernanceCanister", () => {
include_public_neurons_in_full_neurons: [],
page_number: [],
page_size: [],
neuron_subaccounts: [],
});
expect(service.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand Down
4 changes: 4 additions & 0 deletions packages/nns/src/governance.canister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
_SERVICE as GovernanceService,
ListProposalInfo,
MergeResponse,
NeuronSubaccount,
Neuron as RawNeuron,
NeuronInfo as RawNeuronInfo,
ProposalInfo as RawProposalInfo,
Expand Down Expand Up @@ -148,16 +149,19 @@ export class GovernanceCanister {
neuronIds,
includeEmptyNeurons,
includePublicNeurons,
neuronSubaccounts,
}: {
certified: boolean;
neuronIds?: NeuronId[];
includeEmptyNeurons?: boolean;
includePublicNeurons?: boolean;
neuronSubaccounts?: NeuronSubaccount[];
}): Promise<NeuronInfo[]> => {
const rawRequest = fromListNeurons({
neuronIds,
includeEmptyNeurons,
includePublicNeurons,
neuronSubaccounts,
});
// The Ledger app version 2.4.9 does not support
// include_empty_neurons_readable_by_caller nor include_public_neurons_in_full_neurons,
Expand Down

0 comments on commit d484d70

Please sign in to comment.