WA-238 Refactoring 3 owners 3 threshold DOM test

This commit is contained in:
apanizo 2018-06-04 10:21:50 +02:00
parent d31dc60645
commit ddf43fc60a
3 changed files with 41 additions and 130 deletions

View File

@ -8,8 +8,7 @@ import { aDeployedSafe } from '~/routes/safe/store/test/builder/deployedSafe.bui
import { SAFELIST_ADDRESS } from '~/routes/routes'
import AppRoutes from '~/routes'
import AddTransactionComponent from '~/routes/safe/component/AddTransaction'
import { safeTransactionsSelector } from '~/routes/safe/store/selectors/index'
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getTagFromTransaction, expandTransactionOf } from '~/routes/safe/test/testMultisig'
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getTagFromTransaction, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
const renderSafe = localStore => (
TestUtils.renderIntoDocument((
@ -35,21 +34,6 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 1 thresh
SafeDom = renderSafe(store)
})
const getTransactionFromReduxStore = () => {
const transactions = safeTransactionsSelector(store.getState(), { safeAddress: address })
return transactions.get(0)
}
const confirmOwners = async (...statusses: string[]) => {
const paragraphsWithOwners = getTagFromTransaction(SafeDom, 'h3')
for (let i = 0; i < statusses.length; i += 1) {
const ownerIndex = i + 6
const ownerParagraph = paragraphsWithOwners[ownerIndex].innerHTML
expect(statusses[i]).toEqual(ownerParagraph)
}
}
it('should execute transaction after 2 owners have confirmed and the last one executed correctly', async () => {
await addFundsTo(SafeDom, address)
await checkBalanceOf(address, '0.1')
@ -57,8 +41,8 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 1 thresh
await checkBalanceOf(address, '0.09')
await listTxsOf(SafeDom)
await expandTransactionOf(SafeDom, 3)
await confirmOwners('Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Not confirmed]', 'Adolfo 3 Eth Account [Not confirmed]')
await expandTransactionOf(SafeDom, 3, 1)
await confirmOwners(SafeDom, 'Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Not confirmed]', 'Adolfo 3 Eth Account [Not confirmed]')
const paragraphs = getTagFromTransaction(SafeDom, 'p')
@ -66,7 +50,7 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 1 thresh
expect(status).toBe('Already executed')
const confirmed = paragraphs[3].innerHTML
const tx = getTransactionFromReduxStore()
const tx = getTransactionFromReduxStore(store, address)
expect(confirmed).toBe(tx.get('tx'))
const ownerTx = paragraphs[6].innerHTML

View File

@ -3,23 +3,18 @@ import * as React from 'react'
import TestUtils from 'react-dom/test-utils'
import { Provider } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux'
import Button from '~/components/layout/Button'
import { aNewStore, history } from '~/store'
import { addEtherTo } from '~/test/addEtherTo'
import { aDeployedSafe } from '~/routes/safe/store/test/builder/deployedSafe.builder'
import { SAFELIST_ADDRESS } from '~/routes/routes'
import SafeView from '~/routes/safe/component/Safe'
import AppRoutes from '~/routes'
import { getBalanceInEtherOf, getWeb3 } from '~/wallets/getWeb3'
import { getWeb3 } from '~/wallets/getWeb3'
import { sleep } from '~/utils/timer'
import { ADD_MULTISIG_BUTTON_TEXT, SEE_MULTISIG_BUTTON_TEXT } from '~/routes/safe/component/Safe/MultisigTx'
import AddTransactionComponent from '~/routes/safe/component/AddTransaction'
import TransactionsComponent from '~/routes/safe/component/Transactions'
import TransactionComponent from '~/routes/safe/component/Transactions/Transaction'
import { promisify } from '~/utils/promisify'
import AddTransactionComponent from '~/routes/safe/component/AddTransaction'
import { processTransaction } from '~/routes/safe/component/Transactions/processTransactions'
import { safeTransactionsSelector, confirmationsTransactionSelector } from '~/routes/safe/store/selectors/index'
import { confirmationsTransactionSelector } from '~/routes/safe/store/selectors/index'
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getTagFromTransaction, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
const renderSafe = localStore => (
TestUtils.renderIntoDocument((
@ -47,121 +42,37 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 3 thresh
accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
})
const listTxs = () => {
const Safe = TestUtils.findRenderedComponentWithType(SafeDom, SafeView)
// $FlowFixMe
const buttons = TestUtils.scryRenderedComponentsWithType(Safe, Button)
const seeTx = buttons[2]
expect(seeTx.props.children).toEqual(SEE_MULTISIG_BUTTON_TEXT)
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(seeTx, 'button')[0])
}
const createMultisigTxFilling = async () => {
// Get AddTransaction form component
const AddTransaction = TestUtils.findRenderedComponentWithType(SafeDom, AddTransactionComponent)
// $FlowFixMe
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(AddTransaction, 'input')
const name = inputs[0]
const destination = inputs[1]
const amountInEth = inputs[2]
TestUtils.Simulate.change(name, { target: { value: 'Buying betteries' } })
TestUtils.Simulate.change(amountInEth, { target: { value: '0.01' } })
TestUtils.Simulate.change(destination, { target: { value: store.getState().providers.account } })
// $FlowFixMe
const form = TestUtils.findRenderedDOMComponentWithTag(AddTransaction, 'form')
TestUtils.Simulate.submit(form) // fill the form
TestUtils.Simulate.submit(form) // confirming data
return sleep(4000)
}
const checkBalanceOf = async (addressToTest: string, value: string) => {
const safeBalance = await getBalanceInEtherOf(addressToTest)
expect(safeBalance).toBe(value)
}
const addFundsTo = async (destination: string) => {
// add funds to safe
await addEtherTo(destination, '0.1')
const Safe = TestUtils.findRenderedComponentWithType(SafeDom, SafeView)
// $FlowFixMe
const buttons = TestUtils.scryRenderedComponentsWithType(Safe, Button)
const addTxButton = buttons[1]
expect(addTxButton.props.children).toEqual(ADD_MULTISIG_BUTTON_TEXT)
await sleep(1800) // Give time to enable Add button
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(addTxButton, 'button')[0])
}
const getTransactionFromReduxStore = () => {
const transactions = safeTransactionsSelector(store.getState(), { safeAddress: address })
return transactions.get(0)
}
const getAlreadyConfirmed = () => {
const tx = getTransactionFromReduxStore()
const tx = getTransactionFromReduxStore(store, address)
const confirmed = confirmationsTransactionSelector(store.getState(), { transaction: tx })
return confirmed
}
const getTagFromTransaction = (tag: string) => {
const Transactions = TestUtils.findRenderedComponentWithType(SafeDom, TransactionsComponent)
if (!Transactions) throw new Error()
const Transaction = TestUtils.findRenderedComponentWithType(Transactions, TransactionComponent)
if (!Transaction) throw new Error()
return TestUtils.scryRenderedDOMComponentsWithTag(Transaction, tag)
}
const expandTransactionOf = async (numOwners) => {
const paragraphs = getTagFromTransaction('p')
TestUtils.Simulate.click(paragraphs[2]) // expanded
await sleep(1000) // Time to expand
const paragraphsExpanded = getTagFromTransaction('p')
const threshold = paragraphsExpanded[5]
expect(threshold.innerHTML).toContain('confirmations needed')
TestUtils.Simulate.click(threshold) // expanded
await sleep(1000) // Time to expand
expect(paragraphsExpanded.length).toBe(paragraphs.length + numOwners)
}
const confirmOwners = async (...statusses: string[]) => {
const paragraphsWithOwners = getTagFromTransaction('h3')
for (let i = 0; i < statusses.length; i += 1) {
const ownerIndex = i + 6
const ownerParagraph = paragraphsWithOwners[ownerIndex].innerHTML
expect(statusses[i]).toEqual(ownerParagraph)
}
}
const makeConfirmation = async (executor) => {
const alreadyConfirmed = getAlreadyConfirmed()
const tx = getTransactionFromReduxStore()
const tx = getTransactionFromReduxStore(store, address)
await processTransaction(address, tx, alreadyConfirmed, executor)
await sleep(800)
store.dispatch(fetchTransactions())
sleep(1800)
SafeDom = renderSafe(store)
sleep(1800)
await listTxs()
await listTxsOf(SafeDom)
sleep(800)
await expandTransactionOf(3)
await expandTransactionOf(SafeDom, 3, 3)
sleep(800)
}
it('should execute transaction after 2 owners have confirmed and the last one executed correctly', async () => {
await addFundsTo(address)
await createMultisigTxFilling()
await addFundsTo(SafeDom, address)
await createMultisigTxFilling(SafeDom, AddTransactionComponent, store)
await checkBalanceOf(address, '0.1')
await listTxs()
const paragraphs = getTagFromTransaction('p')
await listTxsOf(SafeDom)
sleep(800)
const paragraphs = getTagFromTransaction(SafeDom, 'p')
const status = paragraphs[2].innerHTML
expect(status).toBe('1 of the 3 confirmations needed')
@ -169,22 +80,22 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 3 thresh
const confirmed = paragraphs[3].innerHTML
expect(confirmed).toBe('Waiting for the rest of confirmations')
await expandTransactionOf(3)
await confirmOwners('Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Not confirmed]', 'Adolfo 3 Eth Account [Not confirmed]')
await expandTransactionOf(SafeDom, 3, 3)
await confirmOwners(SafeDom, 'Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Not confirmed]', 'Adolfo 3 Eth Account [Not confirmed]')
await makeConfirmation(accounts[1])
await confirmOwners('Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Confirmed]', 'Adolfo 3 Eth Account [Not confirmed]')
await confirmOwners(SafeDom, 'Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Confirmed]', 'Adolfo 3 Eth Account [Not confirmed]')
await makeConfirmation(accounts[2])
await confirmOwners('Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Confirmed]', 'Adolfo 3 Eth Account [Confirmed]')
await confirmOwners(SafeDom, 'Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Confirmed]', 'Adolfo 3 Eth Account [Confirmed]')
const paragraphsExecuted = getTagFromTransaction('p')
const paragraphsExecuted = getTagFromTransaction(SafeDom, 'p')
const statusExecuted = paragraphsExecuted[2].innerHTML
expect(statusExecuted).toBe('Already executed')
const confirmedExecuted = paragraphsExecuted[3].innerHTML
const tx = getTransactionFromReduxStore()
const tx = getTransactionFromReduxStore(store, address)
expect(confirmedExecuted).toBe(tx.get('tx'))
})
})

