WA-232 Added move ERC20 Tokens tests
This commit is contained in:
parent
731e591218
commit
dd606940fa
|
@ -0,0 +1,70 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
|
import TestUtils from 'react-dom/test-utils'
|
||||||
|
import * as fetchBalancesAction from '~/routes/safe/store/actions/fetchBalances'
|
||||||
|
import { aNewStore } from '~/store'
|
||||||
|
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
|
||||||
|
import { addTknTo, getTokenContract } from '~/test/utils/tokenMovements'
|
||||||
|
import { EXPAND_BALANCE_INDEX, travelToSafe } from '~/test/builder/safe.dom.utils'
|
||||||
|
import { promisify } from '~/utils/promisify'
|
||||||
|
import { getWeb3 } from '~/wallets/getWeb3'
|
||||||
|
import { sendMoveTokensForm, dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper'
|
||||||
|
import { sleep } from '~/utils/timer'
|
||||||
|
|
||||||
|
describe('DOM > Feature > SAFE ERC20 TOKENS', () => {
|
||||||
|
let store
|
||||||
|
let safeAddress: string
|
||||||
|
let accounts
|
||||||
|
beforeEach(async () => {
|
||||||
|
store = aNewStore()
|
||||||
|
safeAddress = await aMinedSafe(store)
|
||||||
|
accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sends ERC20 tokens', async () => {
|
||||||
|
// GIVEN
|
||||||
|
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)
|
||||||
|
expect(Number(safeFunds)).toBe(80)
|
||||||
|
const receiverFunds = await fetchBalancesAction.calculateBalanceOf(tokenAddress, receiver)
|
||||||
|
expect(Number(receiverFunds)).toBe(20)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('disables send token button when balance is 0', async () => {
|
||||||
|
// GIVEN
|
||||||
|
const token = await getTokenContract(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)
|
||||||
|
})
|
||||||
|
})
|
|
@ -4,7 +4,7 @@ import { getProviderInfo, getBalanceInEtherOf, getWeb3 } from '~/wallets/getWeb3
|
||||||
import { promisify } from '~/utils/promisify'
|
import { promisify } from '~/utils/promisify'
|
||||||
import withdraw, { DESTINATION_PARAM, VALUE_PARAM } from '~/routes/safe/component/Withdraw/withdraw'
|
import withdraw, { DESTINATION_PARAM, VALUE_PARAM } from '~/routes/safe/component/Withdraw/withdraw'
|
||||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||||
import Token from '#/test/Token.json'
|
import Token from '#/test/FixedSupplyToken.json'
|
||||||
import { ensureOnce } from '~/utils/singleton'
|
import { ensureOnce } from '~/utils/singleton'
|
||||||
|
|
||||||
export const addEtherTo = async (address: string, eth: string) => {
|
export const addEtherTo = async (address: string, eth: string) => {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import addBalances from '~/routes/safe/store/actions/addBalances'
|
||||||
export const sendMoveTokensForm = async (
|
export const sendMoveTokensForm = async (
|
||||||
SafeDom: React$Component<any, any>,
|
SafeDom: React$Component<any, any>,
|
||||||
expandBalance: React$Component<any, any>,
|
expandBalance: React$Component<any, any>,
|
||||||
txName: string,
|
|
||||||
value: number,
|
value: number,
|
||||||
destination: string,
|
destination: string,
|
||||||
) => {
|
) => {
|
||||||
|
@ -28,10 +27,8 @@ export const sendMoveTokensForm = async (
|
||||||
|
|
||||||
// fill the form
|
// fill the form
|
||||||
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'input')
|
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'input')
|
||||||
const nameInput = inputs[0]
|
const destinationInput = inputs[0]
|
||||||
const destinationInput = inputs[1]
|
const amountofTokens = inputs[1]
|
||||||
const amountofTokens = inputs[2]
|
|
||||||
TestUtils.Simulate.change(nameInput, { target: { value: txName } })
|
|
||||||
TestUtils.Simulate.change(amountofTokens, { target: { value } })
|
TestUtils.Simulate.change(amountofTokens, { target: { value } })
|
||||||
TestUtils.Simulate.change(destinationInput, { target: { value: destination } })
|
TestUtils.Simulate.change(destinationInput, { target: { value: destination } })
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
|
|
Loading…
Reference in New Issue