add test for sending funds with threshold = 2
This commit is contained in:
parent
0bf8b3e658
commit
7876dcf845
|
@ -57,6 +57,10 @@ const getProviderName: Function = (web3Provider): boolean => {
|
||||||
const getAccountFrom: Function = async (web3Provider): Promise<string | null> => {
|
const getAccountFrom: Function = async (web3Provider): Promise<string | null> => {
|
||||||
const accounts = await web3Provider.eth.getAccounts()
|
const accounts = await web3Provider.eth.getAccounts()
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'test' && window.testAccountIndex) {
|
||||||
|
return accounts[window.testAccountIndex]
|
||||||
|
}
|
||||||
|
|
||||||
return accounts && accounts.length > 0 ? accounts[0] : null
|
return accounts && accounts.length > 0 ? accounts[0] : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import Transactions from './TransactionsNew'
|
||||||
import Settings from './Settings'
|
import Settings from './Settings'
|
||||||
|
|
||||||
export const SETTINGS_TAB_BTN_TESTID = 'settings-tab-btn'
|
export const SETTINGS_TAB_BTN_TESTID = 'settings-tab-btn'
|
||||||
|
export const TRANSACTIONS_TAB_BTN_TESTID = 'transactions-tab-btn'
|
||||||
export const SAFE_VIEW_NAME_HEADING_TESTID = 'safe-name-heading'
|
export const SAFE_VIEW_NAME_HEADING_TESTID = 'safe-name-heading'
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
|
@ -144,7 +145,7 @@ class Layout extends React.Component<Props, State> {
|
||||||
<Row>
|
<Row>
|
||||||
<Tabs value={tabIndex} onChange={this.handleChange} indicatorColor="secondary" textColor="secondary">
|
<Tabs value={tabIndex} onChange={this.handleChange} indicatorColor="secondary" textColor="secondary">
|
||||||
<Tab label="Balances" />
|
<Tab label="Balances" />
|
||||||
<Tab label="Transactions" />
|
<Tab label="Transactions" data-testid={TRANSACTIONS_TAB_BTN_TESTID} />
|
||||||
<Tab label="Settings" data-testid={SETTINGS_TAB_BTN_TESTID} />
|
<Tab label="Settings" data-testid={SETTINGS_TAB_BTN_TESTID} />
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
|
@ -16,6 +16,8 @@ import Paragraph from '~/components/layout/Paragraph'
|
||||||
import { type Transaction } from '~/routes/safe/store/models/transaction'
|
import { type Transaction } from '~/routes/safe/store/models/transaction'
|
||||||
import { styles } from './style'
|
import { styles } from './style'
|
||||||
|
|
||||||
|
export const APPROVE_TX_MODAL_SUBMIT_BTN_TESTID = 'approve-tx-modal-submit-btn'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: () => void,
|
onClose: () => void,
|
||||||
classes: Object,
|
classes: Object,
|
||||||
|
@ -113,6 +115,7 @@ const ApproveTxModal = ({
|
||||||
minHeight={42}
|
minHeight={42}
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={approveTx}
|
onClick={approveTx}
|
||||||
|
testId={APPROVE_TX_MODAL_SUBMIT_BTN_TESTID}
|
||||||
>
|
>
|
||||||
{title}
|
{title}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -7,6 +7,9 @@ import Row from '~/components/layout/Row'
|
||||||
import Button from '~/components/layout/Button'
|
import Button from '~/components/layout/Button'
|
||||||
import { sm, lg } from '~/theme/variables'
|
import { sm, lg } from '~/theme/variables'
|
||||||
|
|
||||||
|
export const CONFIRM_TX_BTN_TESTID = 'confirm-btn'
|
||||||
|
export const EXECUTE_TX_BTN_TESTID = 'execute-btn'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onTxConfirm: Function,
|
onTxConfirm: Function,
|
||||||
onTxCancel: Function,
|
onTxCancel: Function,
|
||||||
|
@ -54,14 +57,28 @@ const ButtonRow = ({
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{showConfirmBtn && (
|
{showConfirmBtn && (
|
||||||
<Button className={classes.button} variant="contained" minWidth={140} color="primary" onClick={onTxConfirm}>
|
<Button
|
||||||
|
className={classes.button}
|
||||||
|
variant="contained"
|
||||||
|
minWidth={140}
|
||||||
|
color="primary"
|
||||||
|
onClick={onTxConfirm}
|
||||||
|
testId={CONFIRM_TX_BTN_TESTID}
|
||||||
|
>
|
||||||
<EditIcon className={classes.icon} />
|
<EditIcon className={classes.icon} />
|
||||||
{' '}
|
{' '}
|
||||||
Confirm TX
|
Confirm TX
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{showExecuteBtn && (
|
{showExecuteBtn && (
|
||||||
<Button className={classes.button} variant="contained" minWidth={140} color="primary" onClick={onTxExecute}>
|
<Button
|
||||||
|
className={classes.button}
|
||||||
|
variant="contained"
|
||||||
|
minWidth={140}
|
||||||
|
color="primary"
|
||||||
|
onClick={onTxExecute}
|
||||||
|
testId={EXECUTE_TX_BTN_TESTID}
|
||||||
|
>
|
||||||
<EditIcon className={classes.icon} />
|
<EditIcon className={classes.icon} />
|
||||||
{' '}
|
{' '}
|
||||||
Execute TX
|
Execute TX
|
||||||
|
|
|
@ -22,6 +22,8 @@ import {
|
||||||
import { styles } from './style'
|
import { styles } from './style'
|
||||||
import Status from './Status'
|
import Status from './Status'
|
||||||
|
|
||||||
|
export const TRANSACTION_ROW_TEST_ID = 'tx-row'
|
||||||
|
|
||||||
const expandCellStyle = {
|
const expandCellStyle = {
|
||||||
paddingLeft: 0,
|
paddingLeft: 0,
|
||||||
paddingRight: 0,
|
paddingRight: 0,
|
||||||
|
@ -77,6 +79,7 @@ const TxsTable = ({
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
className={cn(classes.row, expandedTx === row.tx.creationTxHash && classes.expandedRow)}
|
className={cn(classes.row, expandedTx === row.tx.creationTxHash && classes.expandedRow)}
|
||||||
onClick={() => handleTxExpand(row.tx.creationTxHash)}
|
onClick={() => handleTxExpand(row.tx.creationTxHash)}
|
||||||
|
data-testid={TRANSACTION_ROW_TEST_ID}
|
||||||
>
|
>
|
||||||
{autoColumns.map((column: Column) => (
|
{autoColumns.map((column: Column) => (
|
||||||
<TableCell
|
<TableCell
|
||||||
|
|
|
@ -55,7 +55,7 @@ export const buildTransactionFrom = async (safeAddress: string, tx: TxServiceMod
|
||||||
const modifySettingsTx = tx.to === safeAddress && Number(tx.value) === 0 && !!tx.data
|
const modifySettingsTx = tx.to === safeAddress && Number(tx.value) === 0 && !!tx.data
|
||||||
const cancellationTx = tx.to === safeAddress && Number(tx.value) === 0 && !tx.data
|
const cancellationTx = tx.to === safeAddress && Number(tx.value) === 0 && !tx.data
|
||||||
const isTokenTransfer = await isAddressAToken(tx.to)
|
const isTokenTransfer = await isAddressAToken(tx.to)
|
||||||
const creationTxHash = confirmations.last().hash
|
const creationTxHash = confirmations.first().hash
|
||||||
|
|
||||||
let executionTxHash
|
let executionTxHash
|
||||||
const executionTx = confirmations.find(conf => conf.type === TX_TYPE_EXECUTION)
|
const executionTx = confirmations.find(conf => conf.type === TX_TYPE_EXECUTION)
|
||||||
|
|
|
@ -56,9 +56,7 @@ const processTransaction = (
|
||||||
openSnackbar('Approval transaction has been confirmed', 'success')
|
openSnackbar('Approval transaction has been confirmed', 'success')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process.env.NODE_ENV === 'test') {
|
dispatch(fetchTransactions(safeAddress))
|
||||||
dispatch(fetchTransactions(safeAddress))
|
|
||||||
}
|
|
||||||
|
|
||||||
return txHash
|
return txHash
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { fireEvent, cleanup } from '@testing-library/react'
|
import { fireEvent, cleanup } from '@testing-library/react'
|
||||||
import { List } from 'immutable'
|
|
||||||
import { aNewStore } from '~/store'
|
import { aNewStore } from '~/store'
|
||||||
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
|
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
|
||||||
import { sendTokenTo, sendEtherTo } from '~/test/utils/tokenMovements'
|
import { sendTokenTo, sendEtherTo } from '~/test/utils/tokenMovements'
|
||||||
|
@ -8,18 +7,17 @@ import { renderSafeView } from '~/test/builder/safe.dom.utils'
|
||||||
import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
|
import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
|
||||||
import { dispatchAddTokenToList } from '~/test/utils/transactions/moveTokens.helper'
|
import { dispatchAddTokenToList } from '~/test/utils/transactions/moveTokens.helper'
|
||||||
import { sleep } from '~/utils/timer'
|
import { sleep } from '~/utils/timer'
|
||||||
import TokenBalanceRecord from '~/routes/safe/store/models/tokenBalance'
|
|
||||||
import { calculateBalanceOf } from '~/routes/safe/store/actions/fetchTokenBalances'
|
|
||||||
import updateActiveTokens from '~/routes/safe/store/actions/updateActiveTokens'
|
|
||||||
import { addTransactions } from '~/routes/safe/store/actions/addTransactions'
|
|
||||||
import { buildTransactionFrom } from '~/routes/safe/store/actions/fetchTransactions'
|
|
||||||
import '@testing-library/jest-dom/extend-expect'
|
import '@testing-library/jest-dom/extend-expect'
|
||||||
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
|
||||||
import { BALANCE_ROW_TEST_ID } from '~/routes/safe/components/Balances'
|
import { BALANCE_ROW_TEST_ID } from '~/routes/safe/components/Balances'
|
||||||
import { fillAndSubmitSendFundsForm } from './utils/transactions'
|
import { fillAndSubmitSendFundsForm } from './utils/transactions'
|
||||||
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions';
|
import { TRANSACTIONS_TAB_BTN_TESTID } from '~/routes/safe/components/Layout'
|
||||||
|
import { TRANSACTION_ROW_TEST_ID } from '~/routes/safe/components/TransactionsNew/TxsTable'
|
||||||
|
import { useTestAccountAt, resetTestAccount } from './utils/accounts'
|
||||||
|
import { CONFIRM_TX_BTN_TESTID, EXECUTE_TX_BTN_TESTID } from '~/routes/safe/components/TransactionsNew/TxsTable/ExpandedTx/OwnersColumn/ButtonRow'
|
||||||
|
import { APPROVE_TX_MODAL_SUBMIT_BTN_TESTID } from '~/routes/safe/components/TransactionsNew/TxsTable/ExpandedTx/ApproveTxModal'
|
||||||
|
|
||||||
afterEach(cleanup)
|
afterEach(cleanup)
|
||||||
|
afterEach(resetTestAccount)
|
||||||
|
|
||||||
describe('DOM > Feature > Sending Funds', () => {
|
describe('DOM > Feature > Sending Funds', () => {
|
||||||
let store
|
let store
|
||||||
|
@ -51,21 +49,28 @@ describe('DOM > Feature > Sending Funds', () => {
|
||||||
await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[0])
|
await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[0])
|
||||||
|
|
||||||
// CONFIRM TX
|
// CONFIRM TX
|
||||||
const transaction = {
|
fireEvent.click(SafeDom.getByTestId(TRANSACTIONS_TAB_BTN_TESTID))
|
||||||
to: accounts[0],
|
await sleep(200)
|
||||||
value: parseInt(ethAmount, 10) * (10 ** 18),
|
|
||||||
data: EMPTY_DATA,
|
|
||||||
operation: 0,
|
|
||||||
nonce: 0,
|
|
||||||
submissionDate: new Date().toISOString(),
|
|
||||||
executionDate: null,
|
|
||||||
isExecuted: false,
|
|
||||||
confirmations: [
|
|
||||||
owner: accounts[0],
|
|
||||||
submissionDate: new Date().toISOString(),
|
|
||||||
|
|
||||||
]
|
useTestAccountAt(1)
|
||||||
}
|
await sleep(2200)
|
||||||
|
const txRows = SafeDom.getAllByTestId(TRANSACTION_ROW_TEST_ID)
|
||||||
|
expect(txRows.length).toBe(1)
|
||||||
|
|
||||||
|
fireEvent.click(txRows[0])
|
||||||
|
await sleep(100)
|
||||||
|
fireEvent.click(SafeDom.getByTestId(CONFIRM_TX_BTN_TESTID))
|
||||||
|
await sleep(100)
|
||||||
|
|
||||||
|
// Travel confirm modal
|
||||||
|
fireEvent.click(SafeDom.getByTestId(APPROVE_TX_MODAL_SUBMIT_BTN_TESTID))
|
||||||
|
await sleep(500)
|
||||||
|
|
||||||
|
// EXECUTE TX
|
||||||
|
fireEvent.click(SafeDom.getByTestId(EXECUTE_TX_BTN_TESTID))
|
||||||
|
await sleep(100)
|
||||||
|
fireEvent.click(SafeDom.getByTestId(APPROVE_TX_MODAL_SUBMIT_BTN_TESTID))
|
||||||
|
await sleep(500)
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
const safeFunds = await getBalanceInEtherOf(safeAddress)
|
const safeFunds = await getBalanceInEtherOf(safeAddress)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
// @flow
|
||||||
|
function useTestAccountAt(index: number = 0) {
|
||||||
|
window.testAccountIndex = index
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetTestAccount() {
|
||||||
|
delete window.testAccountIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
useTestAccountAt,
|
||||||
|
resetTestAccount,
|
||||||
|
}
|
Loading…
Reference in New Issue