View File

@ -8,6 +8,7 @@ import { addEtherTo } from '~/test/addEtherTo'
import SafeView from '~/routes/safe/component/Safe'
import TransactionsComponent from '~/routes/safe/component/Transactions'
import TransactionComponent from '~/routes/safe/component/Transactions/Transaction'
import { safeTransactionsSelector } from '~/routes/safe/store/selectors/index'
export const createMultisigTxFilling = async (SafeDom, AddTransactionComponent, store) => {
// Get AddTransaction form component
@ -67,14 +68,29 @@ export const getTagFromTransaction = (SafeDom, tag: string) => {
return TestUtils.scryRenderedDOMComponentsWithTag(Transaction, tag)
}
export const expandTransactionOf = async (SafeDom, numOwners) => {
export const expandTransactionOf = async (SafeDom, numOwners, safeThreshold) => {
const paragraphs = getTagFromTransaction(SafeDom, 'p')
TestUtils.Simulate.click(paragraphs[2]) // expanded
await sleep(1000) // Time to expand
const paragraphsExpanded = getTagFromTransaction(SafeDom, 'p')
const threshold = paragraphsExpanded[5]
expect(threshold.innerHTML).toContain(`confirmation${numOwners === 1 ? 's' : ''} needed`)
expect(threshold.innerHTML).toContain(`confirmation${safeThreshold === 1 ? '' : 's'} needed`)
TestUtils.Simulate.click(threshold) // expanded
await sleep(1000) // Time to expand
expect(paragraphsExpanded.length).toBe(paragraphs.length + numOwners)
}
export const getTransactionFromReduxStore = (store, address) => {
const transactions = safeTransactionsSelector(store.getState(), { safeAddress: address })
return transactions.get(0)
}
export const confirmOwners = async (SafeDom, ...statusses: string[]) => {
const paragraphsWithOwners = getTagFromTransaction(SafeDom, 'h3')
for (let i = 0; i < statusses.length; i += 1) {
const ownerIndex = i + 6
const ownerParagraph = paragraphsWithOwners[ownerIndex].innerHTML
expect(statusses[i]).toEqual(ownerParagraph)
}
}