diff --git a/tests/eth/eth-socket.spec.js b/tests/eth/eth-socket.spec.js index 28ce84eb9..7a8a5ddfd 100644 --- a/tests/eth/eth-socket.spec.js +++ b/tests/eth/eth-socket.spec.js @@ -3,14 +3,22 @@ const EthSocket = require('../../src/eth/eth-socket'); describe('EthSocket', () => { const url = 'wss://ws.blockchain.info/eth/inv' - const balanceResponse = JSON.stringify({ op: 'account_sub', account: '0xasdf', balance: '1000', nonce: 1, txHash: 'xyz' }) + const balanceResponse = JSON.stringify({ op: 'account_sub', account: '0xasdf', balance: '1000', nonce: 1, txHash: 'xyz', tx: { hash: 'xyz' } }) const blockResponse = JSON.stringify({ op: 'block_sub', height: 123 }) let account let ethWallet + let mockAccount = (address) => ({ + address, + setData () {}, + fetchTransaction () {}, + appendTransaction () {}, + isCorrectAddress (a) { return a === address } + }) + beforeEach(() => { - account = { address: '0xasdf', setData () {}, fetchTransaction () {} } + account = mockAccount('0xasdf') ethWallet = { setLatestBlock () {} } }) @@ -64,11 +72,11 @@ describe('EthSocket', () => { expect(account.setData).toHaveBeenCalledWith(jasmine.objectContaining({ balance: '1000', nonce: 1 })) }) - it('should call .fetchTransaction on message', () => { + it('should call .appendTransaction with the tx object', () => { let handler = EthSocket.accountMessageHandler(account) - spyOn(account, 'fetchTransaction') + spyOn(account, 'appendTransaction') handler(balanceResponse) - expect(account.fetchTransaction).toHaveBeenCalledWith('xyz') + expect(account.appendTransaction).toHaveBeenCalledWith({ hash: 'xyz' }) }) it('should do nothing for non-balance message', () => { @@ -86,8 +94,9 @@ describe('EthSocket', () => { }) it('should reset the balance of a legacy address', () => { - let legacyAccount = { address: '0xabcd', setData: jasmine.createSpy('setData') } + let legacyAccount = mockAccount('0xabcd') let handler = EthSocket.accountMessageHandler(account, legacyAccount) + spyOn(legacyAccount, 'setData') handler(JSON.stringify({ op: 'account_sub', account: '0xasdf', tx: { from: '0xabcd' } })) expect(legacyAccount.setData).toHaveBeenCalledWith({ balance: '0' }) }) diff --git a/tests/eth/eth-wallet-tx.spec.js b/tests/eth/eth-wallet-tx.spec.js index 9fb598d84..e8b473f8d 100644 --- a/tests/eth/eth-wallet-tx.spec.js +++ b/tests/eth/eth-wallet-tx.spec.js @@ -14,6 +14,12 @@ describe('EthWalletTx', () => { 'gasUsed': 21000 } + const mockAccount = (addr) => ({ + isCorrectAddress (a) { + return a === addr + } + }) + describe('instance', () => { let tx beforeEach(() => { @@ -56,41 +62,41 @@ describe('EthWalletTx', () => { describe('.getTxType()', () => { it('should identify a received tx', () => { - let account = { address: '0xasdf2' } + let account = mockAccount('0xasdf2') expect(tx.getTxType(account)).toEqual('received') }) it('should identify a sent tx', () => { - let account = { address: '0xasdf1' } + let account = mockAccount('0xasdf1') expect(tx.getTxType(account)).toEqual('sent') }) it('should return null if neither sent or received', () => { - let account = { address: '0xasdf3' } + let account = mockAccount('0xasdf3') expect(tx.getTxType(account)).toEqual(null) }) }) describe('.isToAccount()', () => { it('should be true if tx is to account', () => { - let account = { address: '0xasdf2' } + let account = mockAccount('0xasdf2') expect(tx.isToAccount(account)).toEqual(true) }) it('should be false if tx is not to account', () => { - let account = { address: '0xasdf1' } + let account = mockAccount('0xasdf1') expect(tx.isToAccount(account)).toEqual(false) }) }) describe('.isFromAccount()', () => { it('should be true if tx is from account', () => { - let account = { address: '0xasdf1' } + let account = mockAccount('0xasdf1') expect(tx.isFromAccount(account)).toEqual(true) }) it('should be false if tx is not from account', () => { - let account = { address: '0xasdf2' } + let account = mockAccount('0xasdf2') expect(tx.isFromAccount(account)).toEqual(false) }) })