Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-zhang-sv committed Mar 15, 2024
1 parent f4c255b commit 1416b4e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions packages/wallet-sdk/src/sign/scw/SCWStateManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('SCWStateManager', () => {

beforeEach(() => {
stateManager = new SCWStateManager({
appChainIds: [DEFAULT_CHAIN.id],
updateListener: {
onAccountsUpdate: jest.fn(),
onChainUpdate: jest.fn(),
Expand All @@ -22,6 +23,35 @@ describe('SCWStateManager', () => {
stateManager.clear();
});

describe('fallback to appChainIds[0]', () => {
const appChainIds = [10];

let stateManager: SCWStateManager;
beforeEach(() => {
stateManager = new SCWStateManager({
appChainIds,
updateListener: {
onAccountsUpdate: jest.fn(),
onChainUpdate: jest.fn(),
},
});
});
it('should use the first chain id from appChainIds as the active chain', () => {
expect(stateManager.activeChain.id).toBe(appChainIds[0]);
});

it('should use the first chain id from appChainIds as the active chain when appChainIds is empty', () => {
stateManager = new SCWStateManager({
appChainIds: [],
updateListener: {
onAccountsUpdate: jest.fn(),
onChainUpdate: jest.fn(),
},
});
expect(stateManager.activeChain.id).toBe(1);
});
});

describe('switchChain', () => {
beforeEach(() => {
stateManager.updateAvailableChains(AVAILABLE_CHAINS);
Expand Down Expand Up @@ -64,6 +94,7 @@ describe('SCWStateManager', () => {

beforeEach(() => {
stateManager = new SCWStateManager({
appChainIds: [1],
updateListener: {
onAccountsUpdate: jest.fn(),
onChainUpdate: chainUpdatedListener,
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-sdk/src/sign/scw/SCWStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SCWStateManager {
}

this._accounts = accounts || [];
this._activeChain = chain || { id: options.appChainIds[0] };
this._activeChain = chain || { id: options.appChainIds?.[0] ?? 1 };
}

updateAccounts(accounts: AddressString[]) {
Expand Down

0 comments on commit 1416b4e

Please sign in to comment.