mirror of
https://github.com/status-im/safe-react.git
synced 2025-01-23 16:19:40 +00:00
WA-234 Fix tests
This commit is contained in:
parent
b1eeab65e7
commit
c0a0f96af0
@ -1,6 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import ListItemText from '@material-ui/core/ListItemText'
|
import MuiListItemText from '@material-ui/core/ListItemText'
|
||||||
import { withStyles } from '@material-ui/core/styles'
|
import { withStyles } from '@material-ui/core/styles'
|
||||||
import { type WithStyles } from '~/theme/mui'
|
import { type WithStyles } from '~/theme/mui'
|
||||||
|
|
||||||
@ -18,21 +18,26 @@ const styles = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const GnoListItemText = ({
|
class ListItemText extends React.PureComponent<Props> {
|
||||||
primary, secondary, classes, cut = false,
|
render() {
|
||||||
}: Props) => {
|
const {
|
||||||
const cutStyle = cut ? {
|
primary, secondary, classes, cut = false,
|
||||||
secondary: classes.itemTextSecondary,
|
} = this.props
|
||||||
} : undefined
|
|
||||||
|
|
||||||
return (
|
const cutStyle = cut ? {
|
||||||
<ListItemText
|
secondary: classes.itemTextSecondary,
|
||||||
classes={cutStyle}
|
} : undefined
|
||||||
inset
|
|
||||||
primary={primary}
|
return (
|
||||||
secondary={secondary}
|
<MuiListItemText
|
||||||
/>
|
classes={cutStyle}
|
||||||
)
|
inset
|
||||||
|
primary={primary}
|
||||||
|
secondary={secondary}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withStyles(styles)(GnoListItemText)
|
|
||||||
|
export default withStyles(styles)(ListItemText)
|
||||||
|
@ -111,16 +111,16 @@ export const createTransaction = async (
|
|||||||
await gnosisSafe.execTransactionIfApproved(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
|
await gnosisSafe.execTransactionIfApproved(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
|
||||||
await checkReceiptStatus(txHash.tx)
|
await checkReceiptStatus(txHash.tx)
|
||||||
const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(safe.get('owners'), user)
|
const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(safe.get('owners'), user)
|
||||||
return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash, safeAddress, safe.get('threshold'), data)
|
return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash.tx, safeAddress, safe.get('threshold'), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
const txData = gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce)
|
const txData = gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce)
|
||||||
const gas = await calculateGasOf(txData, user, safeAddress)
|
const gas = await calculateGasOf(txData, user, safeAddress)
|
||||||
const txConfirmationHash = await gnosisSafe
|
const txConfirmationHash = await gnosisSafe
|
||||||
.approveTransactionWithParameters(txDest, valueInWei, txData, CALL, nonce, { from: user, gas, gasPrice })
|
.approveTransactionWithParameters(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
|
||||||
await checkReceiptStatus(txConfirmationHash)
|
await checkReceiptStatus(txConfirmationHash.tx)
|
||||||
|
|
||||||
const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash)
|
const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash.tx)
|
||||||
|
|
||||||
return storeTransaction(txName, nonce, txDest, txValue, user, confirmations, '', safeAddress, safe.get('threshold'), data)
|
return storeTransaction(txName, nonce, txDest, txValue, user, confirmations, '', safeAddress, safe.get('threshold'), data)
|
||||||
}
|
}
|
||||||
|
@ -50,12 +50,13 @@ const execTransaction = async (
|
|||||||
const CALL = getOperation()
|
const CALL = getOperation()
|
||||||
const web3 = getWeb3()
|
const web3 = getWeb3()
|
||||||
const valueInWei = web3.toWei(txValue, 'ether')
|
const valueInWei = web3.toWei(txValue, 'ether')
|
||||||
|
|
||||||
const txData = await gnosisSafe.contract.execTransactionIfApproved.getData(destination, valueInWei, data, CALL, nonce)
|
const txData = await gnosisSafe.contract.execTransactionIfApproved.getData(destination, valueInWei, data, CALL, nonce)
|
||||||
const gas = await calculateGasOf(txData, executor, gnosisSafe.address)
|
const gas = await calculateGasOf(txData, executor, gnosisSafe.address)
|
||||||
const gasPrice = await calculateGasPrice()
|
const gasPrice = await calculateGasPrice()
|
||||||
|
|
||||||
return gnosisSafe
|
return gnosisSafe
|
||||||
.execTransactionIfApproved(destination, valueInWei, txData, CALL, nonce, { from: executor, gas, gasPrice })
|
.execTransactionIfApproved(destination, valueInWei, data, CALL, nonce, { from: executor, gas, gasPrice })
|
||||||
}
|
}
|
||||||
|
|
||||||
const execConfirmation = async (
|
const execConfirmation = async (
|
||||||
|
@ -75,6 +75,7 @@ describe('React DOM TESTS > Withdrawn funds from safe', () => {
|
|||||||
const addTransactionButtons = TestUtils.scryRenderedComponentsWithType(AddTransaction, Button)
|
const addTransactionButtons = TestUtils.scryRenderedComponentsWithType(AddTransaction, Button)
|
||||||
expect(addTransactionButtons.length).toBe(1)
|
expect(addTransactionButtons.length).toBe(1)
|
||||||
const visitTxsButton = addTransactionButtons[0]
|
const visitTxsButton = addTransactionButtons[0]
|
||||||
|
|
||||||
expect(visitTxsButton.props.children).toEqual(SEE_TXS_BUTTON_TEXT)
|
expect(visitTxsButton.props.children).toEqual(SEE_TXS_BUTTON_TEXT)
|
||||||
|
|
||||||
// NOW it is time to check the just executed transaction
|
// NOW it is time to check the just executed transaction
|
||||||
|
@ -8,7 +8,7 @@ import { aDeployedSafe } from '~/routes/safe/store/test/builder/deployedSafe.bui
|
|||||||
import { SAFELIST_ADDRESS } from '~/routes/routes'
|
import { SAFELIST_ADDRESS } from '~/routes/routes'
|
||||||
import AppRoutes from '~/routes'
|
import AppRoutes from '~/routes'
|
||||||
import AddTransactionComponent from '~/routes/safe/component/AddTransaction'
|
import AddTransactionComponent from '~/routes/safe/component/AddTransaction'
|
||||||
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getTagFromTransaction, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
|
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getListItemsFrom, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
|
||||||
import { sleep } from '~/utils/timer'
|
import { sleep } from '~/utils/timer'
|
||||||
|
|
||||||
const renderSafe = localStore => (
|
const renderSafe = localStore => (
|
||||||
@ -46,17 +46,17 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 1 thresh
|
|||||||
await expandTransactionOf(SafeDom, 3, 1)
|
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]')
|
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')
|
const listItems = getListItemsFrom(SafeDom)
|
||||||
|
|
||||||
const status = paragraphs[2].innerHTML
|
const status = listItems[2].props.secondary
|
||||||
expect(status).toBe('Already executed')
|
expect(status).toBe('Already executed')
|
||||||
|
|
||||||
const confirmed = paragraphs[3].innerHTML
|
const confirmed = listItems[3].props.secondary
|
||||||
const tx = getTransactionFromReduxStore(store, address)
|
const tx = getTransactionFromReduxStore(store, address)
|
||||||
if (!tx) throw new Error()
|
if (!tx) throw new Error()
|
||||||
expect(confirmed).toBe(tx.get('tx'))
|
expect(confirmed).toBe(tx.get('tx'))
|
||||||
|
|
||||||
const ownerTx = paragraphs[6].innerHTML
|
const ownerTx = listItems[6].props.secondary
|
||||||
expect(ownerTx).toBe('Confirmation hash: EXECUTED')
|
expect(ownerTx).toBe('Confirmation hash: EXECUTED')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -14,7 +14,7 @@ import AddTransactionComponent from '~/routes/safe/component/AddTransaction'
|
|||||||
import { processTransaction } from '~/routes/safe/component/Transactions/processTransactions'
|
import { processTransaction } from '~/routes/safe/component/Transactions/processTransactions'
|
||||||
import { confirmationsTransactionSelector } from '~/routes/safe/store/selectors/index'
|
import { confirmationsTransactionSelector } from '~/routes/safe/store/selectors/index'
|
||||||
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
|
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
|
||||||
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getTagFromTransaction, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
|
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getListItemsFrom, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
|
||||||
|
|
||||||
const renderSafe = localStore => (
|
const renderSafe = localStore => (
|
||||||
TestUtils.renderIntoDocument((
|
TestUtils.renderIntoDocument((
|
||||||
@ -74,12 +74,12 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 3 thresh
|
|||||||
await checkBalanceOf(address, '0.1')
|
await checkBalanceOf(address, '0.1')
|
||||||
await listTxsOf(SafeDom)
|
await listTxsOf(SafeDom)
|
||||||
sleep(1400)
|
sleep(1400)
|
||||||
const paragraphs = getTagFromTransaction(SafeDom, 'p')
|
const listItems = getListItemsFrom(SafeDom)
|
||||||
|
|
||||||
const status = paragraphs[2].innerHTML
|
const status = listItems[2].props.secondary
|
||||||
expect(status).toBe('1 of the 3 confirmations needed')
|
expect(status).toBe('1 of the 3 confirmations needed')
|
||||||
|
|
||||||
const confirmed = paragraphs[3].innerHTML
|
const confirmed = listItems[3].props.secondary
|
||||||
expect(confirmed).toBe('Waiting for the rest of confirmations')
|
expect(confirmed).toBe('Waiting for the rest of confirmations')
|
||||||
|
|
||||||
await expandTransactionOf(SafeDom, 3, 3)
|
await expandTransactionOf(SafeDom, 3, 3)
|
||||||
@ -91,12 +91,12 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 3 thresh
|
|||||||
await makeConfirmation(accounts[2])
|
await makeConfirmation(accounts[2])
|
||||||
await confirmOwners(SafeDom, '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(SafeDom, 'p')
|
const listItemsExecuted = getListItemsFrom(SafeDom)
|
||||||
|
|
||||||
const statusExecuted = paragraphsExecuted[2].innerHTML
|
const statusExecuted = listItemsExecuted[2].props.secondary
|
||||||
expect(statusExecuted).toBe('Already executed')
|
expect(statusExecuted).toBe('Already executed')
|
||||||
|
|
||||||
const confirmedExecuted = paragraphsExecuted[3].innerHTML
|
const confirmedExecuted = listItemsExecuted[3].props.secondary
|
||||||
const tx = getTransactionFromReduxStore(store, address)
|
const tx = getTransactionFromReduxStore(store, address)
|
||||||
if (!tx) throw new Error()
|
if (!tx) throw new Error()
|
||||||
expect(confirmedExecuted).toBe(tx.get('tx'))
|
expect(confirmedExecuted).toBe(tx.get('tx'))
|
||||||
|
@ -10,6 +10,7 @@ import TransactionsComponent from '~/routes/safe/component/Transactions'
|
|||||||
import TransactionComponent from '~/routes/safe/component/Transactions/Transaction'
|
import TransactionComponent from '~/routes/safe/component/Transactions/Transaction'
|
||||||
import { safeTransactionsSelector } from '~/routes/safe/store/selectors/index'
|
import { safeTransactionsSelector } from '~/routes/safe/store/selectors/index'
|
||||||
import { type GlobalState } from '~/store/index'
|
import { type GlobalState } from '~/store/index'
|
||||||
|
import ListItemText from '~/components/List/ListItemText'
|
||||||
|
|
||||||
export const createMultisigTxFilling = async (
|
export const createMultisigTxFilling = async (
|
||||||
SafeDom: React$Component<any, any>,
|
SafeDom: React$Component<any, any>,
|
||||||
@ -64,13 +65,13 @@ export const listTxsOf = (SafeDom: React$Component<any, any>) => {
|
|||||||
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(seeTx, 'button')[0])
|
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(seeTx, 'button')[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getTagFromTransaction = (SafeDom: React$Component<any, any>, tag: string) => {
|
export const getListItemsFrom = (SafeDom: React$Component<any, any>) => {
|
||||||
const Transactions = TestUtils.findRenderedComponentWithType(SafeDom, TransactionsComponent)
|
const Transactions = TestUtils.findRenderedComponentWithType(SafeDom, TransactionsComponent)
|
||||||
if (!Transactions) throw new Error()
|
if (!Transactions) throw new Error()
|
||||||
const Transaction = TestUtils.findRenderedComponentWithType(Transactions, TransactionComponent)
|
const Transaction = TestUtils.findRenderedComponentWithType(Transactions, TransactionComponent)
|
||||||
if (!Transaction) throw new Error()
|
if (!Transaction) throw new Error()
|
||||||
|
|
||||||
return TestUtils.scryRenderedDOMComponentsWithTag(Transaction, tag)
|
return TestUtils.scryRenderedComponentsWithType(Transaction, ListItemText)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const expandTransactionOf = async (
|
export const expandTransactionOf = async (
|
||||||
@ -78,15 +79,15 @@ export const expandTransactionOf = async (
|
|||||||
numOwners: number,
|
numOwners: number,
|
||||||
safeThreshold: number,
|
safeThreshold: number,
|
||||||
) => {
|
) => {
|
||||||
const paragraphs = getTagFromTransaction(SafeDom, 'p')
|
const listItems = getListItemsFrom(SafeDom)
|
||||||
TestUtils.Simulate.click(paragraphs[2]) // expanded
|
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(listItems[2], 'p')[0]) // expanded
|
||||||
await sleep(2500) // Time to expand
|
await sleep(2500) // Time to expand
|
||||||
const paragraphsExpanded = getTagFromTransaction(SafeDom, 'p')
|
const listItemsExpanded = getListItemsFrom(SafeDom)
|
||||||
const threshold = paragraphsExpanded[5]
|
const threshold = listItemsExpanded[5]
|
||||||
expect(threshold.innerHTML).toContain(`confirmation${safeThreshold === 1 ? '' : 's'} needed`)
|
expect(threshold.props.secondary).toContain(`confirmation${safeThreshold === 1 ? '' : 's'} needed`)
|
||||||
TestUtils.Simulate.click(threshold) // expanded
|
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(threshold, 'p')[0]) // expanded
|
||||||
await sleep(2500) // Time to expand
|
await sleep(2500) // Time to expand
|
||||||
expect(paragraphsExpanded.length).toBe(paragraphs.length + numOwners)
|
expect(listItemsExpanded.length).toBe(listItems.length + numOwners)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getTransactionFromReduxStore = (store: Store<GlobalState>, address: string, index: number = 0) => {
|
export const getTransactionFromReduxStore = (store: Store<GlobalState>, address: string, index: number = 0) => {
|
||||||
@ -96,10 +97,16 @@ export const getTransactionFromReduxStore = (store: Store<GlobalState>, address:
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const confirmOwners = async (SafeDom: React$Component<any, any>, ...statusses: string[]) => {
|
export const confirmOwners = async (SafeDom: React$Component<any, any>, ...statusses: string[]) => {
|
||||||
const paragraphsWithOwners = getTagFromTransaction(SafeDom, 'span')
|
const Transactions = TestUtils.findRenderedComponentWithType(SafeDom, TransactionsComponent)
|
||||||
|
if (!Transactions) throw new Error()
|
||||||
|
const Transaction = TestUtils.findRenderedComponentWithType(Transactions, TransactionComponent)
|
||||||
|
if (!Transaction) throw new Error()
|
||||||
|
|
||||||
|
const listItems = TestUtils.scryRenderedComponentsWithType(Transaction, ListItemText)
|
||||||
|
|
||||||
for (let i = 0; i < statusses.length; i += 1) {
|
for (let i = 0; i < statusses.length; i += 1) {
|
||||||
const ownerIndex = i + 6
|
const ownerIndex = i + 6
|
||||||
const ownerParagraph = paragraphsWithOwners[ownerIndex].innerHTML
|
const ownerParagraph = listItems[ownerIndex].props.primary
|
||||||
|
|
||||||
expect(statusses[i]).toEqual(ownerParagraph)
|
expect(statusses[i]).toEqual(ownerParagraph)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user