refactor send ETH test
This commit is contained in:
parent
cc07503f99
commit
a9cc34a0d6
|
@ -138,7 +138,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.338Z",
|
"updatedAt": "2019-06-03T08:59:02.077Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"methods": {}
|
"methods": {}
|
||||||
},
|
},
|
||||||
|
|
|
@ -32319,7 +32319,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.349Z",
|
"updatedAt": "2019-06-03T08:59:02.114Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"author": "Alan Lu - <alan.lu@gnosis.pm>Stefan George - <stefan@gnosis.pm>",
|
"author": "Alan Lu - <alan.lu@gnosis.pm>Stefan George - <stefan@gnosis.pm>",
|
||||||
"methods": {
|
"methods": {
|
||||||
|
|
|
@ -5582,7 +5582,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.346Z",
|
"updatedAt": "2019-06-03T08:59:02.084Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"methods": {
|
"methods": {
|
||||||
"allowance(address,address)": {
|
"allowance(address,address)": {
|
||||||
|
|
|
@ -1369,7 +1369,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.344Z",
|
"updatedAt": "2019-06-03T08:59:02.080Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"methods": {}
|
"methods": {}
|
||||||
},
|
},
|
||||||
|
|
|
@ -971,7 +971,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.362Z",
|
"updatedAt": "2019-06-03T08:59:02.136Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"author": "Alan Lu - <alan@gnosis.pm>",
|
"author": "Alan Lu - <alan@gnosis.pm>",
|
||||||
"methods": {},
|
"methods": {},
|
||||||
|
|
|
@ -987,7 +987,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.362Z",
|
"updatedAt": "2019-06-03T08:59:02.137Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"author": "Stefan George - <stefan@gnosis.pm>",
|
"author": "Stefan George - <stefan@gnosis.pm>",
|
||||||
"methods": {
|
"methods": {
|
||||||
|
|
|
@ -5408,7 +5408,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.347Z",
|
"updatedAt": "2019-06-03T08:59:02.087Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"methods": {}
|
"methods": {}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1854,7 +1854,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.363Z",
|
"updatedAt": "2019-06-03T08:59:02.139Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"methods": {},
|
"methods": {},
|
||||||
"title": "Abstract token contract - Functions to be implemented by token contracts"
|
"title": "Abstract token contract - Functions to be implemented by token contracts"
|
||||||
|
|
|
@ -953,7 +953,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.345Z",
|
"updatedAt": "2019-06-03T08:59:02.081Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"methods": {
|
"methods": {
|
||||||
"allowance(address,address)": {
|
"allowance(address,address)": {
|
||||||
|
|
|
@ -953,7 +953,7 @@
|
||||||
},
|
},
|
||||||
"networks": {},
|
"networks": {},
|
||||||
"schemaVersion": "3.0.10",
|
"schemaVersion": "3.0.10",
|
||||||
"updatedAt": "2019-05-31T13:47:05.345Z",
|
"updatedAt": "2019-06-03T08:59:02.082Z",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"methods": {
|
"methods": {
|
||||||
"allowance(address,address)": {
|
"allowance(address,address)": {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { createBrowserHistory } from 'history'
|
import { createBrowserHistory, createMemoryHistory } from 'history'
|
||||||
import { connectRouter, routerMiddleware } from 'connected-react-router'
|
import { connectRouter, routerMiddleware } from 'connected-react-router'
|
||||||
import {
|
import {
|
||||||
combineReducers, createStore, applyMiddleware, compose, type Reducer, type Store,
|
combineReducers, createStore, applyMiddleware, compose, type Reducer, type Store,
|
||||||
|
@ -14,7 +14,7 @@ import transactions, {
|
||||||
TRANSACTIONS_REDUCER_ID,
|
TRANSACTIONS_REDUCER_ID,
|
||||||
} from '~/routes/safe/store/reducer/transactions'
|
} from '~/routes/safe/store/reducer/transactions'
|
||||||
|
|
||||||
export const history = createBrowserHistory()
|
export const history = process.env.NODE_ENV === 'test' ? createMemoryHistory() : createBrowserHistory()
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
|
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
|
||||||
|
|
|
@ -8,6 +8,9 @@ import { EXPAND_BALANCE_INDEX, renderSafeView } from '~/test/builder/safe.dom.ut
|
||||||
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
||||||
import { sendMoveTokensForm, dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper'
|
import { sendMoveTokensForm, dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper'
|
||||||
import { sleep } from '~/utils/timer'
|
import { sleep } from '~/utils/timer'
|
||||||
|
import { ETH_ADDRESS } from '~/logic/tokens/utils/tokenHelpers'
|
||||||
|
import { calculateBalanceOf } from '~/routes/safe/store/actions/fetchTokenBalances'
|
||||||
|
import 'jest-dom/extend-expect'
|
||||||
|
|
||||||
afterEach(cleanup)
|
afterEach(cleanup)
|
||||||
|
|
||||||
|
@ -37,20 +40,33 @@ describe('DOM > Feature > Funds', () => {
|
||||||
await sleep(800)
|
await sleep(800)
|
||||||
|
|
||||||
const balanceRows = SafeDom.getAllByTestId('balance-row')
|
const balanceRows = SafeDom.getAllByTestId('balance-row')
|
||||||
const buttons = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'button')
|
expect(balanceRows[0]).toHaveTextContent(`${ethAmount} ETH`)
|
||||||
const expandBalance = buttons[EXPAND_BALANCE_INDEX]
|
const sendButton = SafeDom.getByTestId('balance-send-btn')
|
||||||
const receiver = accounts[2]
|
fireEvent.click(sendButton)
|
||||||
await sendMoveTokensForm(SafeDom, expandBalance, 20, accounts[2])
|
|
||||||
|
// Fill first send funds screen
|
||||||
|
const recipientInput = SafeDom.getByPlaceholderText('Recipient*')
|
||||||
|
const amountInput = SafeDom.getByPlaceholderText('Amount*')
|
||||||
|
const reviewBtn = SafeDom.getByTestId('review-tx-btn')
|
||||||
|
fireEvent.change(recipientInput, { target: { value: accounts[0] } })
|
||||||
|
fireEvent.change(amountInput, { target: { value: ethAmount } })
|
||||||
|
await sleep(200)
|
||||||
|
fireEvent.click(reviewBtn)
|
||||||
|
|
||||||
|
// Submit the tx (Review Tx screen)
|
||||||
|
const submitBtn = SafeDom.getByTestId('submit-tx-btn')
|
||||||
|
fireEvent.click(submitBtn)
|
||||||
|
await sleep(1000)
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
const safeFunds = await fetchBalancesAction.calculateBalanceOf(tokenAddress, safeAddress, 18)
|
const safeFunds = await calculateBalanceOf(ETH_ADDRESS, safeAddress, 18)
|
||||||
expect(Number(safeFunds)).toBe(80)
|
expect(Number(safeFunds)).toBe(0)
|
||||||
const receiverFunds = await fetchBalancesAction.calculateBalanceOf(tokenAddress, receiver, 18)
|
|
||||||
expect(Number(receiverFunds)).toBe(20)
|
|
||||||
|
|
||||||
const token = await getFirstTokenContract(getWeb3(), accounts[0])
|
const receiverFunds = await getBalanceInEtherOf(accounts[0])
|
||||||
const nativeSafeFunds = await token.balanceOf(safeAddress)
|
const ESTIMATED_GASCOSTS = 0.1
|
||||||
expect(Number(nativeSafeFunds.valueOf())).toEqual(80 * 10 ** 18)
|
expect(Number(parseInt(receiverFunds, 10) - parseInt(balanceAfterSendingEthToSafe, 10))).toBeGreaterThan(
|
||||||
|
parseInt(ethAmount, 10) - ESTIMATED_GASCOSTS,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Sends Tokens', async () => {
|
it('Sends Tokens', async () => {
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
|
import TestUtils from 'react-dom/test-utils'
|
||||||
|
import * as fetchBalancesAction from '~/logic/tokens/store/actions/fetchTokens'
|
||||||
|
import { aNewStore } from '~/store'
|
||||||
|
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
|
||||||
|
import { addTknTo, getFirstTokenContract } from '~/test/utils/tokenMovements'
|
||||||
|
import { EXPAND_BALANCE_INDEX, travelToSafe } from '~/test/builder/safe.dom.utils'
|
||||||
|
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
||||||
|
import { sendMoveTokensForm, dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper'
|
||||||
|
import { sleep } from '~/utils/timer'
|
||||||
|
|
||||||
|
describe('DOM > Feature > SAFE ERC20 TOKENS', () => {
|
||||||
|
let accounts
|
||||||
|
beforeEach(async () => {
|
||||||
|
accounts = await getWeb3().eth.getAccounts()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sends ERC20 tokens', async () => {
|
||||||
|
// GIVEN
|
||||||
|
const store = aNewStore()
|
||||||
|
const safeAddress = await aMinedSafe(store)
|
||||||
|
|
||||||
|
const numTokens = '100'
|
||||||
|
const tokenAddress = await addTknTo(safeAddress, numTokens)
|
||||||
|
|
||||||
|
await dispatchTknBalance(store, tokenAddress, safeAddress)
|
||||||
|
// const StandardToken = await fetchBalancesAction.getStandardTokenContract()
|
||||||
|
// const myToken = await StandardToken.at(tokenAddress)
|
||||||
|
// console.log(await myToken.allowance(safeAddress, accounts[2]))
|
||||||
|
// console.log(await myToken.balanceOf(safeAddress))
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
const SafeDom = await travelToSafe(store, safeAddress)
|
||||||
|
await sleep(800)
|
||||||
|
// $FlowFixMe
|
||||||
|
const buttons = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'button')
|
||||||
|
const expandBalance = buttons[EXPAND_BALANCE_INDEX]
|
||||||
|
const receiver = accounts[2]
|
||||||
|
await sendMoveTokensForm(SafeDom, expandBalance, 20, accounts[2])
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
const safeFunds = await fetchBalancesAction.calculateBalanceOf(tokenAddress, safeAddress, 18)
|
||||||
|
expect(Number(safeFunds)).toBe(80)
|
||||||
|
const receiverFunds = await fetchBalancesAction.calculateBalanceOf(tokenAddress, receiver, 18)
|
||||||
|
expect(Number(receiverFunds)).toBe(20)
|
||||||
|
|
||||||
|
const token = await getFirstTokenContract(getWeb3(), accounts[0])
|
||||||
|
const nativeSafeFunds = await token.balanceOf(safeAddress)
|
||||||
|
expect(Number(nativeSafeFunds.valueOf())).toEqual(80 * 10 ** 18)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('disables send token button when balance is 0', async () => {
|
||||||
|
// GIVEN
|
||||||
|
const token = await getFirstTokenContract(getWeb3(), accounts[0])
|
||||||
|
await dispatchTknBalance(store, token.address, safeAddress)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
const SafeDom = travelToSafe(store, safeAddress)
|
||||||
|
|
||||||
|
// $FlowFixMe
|
||||||
|
const buttons = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'button')
|
||||||
|
const expandBalance = buttons[EXPAND_BALANCE_INDEX]
|
||||||
|
|
||||||
|
TestUtils.Simulate.click(expandBalance)
|
||||||
|
await sleep(800)
|
||||||
|
|
||||||
|
// $FlowFixMe
|
||||||
|
const balanceButtons = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'button')
|
||||||
|
const tokenButton = balanceButtons[EXPAND_BALANCE_INDEX + 1] // expand button, and the next one is for sending
|
||||||
|
expect(tokenButton.hasAttribute('disabled')).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
|
@ -22,7 +22,9 @@ export const checkBalanceOf = async (addressToTest: string, value: string) => {
|
||||||
const createTokenOMGContract = async (web3: any, creator: string) => {
|
const createTokenOMGContract = async (web3: any, creator: string) => {
|
||||||
const token = contract(TokenOMG)
|
const token = contract(TokenOMG)
|
||||||
const { toBN } = web3.utils
|
const { toBN } = web3.utils
|
||||||
const amount = toBN(50000).mul(toBN(10).pow(toBN(18))).toString()
|
const amount = toBN(50000)
|
||||||
|
.mul(toBN(10).pow(toBN(18)))
|
||||||
|
.toString()
|
||||||
token.setProvider(web3.currentProvider)
|
token.setProvider(web3.currentProvider)
|
||||||
|
|
||||||
return token.new(amount, { from: creator })
|
return token.new(amount, { from: creator })
|
||||||
|
@ -31,7 +33,9 @@ const createTokenOMGContract = async (web3: any, creator: string) => {
|
||||||
const createTokenRDNContract = async (web3: any, creator: string) => {
|
const createTokenRDNContract = async (web3: any, creator: string) => {
|
||||||
const token = contract(TokenRDN)
|
const token = contract(TokenRDN)
|
||||||
const { toBN } = web3.utils
|
const { toBN } = web3.utils
|
||||||
const amount = toBN(50000).mul(toBN(10).pow(toBN(18))).toString()
|
const amount = toBN(50000)
|
||||||
|
.mul(toBN(10).pow(toBN(18)))
|
||||||
|
.toString()
|
||||||
token.setProvider(web3.currentProvider)
|
token.setProvider(web3.currentProvider)
|
||||||
|
|
||||||
return token.new(amount, { from: creator })
|
return token.new(amount, { from: creator })
|
||||||
|
|
|
@ -1294,12 +1294,6 @@
|
||||||
resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.2.2.tgz#63985d3d8b02530e0869962f4da09142ee8e200e"
|
resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.2.2.tgz#63985d3d8b02530e0869962f4da09142ee8e200e"
|
||||||
integrity sha512-n/VQ4mbfr81aqkx/XmVicOLjviMuy02eenSdJY33SVA7S2J42EU0P1H0mOogfYedb3wXA0d/LVtBrgTSm04WEA==
|
integrity sha512-n/VQ4mbfr81aqkx/XmVicOLjviMuy02eenSdJY33SVA7S2J42EU0P1H0mOogfYedb3wXA0d/LVtBrgTSm04WEA==
|
||||||
|
|
||||||
"@gnosis.pm/mock-contract@github:gnosis/mock-contract#sol_0_5_0":
|
|
||||||
version "2.0.2"
|
|
||||||
resolved "https://codeload.github.com/gnosis/mock-contract/tar.gz/2ec1266eeef1baf7514cdb65b3a3a1aef224f3f2"
|
|
||||||
dependencies:
|
|
||||||
ethereumjs-abi "^0.6.5"
|
|
||||||
|
|
||||||
"@gnosis.pm/safe-contracts@^1.0.0":
|
"@gnosis.pm/safe-contracts@^1.0.0":
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-contracts/-/safe-contracts-1.0.0.tgz#2b562b1e23a0da1047a9f38ef71a70f811e75dd9"
|
resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-contracts/-/safe-contracts-1.0.0.tgz#2b562b1e23a0da1047a9f38ef71a70f811e75dd9"
|
||||||
|
@ -6890,7 +6884,7 @@ ethereumjs-abi@0.6.5:
|
||||||
bn.js "^4.10.0"
|
bn.js "^4.10.0"
|
||||||
ethereumjs-util "^4.3.0"
|
ethereumjs-util "^4.3.0"
|
||||||
|
|
||||||
ethereumjs-abi@^0.6.5, ethereumjs-abi@^0.6.7, "ethereumjs-abi@git+https://github.com/ethereumjs/ethereumjs-abi.git":
|
ethereumjs-abi@^0.6.7, "ethereumjs-abi@git+https://github.com/ethereumjs/ethereumjs-abi.git":
|
||||||
version "0.6.7"
|
version "0.6.7"
|
||||||
resolved "git+https://github.com/ethereumjs/ethereumjs-abi.git#8431eab7b3384e65e8126a4602520b78031666fb"
|
resolved "git+https://github.com/ethereumjs/ethereumjs-abi.git#8431eab7b3384e65e8126a4602520b78031666fb"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in New Issue