Removing daily limit refences in tests

This commit is contained in:
apanizo 2018-10-15 12:45:02 +02:00
parent 15613c869d
commit 9b647a8e20
9 changed files with 62 additions and 343 deletions

View File

@ -1,6 +1,6 @@
// @flow
import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import { buildOwnersFrom, buildDailyLimitFrom } from '~/routes/safe/store/actions'
import { buildOwnersFrom } from '~/routes/safe/store/actions'
class SafeBuilder {
safe: Safe
@ -24,12 +24,6 @@ class SafeBuilder {
return this
}
withDailyLimit(limit: number, spentToday: number = 0) {
const dailyLimit = buildDailyLimitFrom(limit, spentToday)
this.safe = this.safe.set('dailyLimit', dailyLimit)
return this
}
withOwner(names: string[], adresses: string[]) {
const owners = buildOwnersFrom(names, adresses)
this.safe = this.safe.set('owners', owners)
@ -48,7 +42,6 @@ export class SafeFactory {
.withAddress('0x03db1a8b26d08df23337e9276a36b474510f0025')
.withName('Adol ICO Safe')
.withConfirmations(1)
.withDailyLimit(10)
.withOwner(['Adol Metamask'], [ownerAddress])
.get()
@ -60,19 +53,7 @@ export class SafeFactory {
['Adol Metamask', 'Tobias Metamask'],
[firstOwner, secondOwner],
)
.withDailyLimit(10, 1.34)
.get()
static dailyLimitSafe = (dailyLimit: number, spentToday: number) => aSafe()
.withAddress('0x03db1a8b26d08df23337e9276a36b474510f0027')
.withName('Adol & Tobias Safe')
.withConfirmations(2)
.withOwner(
['Adol Metamask', 'Tobias Metamask'],
['0x03db1a8b26d08df23337e9276a36b474510f0023', '0x03db1a8b26d08df23337e9276a36b474510f0024'],
)
.withDailyLimit(dailyLimit, spentToday)
.get()
}
export default aSafe

View File

@ -34,7 +34,6 @@ const SafeTable = ({ safes }: Props) => (
<TableCell padding="none">{safe.get('address')}</TableCell>
<TableCell padding="none" numeric>{safe.get('threshold')}</TableCell>
<TableCell padding="none" numeric>{safe.get('owners').count()}</TableCell>
<TableCell padding="none" numeric>{`${safe.get('dailyLimit').get('value')} ETH`}</TableCell>
</TableRow>
))}
</TableBody>

View File

