-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move getLedgerCanisterIdFromUniverse to utils (#6002)
# Motivation Token prices in USD are looked up based on the ledger canister ID. `frontend/src/lib/derived/tokens-list-base.derived.ts` has a function `getLedgerCanisterIdFromUniverse` to get the ledger canister ID of a universe. This will be useful for the USD values of neuron stakes as well. # Changes Move `getLedgerCanisterIdFromUniverse` form `frontend/src/lib/derived/tokens-list-base.derived.ts` to `frontend/src/lib/utils/universe.utils.ts`. # Tests 1. Unit tests added. 2. Existing tests continue to pass. # Todos - [ ] Add entry to changelog (if necessary). not necessary
- Loading branch information
Showing
3 changed files
with
67 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { LEDGER_CANISTER_ID } from "$lib/constants/canister-ids.constants"; | ||
import { CKBTC_LEDGER_CANISTER_ID } from "$lib/constants/ckbtc-canister-ids.constants"; | ||
import { nnsUniverseStore } from "$lib/derived//nns-universe.derived"; | ||
import { ckBTCUniverseStore } from "$lib/derived/ckbtc-universe.derived"; | ||
import { snsSummariesStore } from "$lib/stores/sns.store"; | ||
import { | ||
createUniverse, | ||
getLedgerCanisterIdFromUniverse, | ||
} from "$lib/utils/universe.utils"; | ||
import { principal } from "$tests/mocks/sns-projects.mock"; | ||
import { setSnsProjects } from "$tests/utils/sns.test-utils"; | ||
import { get } from "svelte/store"; | ||
|
||
describe("universe.utils", () => { | ||
describe("getLedgerCanisterIdFromUniverse", () => { | ||
const nnsUniverse = get(nnsUniverseStore); | ||
const ckBtcUniverse = get(ckBTCUniverseStore); | ||
|
||
it("should return the ledger canister ID for the NNS universe", () => { | ||
expect(getLedgerCanisterIdFromUniverse(nnsUniverse)).toBe( | ||
LEDGER_CANISTER_ID | ||
); | ||
}); | ||
|
||
it("should return the ledger canister ID for the ckBTC universe", () => { | ||
expect(getLedgerCanisterIdFromUniverse(ckBtcUniverse).toText()).toBe( | ||
CKBTC_LEDGER_CANISTER_ID.toText() | ||
); | ||
}); | ||
|
||
it("should return the ledger canister ID for an SNS universe", () => { | ||
const rootCanisterId = principal(0); | ||
const ledgerCanisterId = principal(1); | ||
setSnsProjects([ | ||
{ | ||
rootCanisterId, | ||
ledgerCanisterId, | ||
}, | ||
]); | ||
const snsSummaries = get(snsSummariesStore); | ||
expect(snsSummaries).toHaveLength(1); | ||
const snsUniverse = createUniverse(snsSummaries[0]); | ||
expect(getLedgerCanisterIdFromUniverse(snsUniverse).toText()).toBe( | ||
ledgerCanisterId.toText() | ||
); | ||
}); | ||
}); | ||
}); |