-
Notifications
You must be signed in to change notification settings - Fork 37
test(wallet-sdk): init sdk unit tests #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mateuszpiatkowski-da
wants to merge
17
commits into
main
Choose a base branch
from
mateuszpiatkowski-da/init-sdk-unit-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1267c60
test(wallet-sdk): add party namespace tests
mateuszpiatkowski-da 59d7737
chore: signing security disclaimer (#1984)
mjuchli-da d8adf6b
feat(example-portfolio): support configured token registries (#1972)
fayi-da 21b0b68
test: wallet sdk keys namespace test (#1973)
rukmini-basu-da 33f4171
feat: implement offers page in portfolio (#1989)
fayi-da 2339c45
feat: display list of suggested wallet extensions (#1987)
alexmatson-da 764c549
test: wallet-sdk asset namespace test (#1969)
rukmini-basu-da 9c72515
chore: update yarn (#1993)
alexmatson-da d8417f8
test: wallet sdk logging package and utils (#1986)
rukmini-basu-da c3b29d1
feat: deliver CIP-103 push events through DappSyncProvider (#1814)
alleneubank 0934f4e
chore(deps-dev): bump esbuild from 0.27.3 to 0.28.1 (#1996)
dependabot[bot] 137352c
Add wallet SDK npm metadata (#1966)
yanziwei b19a598
test(wallet-sdk): start writing tests for init SDK
mateuszpiatkowski-da 3d829a9
refactor(wallet-sdk): change type imports
mateuszpiatkowski-da 1db652a
test(wallet-sdk): add tests for plugin system
mateuszpiatkowski-da 6de11ad
test(wallet-sdk): finalize init sdk unit tests
mateuszpiatkowski-da 3281a47
Merge branch 'main' into mateuszpiatkowski-da/init-sdk-unit-tests
mateuszpiatkowski-da File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,172 @@ | ||
| // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import * as mock from '../../__test__/mocks' | ||
| import { | ||
| InitializedSDK, | ||
| OfflineInitializedSDK, | ||
| ExtendedInitializedSDK, | ||
| } from '../..' | ||
| import { KeysNamespace } from '../../namespace/keys' | ||
| import { SDKUtilsNamespace } from '../../namespace/utils' | ||
| import { LedgerNamespace } from '../../namespace/ledger' | ||
| import { PartyNamespace } from '../../namespace/party' | ||
| import { UserNamespace } from '../../namespace/user' | ||
| import { AmuletNamespace } from '../../namespace/amulet' | ||
| import { AssetNamespace } from '../../namespace/asset' | ||
| import { EventsNamespace } from '../../namespace/events' | ||
| import { TokenNamespace } from '../../namespace/token' | ||
|
|
||
| const { | ||
| ValidatorInternalClient, | ||
| get, | ||
| TokenStandardService, | ||
| AmuletService, | ||
| ScanProxyClient, | ||
| ScanClient, | ||
| } = vi.hoisted(() => { | ||
| const get = vi.fn().mockImplementation(() => | ||
| Promise.resolve({ | ||
| party_id: 'partyId', | ||
| }) | ||
| ) | ||
|
|
||
| const registriesToAssets = vi.fn().mockResolvedValue([]) | ||
|
|
||
| return { | ||
| ValidatorInternalClient: vi.fn( | ||
| class { | ||
| get = get | ||
| } | ||
| ), | ||
| get, | ||
| TokenStandardService: vi.fn( | ||
| class { | ||
| registriesToAssets = registriesToAssets | ||
| } | ||
| ), | ||
| AmuletService: vi.fn(class {}), | ||
| ScanProxyClient: vi.fn(class {}), | ||
| ScanClient: vi.fn(class {}), | ||
| } | ||
| }) | ||
|
|
||
| vi.mock('@canton-network/core-splice-client', async (importOriginal) => { | ||
| const actual = | ||
| await importOriginal< | ||
| typeof import('@canton-network/core-splice-client') | ||
| >() | ||
| return { | ||
| ...actual, | ||
| ValidatorInternalClient, | ||
| ScanProxyClient, | ||
| ScanClient, | ||
| } | ||
| }) | ||
|
|
||
| vi.mock('@canton-network/core-token-standard-service', () => ({ | ||
| TokenStandardService, | ||
| })) | ||
|
|
||
| vi.mock('@canton-network/core-amulet-service', () => ({ | ||
| AmuletService, | ||
| })) | ||
|
|
||
| describe('init SDK', () => { | ||
| describe('offline', () => { | ||
| let sdk: OfflineInitializedSDK | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
|
|
||
| sdk = new OfflineInitializedSDK(mock.ctx) | ||
| }) | ||
|
|
||
| it('should expose offline interface', () => { | ||
| expect(sdk.keys).toBeInstanceOf(KeysNamespace) | ||
| expect(sdk.utils).toBeInstanceOf(SDKUtilsNamespace) | ||
| }) | ||
| }) | ||
|
|
||
| describe('basic', () => { | ||
| let sdk: InitializedSDK | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
|
|
||
| sdk = new InitializedSDK(mock.ctx) | ||
| }) | ||
|
|
||
| it('should expose basic interface', () => { | ||
| sdk = new InitializedSDK(mock.ctx) | ||
|
|
||
| // OfflineSDKInterface | ||
| expect(sdk.keys).toBeInstanceOf(KeysNamespace) | ||
| expect(sdk.utils).toBeInstanceOf(SDKUtilsNamespace) | ||
|
|
||
| // BasicSDKInterface | ||
| expect(sdk.ledger).toBeInstanceOf(LedgerNamespace) | ||
| expect(sdk.party).toBeInstanceOf(PartyNamespace) | ||
| expect(sdk.user).toBeInstanceOf(UserNamespace) | ||
| expect(sdk.registerPlugins).toBeDefined() | ||
| }) | ||
| }) | ||
|
|
||
| describe('extended', () => { | ||
| beforeEach(async () => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it('should expose extended interface', async () => { | ||
| const sdk = await ExtendedInitializedSDK.create(mock.ctx, { | ||
| amulet: mock.amuletConfig, | ||
| asset: mock.assetConfig, | ||
| events: mock.eventsConfig, | ||
| token: mock.tokenConfig, | ||
| }) | ||
|
|
||
| // OfflineSDKInterface | ||
| expect(sdk.keys).toBeInstanceOf(KeysNamespace) | ||
| expect(sdk.utils).toBeInstanceOf(SDKUtilsNamespace) | ||
|
|
||
| // BasicSDKInterface | ||
| expect(sdk.ledger).toBeInstanceOf(LedgerNamespace) | ||
| expect(sdk.party).toBeInstanceOf(PartyNamespace) | ||
| expect(sdk.user).toBeInstanceOf(UserNamespace) | ||
| expect(sdk.registerPlugins).toBeDefined() | ||
|
|
||
| // ExtendedInitializedSDK | ||
| expect(sdk.amulet).toBeInstanceOf(AmuletNamespace) | ||
| expect(sdk.asset).toBeInstanceOf(AssetNamespace) | ||
| expect(sdk.events).toBeInstanceOf(EventsNamespace) | ||
| expect(sdk.token).toBeInstanceOf(TokenNamespace) | ||
| }) | ||
|
|
||
| it('should create amulet namespace based on services', async () => { | ||
| await ExtendedInitializedSDK.create(mock.ctx, { | ||
| amulet: mock.amuletConfig, | ||
| }) | ||
|
|
||
| expect(ScanClient).toHaveBeenCalledOnce() | ||
| expect(ScanProxyClient).toHaveBeenCalledOnce() | ||
| expect(TokenStandardService).toHaveBeenCalledOnce() | ||
| expect(AmuletService).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('should create token namespace based on services', async () => { | ||
| await ExtendedInitializedSDK.create(mock.ctx, { | ||
| token: mock.tokenConfig, | ||
| }) | ||
|
|
||
| expect(get).toHaveBeenCalledOnce() | ||
| expect(TokenStandardService).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('should create asset namespace based on services', async () => { | ||
| await ExtendedInitializedSDK.create(mock.ctx, { | ||
| asset: mock.assetConfig, | ||
| }) | ||
|
|
||
| expect(TokenStandardService).toHaveBeenCalledOnce() | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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,90 @@ | ||
| // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { EXTENDED_SDK_OPTION_KEYS, SDKPlugin } from '../' | ||
| import * as mock from '../../__test__/mocks' | ||
| import { SDK, SDKContext } from '../..' | ||
|
|
||
| const testPluginFactory = (key: string) => { | ||
| return vi.fn( | ||
| class extends SDKPlugin { | ||
| constructor(ctx: SDKContext) { | ||
| super(key, ctx) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| const pluginName = 'pluginName' | ||
|
|
||
| class TestPlugin extends SDKPlugin { | ||
| constructor(ctx: SDKContext) { | ||
| super(pluginName, ctx) | ||
| } | ||
|
|
||
| public testMethod() { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| describe('plugin', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| EXTENDED_SDK_OPTION_KEYS.forEach((key) => { | ||
| it(`should throw error if ${key} is used as a name`, () => { | ||
| expect(() => new (testPluginFactory(key))(mock.ctx)).toThrow() | ||
| }) | ||
| }) | ||
|
|
||
| it('should call a plugin constructor when registering', async () => { | ||
| // Mock the authenticated user response | ||
| mock.ledgerProvider.request | ||
| .mockResolvedValueOnce({ | ||
| user: { id: 'test-user-id' }, | ||
| }) | ||
| // Mock the connected synchronizers response | ||
| .mockResolvedValueOnce({ | ||
| connectedSynchronizers: [{ id: 'sync-1' }], | ||
| }) | ||
|
|
||
| const sdk = await SDK.create({ | ||
| ledgerProvider: mock.ledgerProvider as never, | ||
| }) | ||
|
|
||
| const PluginClass = testPluginFactory('plugin') | ||
|
|
||
| const SDKWithPlugin = sdk.registerPlugins({ | ||
| plugin: PluginClass, | ||
| }) | ||
|
|
||
| expect(SDKWithPlugin.plugin).toBeInstanceOf(PluginClass) | ||
| expect(PluginClass).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('should successfully register a plugin under provided name', async () => { | ||
| // Mock the authenticated user response | ||
| mock.ledgerProvider.request | ||
| .mockResolvedValueOnce({ | ||
| user: { id: 'test-user-id' }, | ||
| }) | ||
| // Mock the connected synchronizers response | ||
| .mockResolvedValueOnce({ | ||
| connectedSynchronizers: [{ id: 'sync-1' }], | ||
| }) | ||
|
|
||
| const sdk = await SDK.create({ | ||
| ledgerProvider: mock.ledgerProvider as never, | ||
| }) | ||
| const SDKWithPlugin = sdk.registerPlugins({ | ||
| [pluginName]: TestPlugin, | ||
| }) | ||
|
|
||
| const registeredPlugin = SDKWithPlugin[pluginName] | ||
|
|
||
| expect(registeredPlugin).toBeDefined() | ||
| expect(registeredPlugin.testMethod()).toBe(true) | ||
| }) | ||
| }) | ||
This file contains hidden or 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,6 +1,7 @@ | ||
| // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| export * from './types/context.js' | ||
| export * from './initializedSDK.js' | ||
| export * from './types/index.js' | ||
| export { SDKPlugin } from './plugin.js' |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to do
sdk[pluginName].testMethod()(on the originalsdkobject) directly? would be nice to test that