@ -1,6 +1,6 @@
// @flow
import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import { buildOwnersFrom, buildDailyLimitFrom } from '~/routes/safe/store/actions'
import { buildOwnersFrom } from '~/routes/safe/store/actions'
import { FIELD_NAME, FIELD_CONFIRMATIONS, FIELD_OWNERS, getOwnerNameBy, getOwnerAddressBy, FIELD_DAILY_LIMIT } from '~/routes/open/components/fields'
import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
@ -32,12 +32,6 @@ class SafeBuilder {
return this
}
withDailyLimit(limit: number, spentToday: number = 0) {
const dailyLimit = buildDailyLimitFrom(limit, spentToday)
this.safe = this.safe.set('dailyLimit', dailyLimit)
return this
}
withOwner(names: string[], adresses: string[]) {
const owners = buildOwnersFrom(names, adresses)
this.safe = this.safe.set('owners', owners)
@ -56,7 +50,6 @@ export class SafeFactory {
.withAddress('0x03db1a8b26d08df23337e9276a36b474510f0025')
.withName('Adol ICO Safe')
.withConfirmations(1)
.withDailyLimit(10)
.withOwner(['Adol Metamask'], [ownerAddress])
.get()
@ -68,19 +61,7 @@ export class SafeFactory {
['Adol Metamask', 'Tobias Metamask'],
[firstOwner, secondOwner],
)
.withDailyLimit(10, 1.34)
.get()
static dailyLimitSafe = (dailyLimit: number, spentToday: number) => aSafe()
.withAddress('0x03db1a8b26d08df23337e9276a36b474510f0027')
.withName('Adol & Tobias Safe')
.withConfirmations(2)
.withOwner(
['Adol Metamask', 'Tobias Metamask'],
['0x03db1a8b26d08df23337e9276a36b474510f0023', '0x03db1a8b26d08df23337e9276a36b474510f0024'],
)
.withDailyLimit(dailyLimit, spentToday)
.get()
}
export const aMinedSafe = async (

View File

@ -1,33 +0,0 @@
// @flow
import { type Match } from 'react-router-dom'
import { aNewStore } from '~/store'
import { addEtherTo, executeWithdrawOn } from '~/test/utils/tokenMovements'
import { buildMathPropsFrom } from '~/test/utils/buildReactRouterProps'
import { safeSelector } from '~/routes/safe/store/selectors/index'
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
describe('DailyLimit Blockchain Test', () => {
let store
beforeEach(async () => {
store = aNewStore()
})
it('wihdrawn should return revert error if exceeded dailyLimit', async () => {
// GIVEN
const dailyLimitValue = 0.30
const safeAddress = await aMinedSafe(store, 1, 1, dailyLimitValue)
await addEtherTo(safeAddress, '0.7')
const value = 0.15
// WHEN
const match: Match = buildMathPropsFrom(safeAddress)
const safe = safeSelector(store.getState(), { match })
if (!safe) throw new Error()
await executeWithdrawOn(safe, value)
await executeWithdrawOn(safe, value)
// THEN
expect(executeWithdrawOn(safe, value)).rejects.toThrow('VM Exception while processing transaction: revert Daily limit has been reached')
})
})

View File

@ -1,17 +1,16 @@
// @flow
import TestUtils from 'react-dom/test-utils'
import { List } from 'immutable'
import Transaction from '~/routes/safe/component/Transactions/Transaction'
import { listTxsClickingOn, LIST_TXS_INDEX, ADD_OWNERS_INDEX, EXPAND_OWNERS_INDEX, EDIT_THRESHOLD_INDEX, WITHDRAW_INDEX, refreshTransactions, EXPAND_BALANCE_INDEX } from '~/test/builder/safe.dom.utils'
import { listTxsClickingOn, LIST_TXS_INDEX, ADD_OWNERS_INDEX, EXPAND_OWNERS_INDEX, EDIT_THRESHOLD_INDEX, refreshTransactions, EXPAND_BALANCE_INDEX } from '~/test/builder/safe.dom.utils'
import { renderSafeInDom, type DomSafe } from '~/test/builder/safe.dom.builder'
import { sendMoveFundsForm, checkMinedMoveFundsTx, checkPendingMoveFundsTx } from '~/test/utils/transactions/moveFunds.helper'
import { sendAddOwnerForm, checkMinedAddOwnerTx, checkPendingAddOwnerTx } from '~/test/utils/transactions/addOwner.helper'
import { sendRemoveOwnerForm, checkMinedRemoveOwnerTx, checkPendingRemoveOwnerTx } from '~/test/utils/transactions/removeOwner.helper'
import { checkMinedThresholdTx, sendChangeThresholdForm, checkThresholdOf } from '~/test/utils/transactions/threshold.helper'
import { sendWithdrawForm, checkMinedWithdrawTx } from '~/test/utils/transactions/withdraw.helper'
import { checkBalanceOf } from '~/test/utils/tokenMovements'
import { sleep } from '~/utils/timer'
import { processTransaction } from '~/logic/safe/safeFrontendOperations'
import { allowedModulesInTxHistoryService } from '~/config'
describe('DOM > Feature > SAFE MULTISIG Transactions', () => {
let domSafe: DomSafe
@ -24,12 +23,8 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => {
address, safe: SafeDom, safeButtons, accounts, store,
} = domSafe
const allowedModules = allowedModulesInTxHistoryService()
// WHEN
await sendMoveFundsForm(SafeDom, safeButtons[EXPAND_BALANCE_INDEX], '0.01', accounts[1])
if (allowedModules) {
await sendWithdrawForm(SafeDom, safeButtons[WITHDRAW_INDEX], '0.01', accounts[3])
}
await sendAddOwnerForm(SafeDom, safeButtons[ADD_OWNERS_INDEX], 'Adol Metamask 2', accounts[1])
await sleep(1200)
await sendChangeThresholdForm(SafeDom, safeButtons[EDIT_THRESHOLD_INDEX], '2')
@ -39,14 +34,8 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => {
const transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
checkMinedMoveFundsTx(transactions[0], 'Send 0.01 ETH to')
if (allowedModules) {
await checkMinedWithdrawTx(transactions[1], 'Withdraw movement of 0.01', address, '0.08') // 0.1 - 0.01 tx - 0.01 withdraw
checkMinedAddOwnerTx(transactions[2], 'Add Owner Adol Metamask 2')
checkMinedThresholdTx(transactions[3], 'Change Safe\'s threshold')
} else {
checkMinedAddOwnerTx(transactions[1], 'Add Owner Adol Metamask 2')
checkMinedThresholdTx(transactions[2], 'Change Safe\'s threshold')
}
checkMinedAddOwnerTx(transactions[1], 'Add Owner Adol Metamask 2')
checkMinedThresholdTx(transactions[2], 'Change Safe\'s threshold')
})
it.only('mines withdraw process correctly all multisig txs in a 2 owner & 2 threshold safe', async () => {
@ -55,30 +44,19 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => {
address, safe: SafeDom, safeButtons, accounts, store,
} = domSafe
const allowedModules = allowedModulesInTxHistoryService()
// WHEN
await sendMoveFundsForm(SafeDom, safeButtons[EXPAND_BALANCE_INDEX], '0.01', accounts[1])
const increaseThreshold = true
await sendAddOwnerForm(SafeDom, safeButtons[ADD_OWNERS_INDEX], 'Adol Metamask 3', accounts[2], increaseThreshold)
if (allowedModules) {
await sendWithdrawForm(SafeDom, safeButtons[WITHDRAW_INDEX], '0.01', accounts[3])
}
// THEN
await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX], address)
const transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
if (allowedModules) {
const statusses = ['Adol 1 Eth Account [Confirmed]']
await checkPendingMoveFundsTx(transactions[4], 2, 'Send 0.01 ETH to', statusses)
await checkPendingAddOwnerTx(transactions[5], 2, 'Add Owner Adol Metamask 3', statusses)
await checkMinedWithdrawTx(transactions[6], 'Withdraw movement of 0.01', address, '0.07')
} else {
const statusses = ['Adol 1 Eth Account [Confirmed]']
await checkPendingMoveFundsTx(transactions[3], 2, 'Send 0.01 ETH to', statusses)
await checkPendingAddOwnerTx(transactions[4], 2, 'Add Owner Adol Metamask 3', statusses)
await checkBalanceOf(address, '0.09')
}
const statusses = ['Adol 1 Eth Account [Confirmed]']
await checkPendingMoveFundsTx(transactions[3], 2, 'Send 0.01 ETH to', statusses)
await checkPendingAddOwnerTx(transactions[4], 2, 'Add Owner Adol Metamask 3', statusses)
await checkBalanceOf(address, '0.09')
})
it.only('approves and executes pending transactions', async () => {
@ -87,103 +65,59 @@ describe('DOM > Feature > SAFE MULTISIG Transactions', () => {
address, safe: SafeDom, safeButtons, accounts, store,
} = domSafe
const allowedModules = allowedModulesInTxHistoryService()
let transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
expect(transactions.length).toBe(5)
await checkThresholdOf(address, 2)
if (allowedModules) {
let transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
expect(transactions.length).toBe(7)
await checkThresholdOf(address, 3)
// WHEN... processing pending TXs
await processTransaction(address, transactions[3].props.transaction, 1, accounts[1], 2, List([accounts[0]]))
await processTransaction(address, transactions[4].props.transaction, 1, accounts[1], 2, List([accounts[0]]))
await refreshTransactions(store, address)
// WHEN... processing pending TXs
await processTransaction(address, transactions[4].props.transaction, 1, accounts[1], 3)
await processTransaction(address, transactions[5].props.transaction, 1, accounts[1], 3)
await refreshTransactions(store, address)
// THEN
checkMinedMoveFundsTx(transactions[3], 'Send 0.01 ETH to')
await checkBalanceOf(address, '0.08')
checkMinedAddOwnerTx(transactions[4], 'Add Owner Adol Metamask 3')
await checkThresholdOf(address, 3)
// THEN
checkMinedMoveFundsTx(transactions[4], 'Send 0.01 ETH to')
await checkBalanceOf(address, '0.06')
checkMinedAddOwnerTx(transactions[5], 'Add Owner Adol Metamask 3')
await checkThresholdOf(address, 3)
// WHEN... reducing threshold
await sendRemoveOwnerForm(SafeDom, safeButtons[EXPAND_OWNERS_INDEX])
// WHEN... reducing threshold
await sendRemoveOwnerForm(SafeDom, safeButtons[EXPAND_OWNERS_INDEX])
// THEN
await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX], address)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
expect(transactions.length).toBe(6)
let statusses = ['Adol 1 Eth Account [Confirmed]']
await checkPendingRemoveOwnerTx(transactions[5], 3, 'Remove Owner Adol Metamask 3', statusses)
// THEN
await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX], address)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
expect(transactions.length).toBe(8)
let statusses = ['Adol Metamask 3 [Not confirmed]', 'Adol Metamask 2 [Not confirmed]', 'Adol 1 Eth Account [Confirmed]']
await checkPendingRemoveOwnerTx(transactions[7], 3, 'Remove Owner Adol Metamask 3', statusses)
await processTransaction(address, transactions[5].props.transaction, 1, accounts[2], 3, List([accounts[0]]))
await refreshTransactions(store, address)
await processTransaction(address, transactions[7].props.transaction, 1, accounts[1], 3)
await refreshTransactions(store, address)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
statusses = ['Adol Metamask 3 [Not confirmed]', 'Adol Metamask 2 [Confirmed]', 'Adol 1 Eth Account [Confirmed]']
await checkPendingRemoveOwnerTx(transactions[7], 2, 'Remove Owner Adol Metamask 3', statusses)
await checkThresholdOf(address, 3)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
statusses = ['Adol Metamask 3 [Confirmed]', 'Adol 1 Eth Account [Confirmed]']
await checkPendingRemoveOwnerTx(transactions[5], 3, 'Remove Owner Adol Metamask 3', statusses)
await checkThresholdOf(address, 3)
await processTransaction(
address,
transactions[5].props.transaction,
2,
accounts[1],
3,
List([accounts[0], accounts[2]]),
)
await processTransaction(address, transactions[7].props.transaction, 2, accounts[2], 3)
await refreshTransactions(store, address)
await checkThresholdOf(address, 2)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
await checkMinedRemoveOwnerTx(transactions[7], 'Remove Owner')
await refreshTransactions(store, address)
await checkThresholdOf(address, 2)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
await checkMinedRemoveOwnerTx(transactions[5], 'Remove Owner')
// WHEN... changing threshold
await sendChangeThresholdForm(SafeDom, safeButtons[EDIT_THRESHOLD_INDEX], '1')
await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX], address)
// WHEN... changing threshold
await sendChangeThresholdForm(SafeDom, safeButtons[EDIT_THRESHOLD_INDEX], '1')
await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX], address)
// THEN
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
await processTransaction(address, transactions[8].props.transaction, 1, accounts[1], 2)
await checkThresholdOf(address, 1)
} else {
let transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
expect(transactions.length).toBe(5)
await checkThresholdOf(address, 2)
// WHEN... processing pending TXs
await processTransaction(address, transactions[3].props.transaction, 1, accounts[1], 2)
await processTransaction(address, transactions[4].props.transaction, 1, accounts[1], 2)
await refreshTransactions(store, address)
// THEN
checkMinedMoveFundsTx(transactions[3], 'Send 0.01 ETH to')
await checkBalanceOf(address, '0.08')
checkMinedAddOwnerTx(transactions[4], 'Add Owner Adol Metamask 3')
await checkThresholdOf(address, 3)
// WHEN... reducing threshold
await sendRemoveOwnerForm(SafeDom, safeButtons[EXPAND_OWNERS_INDEX])
// THEN
await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX], address)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
expect(transactions.length).toBe(6)
let statusses = ['Adol 1 Eth Account [Confirmed]']
await checkPendingRemoveOwnerTx(transactions[5], 3, 'Remove Owner Adol Metamask 3', statusses)
await processTransaction(address, transactions[5].props.transaction, 1, accounts[2], 3)
await refreshTransactions(store, address)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
statusses = ['Adol Metamask 3 [Confirmed]', 'Adol 1 Eth Account [Confirmed]']
await checkPendingRemoveOwnerTx(transactions[5], 3, 'Remove Owner Adol Metamask 3', statusses)
await checkThresholdOf(address, 3)
await processTransaction(address, transactions[5].props.transaction, 2, accounts[1], 3)
await refreshTransactions(store, address)
await checkThresholdOf(address, 2)
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
await checkMinedRemoveOwnerTx(transactions[5], 'Remove Owner')
// WHEN... changing threshold
await sendChangeThresholdForm(SafeDom, safeButtons[EDIT_THRESHOLD_INDEX], '1')
await listTxsClickingOn(store, safeButtons[LIST_TXS_INDEX], address)
// THEN
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
await processTransaction(address, transactions[6].props.transaction, 1, accounts[1], 2)
await checkThresholdOf(address, 1)
}
// THEN
transactions = TestUtils.scryRenderedComponentsWithType(SafeDom, Transaction)
await processTransaction(address, transactions[6].props.transaction, 1, accounts[1], 2, List([accounts[0]]))
await checkThresholdOf(address, 1)
})
})

