From 5ccf024dc272d0c6ebc01996d0ea7926495650f7 Mon Sep 17 00:00:00 2001 From: apanizo Date: Thu, 5 Jul 2018 09:39:38 +0200 Subject: [PATCH] WA-232 Making sync fulfillment of Safe Forms per feature --- src/routes/safe/component/SendToken/index.jsx | 4 +-- src/test/utils/logTransactions.js | 32 +++++++++++++++++++ .../utils/transactions/addOwner.helper.js | 4 ++- .../utils/transactions/moveFunds.helper.js | 6 +++- .../utils/transactions/moveTokens.helper.js | 4 ++- .../utils/transactions/removeOwner.helper.js | 4 ++- .../utils/transactions/threshold.helper.js | 4 ++- .../utils/transactions/withdraw.helper.js | 4 ++- 8 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/routes/safe/component/SendToken/index.jsx b/src/routes/safe/component/SendToken/index.jsx index cd169590..63d80b01 100644 --- a/src/routes/safe/component/SendToken/index.jsx +++ b/src/routes/safe/component/SendToken/index.jsx @@ -53,7 +53,7 @@ const processTokenTransfer = async (safe: Safe, balance: Balance, to: string, am return createTransaction(safe, name, destination, value, nonce, userAddress, data) } -class AddTransaction extends React.Component { +class SendToken extends React.Component { state = { done: false, } @@ -109,4 +109,4 @@ class AddTransaction extends React.Component { } } -export default connect(selector, actions)(AddTransaction) +export default connect(selector, actions)(SendToken) diff --git a/src/test/utils/logTransactions.js b/src/test/utils/logTransactions.js index d86237cf..89685caa 100644 --- a/src/test/utils/logTransactions.js +++ b/src/test/utils/logTransactions.js @@ -1,5 +1,7 @@ // @flow import { getGnosisSafeInstanceAt } from '~/wallets/safeContracts' +import Stepper from '~/components/Stepper' +import TestUtils from 'react-dom/test-utils' export const printOutApprove = async ( subject: string, @@ -24,3 +26,33 @@ export const printOutApprove = async ( // eslint-disable-next-line console.log(`EO transaction executed ${await gnosisSafe.isExecuted(transactionHash)}`) } + +const MAX_TIMES_EXECUTED = 20 +const INTERVAL = 500 +type FinsihedTx = { + finishedTransaction: boolean, +} +export const whenExecuted = ( + SafeDom: React$Component, + ParentComponent: React$ElementType, +): Promise => new Promise((resolve, reject) => { + let times = 0 + const interval = setInterval(() => { + if (times >= MAX_TIMES_EXECUTED) { + clearInterval(interval) + reject() + } + + // $FlowFixMe + const SafeComponent = TestUtils.findRenderedComponentWithType(SafeDom, ParentComponent) + type StepperType = React$Component + // $FlowFixMe + const StepperComponent: StepperType = TestUtils.findRenderedComponentWithType(SafeComponent, Stepper) + + if (StepperComponent.props.finishedTransaction === true) { + clearInterval(interval) + resolve() + } + times += 1 + }, INTERVAL) +}) diff --git a/src/test/utils/transactions/addOwner.helper.js b/src/test/utils/transactions/addOwner.helper.js index 32840600..e04f2acf 100644 --- a/src/test/utils/transactions/addOwner.helper.js +++ b/src/test/utils/transactions/addOwner.helper.js @@ -2,6 +2,8 @@ import TestUtils from 'react-dom/test-utils' import { sleep } from '~/utils/timer' import { checkMinedTx, checkPendingTx } from '~/test/builder/safe.dom.utils' +import { whenExecuted } from '~/test/utils/logTransactions' +import AddOwner from '~/routes/safe/component/AddOwner' export const sendAddOwnerForm = async ( SafeDom: React$Component, @@ -34,7 +36,7 @@ export const sendAddOwnerForm = async ( TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) - return sleep(200) + return whenExecuted(SafeDom, AddOwner) } 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 0fa07b27..9c0970cf 100644 --- a/src/test/utils/transactions/moveFunds.helper.js +++ b/src/test/utils/transactions/moveFunds.helper.js @@ -2,6 +2,9 @@ import TestUtils from 'react-dom/test-utils' import { sleep } from '~/utils/timer' import { checkMinedTx, checkPendingTx } from '~/test/builder/safe.dom.utils' +import SendToken from '~/routes/safe/component/SendToken' +import { whenExecuted } from '~/test/utils/logTransactions' + export const sendMoveFundsForm = async ( SafeDom: React$Component, @@ -33,7 +36,8 @@ export const sendMoveFundsForm = async ( TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) - return sleep(200) + + return whenExecuted(SafeDom, SendToken) } 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 c7896649..0f74a2d6 100644 --- a/src/test/utils/transactions/moveTokens.helper.js +++ b/src/test/utils/transactions/moveTokens.helper.js @@ -6,6 +6,8 @@ import * as fetchBalancesAction from '~/routes/safe/store/actions/fetchBalances' import { checkMinedTx, checkPendingTx, EXPAND_BALANCE_INDEX } from '~/test/builder/safe.dom.utils' import { makeBalance, type Balance } from '~/routes/safe/store/model/balance' import addBalances from '~/routes/safe/store/actions/addBalances' +import { whenExecuted } from '~/test/utils/logTransactions' +import SendToken from '~/routes/safe/component/SendToken' export const sendMoveTokensForm = async ( SafeDom: React$Component, @@ -38,7 +40,7 @@ export const sendMoveTokensForm = async ( TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) - return sleep(200) + return whenExecuted(SafeDom, SendToken) } 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 5d400907..abe82254 100644 --- a/src/test/utils/transactions/removeOwner.helper.js +++ b/src/test/utils/transactions/removeOwner.helper.js @@ -3,6 +3,8 @@ import TestUtils from 'react-dom/test-utils' import { sleep } from '~/utils/timer' import { checkMinedTx, EXPAND_OWNERS_INDEX, checkPendingTx } from '~/test/builder/safe.dom.utils' import { filterMoveButtonsFrom } from '~/test/builder/safe.dom.builder' +import { whenExecuted } from '~/test/utils/logTransactions' +import RemoveOwner from '~/routes/safe/component/RemoveOwner' export const sendRemoveOwnerForm = async ( SafeDom: React$Component, @@ -29,7 +31,7 @@ export const sendRemoveOwnerForm = async ( TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) - return sleep(200) + return whenExecuted(SafeDom, RemoveOwner) } 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 1b710a02..7d396c67 100644 --- a/src/test/utils/transactions/threshold.helper.js +++ b/src/test/utils/transactions/threshold.helper.js @@ -3,6 +3,8 @@ import TestUtils from 'react-dom/test-utils' import { sleep } from '~/utils/timer' import { checkMinedTx } from '~/test/builder/safe.dom.utils' import { getGnosisSafeInstanceAt } from '~/wallets/safeContracts' +import Threshold from '~/routes/safe/component/Threshold' +import { whenExecuted } from '~/test/utils/logTransactions' export const sendChangeThresholdForm = async ( SafeDom: React$Component, @@ -24,7 +26,7 @@ export const sendChangeThresholdForm = async ( TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) - return sleep(200) + return whenExecuted(SafeDom, Threshold) } 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 c2f9a838..2967fb5f 100644 --- a/src/test/utils/transactions/withdraw.helper.js +++ b/src/test/utils/transactions/withdraw.helper.js @@ -3,6 +3,8 @@ import TestUtils from 'react-dom/test-utils' import { sleep } from '~/utils/timer' import { checkBalanceOf } from '~/test/utils/tokenMovements' import { checkMinedTx } from '~/test/builder/safe.dom.utils' +import { whenExecuted } from '~/test/utils/logTransactions' +import Withdraw from '~/routes/safe/component/Withdraw' export const sendWithdrawForm = async ( SafeDom: React$Component, @@ -28,7 +30,7 @@ export const sendWithdrawForm = async ( TestUtils.Simulate.submit(form) TestUtils.Simulate.submit(form) - return sleep(200) + return whenExecuted(SafeDom, Withdraw) } export const checkMinedWithdrawTx = async (