diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index d2e7a7a0..158842b1 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -46,7 +46,7 @@ const buildTransactionFrom = (safeAddress: string, tx: TxServiceModel, safeSubje return makeTransaction({ name, nonce: tx.nonce, - value: tx.value, + value: Number(tx.value), confirmations, destination: tx.to, data: `0x${tx.data || ''}`, diff --git a/src/test/safe.redux.transactions.test.js b/src/test/safe.redux.transactions.test.js index b93a2132..b33bb241 100644 --- a/src/test/safe.redux.transactions.test.js +++ b/src/test/safe.redux.transactions.test.js @@ -11,8 +11,10 @@ import { getSafeFrom } from '~/test/utils/safeHelper' import { promisify } from '~/utils/promisify' import { getWeb3 } from '~/logic/wallets/getWeb3' import { safeTransactionsSelector } from '~/routes/safe/store/selectors' +import fetchSafe from '~/routes/safe/store/actions/fetchSafe' import { testTransactionFrom, testSizeOfTransactions } from './utils/historyServiceHelper' + describe('Transactions Suite', () => { let store: Store let safeAddress: string @@ -28,24 +30,29 @@ describe('Transactions Suite', () => { }) it('retrieves tx info from service having subject available', async () => { - const safe: Safe = getSafeFrom(store.getState(), safeAddress) + let safe: Safe = getSafeFrom(store.getState(), safeAddress) const gnosisSafe = await getSafeEthereumInstance(safeAddress) const firstTxData = gnosisSafe.contract.addOwnerWithThreshold.getData(accounts[1], 2) const executor = accounts[0] const nonce = Date.now() const firstTxHash = await createTransaction(safe, 'Add Owner Second account', safeAddress, 0, nonce, executor, firstTxData) + await store.dispatch(fetchSafe(safe)) + safe = getSafeFrom(store.getState(), safeAddress) + const secondTxData = gnosisSafe.contract.addOwnerWithThreshold.getData(accounts[2], 2) const secondTxHash = await createTransaction(safe, 'Add Owner Third account', safeAddress, 0, nonce + 100, executor, secondTxData) + await store.dispatch(fetchSafe(safe)) + safe = getSafeFrom(store.getState(), safeAddress) // WHEN - store.dispatch(fetchTransactions(safeAddress)) + await store.dispatch(fetchTransactions(safeAddress)) let transactions = safeTransactionsSelector(store.getState(), { safeAddress }) testSizeOfTransactions(transactions, 2) // THEN const firstTxConfirmations = List([ makeConfirmation({ - owner: makeOwner({ address: executor }), + owner: makeOwner({ address: getWeb3().toChecksumAddress(executor), name: 'Adol 1 Eth Account' }), type: 'execution', hash: firstTxHash, }), @@ -54,7 +61,7 @@ describe('Transactions Suite', () => { const secondTxConfirmations = List([ makeConfirmation({ - owner: makeOwner({ address: accounts[0] }), + owner: makeOwner({ address: getWeb3().toChecksumAddress(accounts[0]), name: 'Adol 1 Eth Account' }), type: 'confirmation', hash: secondTxHash, }), @@ -63,11 +70,26 @@ describe('Transactions Suite', () => { localStorage.clear() - store.dispatch(fetchTransactions(safeAddress)) + await store.dispatch(fetchTransactions(safeAddress)) transactions = safeTransactionsSelector(store.getState(), { safeAddress }) + testSizeOfTransactions(transactions, 2) - testTransactionFrom(transactions, 0, 'Unknown', nonce, 0, safeAddress, firstTxData, true, firstTxConfirmations) - testTransactionFrom(transactions, 1, 'Unknown', nonce + 100, 0, safeAddress, secondTxData, false, secondTxConfirmations) + const firstTxConfWithoutStorage = List([ + makeConfirmation({ + owner: makeOwner({ address: getWeb3().toChecksumAddress(executor), name: 'UNKNOWN' }), + type: 'execution', + hash: firstTxHash, + }), + ]) + testTransactionFrom(transactions, 0, 'Unknown', nonce, 0, safeAddress, firstTxData, true, firstTxConfWithoutStorage) + const secondTxConfWithoutStorage = List([ + makeConfirmation({ + owner: makeOwner({ address: getWeb3().toChecksumAddress(executor), name: 'UNKNOWN' }), + type: 'confirmation', + hash: secondTxHash, + }), + ]) + testTransactionFrom(transactions, 1, 'Unknown', nonce + 100, 0, safeAddress, secondTxData, false, secondTxConfWithoutStorage) }) it('returns empty list of trnsactions when safe is not configured', async () => { diff --git a/src/test/utils/historyServiceHelper.js b/src/test/utils/historyServiceHelper.js index 1d6aebe9..7063abd9 100644 --- a/src/test/utils/historyServiceHelper.js +++ b/src/test/utils/historyServiceHelper.js @@ -2,6 +2,7 @@ import { List, Map } from 'immutable' import { type Confirmation } from '~/routes/safe/store/model/confirmation' import { type Transaction } from '~/routes/safe/store/model/transaction' +import { sameAddress } from '~/logic/wallets/ethAddresses' export const testSizeOfSafesWith = (transactions: Map>, size: number) => { expect(transactions).not.toBe(undefined) @@ -28,8 +29,8 @@ export const testTransactionFrom = ( expect(tx.get('name')).toBe(name) expect(tx.get('nonce')).toBe(nonce) expect(tx.get('value')).toBe(value) - expect(tx.get('destination')).toBe(destination) + expect(sameAddress(tx.get('destination'), destination)).toBe(true) expect(tx.get('data')).toBe(data) expect(tx.get('isExecuted')).toBe(isExecuted) - expect(tx.get('confirmations')).toBe(confirmations) + expect(tx.get('confirmations')).toEqual(confirmations) }