From ca53182b6528fda76fa4c6452770666147e76202 Mon Sep 17 00:00:00 2001 From: apanizo Date: Wed, 4 Jul 2018 16:31:15 +0200 Subject: [PATCH] WA-232 Fix tests --- .../safe/component/RemoveOwner/index.jsx | 5 ++--- src/routes/safe/test/Safe.withdraw.test.js | 4 +++- src/test/builder/safe.dom.utils.js | 6 ++++-- src/test/safe.dom.tokens.test.js | 1 + src/test/safe.dom.transactions.test.js | 18 +++++++++--------- src/test/utils/transactions/addOwner.helper.js | 2 ++ .../utils/transactions/moveFunds.helper.js | 2 ++ .../utils/transactions/moveTokens.helper.js | 2 ++ .../utils/transactions/removeOwner.helper.js | 2 ++ .../utils/transactions/threshold.helper.js | 2 ++ src/test/utils/transactions/withdraw.helper.js | 2 ++ 11 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/routes/safe/component/RemoveOwner/index.jsx b/src/routes/safe/component/RemoveOwner/index.jsx index eea7dcfe..25af2595 100644 --- a/src/routes/safe/component/RemoveOwner/index.jsx +++ b/src/routes/safe/component/RemoveOwner/index.jsx @@ -45,13 +45,12 @@ export const removeOwner = async ( const newThreshold = values[DECREASE_PARAM] ? threshold - 1 : threshold const safeAddress = safe.get('address') const gnosisSafe = await getSafeEthereumInstance(safeAddress) - const storedOwners = await gnosisSafe.getOwners() const index = storedOwners.findIndex(ownerAddress => ownerAddress === userToRemove) const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1] const data = gnosisSafe.contract.removeOwner.getData(prevAddress, userToRemove, newThreshold) - const text = name || userToRemove + return createTransaction(safe, `Remove Owner ${text}`, safeAddress, 0, nonce, executor, data) } @@ -65,7 +64,7 @@ class RemoveOwner extends React.Component { const { safe, threshold, executor, fetchTransactions, userToRemove, name, } = this.props - await removeOwner(values, safe, threshold, userToRemove, executor, name) + await removeOwner(values, safe, threshold, userToRemove, name, executor) fetchTransactions() this.setState({ done: true }) } catch (error) { diff --git a/src/routes/safe/test/Safe.withdraw.test.js b/src/routes/safe/test/Safe.withdraw.test.js index 9e67a314..5699ec58 100644 --- a/src/routes/safe/test/Safe.withdraw.test.js +++ b/src/routes/safe/test/Safe.withdraw.test.js @@ -20,6 +20,7 @@ import { type DailyLimitProps } from '~/routes/safe/store/model/dailyLimit' import { WITHDRAW_INDEX } from '~/test/builder/safe.dom.utils' import { buildMathPropsFrom } from '~/test/utils/buildReactRouterProps' import { safeSelector } from '~/routes/safe/store/selectors/index' +import { filterMoveButtonsFrom } from '~/test/builder/safe.dom.builder' describe('React DOM TESTS > Withdraw funds from safe', () => { let SafeDom @@ -48,7 +49,8 @@ describe('React DOM TESTS > Withdraw funds from safe', () => { const Safe = TestUtils.findRenderedComponentWithType(SafeDom, SafeView) // $FlowFixMe - const buttons = TestUtils.scryRenderedDOMComponentsWithTag(Safe, 'button') + const expandedButtons = TestUtils.scryRenderedDOMComponentsWithTag(Safe, 'button') + const buttons = filterMoveButtonsFrom(expandedButtons) const addWithdrawButton = buttons[WITHDRAW_INDEX] expect(addWithdrawButton.getElementsByTagName('span')[0].innerHTML).toEqual(WITHDRAW_BUTTON_TEXT) TestUtils.Simulate.click(addWithdrawButton) diff --git a/src/test/builder/safe.dom.utils.js b/src/test/builder/safe.dom.utils.js index 82dc6a24..c11d7571 100644 --- a/src/test/builder/safe.dom.utils.js +++ b/src/test/builder/safe.dom.utils.js @@ -20,12 +20,14 @@ export const EDIT_INDEX = 4 export const WITHDRAW_INDEX = 5 export const LIST_TXS_INDEX = 6 -export const listTxsClickingOn = async (seeTxsButton: Element) => { +export const listTxsClickingOn = async (store: Store, seeTxsButton: Element) => { + await store.dispatch(fetchTransactions()) + await sleep(1200) expect(seeTxsButton.getElementsByTagName('span')[0].innerHTML).toEqual(SEE_MULTISIG_BUTTON_TEXT) TestUtils.Simulate.click(seeTxsButton) // give some time to expand the transactions - await sleep(1500) + await sleep(800) } export const checkMinedTx = (Transaction: React$Component, name: string) => { diff --git a/src/test/safe.dom.tokens.test.js b/src/test/safe.dom.tokens.test.js index f6a7676e..7a1afbdf 100644 --- a/src/test/safe.dom.tokens.test.js +++ b/src/test/safe.dom.tokens.test.js @@ -39,6 +39,7 @@ describe('DOM > Feature > SAFE ERC20 TOKENS', () => { const expandBalance = buttons[EXPAND_BALANCE_INDEX] const receiver = accounts[2] await sendMoveTokensForm(SafeDom, expandBalance, 20, accounts[2]) + await sleep(800) // THEN const safeFunds = await fetchBalancesAction.calculateBalanceOf(tokenAddress, safeAddress) diff --git a/src/test/safe.dom.transactions.test.js b/src/test/safe.dom.transactions.test.js index 0283cc96..517e0428 100644 --- a/src/test/safe.dom.transactions.test.js +++ b/src/test/safe.dom.transactions.test.js @@ -20,7 +20,7 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => { const threshold = 1 domSafe = await renderSafeInDom(owners, threshold) const { - address, safe: SafeDom, safeButtons, accounts, + address, safe: SafeDom, safeButtons, accounts, store, } = domSafe // WHEN @@ -31,7 +31,7 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => { await sendChangeThresholdForm(SafeDom, safeButtons[EDIT_THRESHOLD_INDEX], '2') // THEN - await listTxsClickingOn(safeButtons[LIST_TXS_INDEX]) + await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX]) const transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction) checkMinedMoveFundsTx(transactions[0], 'Send 0.01 ETH to') @@ -43,7 +43,7 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => { it('mines withdraw process correctly all multisig txs in a 2 owner & 2 threshold safe', async () => { // GIVEN reusing the state from previous test const { - address, safe: SafeDom, safeButtons, accounts, + address, safe: SafeDom, safeButtons, accounts, store, } = domSafe // WHEN @@ -53,10 +53,10 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => { await sendWithdrawForm(SafeDom, safeButtons[WITHDRAW_INDEX], '0.01', accounts[3]) // THEN - await listTxsClickingOn(safeButtons[LIST_TXS_INDEX]) + await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX]) const transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction) - const statusses = ['Adol Metamask 2 [Not confirmed]', 'Adolfo 1 Eth Account [Confirmed]'] + const statusses = ['Adol Metamask 2 [Not confirmed]', 'Adol 1 Eth Account [Confirmed]'] await checkPendingMoveFundsTx(transactions[4], 2, 'Send 0.01 ETH to', statusses) await checkPendingAddOwnerTx(transactions[5], 2, 'Add Owner Adol Metamask 3', statusses) // checkMinedThresholdTx(transactions[4], 'Add Owner Adol Metamask 3') @@ -87,16 +87,16 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => { await sendRemoveOwnerForm(SafeDom, safeButtons[EXPAND_OWNERS_INDEX]) // THEN - await listTxsClickingOn(safeButtons[LIST_TXS_INDEX]) + await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX]) transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction) expect(transactions.length).toBe(8) - let statusses = ['Adol Metamask 3 [Not confirmed]', 'Adol Metamask 2 [Not confirmed]', 'Adolfo 1 Eth Account [Confirmed]'] + let statusses = ['Adol Metamask 3 [Not confirmed]', 'Adol Metamask 2 [Not confirmed]', 'Adol 1 Eth Account [Confirmed]'] await checkPendingRemoveOwnerTx(transactions[7], 3, 'Remove Owner Adol Metamask 3', statusses) await processTransaction(address, transactions[7].props.transaction, 1, accounts[1]) await refreshTransactions(store) transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction) - statusses = ['Adol Metamask 3 [Not confirmed]', 'Adol Metamask 2 [Confirmed]', 'Adolfo 1 Eth Account [Confirmed]'] + statusses = ['Adol Metamask 3 [Not confirmed]', 'Adol Metamask 2 [Confirmed]', 'Adol 1 Eth Account [Confirmed]'] await checkPendingRemoveOwnerTx(transactions[7], 2, 'Remove Owner Adol Metamask 3', statusses) await checkThresholdOf(address, 3) @@ -108,7 +108,7 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => { // WHEN... changing threshold await sendChangeThresholdForm(SafeDom, safeButtons[EDIT_THRESHOLD_INDEX], '1') - await listTxsClickingOn(safeButtons[LIST_TXS_INDEX]) + await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX]) // THEN transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction) diff --git a/src/test/utils/transactions/addOwner.helper.js b/src/test/utils/transactions/addOwner.helper.js index 941f3f43..32840600 100644 --- a/src/test/utils/transactions/addOwner.helper.js +++ b/src/test/utils/transactions/addOwner.helper.js @@ -33,6 +33,8 @@ export const sendAddOwnerForm = async ( // submit it TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) + + return sleep(200) } export const checkMinedAddOwnerTx = (Transaction: React$Component, name: string) => { diff --git a/src/test/utils/transactions/moveFunds.helper.js b/src/test/utils/transactions/moveFunds.helper.js index 5a988927..0fa07b27 100644 --- a/src/test/utils/transactions/moveFunds.helper.js +++ b/src/test/utils/transactions/moveFunds.helper.js @@ -32,6 +32,8 @@ export const sendMoveFundsForm = async ( // submit it TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) + + return sleep(200) } export const checkMinedMoveFundsTx = (Transaction: React$Component, name: string) => { diff --git a/src/test/utils/transactions/moveTokens.helper.js b/src/test/utils/transactions/moveTokens.helper.js index 81094a69..c7896649 100644 --- a/src/test/utils/transactions/moveTokens.helper.js +++ b/src/test/utils/transactions/moveTokens.helper.js @@ -37,6 +37,8 @@ export const sendMoveTokensForm = async ( // submit it TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) + + return sleep(200) } export const dispatchTknBalance = async (store: Store, tokenAddress: string, address: string) => { diff --git a/src/test/utils/transactions/removeOwner.helper.js b/src/test/utils/transactions/removeOwner.helper.js index 30ceda46..5d400907 100644 --- a/src/test/utils/transactions/removeOwner.helper.js +++ b/src/test/utils/transactions/removeOwner.helper.js @@ -28,6 +28,8 @@ export const sendRemoveOwnerForm = async ( // submit it TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) + + return sleep(200) } export const checkMinedRemoveOwnerTx = (Transaction: React$Component, name: string) => { diff --git a/src/test/utils/transactions/threshold.helper.js b/src/test/utils/transactions/threshold.helper.js index 9168aa42..1b710a02 100644 --- a/src/test/utils/transactions/threshold.helper.js +++ b/src/test/utils/transactions/threshold.helper.js @@ -23,6 +23,8 @@ export const sendChangeThresholdForm = async ( // submit it TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) + + return sleep(200) } export const checkMinedThresholdTx = (Transaction: React$Component, name: string) => { diff --git a/src/test/utils/transactions/withdraw.helper.js b/src/test/utils/transactions/withdraw.helper.js index d8e34d05..c2f9a838 100644 --- a/src/test/utils/transactions/withdraw.helper.js +++ b/src/test/utils/transactions/withdraw.helper.js @@ -27,6 +27,8 @@ export const sendWithdrawForm = async ( // submit it TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) + + return sleep(200) } export const checkMinedWithdrawTx = async (