|
| 1 | +import type { ConcordiumAccount } from "../types"; |
1 | 2 | import { createBridges } from "."; |
2 | 3 |
|
| 4 | +jest.mock("@ledgerhq/ledger-wallet-framework/bridge/jsHelpers", () => ({ |
| 5 | + getSerializedAddressParameters: jest.fn(), |
| 6 | + makeSync: jest.fn(() => jest.fn()), |
| 7 | + makeScanAccounts: jest.fn(() => jest.fn()), |
| 8 | + mergeOps: jest.fn(), |
| 9 | +})); |
| 10 | + |
| 11 | +jest.mock("../config", () => ({ |
| 12 | + __esModule: true, |
| 13 | + default: { setCoinConfig: jest.fn(), getCoinConfig: jest.fn() }, |
| 14 | +})); |
| 15 | + |
| 16 | +const { makeSync, makeScanAccounts } = jest.requireMock( |
| 17 | + "@ledgerhq/ledger-wallet-framework/bridge/jsHelpers", |
| 18 | +); |
| 19 | +const coinConfig = jest.requireMock("../config").default; |
| 20 | + |
| 21 | +type PostSync = (initial: ConcordiumAccount, synced: ConcordiumAccount) => ConcordiumAccount; |
| 22 | + |
| 23 | +const account = (subAccounts?: unknown[]): ConcordiumAccount => |
| 24 | + ({ |
| 25 | + id: "acc", |
| 26 | + currency: { id: "concordium_testnet" }, |
| 27 | + ...(subAccounts === undefined ? {} : { subAccounts }), |
| 28 | + }) as unknown as ConcordiumAccount; |
| 29 | + |
3 | 30 | describe("createBridges", () => { |
4 | 31 | it("has a currency bridge and an account bridge with required methods", () => { |
5 | 32 | expect(createBridges(undefined as any, {} as any)).toEqual({ |
@@ -28,3 +55,52 @@ describe("createBridges", () => { |
28 | 55 | }); |
29 | 56 | }); |
30 | 57 | }); |
| 58 | + |
| 59 | +/** |
| 60 | + * Token visibility is cleared in `postSync` rather than in the account shape, so |
| 61 | + * omitting it from either builder silently reintroduces the empty token section. |
| 62 | + */ |
| 63 | +describe("createBridges token visibility wiring", () => { |
| 64 | + const build = (enableTokens: boolean): { sync: PostSync; scan: PostSync } => { |
| 65 | + jest.clearAllMocks(); |
| 66 | + coinConfig.getCoinConfig.mockReturnValue({ enableTokens }); |
| 67 | + createBridges(undefined as never, {} as never); |
| 68 | + |
| 69 | + return { |
| 70 | + sync: makeSync.mock.calls[0][0].postSync, |
| 71 | + scan: makeScanAccounts.mock.calls[0][0].postSync, |
| 72 | + }; |
| 73 | + }; |
| 74 | + |
| 75 | + it("passes a postSync to both makeSync and makeScanAccounts", () => { |
| 76 | + const { sync, scan } = build(false); |
| 77 | + |
| 78 | + expect(sync).toEqual(expect.any(Function)); |
| 79 | + expect(scan).toEqual(expect.any(Function)); |
| 80 | + }); |
| 81 | + |
| 82 | + it.each([ |
| 83 | + ["sync", (b: { sync: PostSync; scan: PostSync }) => b.sync], |
| 84 | + ["scan", (b: { sync: PostSync; scan: PostSync }) => b.scan], |
| 85 | + ])("removes subAccounts on the %s path when tokens are off", (_name, pick) => { |
| 86 | + const result = pick(build(false))(account(), account([{ id: "sub" }])); |
| 87 | + |
| 88 | + expect("subAccounts" in result).toBe(false); |
| 89 | + }); |
| 90 | + |
| 91 | + it.each([ |
| 92 | + ["sync", (b: { sync: PostSync; scan: PostSync }) => b.sync], |
| 93 | + ["scan", (b: { sync: PostSync; scan: PostSync }) => b.scan], |
| 94 | + ])("keeps subAccounts on the %s path when tokens are on", (_name, pick) => { |
| 95 | + const built = build(true); |
| 96 | + const synced = account([{ id: "sub" }]); |
| 97 | + |
| 98 | + expect(pick(built)(account(), synced)).toBe(synced); |
| 99 | + }); |
| 100 | + |
| 101 | + it("reads the flag per currency, so one network can differ from the other", () => { |
| 102 | + build(false).sync(account(), account([])); |
| 103 | + |
| 104 | + expect(coinConfig.getCoinConfig).toHaveBeenCalledWith("concordium_testnet"); |
| 105 | + }); |
| 106 | +}); |
0 commit comments