diff --git a/packages/web3-eth-accounts/src/models/Wallet.js b/packages/web3-eth-accounts/src/models/Wallet.js index a43b596e015..78a0fa0b7ca 100644 --- a/packages/web3-eth-accounts/src/models/Wallet.js +++ b/packages/web3-eth-accounts/src/models/Wallet.js @@ -40,6 +40,10 @@ export default class Wallet { return target.accounts[name]; } + if (name === 'length') { + return target.accountsIndex; + } + return target[name]; } }); diff --git a/packages/web3-eth-accounts/tests/src/models/WalletTest.js b/packages/web3-eth-accounts/tests/src/models/WalletTest.js index 43c29ee56a3..79d810c7398 100644 --- a/packages/web3-eth-accounts/tests/src/models/WalletTest.js +++ b/packages/web3-eth-accounts/tests/src/models/WalletTest.js @@ -33,7 +33,13 @@ describe('WalletTest', () => { expect(wallet.defaultKeyName).toEqual('web3js_wallet'); }); - it('calls wallet.create and returns the expected value', () => { + it('calls the length property and returns the accountsIndex', () => { + wallet.accountsIndex = 99; + + expect(wallet.length).toEqual(99); + }); + + it('calls create and returns the expected value', () => { Utils.randomHex.mockReturnValueOnce('asdf'); Account.from.mockReturnValueOnce({address: '0x0', privateKey: '0x0'}); @@ -164,7 +170,7 @@ describe('WalletTest', () => { expect(() => { wallet.decrypt([true], 'pw'); - }).toThrow("Couldn't decrypt accounts. Password wrong?"); + }).toThrow('Couldn\'t decrypt accounts. Password wrong?'); expect(Account.fromV3Keystore).toHaveBeenCalledWith(true, 'pw', false, accountsMock); });