-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sns wrapper for nns-dapp (#137)
# Motivation For nns-dapp - and for any devs - we want to provide an easy way that loads all the canisters' actors of a particular sns and provide all features. # Changes - new `SnsWrapper` that contains all actors and wrap all features for a particular sns - `initSns` that query a particular root canister about other canister id and load all actor and provide the `SnsWrapper` - init `GovernanceCanister` and provide `listNeurons` - build bundle improved by chunking all code and making code also available in `index`
- Loading branch information
1 parent
b568756
commit 02c2b6f
Showing
37 changed files
with
590 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { Principal } from "@dfinity/principal"; | ||
import type { DeployedSns } from "../../candid/sns_wasm"; | ||
|
||
export const snsMock: DeployedSns[] = [ | ||
export const deployedSnsMock: DeployedSns[] = [ | ||
{ | ||
root_canister_id: [Principal.fromText("sp3hj-caaaa-aaaaa-aaajq-cai")], | ||
root_canister_id: [Principal.fromText("pin7y-wyaaa-aaaaa-aacpa-cai")], | ||
}, | ||
{ | ||
root_canister_id: [Principal.fromText("ryjl3-tyaaa-aaaaa-aaaba-cai")], | ||
root_canister_id: [Principal.fromText("zdlco-vyaaa-aaaaa-aabva-cai")], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { ActorSubclass } from "@dfinity/agent"; | ||
import { mock } from "jest-mock-extended"; | ||
import type { _SERVICE as SnsWasmService } from "../candid/sns_wasm"; | ||
import { snsMock } from "./mocks/sns_wasm.mock"; | ||
import { deployedSnsMock } from "./mocks/sns_wasm.mock"; | ||
import { SnsWasmCanister } from "./sns_wasm.canister"; | ||
|
||
describe("Sns-wasm", () => { | ||
it("should return the list of sns", async () => { | ||
const service = mock<ActorSubclass<SnsWasmService>>(); | ||
service.list_deployed_snses.mockResolvedValue({ | ||
instances: snsMock, | ||
instances: deployedSnsMock, | ||
}); | ||
|
||
const canister = SnsWasmCanister.create({ | ||
certifiedServiceOverride: service, | ||
}); | ||
const res = await canister.listSnses({}); | ||
expect(res).toEqual(snsMock); | ||
expect(res).toEqual(deployedSnsMock); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { _SERVICE as SnsWasmService } from "../../candid/sns_wasm"; | ||
import type { CanisterOptions } from "./canister.options"; | ||
|
||
export type SnsWasmCanisterOptions = CanisterOptions<SnsWasmService>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* A default length for the queried list of neurons | ||
* | ||
* Source: https://github.com/dfinity/ic/blob/master/rs/sns/governance/src/neuron.rs | ||
*/ | ||
export const MAX_LIST_NEURONS_RESULTS = 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { ActorSubclass } from "@dfinity/agent"; | ||
import { mock } from "jest-mock-extended"; | ||
import type { _SERVICE as SnsGovernanceCanister } from "../candid/sns_governance"; | ||
import { MAX_LIST_NEURONS_RESULTS } from "./constants/governance.constants"; | ||
import { GovernanceCanister } from "./governance.canister"; | ||
import { neuronsMock } from "./mocks/governance.mock"; | ||
import { rootCanisterIdMock } from "./mocks/sns.mock"; | ||
|
||
describe("Governance canister", () => { | ||
it("should return the list of neurons of the sns", async () => { | ||
const service = mock<ActorSubclass<SnsGovernanceCanister>>(); | ||
service.list_neurons.mockResolvedValue({ neurons: neuronsMock }); | ||
|
||
const canister = GovernanceCanister.create({ | ||
canisterId: rootCanisterIdMock, | ||
certifiedServiceOverride: service, | ||
}); | ||
const res = await canister.listNeurons({}); | ||
expect(res).toEqual(neuronsMock); | ||
}); | ||
|
||
it("should call list of neurons with default param", async () => { | ||
const service = mock<ActorSubclass<SnsGovernanceCanister>>(); | ||
const mockListNeurons = service.list_neurons.mockResolvedValue({ | ||
neurons: neuronsMock, | ||
}); | ||
|
||
const canister = GovernanceCanister.create({ | ||
canisterId: rootCanisterIdMock, | ||
certifiedServiceOverride: service, | ||
}); | ||
await canister.listNeurons({}); | ||
expect(mockListNeurons).toHaveBeenCalledWith({ | ||
limit: MAX_LIST_NEURONS_RESULTS, | ||
of_principal: [], | ||
start_page_at: [], | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.