Skip to content

Commit

Permalink
Update candid files (#691)
Browse files Browse the repository at this point in the history
# Motivation

The canisters APIs have been updated.
Based on the bot pr - #690

# Changes

* Update the listNeurons interface. Follow the same logic as for
includeEmptyNeurons (expecting the new field
`include_public_neurons_in_full_neurons` to be not yet supported by the
Ledger API).
* `npm run docs`.

# Tests`

- Unit tests were adjusted and extended to support the new field.

# Todos

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

---------

Co-authored-by: gix-bot <gix-bot@users.noreply.github.com>
  • Loading branch information
mstrasinskis and gix-bot authored Aug 6, 2024
1 parent 2cb316f commit c168456
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 41 deletions.
66 changes: 33 additions & 33 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 2b109fb9ba (2024-07-25) 'rs/nns/gtc/canister/gtc.did' by import-candid
// Generated from IC repo commit 3d0b3f1 (2024-08-02 tags: release-2024-08-02_01-30-base) 'rs/nns/gtc/canister/gtc.did' by import-candid
type AccountState = record {
authenticated_principal_id : opt principal;
successfully_transferred_neurons : vec TransferredNeuron;
Expand Down
3 changes: 3 additions & 0 deletions packages/nns/candid/governance.certified.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ export const idlFactory = ({ IDL }) => {
'not_dissolving_neurons_e8s_buckets_seed' : IDL.Vec(
IDL.Tuple(IDL.Nat64, IDL.Float64)
),
'public_neuron_subset_metrics' : IDL.Opt(NeuronSubsetMetrics),
'timestamp_seconds' : IDL.Nat64,
'seed_neuron_count' : IDL.Nat64,
});
Expand Down Expand Up @@ -730,6 +731,7 @@ export const idlFactory = ({ IDL }) => {
'known_neurons' : IDL.Vec(KnownNeuron),
});
const ListNeurons = IDL.Record({
'include_public_neurons_in_full_neurons' : IDL.Opt(IDL.Bool),
'neuron_ids' : IDL.Vec(IDL.Nat64),
'include_empty_neurons_readable_by_caller' : IDL.Opt(IDL.Bool),
'include_neurons_readable_by_caller' : IDL.Bool,
Expand Down Expand Up @@ -1333,6 +1335,7 @@ export const init = ({ IDL }) => {
'not_dissolving_neurons_e8s_buckets_seed' : IDL.Vec(
IDL.Tuple(IDL.Nat64, IDL.Float64)
),
'public_neuron_subset_metrics' : IDL.Opt(NeuronSubsetMetrics),
'timestamp_seconds' : IDL.Nat64,
'seed_neuron_count' : IDL.Nat64,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/nns/candid/governance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export interface GovernanceCachedMetrics {
total_staked_maturity_e8s_equivalent_seed: bigint;
community_fund_total_staked_e8s: bigint;
not_dissolving_neurons_e8s_buckets_seed: Array<[bigint, number]>;
public_neuron_subset_metrics: [] | [NeuronSubsetMetrics];
timestamp_seconds: bigint;
seed_neuron_count: bigint;
}
Expand Down Expand Up @@ -346,6 +347,7 @@ export interface ListKnownNeuronsResponse {
known_neurons: Array<KnownNeuron>;
}
export interface ListNeurons {
include_public_neurons_in_full_neurons: [] | [boolean];
neuron_ids: BigUint64Array | bigint[];
include_empty_neurons_readable_by_caller: [] | [boolean];
include_neurons_readable_by_caller: boolean;
Expand Down
4 changes: 3 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 2b109fb9ba (2024-07-25) 'rs/nns/governance/canister/governance.did' by import-candid
// Generated from IC repo commit 3d0b3f1 (2024-08-02 tags: release-2024-08-02_01-30-base) 'rs/nns/governance/canister/governance.did' by import-candid
type AccountIdentifier = record { hash : blob };
type Action = variant {
RegisterKnownNeuron : KnownNeuron;
Expand Down Expand Up @@ -237,6 +237,7 @@ type GovernanceCachedMetrics = record {
total_staked_maturity_e8s_equivalent_seed : nat64;
community_fund_total_staked_e8s : nat64;
not_dissolving_neurons_e8s_buckets_seed : vec record { nat64; float64 };
public_neuron_subset_metrics : opt NeuronSubsetMetrics;
timestamp_seconds : nat64;
seed_neuron_count : nat64;
};
Expand Down Expand Up @@ -285,6 +286,7 @@ type LedgerParameters = record {
};
type ListKnownNeuronsResponse = record { known_neurons : vec KnownNeuron };
type ListNeurons = record {
include_public_neurons_in_full_neurons : opt bool;
neuron_ids : vec nat64;
include_empty_neurons_readable_by_caller : opt bool;
include_neurons_readable_by_caller : bool;
Expand Down
3 changes: 3 additions & 0 deletions packages/nns/candid/governance.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ export const idlFactory = ({ IDL }) => {
'not_dissolving_neurons_e8s_buckets_seed' : IDL.Vec(
IDL.Tuple(IDL.Nat64, IDL.Float64)
),
'public_neuron_subset_metrics' : IDL.Opt(NeuronSubsetMetrics),
'timestamp_seconds' : IDL.Nat64,
'seed_neuron_count' : IDL.Nat64,
});
Expand Down Expand Up @@ -730,6 +731,7 @@ export const idlFactory = ({ IDL }) => {
'known_neurons' : IDL.Vec(KnownNeuron),
});
const ListNeurons = IDL.Record({
'include_public_neurons_in_full_neurons' : IDL.Opt(IDL.Bool),
'neuron_ids' : IDL.Vec(IDL.Nat64),
'include_empty_neurons_readable_by_caller' : IDL.Opt(IDL.Bool),
'include_neurons_readable_by_caller' : IDL.Bool,
Expand Down Expand Up @@ -1349,6 +1351,7 @@ export const init = ({ IDL }) => {
'not_dissolving_neurons_e8s_buckets_seed' : IDL.Vec(
IDL.Tuple(IDL.Nat64, IDL.Float64)
),
'public_neuron_subset_metrics' : IDL.Opt(NeuronSubsetMetrics),
'timestamp_seconds' : IDL.Nat64,
'seed_neuron_count' : IDL.Nat64,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/nns/candid/governance_test.certified.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ export const idlFactory = ({ IDL }) => {
'not_dissolving_neurons_e8s_buckets_seed' : IDL.Vec(
IDL.Tuple(IDL.Nat64, IDL.Float64)
),
'public_neuron_subset_metrics' : IDL.Opt(NeuronSubsetMetrics),
'timestamp_seconds' : IDL.Nat64,
'seed_neuron_count' : IDL.Nat64,
});
Expand Down Expand Up @@ -730,6 +731,7 @@ export const idlFactory = ({ IDL }) => {
'known_neurons' : IDL.Vec(KnownNeuron),
});
const ListNeurons = IDL.Record({
'include_public_neurons_in_full_neurons' : IDL.Opt(IDL.Bool),
'neuron_ids' : IDL.Vec(IDL.Nat64),
'include_empty_neurons_readable_by_caller' : IDL.Opt(IDL.Bool),
'include_neurons_readable_by_caller' : IDL.Bool,
Expand Down Expand Up @@ -1334,6 +1336,7 @@ export const init = ({ IDL }) => {
'not_dissolving_neurons_e8s_buckets_seed' : IDL.Vec(
IDL.Tuple(IDL.Nat64, IDL.Float64)
),
'public_neuron_subset_metrics' : IDL.Opt(NeuronSubsetMetrics),
'timestamp_seconds' : IDL.Nat64,
'seed_neuron_count' : IDL.Nat64,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/nns/candid/governance_test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export interface GovernanceCachedMetrics {
total_staked_maturity_e8s_equivalent_seed: bigint;
community_fund_total_staked_e8s: bigint;
not_dissolving_neurons_e8s_buckets_seed: Array<[bigint, number]>;
public_neuron_subset_metrics: [] | [NeuronSubsetMetrics];
timestamp_seconds: bigint;
seed_neuron_count: bigint;
}
Expand Down Expand Up @@ -346,6 +347,7 @@ export interface ListKnownNeuronsResponse {
known_neurons: Array<KnownNeuron>;
}
export interface ListNeurons {
include_public_neurons_in_full_neurons: [] | [boolean];
neuron_ids: BigUint64Array | bigint[];
include_empty_neurons_readable_by_caller: [] | [boolean];
include_neurons_readable_by_caller: boolean;
Expand Down
4 changes: 3 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 2b109fb9ba (2024-07-25) 'rs/nns/governance/canister/governance_test.did' by import-candid
// Generated from IC repo commit 3d0b3f1 (2024-08-02 tags: release-2024-08-02_01-30-base) 'rs/nns/governance/canister/governance_test.did' by import-candid
type AccountIdentifier = record { hash : blob };
type Action = variant {
RegisterKnownNeuron : KnownNeuron;
Expand Down Expand Up @@ -237,6 +237,7 @@ type GovernanceCachedMetrics = record {
total_staked_maturity_e8s_equivalent_seed : nat64;
community_fund_total_staked_e8s : nat64;
not_dissolving_neurons_e8s_buckets_seed : vec record { nat64; float64 };
public_neuron_subset_metrics : opt NeuronSubsetMetrics;
timestamp_seconds : nat64;
seed_neuron_count : nat64;
};
Expand Down Expand Up @@ -285,6 +286,7 @@ type LedgerParameters = record {
};
type ListKnownNeuronsResponse = record { known_neurons : vec KnownNeuron };
type ListNeurons = record {
include_public_neurons_in_full_neurons : opt bool;
neuron_ids : vec nat64;
include_empty_neurons_readable_by_caller : opt bool;
include_neurons_readable_by_caller : bool;
Expand Down
3 changes: 3 additions & 0 deletions packages/nns/candid/governance_test.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ export const idlFactory = ({ IDL }) => {
'not_dissolving_neurons_e8s_buckets_seed' : IDL.Vec(
IDL.Tuple(IDL.Nat64, IDL.Float64)
),
'public_neuron_subset_metrics' : IDL.Opt(NeuronSubsetMetrics),
'timestamp_seconds' : IDL.Nat64,
'seed_neuron_count' : IDL.Nat64,
});
Expand Down Expand Up @@ -730,6 +731,7 @@ export const idlFactory = ({ IDL }) => {
'known_neurons' : IDL.Vec(KnownNeuron),
});
const ListNeurons = IDL.Record({
'include_public_neurons_in_full_neurons' : IDL.Opt(IDL.Bool),
'neuron_ids' : IDL.Vec(IDL.Nat64),
'include_empty_neurons_readable_by_caller' : IDL.Opt(IDL.Bool),
'include_neurons_readable_by_caller' : IDL.Bool,
Expand Down Expand Up @@ -1350,6 +1352,7 @@ export const init = ({ IDL }) => {
'not_dissolving_neurons_e8s_buckets_seed' : IDL.Vec(
IDL.Tuple(IDL.Nat64, IDL.Float64)
),
'public_neuron_subset_metrics' : IDL.Opt(NeuronSubsetMetrics),
'timestamp_seconds' : IDL.Nat64,
'seed_neuron_count' : IDL.Nat64,
});
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 2b109fb9ba (2024-07-25) 'rs/nns/sns-wasm/canister/sns-wasm.did' by import-candid
// Generated from IC repo commit 3d0b3f1 (2024-08-02 tags: release-2024-08-02_01-30-base) 'rs/nns/sns-wasm/canister/sns-wasm.did' by import-candid
type AddWasmRequest = record { hash : blob; wasm : opt SnsWasm };
type AddWasmResponse = record { result : opt Result };
type AirdropDistribution = record { airdrop_neurons : vec NeuronDistribution };
Expand Down
3 changes: 3 additions & 0 deletions packages/nns/src/canisters/governance/request.converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,16 @@ const fromClaimOrRefreshBy = (by: By): RawBy => {
export const fromListNeurons = ({
neuronIds,
includeEmptyNeurons,
includePublicNeurons,
}: {
neuronIds?: NeuronId[];
includeEmptyNeurons?: boolean;
includePublicNeurons?: boolean;
}): 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),
});

export const fromManageNeuron = ({
Expand Down
30 changes: 30 additions & 0 deletions packages/nns/src/governance.canister.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,13 @@ describe("GovernanceCanister", () => {
const neurons = await governance.listNeurons({
certified: true,
includeEmptyNeurons: true,
includePublicNeurons: true,
});
expect(certifiedService.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],
});
expect(certifiedService.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand All @@ -480,6 +482,31 @@ describe("GovernanceCanister", () => {
neuron_ids: new BigUint64Array(),
include_neurons_readable_by_caller: true,
include_empty_neurons_readable_by_caller: [false],
include_public_neurons_in_full_neurons: [],
});
expect(service.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
});

it("list user neurons excluding public neurons", 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,
includePublicNeurons: false,
});
expect(service.list_neurons).toBeCalledWith({
neuron_ids: new BigUint64Array(),
include_neurons_readable_by_caller: true,
include_empty_neurons_readable_by_caller: [],
include_public_neurons_in_full_neurons: [false],
});
expect(service.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand All @@ -503,6 +530,8 @@ describe("GovernanceCanister", () => {
include_neurons_readable_by_caller: true,
// The field is present in the argument but ignored by the old service.
include_empty_neurons_readable_by_caller: [],
// The field is present in the argument but ignored by the old service.
include_public_neurons_in_full_neurons: [],
});
expect(oldService.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand All @@ -527,6 +556,7 @@ describe("GovernanceCanister", () => {
neuron_ids: new BigUint64Array(),
include_neurons_readable_by_caller: true,
include_empty_neurons_readable_by_caller: [],
include_public_neurons_in_full_neurons: [],
});
expect(service.list_neurons).toBeCalledTimes(1);
expect(neurons.length).toBe(1);
Expand Down
18 changes: 14 additions & 4 deletions packages/nns/src/governance.canister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,28 @@ export class GovernanceCanister {
certified = true,
neuronIds,
includeEmptyNeurons,
includePublicNeurons,
}: {
certified: boolean;
neuronIds?: NeuronId[];
includeEmptyNeurons?: boolean;
includePublicNeurons?: boolean;
}): Promise<NeuronInfo[]> => {
const rawRequest = fromListNeurons({ neuronIds, includeEmptyNeurons });
const rawRequest = fromListNeurons({
neuronIds,
includeEmptyNeurons,
includePublicNeurons,
});
// The Ledger app version 2.4.9 does not support
// include_empty_neurons_readable_by_caller, even when the field is absent,
// so we use the old service (which does not have this field) if possible,
// include_empty_neurons_readable_by_caller nor include_public_neurons_in_full_neurons,
// even when the field is absent,
// so we use the old service (which does not have these fields) if possible,
// in case the call will be signed by the Ledger device. We only have a
// certified version of the old service.
const useOldMethod = isNullish(includeEmptyNeurons) && certified;
const useOldMethod =
isNullish(includeEmptyNeurons) &&
isNullish(includePublicNeurons) &&
certified;
const service = useOldMethod
? this.oldListNeuronsCertifiedService
: this.getGovernanceService(certified);
Expand Down

0 comments on commit c168456

Please sign in to comment.