add test for sending funds with threshold = 2
This commit is contained in:
parent
4342fc1b7a
commit
abae5ab25a
|
@ -57,6 +57,10 @@ const getProviderName: Function = (web3Provider): boolean => {
|
|||
const getAccountFrom: Function = async (web3Provider): Promise<string | null> => {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import Transactions from './TransactionsNew'
|
|||
import Settings from './Settings'
|
||||
|
||||
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'
|
||||
|
||||
type State = {
|
||||
|
@ -144,7 +145,7 @@ class Layout extends React.Component<Props, State> {
|
|||
<Row>
|
||||
<Tabs value={tabIndex} onChange={this.handleChange} indicatorColor="secondary" textColor="secondary">
|
||||
<Tab label="Balances" />
|
||||
<Tab label="Transactions" />
|
||||
<Tab label="Transactions" data-testid={TRANSACTIONS_TAB_BTN_TESTID} />
|
||||
<Tab label="Settings" data-testid={SETTINGS_TAB_BTN_TESTID} />
|
||||
</Tabs>
|
||||
</Row>
|
||||
|
|
|
@ -16,6 +16,8 @@ import Paragraph from '~/components/layout/Paragraph'
|
|||
import { type Transaction } from '~/routes/safe/store/models/transaction'
|
||||
import { styles } from './style'
|
||||
|
||||
export const APPROVE_TX_MODAL_SUBMIT_BTN_TESTID = 'approve-tx-modal-submit-btn'
|
||||
|
||||
type Props = {
|
||||
onClose: () => void,
|
||||
classes: Object,
|
||||
|
@ -113,6 +115,7 @@ const ApproveTxModal = ({
|
|||
minHeight={42}
|
||||
color="primary"
|
||||
onClick={approveTx}
|
||||
testId={APPROVE_TX_MODAL_SUBMIT_BTN_TESTID}
|
||||
>
|
||||
{title}
|
||||
</Button>
|
||||
|
|
|
@ -7,6 +7,9 @@ import Row from '~/components/layout/Row'
|
|||
import Button from '~/components/layout/Button'
|
||||
import { sm, lg } from '~/theme/variables'
|
||||
|
||||
export const CONFIRM_TX_BTN_TESTID = 'confirm-btn'
|
||||
export const EXECUTE_TX_BTN_TESTID = 'execute-btn'
|
||||
|
||||
type Props = {
|
||||
onTxConfirm: Function,
|
||||
onTxCancel: Function,
|
||||
|
@ -54,14 +57,28 @@ const ButtonRow = ({
|
|||
</Button>
|
||||
)}
|
||||
{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} />
|
||||
{' '}
|
||||
Confirm TX
|
||||
</Button>
|
||||
)}
|
||||
{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} />
|
||||
{' '}
|
||||
Execute TX
|
||||
|
|
|
@ -22,6 +22,8 @@ import {
|
|||
import { styles } from './style'
|
||||
import Status from './Status'
|
||||
|
||||
export const TRANSACTION_ROW_TEST_ID = 'tx-row'
|
||||
|
||||
const expandCellStyle = {
|
||||
paddingLeft: 0,
|
||||
paddingRight: 0,
|
||||
|
@ -77,6 +79,7 @@ const TxsTable = ({
|
|||
tabIndex={-1}
|
||||
className={cn(classes.row, expandedTx === row.tx.creationTxHash && classes.expandedRow)}
|
||||
onClick={() => handleTxExpand(row.tx.creationTxHash)}
|
||||
data-testid={TRANSACTION_ROW_TEST_ID}
|
||||
>
|
||||
{autoColumns.map((column: Column) => (
|
||||
<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 cancellationTx = tx.to === safeAddress && Number(tx.value) === 0 && !tx.data
|
||||
const isTokenTransfer = await isAddressAToken(tx.to)
|
||||
const creationTxHash = confirmations.last().hash
|
||||
const creationTxHash = confirmations.first().hash
|
||||
|
||||
let executionTxHash
|
||||
const executionTx = confirmations.find(conf => conf.type === TX_TYPE_EXECUTION)
|
||||
|
|
|
@ -56,9 +56,7 @@ const processTransaction = (
|
|||
openSnackbar('Approval transaction has been confirmed', 'success')
|
||||
}
|
||||
|
||||
if (!process.env.NODE_ENV === 'test') {
|
||||
dispatch(fetchTransactions(safeAddress))
|
||||
}
|
||||
dispatch(fetchTransactions(safeAddress))
|
||||
|
||||
return txHash
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// @flow
|
||||
import { fireEvent, cleanup } from '@testing-library/react'
|
||||
import { List } from 'immutable'
|
||||
import { aNewStore } from '~/store'
|
||||
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
|
||||
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 { dispatchAddTokenToList } from '~/test/utils/transactions/moveTokens.helper'
|
||||
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 updateSafe from '~/routes/safe/store/actions/updateSafe'
|
||||
import { BALANCE_ROW_TEST_ID } from '~/routes/safe/components/Balances'
|
||||
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(resetTestAccount)
|
||||
|
||||
describe('DOM > Feature > Sending Funds', () => {
|
||||
let store
|
||||
|
@ -51,21 +49,28 @@ describe('DOM > Feature > Sending Funds', () => {
|
|||
await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[0])
|
||||
|
||||
// CONFIRM TX
|
||||
const transaction = {
|
||||
to: accounts[0],
|
||||
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(),
|
||||
fireEvent.click(SafeDom.getByTestId(TRANSACTIONS_TAB_BTN_TESTID))
|
||||
await sleep(200)
|
||||
|
||||
]
|
||||
}
|
||||
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
|
||||
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