From 9e6555a6f5abccb7fed2f4ab5cf271a3161c9307 Mon Sep 17 00:00:00 2001 From: mmv Date: Thu, 18 Jul 2019 23:13:36 +0400 Subject: [PATCH] allow passing fromAccountIndex in sendEtherTo helper, use account 9 for testing sending ETH --- src/test/safe.dom.funds.threshold=1.test.js | 16 ++++++++++------ src/test/safe.dom.funds.threshold>1.test.js | 2 +- src/test/utils/tokenMovements.js | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/test/safe.dom.funds.threshold=1.test.js b/src/test/safe.dom.funds.threshold=1.test.js index aef12d94..d4cfcf36 100644 --- a/src/test/safe.dom.funds.threshold=1.test.js +++ b/src/test/safe.dom.funds.threshold=1.test.js @@ -18,7 +18,7 @@ import { fillAndSubmitSendFundsForm } from './utils/transactions' afterEach(cleanup) -describe('DOM > Feature > Sending Funds', () => { +describe('DOM > Feature > Sending ETH', () => { let store let safeAddress: string let accounts @@ -32,8 +32,11 @@ describe('DOM > Feature > Sending Funds', () => { it('Sends ETH with threshold = 1', async () => { // GIVEN const ethAmount = '5' - await sendEtherTo(safeAddress, ethAmount) - const balanceAfterSendingEthToSafe = await getBalanceInEtherOf(accounts[0]) + + // the tests are run in parallel, lets use account 9 because it's not used anywhere else + // (in other tests we trigger transactions and pay gas for it, so we can't really make reliable + // assumptions on account's ETH balance) + await sendEtherTo(safeAddress, ethAmount, 9) // WHEN const SafeDom = renderSafeView(store, safeAddress) @@ -45,15 +48,16 @@ describe('DOM > Feature > Sending Funds', () => { const sendButton = SafeDom.getByTestId('balance-send-btn') fireEvent.click(sendButton) - await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[0]) + const receiverBalanceBeforeTx = await getBalanceInEtherOf(accounts[9]) + await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[9]) // THEN const safeFunds = await getBalanceInEtherOf(safeAddress) expect(Number(safeFunds)).toBe(0) + const receiverBalanceAfterTx = await getBalanceInEtherOf(accounts[9]) - const receiverFunds = await getBalanceInEtherOf(accounts[0]) const ESTIMATED_GASCOSTS = 0.3 - expect(Number(parseInt(receiverFunds, 10) - parseInt(balanceAfterSendingEthToSafe, 10))).toBeGreaterThan( + expect(Number(parseInt(receiverBalanceAfterTx, 10) - parseInt(receiverBalanceBeforeTx, 10))).toBeGreaterThan( parseInt(ethAmount, 10) - ESTIMATED_GASCOSTS, ) }) diff --git a/src/test/safe.dom.funds.threshold>1.test.js b/src/test/safe.dom.funds.threshold>1.test.js index 1c9b6d42..a21a496f 100644 --- a/src/test/safe.dom.funds.threshold>1.test.js +++ b/src/test/safe.dom.funds.threshold>1.test.js @@ -64,7 +64,7 @@ describe('DOM > Feature > Sending Funds', () => { // Travel confirm modal fireEvent.click(SafeDom.getByTestId(APPROVE_TX_MODAL_SUBMIT_BTN_TESTID)) - await sleep(500) + await sleep(1500) // EXECUTE TX fireEvent.click(SafeDom.getByTestId(EXECUTE_TX_BTN_TESTID)) diff --git a/src/test/utils/tokenMovements.js b/src/test/utils/tokenMovements.js index 60cbaec5..b02095ea 100644 --- a/src/test/utils/tokenMovements.js +++ b/src/test/utils/tokenMovements.js @@ -6,11 +6,11 @@ import { toNative } from '~/logic/wallets/tokens' import TokenOMG from '../../../build/contracts/TokenOMG' import TokenRDN from '../../../build/contracts/TokenRDN' -export const sendEtherTo = async (address: string, eth: string) => { +export const sendEtherTo = async (address: string, eth: string, fromAccountIndex: number = 0) => { const web3 = getWeb3() const accounts = await web3.eth.getAccounts() const { toBN, toWei } = web3.utils - const txData = { from: accounts[0], to: address, value: toBN(toWei(eth, 'ether')) } + const txData = { from: accounts[fromAccountIndex], to: address, value: toBN(toWei(eth, 'ether')) } return web3.eth.sendTransaction(txData) }