Tests wip

This commit is contained in:
Germán Martínez 2019-07-19 17:27:07 +02:00
commit f4d2215f48
2 changed files with 11 additions and 7 deletions

View File

@ -32,8 +32,11 @@ describe('DOM > Feature > Sending Funds', () => {
it('Sends ETH with threshold = 1', async () => { it('Sends ETH with threshold = 1', async () => {
// GIVEN // GIVEN
const ethAmount = '5' 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 // WHEN
const SafeDom = renderSafeView(store, safeAddress) const SafeDom = renderSafeView(store, safeAddress)
@ -45,15 +48,16 @@ describe('DOM > Feature > Sending Funds', () => {
const sendButton = SafeDom.getByTestId('balance-send-btn') const sendButton = SafeDom.getByTestId('balance-send-btn')
fireEvent.click(sendButton) fireEvent.click(sendButton)
await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[0]) const receiverBalanceBeforeTx = await getBalanceInEtherOf(accounts[9])
await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[9])
// THEN // THEN
const safeFunds = await getBalanceInEtherOf(safeAddress) const safeFunds = await getBalanceInEtherOf(safeAddress)
expect(Number(safeFunds)).toBe(0) expect(Number(safeFunds)).toBe(0)
const receiverBalanceAfterTx = await getBalanceInEtherOf(accounts[9])
const receiverFunds = await getBalanceInEtherOf(accounts[0])
const ESTIMATED_GASCOSTS = 0.3 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, parseInt(ethAmount, 10) - ESTIMATED_GASCOSTS,
) )
}) })

View File

@ -6,11 +6,11 @@ import { toNative } from '~/logic/wallets/tokens'
import TokenOMG from '../../../build/contracts/TokenOMG' import TokenOMG from '../../../build/contracts/TokenOMG'
import TokenRDN from '../../../build/contracts/TokenRDN' 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 web3 = getWeb3()
const accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
const { toBN, toWei } = web3.utils 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) return web3.eth.sendTransaction(txData)
} }