Skip to content

Commit

Permalink
test: fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelylovas committed Jan 8, 2025
1 parent 502b25f commit c938f76
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions src/background/services/wallet/handlers/importLedger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('src/background/services/wallet/handlers/importLedger', () => {
xpub: xpubValue,
xpubXP: xpubXPValue,
name: nameValue,
numberOfAccountsToCreate: 1,
numberOfAccountsToCreate: 2,
});

expect(walletService.addPrimaryWallet).toHaveBeenCalledWith({
Expand All @@ -117,8 +117,7 @@ describe('src/background/services/wallet/handlers/importLedger', () => {
name: nameValue,
});

// correlate to numberOfAccountsToCreate
expect(accountsService.addPrimaryAccount).toHaveBeenCalledTimes(1);
expect(accountsService.addPrimaryAccount).toHaveBeenCalledTimes(2);

expect(accountsService.activateAccount).toHaveBeenCalledTimes(1);

Expand All @@ -128,7 +127,8 @@ describe('src/background/services/wallet/handlers/importLedger', () => {
id: walletId,
});
});
it('returns an ImportWalletResult if LedgerLive import is successful', async () => {

it('only imports accounts with pubkeys', async () => {
const walletId = crypto.randomUUID();
const pubKeysValue = [
{
Expand Down Expand Up @@ -160,9 +160,7 @@ describe('src/background/services/wallet/handlers/importLedger', () => {
name: nameValue,
});

// correlate to numberOfAccountsToCreate
expect(accountsService.addPrimaryAccount).toHaveBeenCalledTimes(2);

expect(accountsService.addPrimaryAccount).toHaveBeenCalledTimes(1);
expect(accountsService.activateAccount).toHaveBeenCalledTimes(1);

expect(result).toEqual({
Expand All @@ -171,4 +169,54 @@ describe('src/background/services/wallet/handlers/importLedger', () => {
id: walletId,
});
});

it('imports max 3 accounts', async () => {
const walletId = crypto.randomUUID();
const pubKeysValue = [
{
evm: 'pubKeyEvm1',
},
{
evm: 'pubKeyEvm2',
},
{
evm: 'pubKeyEvm3',
},
{
evm: 'pubKeyEvm4',
},
];
const nameValue = 'walletName';
secretsService.isKnownSecret.mockResolvedValueOnce(false);
walletService.addPrimaryWallet.mockResolvedValue(walletId);
secretsService.getWalletAccountsSecretsById.mockResolvedValue({
secretType: SecretType.LedgerLive,
pubKeys: pubKeysValue,
derivationPath: DerivationPath.LedgerLive,
id: walletId,
name: nameValue,
});

const { result } = await handle({
secretType: SecretType.LedgerLive,
pubKeys: pubKeysValue,
name: nameValue,
numberOfAccountsToCreate: 4,
});

expect(walletService.addPrimaryWallet).toHaveBeenCalledWith({
secretType: SecretType.LedgerLive,
pubKeys: pubKeysValue,
derivationPath: DerivationPath.LedgerLive,
name: nameValue,
});

expect(accountsService.addPrimaryAccount).toHaveBeenCalledTimes(3);

expect(result).toEqual({
type: SecretType.LedgerLive,
name: nameValue,
id: walletId,
});
});
});

0 comments on commit c938f76

Please sign in to comment.