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