allow passing fromAccountIndex in sendEtherTo helper, use account 9 for testing sending ETH

This commit is contained in:
mmv 2019-07-18 23:13:36 +04:00
parent 4955d63bdb
commit 9e6555a6f5
3 changed files with 13 additions and 9 deletions

View File

@ -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,
)
})

View File

@ -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))

View File

@ -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)
}