View File

@ -1,4 +1,5 @@
// @flow
import { List } from 'immutable'
import { aNewStore } from '~/store'
import { getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
@ -19,7 +20,7 @@ import { allowedRemoveSenderInTxHistoryService } from '~/config'
import { calculateValuesAfterRemoving } from '~/routes/open/components/SafeOwnersForm'
describe('React DOM TESTS > Add and remove owners', () => {
const processOwnerModification = async (store, safeAddress, executor, threshold) => {
const processOwnerModification = async (store, safeAddress, executor, threshold, alreadyConfirmed) => {
const reduxTransactions = safeTransactionsSelector(store.getState(), { safeAddress })
const tx = reduxTransactions.get(0)
if (!tx) throw new Error()
@ -30,7 +31,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
expect(data).not.toBe(undefined)
expect(data).not.toBe('')
return processTransaction(safeAddress, tx, confirmed, executor, threshold)
return processTransaction(safeAddress, tx, confirmed, executor, threshold, alreadyConfirmed)
}
const assureThresholdIs = async (gnosisSafe, threshold: number) => {
@ -173,7 +174,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
let safe = getSafeFrom(store.getState(), address)
await removeOwner(values, safe, threshold, accounts[1], 'Adol Metamask 2', accounts[0])
await store.dispatch(fetchTransactions(address))
await processOwnerModification(store, address, accounts[1], 2)
await processOwnerModification(store, address, accounts[1], 2, List([accounts[0]]))
await assureThresholdIs(gnosisSafe, 1)
await assureOwnersAre(gnosisSafe, accounts[0])
@ -198,7 +199,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
let safe = getSafeFrom(store.getState(), address)
await removeOwner(values, safe, threshold, accounts[2], 'Adol Metamask 3', accounts[0])
await store.dispatch(fetchTransactions(address))
await processOwnerModification(store, address, accounts[1], 2)
await processOwnerModification(store, address, accounts[1], 2, List([accounts[0]]))
await assureThresholdIs(gnosisSafe, 1)
await assureOwnersAre(gnosisSafe, accounts[0], accounts[1])
@ -224,7 +225,7 @@ describe('React DOM TESTS > Add and remove owners', () => {
let safe = getSafeFrom(store.getState(), address)
await removeOwner(values, safe, threshold, accounts[2], 'Adol Metamask 3', accounts[0])
await store.dispatch(fetchTransactions(address))
await processOwnerModification(store, address, accounts[1], 2)
await processOwnerModification(store, address, accounts[1], 2, List([accounts[0]]))
await assureThresholdIs(gnosisSafe, 2)
await assureOwnersAre(gnosisSafe, accounts[0], accounts[1])

View File

@ -1,84 +0,0 @@
// @flow
import * as React from 'react'
import TestUtils from 'react-dom/test-utils'
import { Provider } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux'
import { aNewStore, history } from '~/store'
import { addEtherTo } from '~/test/utils/tokenMovements'
import { executeWithdrawOn } from '~/routes/safe/store/test/builder/deployedSafe.builder'
import { SAFELIST_ADDRESS } from '~/routes/routes'
import SafeView from '~/routes/safe/component/Safe'
import AppRoutes from '~/routes'
import { WITHDRAW_BUTTON_TEXT } from '~/routes/safe/component/Safe/DailyLimit'
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
import { sleep } from '~/utils/timer'
import { type DailyLimitProps } from '~/routes/safe/store/model/dailyLimit'
import { WITHDRAW_INDEX } from '~/test/builder/safe.dom.utils'
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { getSafeFrom } from '~/test/utils/safeHelper'
import { filterMoveButtonsFrom } from '~/test/builder/safe.dom.builder'
import { fetchTokens } from '~/routes/tokens/store/actions/fetchTokens'
import { getDailyLimitFrom } from '~/logic/contracts/dailyLimitContracts'
describe('React DOM TESTS > Withdraw funds from safe', () => {
let store
let safeAddress: string
beforeEach(async () => {
store = aNewStore()
safeAddress = await aMinedSafe(store)
})
it('should withdraw funds under dailyLimit without needing confirmations', async () => {
// add funds to safe
await addEtherTo(safeAddress, '0.1')
const safe = getSafeFrom(store.getState(), safeAddress)
await executeWithdrawOn(safe, 0.01)
const safeBalance = await getBalanceInEtherOf(safeAddress)
expect(safeBalance).toBe('0.09')
})
it('spentToday dailyLimitModule property is updated correctly', async () => {
// add funds to safe
await addEtherTo(safeAddress, '0.1')
const safe = getSafeFrom(store.getState(), safeAddress)
await executeWithdrawOn(safe, 0.01)
await executeWithdrawOn(safe, 0.01)
const ethAddress = 0
const dailyLimit: DailyLimitProps = await getDailyLimitFrom(safeAddress, ethAddress)
// THEN
expect(dailyLimit.value).toBe(0.5)
expect(dailyLimit.spentToday).toBe(0.02)
})
it('Withdraw button disabled when balance is 0', async () => {
// navigate to SAFE route
history.push(`${SAFELIST_ADDRESS}/${safeAddress}`)
const SafeDom = TestUtils.renderIntoDocument((
<Provider store={store}>
<ConnectedRouter history={history}>
<AppRoutes />
</ConnectedRouter>
</Provider>
))
await sleep(300)
const Safe = TestUtils.findRenderedComponentWithType(SafeDom, SafeView)
// $FlowFixMe
const buttons = TestUtils.scryRenderedDOMComponentsWithTag(Safe, 'button')
const filteredButtons = filterMoveButtonsFrom(buttons)
const addWithdrawButton = filteredButtons[WITHDRAW_INDEX]
expect(addWithdrawButton.getElementsByTagName('span')[0].innerHTML).toEqual(WITHDRAW_BUTTON_TEXT)
expect(addWithdrawButton.hasAttribute('disabled')).toBe(true)
await addEtherTo(safeAddress, '0.1')
await store.dispatch(fetchTokens(safeAddress))
await sleep(150)
expect(addWithdrawButton.hasAttribute('disabled')).toBe(false)
})
})

View File

@ -1,12 +1,9 @@
// @flow
import contract from 'truffle-contract'
import { getProviderInfo, getBalanceInEtherOf, getWeb3 } from '~/logic/wallets/getWeb3'
import { getBalanceInEtherOf, getWeb3 } from '~/logic/wallets/getWeb3'
import { promisify } from '~/utils/promisify'
import { type Safe } from '~/routes/safe/store/model/safe'
import Token from '#/test/TestToken.json'
import { ensureOnce } from '~/utils/singleton'
import { DESTINATION_PARAM, VALUE_PARAM } from '~/routes/safe/component/Withdraw/WithdrawForm'
import { withdraw } from '~/logic/safe/safeFrontendOperations'
import { toNative } from '~/logic/wallets/tokens'
export const addEtherTo = async (address: string, eth: string) => {
@ -16,18 +13,6 @@ export const addEtherTo = async (address: string, eth: string) => {
return promisify(cb => web3.eth.sendTransaction(txData, cb))
}
export const executeWithdrawOn = async (safe: Safe, value: number) => {
const providerInfo = await getProviderInfo()
const userAddress = providerInfo.account
const values = {
[DESTINATION_PARAM]: userAddress,
[VALUE_PARAM]: `${value}`,
}
return withdraw(values, safe, userAddress)
}
export const checkBalanceOf = async (addressToTest: string, value: string) => {
const safeBalance = await getBalanceInEtherOf(addressToTest)
expect(safeBalance).toBe(value)

View File

@ -1,45 +0,0 @@
// @flow
import TestUtils from 'react-dom/test-utils'
import { sleep } from '~/utils/timer'
import { checkBalanceOf } from '~/test/utils/tokenMovements'
import { checkMinedTx } from '~/test/builder/safe.dom.utils'
import { whenExecuted } from '~/test/utils/logTransactions'
import Withdraw from '~/routes/safe/component/Withdraw'
export const sendWithdrawForm = async (
SafeDom: React$Component<any, any>,
withdrawButton: React$Component<any, any>,
amount: string,
destination: string,
) => {
// load add multisig form component
TestUtils.Simulate.click(withdrawButton)
// give time to re-render it
await sleep(400)
// fill the form
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'input')
const amountInput = inputs[0]
const destinationInput = inputs[1]
TestUtils.Simulate.change(amountInput, { target: { value: amount } })
TestUtils.Simulate.change(destinationInput, { target: { value: destination } })
// $FlowFixMe
const form = TestUtils.findRenderedDOMComponentWithTag(SafeDom, 'form')
// submit it
TestUtils.Simulate.submit(form)
TestUtils.Simulate.submit(form)
return whenExecuted(SafeDom, Withdraw)
}
export const checkMinedWithdrawTx = async (
Transaction: React$Component<any, any>,
name: string,
address: string,
funds: string,
) => {
await checkBalanceOf(address, funds)
checkMinedTx(Transaction, name)
}