From 122be4693407957c39ba718fbf6a0792d5e3fbd2 Mon Sep 17 00:00:00 2001 From: mmv Date: Thu, 14 Mar 2019 17:02:04 +0400 Subject: [PATCH] tests fix wip commit --- package.json | 2 +- src/logic/contracts/safeContracts.js | 3 +- src/logic/safe/safeBlockchainOperations.js | 69 ++++++++++++------- src/logic/safe/safeFrontendOperations.js | 2 +- src/logic/safe/safeTxSignerEIP712.js | 29 +++++--- src/logic/wallets/ethTransactions.js | 5 +- src/logic/wallets/tokens.js | 2 +- src/routes/safe/component/AddOwner/index.jsx | 26 +++---- .../safe/component/Balances/Tokens/index.jsx | 8 +-- src/routes/safe/component/Balances/index.jsx | 44 ++++++++---- .../safe/component/RemoveOwner/index.jsx | 2 +- src/routes/safe/component/SendToken/index.jsx | 2 +- src/routes/safe/component/Threshold/index.jsx | 10 +-- .../tokens/component/AddToken/FirstPage.jsx | 3 +- .../tokens/component/AddToken/index.jsx | 18 ++--- src/routes/tokens/component/Token/index.jsx | 10 +-- src/test/builder/safe.dom.builder.js | 3 +- src/test/builder/safe.dom.utils.js | 2 +- src/test/builder/safe.redux.builder.js | 3 +- src/test/safe.dom.create.test.js | 5 +- src/test/safe.dom.load.test.js | 2 +- src/test/safe.dom.tokens.test.js | 3 +- src/test/safe.redux.load.test.js | 3 +- src/test/safe.redux.owners.test.js | 11 ++- src/test/safe.redux.transactions.test.js | 3 +- src/test/tokens.dom.adding.test.js | 3 +- src/test/tokens.dom.enabling.test.js | 3 +- src/test/tokens.dom.removing.test.js | 3 +- src/test/tokens.redux.adding.test.js | 3 +- src/test/tokens.redux.remove.test.js | 10 ++- src/test/utils/ethereumErrors.js | 10 +-- src/test/utils/tokenMovements.js | 9 ++- 32 files changed, 177 insertions(+), 134 deletions(-) diff --git a/package.json b/package.json index 023ab771..e1518b91 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "collectCoverageFrom": [ "src/**/*.{js,jsx}" ], - "setupTestFrameworkScriptFile": "/config/jest/jest.setup.js", + "setupFilesAfterEnv": ["/config/jest/jest.setup.js"], "setupFiles": [ "/config/webpack.config.test.js", "/config/polyfills.js", diff --git a/src/logic/contracts/safeContracts.js b/src/logic/contracts/safeContracts.js index b58d905b..c1116a91 100644 --- a/src/logic/contracts/safeContracts.js +++ b/src/logic/contracts/safeContracts.js @@ -2,7 +2,6 @@ import contract from 'truffle-contract' import { ensureOnce } from '~/utils/singleton' import { getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import GnosisSafeSol from '#/GnosisSafe.json' import ProxyFactorySol from '#/ProxyFactory.json' import { calculateGasOf, calculateGasPrice } from '~/logic/wallets/ethTransactions' @@ -42,7 +41,7 @@ const instanciateMasterCopies = async () => { // ONLY USED IN TEST ENVIRONMENT const createMasterCopies = async () => { const web3 = getWeb3() - const accounts = await promisify(cb => web3.eth.getAccounts(cb)) + const accounts = await web3.eth.getAccounts() const userAccount = accounts[0] const ProxyFactory = getCreateProxyFactoryContract(web3) diff --git a/src/logic/safe/safeBlockchainOperations.js b/src/logic/safe/safeBlockchainOperations.js index 2f767482..498955bc 100644 --- a/src/logic/safe/safeBlockchainOperations.js +++ b/src/logic/safe/safeBlockchainOperations.js @@ -23,8 +23,17 @@ export const approveTransaction = async ( // return executeTransaction(safeAddress, to, valueInWei, data, operation, nonce, sender) const safe = await getSafeEthereumInstance(safeAddress) const txGasEstimate = await generateTxGasEstimateFrom(safe, safeAddress, data, to, valueInWei, operation) - const signature = - await generateMetamaskSignature(safe, safeAddress, sender, to, valueInWei, nonce, data, operation, txGasEstimate) + const signature = await generateMetamaskSignature( + safe, + safeAddress, + sender, + to, + valueInWei, + nonce, + data, + operation, + txGasEstimate, + ) storeSignature(safeAddress, nonce, signature) return undefined @@ -33,7 +42,7 @@ export const approveTransaction = async ( const gnosisSafe = await getSafeEthereumInstance(safeAddress) const contractTxHash = await gnosisSafe.getTransactionHash(to, valueInWei, data, operation, 0, 0, 0, 0, 0, nonce) - const approveData = gnosisSafe.contract.approveHash.getData(contractTxHash) + const approveData = gnosisSafe.contract.methods.approveHash(contractTxHash).encodeABI() const gas = await calculateGasOf(approveData, sender, safeAddress) const txReceipt = await gnosisSafe.approveHash(contractTxHash, { from: sender, gas, gasPrice }) @@ -60,16 +69,35 @@ export const executeTransaction = async ( if (signaturesViaMetamask()) { const safe = await getSafeEthereumInstance(safeAddress) const txGasEstimate = await generateTxGasEstimateFrom(safe, safeAddress, data, to, valueInWei, operation) - const signature = - await generateMetamaskSignature(safe, safeAddress, sender, to, valueInWei, nonce, data, operation, txGasEstimate) + const signature = await generateMetamaskSignature( + safe, + safeAddress, + sender, + to, + valueInWei, + nonce, + data, + operation, + txGasEstimate, + ) storeSignature(safeAddress, nonce, signature) const sigs = getSignaturesFrom(safeAddress, nonce) const threshold = await safe.getThreshold() - const gas = - await estimateDataGas(safe, to, valueInWei, data, operation, txGasEstimate, 0, nonce, Number(threshold), 0) + const gas = await estimateDataGas( + safe, + to, + valueInWei, + data, + operation, + txGasEstimate, + 0, + nonce, + Number(threshold), + 0, + ) const numOwners = await safe.getOwners() - const gasIncludingRemovingStoreUpfront = gas + txGasEstimate + (numOwners.length * 15000) + const gasIncludingRemovingStoreUpfront = gas + txGasEstimate + numOwners.length * 15000 const txReceipt = await safe.execTransaction( to, @@ -94,24 +122,17 @@ export const executeTransaction = async ( const gnosisSafe = await getSafeEthereumInstance(safeAddress) const signatures = buildSignaturesFrom(ownersWhoHasSigned, sender) - const txExecutionData = - gnosisSafe.contract.execTransaction.getData(to, valueInWei, data, operation, 0, 0, 0, 0, 0, signatures) + const txExecutionData = gnosisSafe.contract.methods + .execTransaction(to, valueInWei, data, operation, 0, 0, 0, 0, 0, signatures) + .encodeABI() const gas = await calculateGasOf(txExecutionData, sender, safeAddress) const numOwners = await gnosisSafe.getOwners() - const gasIncludingRemovingStoreUpfront = gas + (numOwners.length * 15000) - const txReceipt = await gnosisSafe.execTransaction( - to, - valueInWei, - data, - operation, - 0, - 0, - 0, - 0, - 0, - signatures, - { from: sender, gas: gasIncludingRemovingStoreUpfront, gasPrice }, - ) + const gasIncludingRemovingStoreUpfront = gas + numOwners.length * 15000 + const txReceipt = await gnosisSafe.execTransaction(to, valueInWei, data, operation, 0, 0, 0, 0, 0, signatures, { + from: sender, + gas: gasIncludingRemovingStoreUpfront, + gasPrice, + }) const txHash = txReceipt.tx await checkReceiptStatus(txHash) diff --git a/src/logic/safe/safeFrontendOperations.js b/src/logic/safe/safeFrontendOperations.js index f1a4a50c..f75f6d73 100644 --- a/src/logic/safe/safeFrontendOperations.js +++ b/src/logic/safe/safeFrontendOperations.js @@ -42,7 +42,7 @@ export const createTransaction = async ( const web3 = getWeb3() const safeAddress = safe.get('address') const threshold = safe.get('threshold') - const valueInWei = web3.toWei(value, 'ether') + const valueInWei = web3.utils.toWei(value, 'ether') const CALL = 0 const isExecution = hasOneOwner(safe) || threshold === 1 diff --git a/src/logic/safe/safeTxSignerEIP712.js b/src/logic/safe/safeTxSignerEIP712.js index 1bd1c23b..80f21981 100644 --- a/src/logic/safe/safeTxSignerEIP712.js +++ b/src/logic/safe/safeTxSignerEIP712.js @@ -1,6 +1,5 @@ // @flow import { getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import { BigNumber } from 'bignumber.js' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { getSignaturesFrom } from '~/utils/localStorage/signatures' @@ -21,7 +20,6 @@ const estimateDataGasCosts = (data) => { return data.match(/.{2}/g).reduce(reducer, 0) } - export const estimateDataGas = ( safe: any, to: string, @@ -42,8 +40,9 @@ export const estimateDataGas = ( const signatureCost = signatureCount * (68 + 2176 + 2176) // array count (3 -> r, s, v) * signature count const sigs = getSignaturesFrom(safe.address, nonce) - const payload = safe.contract.execTransaction - .getData(to, valueInWei, data, operation, txGasEstimate, 0, gasPrice, gasToken, refundReceiver, sigs) + const payload = safe.contract.methods + .execTransaction(to, valueInWei, data, operation, txGasEstimate, 0, gasPrice, gasToken, refundReceiver, sigs) + .encodeABI() let dataGasEstimate = estimateDataGasCosts(payload) + signatureCost if (dataGasEstimate > 65536) { @@ -64,19 +63,19 @@ export const generateTxGasEstimateFrom = async ( operation: number, ) => { try { - const estimateData = safe.contract.requiredTxGas.getData(to, valueInWei, data, operation) - const estimateResponse = await promisify(cb => getWeb3().eth.call({ + const estimateData = safe.contract.methods.requiredTxGas(to, valueInWei, data, operation).encodeABI() + const estimateResponse = await getWeb3().eth.call({ to: safeAddress, from: safeAddress, data: estimateData, - }, cb)) + }) const txGasEstimate = new BigNumber(estimateResponse.substring(138), 16) // Add 10k else we will fail in case of nested calls return Promise.resolve(txGasEstimate.toNumber() + 10000) } catch (error) { // eslint-disable-next-line - console.log("Error calculating tx gas estimation " + error) + console.log('Error calculating tx gas estimation ' + error) return Promise.resolve(0) } } @@ -151,8 +150,16 @@ export const generateMetamaskSignature = async ( txGasEstimate: number, ) => { const web3 = getWeb3() - const typedData = - await generateTypedDataFrom(safe, safeAddress, to, valueInWei, nonce, data, operation, txGasEstimate) + const typedData = await generateTypedDataFrom( + safe, + safeAddress, + to, + valueInWei, + nonce, + data, + operation, + txGasEstimate, + ) const jsonTypedData = JSON.stringify(typedData) const signedTypedData = { @@ -163,7 +170,7 @@ export const generateMetamaskSignature = async ( params: [jsonTypedData, sender], from: sender, } - const txSignedResponse = await promisify(cb => web3.currentProvider.sendAsync(signedTypedData, cb)) + const txSignedResponse = await web3.currentProvider.sendAsync(signedTypedData) return txSignedResponse.result.replace(EMPTY_DATA, '') } diff --git a/src/logic/wallets/ethTransactions.js b/src/logic/wallets/ethTransactions.js index d7fecb2e..f2b8b54c 100644 --- a/src/logic/wallets/ethTransactions.js +++ b/src/logic/wallets/ethTransactions.js @@ -1,7 +1,6 @@ // @flow import { BigNumber } from 'bignumber.js' import { getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import { enhancedFetch } from '~/utils/fetch' // const MAINNET_NETWORK = 1 @@ -13,7 +12,7 @@ export const checkReceiptStatus = async (hash: string) => { } const web3 = getWeb3() - const txReceipt = await promisify(cb => web3.eth.getTransactionReceipt(hash, cb)) + const txReceipt = await web3.eth.getTransactionReceipt(hash) const { status } = txReceipt if (!status) { @@ -53,7 +52,7 @@ export const calculateGasPrice = async () => { export const calculateGasOf = async (data: Object, from: string, to: string) => { const web3 = getWeb3() try { - const gas = await promisify(cb => web3.eth.estimateGas({ data, from, to }, cb)) + const gas = await web3.eth.estimateGas({ data, from, to }) return gas * 2 } catch (err) { diff --git a/src/logic/wallets/tokens.js b/src/logic/wallets/tokens.js index 3088b8fe..29054228 100644 --- a/src/logic/wallets/tokens.js +++ b/src/logic/wallets/tokens.js @@ -5,5 +5,5 @@ import { BigNumber } from 'bignumber.js' export const toNative = async (amt: string | number | BigNumber, decimal: number): Promise => { const web3 = getWeb3() - return web3.toBigNumber(amt).mul(10 ** decimal) + return web3.utils.BN(amt).mul(10 ** decimal) } diff --git a/src/routes/safe/component/AddOwner/index.jsx b/src/routes/safe/component/AddOwner/index.jsx index 15d1e18f..b8f69092 100644 --- a/src/routes/safe/component/AddOwner/index.jsx +++ b/src/routes/safe/component/AddOwner/index.jsx @@ -12,14 +12,13 @@ import Review from './Review' import selector, { type SelectorProps } from './selector' import actions, { type Actions } from './actions' -const getSteps = () => [ - 'Fill Owner Form', 'Review Add order operation', -] +const getSteps = () => ['Fill Owner Form', 'Review Add order operation'] -type Props = SelectorProps & Actions & { - safe: Safe, - threshold: number, -} +type Props = SelectorProps & + Actions & { + safe: Safe, + threshold: number, + } type State = { done: boolean, @@ -44,7 +43,7 @@ export const addOwner = async (values: Object, safe: Safe, threshold: number, ex const newOwnerAddress = values[OWNER_ADDRESS_PARAM] const newOwnerName = values[NAME_PARAM] - const data = gnosisSafe.contract.addOwnerWithThreshold.getData(newOwnerAddress, newThreshold) + const data = gnosisSafe.contract.methods.addOwnerWithThreshold(newOwnerAddress, newThreshold).encodeABI() await createTransaction(safe, `Add Owner ${newOwnerName}`, safeAddress, 0, nonce, executor, data) setOwners(safeAddress, safe.get('owners').push(makeOwner({ name: newOwnerName, address: newOwnerAddress }))) } @@ -90,15 +89,16 @@ class AddOwner extends React.Component { onReset={this.onReset} > - { AddOwnerForm } - - - { Review } + {AddOwnerForm} + {Review} ) } } -export default connect(selector, actions)(AddOwner) +export default connect( + selector, + actions, +)(AddOwner) diff --git a/src/routes/safe/component/Balances/Tokens/index.jsx b/src/routes/safe/component/Balances/Tokens/index.jsx index d3520680..1b6b1f8f 100644 --- a/src/routes/safe/component/Balances/Tokens/index.jsx +++ b/src/routes/safe/component/Balances/Tokens/index.jsx @@ -37,10 +37,9 @@ type State = { filter: string, } -const filterBy = (filter: string, tokens: List): List => - tokens.filter((token: Token) => !filter || - token.get('symbol').toLowerCase().includes(filter.toLowerCase()) || - token.get('name').toLowerCase().includes(filter.toLowerCase())) +const filterBy = (filter: string, tokens: List): List => tokens.filter((token: Token) => !filter + || token.get('symbol').toLowerCase().includes(filter.toLowerCase()) + || token.get('name').toLowerCase().includes(filter.toLowerCase())) class Tokens extends React.Component { @@ -132,4 +131,3 @@ class Tokens extends React.Component { const TokenComponent = withStyles(styles)(Tokens) export default connect(undefined, actions)(TokenComponent) - diff --git a/src/routes/safe/component/Balances/index.jsx b/src/routes/safe/component/Balances/index.jsx index c63312f4..5dbd135e 100644 --- a/src/routes/safe/component/Balances/index.jsx +++ b/src/routes/safe/component/Balances/index.jsx @@ -16,7 +16,9 @@ import Paragraph from '~/components/layout/Paragraph' import Modal from '~/components/Modal' import { type Column, cellWidth } from '~/components/Table/TableHead' import Table from '~/components/Table' -import { getBalanceData, generateColumns, BALANCE_TABLE_ASSET_ID, type BalanceRow, filterByZero } from './dataFetcher' +import { + getBalanceData, generateColumns, BALANCE_TABLE_ASSET_ID, type BalanceRow, filterByZero, +} from './dataFetcher' import Tokens from './Tokens' import Send from './Send' import Receive from './Receive' @@ -114,32 +116,50 @@ class Balances extends React.Component { > {(sortedData: Array) => sortedData.map((row: any, index: number) => ( - { autoColumns.map((column: Column) => ( - + {autoColumns.map((column: Column) => ( + {row[column.id]} - )) } + ))} - { granted && - - } - - ))} + )) + } - + diff --git a/src/routes/safe/component/RemoveOwner/index.jsx b/src/routes/safe/component/RemoveOwner/index.jsx index 87bb48a0..7121cd65 100644 --- a/src/routes/safe/component/RemoveOwner/index.jsx +++ b/src/routes/safe/component/RemoveOwner/index.jsx @@ -48,7 +48,7 @@ export const removeOwner = async ( const storedOwners = await gnosisSafe.getOwners() const index = storedOwners.findIndex(ownerAddress => ownerAddress === userToRemove) const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1] - const data = gnosisSafe.contract.removeOwner.getData(prevAddress, userToRemove, newThreshold) + const data = gnosisSafe.contract.removeOwner(prevAddress, userToRemove, newThreshold).encodeABI() const text = name || userToRemove return createTransaction(safe, `Remove Owner ${text}`, safeAddress, 0, nonce, executor, data) diff --git a/src/routes/safe/component/SendToken/index.jsx b/src/routes/safe/component/SendToken/index.jsx index ec30142a..a102a856 100644 --- a/src/routes/safe/component/SendToken/index.jsx +++ b/src/routes/safe/component/SendToken/index.jsx @@ -36,7 +36,7 @@ const getTransferData = async (tokenAddress: string, to: string, amount: BigNumb const StandardToken = await getStandardTokenContract() const myToken = await StandardToken.at(tokenAddress) - return myToken.contract.transfer.getData(to, amount) + return myToken.contract.transfer(to, amount).encodeABI() } const processTokenTransfer = async (safe: Safe, token: Token, to: string, amount: number, userAddress: string) => { diff --git a/src/routes/safe/component/Threshold/index.jsx b/src/routes/safe/component/Threshold/index.jsx index 8f86484c..e6ccfed4 100644 --- a/src/routes/safe/component/Threshold/index.jsx +++ b/src/routes/safe/component/Threshold/index.jsx @@ -32,14 +32,14 @@ class Threshold extends React.PureComponent { onThreshold = async (values: Object) => { try { - const { safe, userAddress } = this.props // , fetchThreshold } = this.props + const { safe, userAddress, fetchTransactions } = this.props // , fetchThreshold } = this.props const newThreshold = values[THRESHOLD_PARAM] const safeAddress = safe.get('address') const gnosisSafe = await getSafeEthereumInstance(safeAddress) const nonce = await gnosisSafe.nonce() - const data = gnosisSafe.contract.changeThreshold.getData(newThreshold) + const data = gnosisSafe.contract.changeThreshold(newThreshold).encodeABI() await createTransaction(safe, `Change Safe's threshold [${nonce}]`, safeAddress, 0, nonce, userAddress, data) - await this.props.fetchTransactions(safeAddress) + await fetchTransactions(safeAddress) this.setState({ done: true }) } catch (error) { this.setState({ done: false }) @@ -49,8 +49,10 @@ class Threshold extends React.PureComponent { } onReset = () => { + const { onReset } = this.props this.setState({ done: false }) - this.props.onReset() + + onReset() } render() { diff --git a/src/routes/tokens/component/AddToken/FirstPage.jsx b/src/routes/tokens/component/AddToken/FirstPage.jsx index 6bd7e89e..6a7d194e 100644 --- a/src/routes/tokens/component/AddToken/FirstPage.jsx +++ b/src/routes/tokens/component/AddToken/FirstPage.jsx @@ -5,7 +5,6 @@ import TextField from '~/components/forms/TextField' import { composeValidators, required, mustBeEthereumAddress, uniqueAddress } from '~/components/forms/validator' import Block from '~/components/layout/Block' import Heading from '~/components/layout/Heading' -import { promisify } from '~/utils/promisify' import { getWeb3 } from '~/logic/wallets/getWeb3' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { getStandardTokenContract } from '~/routes/tokens/store/actions/fetchTokens' @@ -17,7 +16,7 @@ type Props = { export const TOKEN_ADRESS_PARAM = 'tokenAddress' export const token = async (tokenAddress: string) => { - const code = await promisify(cb => getWeb3().eth.getCode(tokenAddress, cb)) + const code = await getWeb3().eth.getCode(tokenAddress) const isDeployed = code !== EMPTY_DATA if (!isDeployed) { diff --git a/src/routes/tokens/component/AddToken/index.jsx b/src/routes/tokens/component/AddToken/index.jsx index 0b5d1164..91f82700 100644 --- a/src/routes/tokens/component/AddToken/index.jsx +++ b/src/routes/tokens/component/AddToken/index.jsx @@ -3,11 +3,12 @@ import * as React from 'react' import Stepper from '~/components/Stepper' import { getHumanFriendlyToken } from '~/routes/tokens/store/actions/fetchTokens' import FirstPage, { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage' -import SecondPage, { TOKEN_SYMBOL_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_LOGO_URL_PARAM, TOKEN_NAME_PARAM } from '~/routes/tokens/component/AddToken/SecondPage' +import SecondPage, { + TOKEN_SYMBOL_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_LOGO_URL_PARAM, TOKEN_NAME_PARAM, +} from '~/routes/tokens/component/AddToken/SecondPage' import { makeToken, type Token } from '~/routes/tokens/store/model/token' import addTokenAction from '~/routes/tokens/store/actions/addToken' import { getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import Review from './Review' @@ -69,17 +70,18 @@ class AddToken extends React.Component { const tokenAddress = values[TOKEN_ADRESS_PARAM] const erc20Token = await getHumanFriendlyToken() const instance = await erc20Token.at(tokenAddress) + const web3 = getWeb3() - const dataName = await instance.contract.name.getData() - const nameResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataName }, cb)) + const dataName = await instance.contract.methods.name().encodeABI() + const nameResult = await web3.eth.call({ to: tokenAddress, data: dataName }) const hasName = nameResult !== EMPTY_DATA - const dataSymbol = await instance.contract.symbol.getData() - const symbolResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataSymbol }, cb)) + const dataSymbol = await instance.contract.methods.symbol().encodeABI() + const symbolResult = await web3.eth.call({ to: tokenAddress, data: dataSymbol }) const hasSymbol = symbolResult !== EMPTY_DATA - const dataDecimals = await instance.contract.decimals.getData() - const decimalsResult = await promisify(cb => getWeb3().eth.call({ to: tokenAddress, data: dataDecimals }, cb)) + const dataDecimals = await instance.contract.methods.decimals().encodeABI() + const decimalsResult = await web3.eth.call({ to: tokenAddress, data: dataDecimals }) const hasDecimals = decimalsResult !== EMPTY_DATA diff --git a/src/routes/tokens/component/Token/index.jsx b/src/routes/tokens/component/Token/index.jsx index 80e2a680..17b3696e 100644 --- a/src/routes/tokens/component/Token/index.jsx +++ b/src/routes/tokens/component/Token/index.jsx @@ -76,10 +76,12 @@ class TokenComponent extends React.PureComponent { color="primary" /> {symbol} - { token.get('removable') && - - - + { token.get('removable') + && ( + + + + ) } diff --git a/src/test/builder/safe.dom.builder.js b/src/test/builder/safe.dom.builder.js index 30248b24..8ef4f8fb 100644 --- a/src/test/builder/safe.dom.builder.js +++ b/src/test/builder/safe.dom.builder.js @@ -5,7 +5,6 @@ import SafeView from '~/routes/safe/component/Safe' import { aNewStore, type GlobalState } from '~/store' import { sleep } from '~/utils/timer' import { getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import { addEtherTo } from '~/test/utils/tokenMovements' import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { travelToSafe } from '~/test/builder/safe.dom.utils' @@ -31,7 +30,7 @@ export const renderSafeInDom = async ( // deploy safe updating store const address = await aMinedSafe(store, owners, threshold) // have available accounts - const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + const accounts = await getWeb3().eth.getAccounts() // navigate to SAFE route const SafeDom = travelToSafe(store, address) diff --git a/src/test/builder/safe.dom.utils.js b/src/test/builder/safe.dom.utils.js index c0bb6dbe..209c8e2d 100644 --- a/src/test/builder/safe.dom.utils.js +++ b/src/test/builder/safe.dom.utils.js @@ -6,7 +6,7 @@ import { SEE_MULTISIG_BUTTON_TEXT } from '~/routes/safe/component/Safe/MultisigT import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' import { sleep } from '~/utils/timer' import { Provider } from 'react-redux' -import { ConnectedRouter } from 'react-router-redux' +import { ConnectedRouter } from 'connected-react-router' import AppRoutes from '~/routes' import { SAFELIST_ADDRESS, SETTINS_ADDRESS } from '~/routes/routes' import { history, type GlobalState } from '~/store' diff --git a/src/test/builder/safe.redux.builder.js b/src/test/builder/safe.redux.builder.js index 60968248..34049e0f 100644 --- a/src/test/builder/safe.redux.builder.js +++ b/src/test/builder/safe.redux.builder.js @@ -3,7 +3,6 @@ import { makeSafe, type Safe } from '~/routes/safe/store/model/safe' import addSafe, { buildOwnersFrom } from '~/routes/safe/store/actions/addSafe' import { FIELD_NAME, FIELD_CONFIRMATIONS, FIELD_OWNERS, getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields' import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import { createSafe, type OpenState } from '~/routes/open/container/Open' import { type GlobalState } from '~/store/index' import { makeProvider } from '~/logic/wallets/store/model/provider' @@ -72,7 +71,7 @@ export const aMinedSafe = async ( const walletRecord = makeProvider(provider) store.dispatch(addProvider(walletRecord)) - const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + const accounts = await getWeb3().eth.getAccounts() const form = { [FIELD_NAME]: 'Safe Name', [FIELD_CONFIRMATIONS]: `${threshold}`, diff --git a/src/test/safe.dom.create.test.js b/src/test/safe.dom.create.test.js index 61abdbd2..5551d5eb 100644 --- a/src/test/safe.dom.create.test.js +++ b/src/test/safe.dom.create.test.js @@ -4,7 +4,7 @@ import { type Store } from 'redux' import TestUtils from 'react-dom/test-utils' import Select from '@material-ui/core/Select' import { Provider } from 'react-redux' -import { ConnectedRouter } from 'react-router-redux' +import { ConnectedRouter } from 'connected-react-router' import { ADD_OWNER_BUTTON } from '~/routes/open/components/SafeOwnersForm' import Open from '~/routes/open/container/Open' import { aNewStore, history, type GlobalState } from '~/store' @@ -12,7 +12,6 @@ import { sleep } from '~/utils/timer' import { getProviderInfo, getWeb3 } from '~/logic/wallets/getWeb3' import addProvider from '~/logic/wallets/store/actions/addProvider' import { makeProvider } from '~/logic/wallets/store/model/provider' -import { promisify } from '~/utils/promisify' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { whenSafeDeployed } from './builder/safe.dom.utils' @@ -34,7 +33,7 @@ const fillOpenSafeForm = async (localStore: Store) => { const deploySafe = async (safe: React$Component<{}>, threshold: number, numOwners: number) => { const web3 = getWeb3() - const accounts = await promisify(cb => web3.eth.getAccounts(cb)) + const accounts = await web3.eth.getAccounts() expect(threshold).toBeLessThanOrEqual(numOwners) const form = TestUtils.findRenderedDOMComponentWithTag(safe, 'form') diff --git a/src/test/safe.dom.load.test.js b/src/test/safe.dom.load.test.js index f74057b4..8faf8c6f 100644 --- a/src/test/safe.dom.load.test.js +++ b/src/test/safe.dom.load.test.js @@ -3,7 +3,7 @@ import * as React from 'react' import { type Store } from 'redux' import TestUtils from 'react-dom/test-utils' import { Provider } from 'react-redux' -import { ConnectedRouter } from 'react-router-redux' +import { ConnectedRouter } from 'connected-react-router' import Load from '~/routes/load/container/Load' import { aNewStore, history, type GlobalState } from '~/store' import { sleep } from '~/utils/timer' diff --git a/src/test/safe.dom.tokens.test.js b/src/test/safe.dom.tokens.test.js index 3174373f..ec4332c3 100644 --- a/src/test/safe.dom.tokens.test.js +++ b/src/test/safe.dom.tokens.test.js @@ -6,7 +6,6 @@ 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 { promisify } from '~/utils/promisify' import { getWeb3 } from '~/logic/wallets/getWeb3' import { sendMoveTokensForm, dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper' import { sleep } from '~/utils/timer' @@ -18,7 +17,7 @@ describe('DOM > Feature > SAFE ERC20 TOKENS', () => { beforeEach(async () => { store = aNewStore() safeAddress = await aMinedSafe(store) - accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + accounts = await getWeb3().eth.getAccounts() }) it('sends ERC20 tokens', async () => { diff --git a/src/test/safe.redux.load.test.js b/src/test/safe.redux.load.test.js index fd39b766..36df6122 100644 --- a/src/test/safe.redux.load.test.js +++ b/src/test/safe.redux.load.test.js @@ -8,7 +8,6 @@ import { loadSafe } from '~/routes/load/container/Load' import { safesMapSelector } from '~/routes/safeList/store/selectors' import { makeOwner, type Owner } from '~/routes/safe/store/model/owner' import { getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import { safesInitialState } from '~/routes/safe/store/reducer/safe' import { setOwners, OWNERS_KEY } from '~/utils/localStorage' @@ -20,7 +19,7 @@ describe('Safe - redux load safe', () => { store = aNewStore() address = await aMinedSafe(store) localStorage.clear() - accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + accounts = await getWeb3().eth.getAccounts() }) it('if safe is not present, store and persist it with default names', async () => { diff --git a/src/test/safe.redux.owners.test.js b/src/test/safe.redux.owners.test.js index c185a4fb..16d1963f 100644 --- a/src/test/safe.redux.owners.test.js +++ b/src/test/safe.redux.owners.test.js @@ -2,7 +2,6 @@ import { List } from 'immutable' import { aNewStore } from '~/store' import { getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import { confirmationsTransactionSelector, safeTransactionsSelector } from '~/routes/safe/store/selectors' import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' import { type Safe } from '~/routes/safe/store/model/safe' @@ -103,7 +102,7 @@ describe('React DOM TESTS > Add and remove owners', () => { const threshold = 1 const store = aNewStore() const address = await aMinedSafe(store, numOwners, threshold) - const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + const accounts = await getWeb3().eth.getAccounts() const gnosisSafe = await getGnosisSafeInstanceAt(address) const values = { @@ -132,7 +131,7 @@ describe('React DOM TESTS > Add and remove owners', () => { const threshold = 1 const store = aNewStore() const address = await aMinedSafe(store, numOwners, threshold) - const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + const accounts = await getWeb3().eth.getAccounts() const gnosisSafe = await getGnosisSafeInstanceAt(address) const values = { @@ -164,7 +163,7 @@ describe('React DOM TESTS > Add and remove owners', () => { const threshold = 2 const store = aNewStore() const address = await aMinedSafe(store, numOwners, threshold) - const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + const accounts = await getWeb3().eth.getAccounts() const gnosisSafe = await getGnosisSafeInstanceAt(address) const decrease = shouldDecrease(numOwners, threshold) @@ -190,7 +189,7 @@ describe('React DOM TESTS > Add and remove owners', () => { const threshold = 2 const store = aNewStore() const address = await aMinedSafe(store, numOwners, threshold) - const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + const accounts = await getWeb3().eth.getAccounts() const gnosisSafe = await getGnosisSafeInstanceAt(address) const decrease = true @@ -215,7 +214,7 @@ describe('React DOM TESTS > Add and remove owners', () => { const threshold = 2 const store = aNewStore() const address = await aMinedSafe(store, numOwners, threshold) - const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + const accounts = await getWeb3().eth.getAccounts() const gnosisSafe = await getGnosisSafeInstanceAt(address) const decrease = shouldDecrease(numOwners, threshold) diff --git a/src/test/safe.redux.transactions.test.js b/src/test/safe.redux.transactions.test.js index cffffd8c..a76bca59 100644 --- a/src/test/safe.redux.transactions.test.js +++ b/src/test/safe.redux.transactions.test.js @@ -8,7 +8,6 @@ import { makeConfirmation } from '~/routes/safe/store/model/confirmation' import { aNewStore } from '~/store' import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { getSafeFrom } from '~/test/utils/safeHelper' -import { promisify } from '~/utils/promisify' import { getWeb3 } from '~/logic/wallets/getWeb3' import { safeTransactionsSelector } from '~/routes/safe/store/selectors' import fetchSafe from '~/routes/safe/store/actions/fetchSafe' @@ -20,7 +19,7 @@ describe('Transactions Suite', () => { let safeAddress: string let accounts: string[] beforeAll(async () => { - accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + accounts = await getWeb3().eth.getAccounts() }) beforeEach(async () => { localStorage.clear() diff --git a/src/test/tokens.dom.adding.test.js b/src/test/tokens.dom.adding.test.js index 0054f72c..7bee57d8 100644 --- a/src/test/tokens.dom.adding.test.js +++ b/src/test/tokens.dom.adding.test.js @@ -2,7 +2,6 @@ import * as TestUtils from 'react-dom/test-utils' import { getWeb3 } from '~/logic/wallets/getWeb3' import { type Match } from 'react-router-dom' -import { promisify } from '~/utils/promisify' import TokenComponent from '~/routes/tokens/component/Token' import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements' import { aNewStore } from '~/store' @@ -24,7 +23,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => { beforeAll(async () => { web3 = getWeb3() - accounts = await promisify(cb => web3.eth.getAccounts(cb)) + accounts = await web3.eth.getAccounts() firstErc20Token = await getFirstTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0]) diff --git a/src/test/tokens.dom.enabling.test.js b/src/test/tokens.dom.enabling.test.js index 6fbccab6..7f50dc7b 100644 --- a/src/test/tokens.dom.enabling.test.js +++ b/src/test/tokens.dom.enabling.test.js @@ -3,7 +3,6 @@ import * as TestUtils from 'react-dom/test-utils' import { List } from 'immutable' import { getWeb3 } from '~/logic/wallets/getWeb3' import { type Match } from 'react-router-dom' -import { promisify } from '~/utils/promisify' import TokenComponent from '~/routes/tokens/component/Token' import Checkbox from '@material-ui/core/Checkbox' import { getFirstTokenContract, getSecondTokenContract, addTknTo } from '~/test/utils/tokenMovements' @@ -26,7 +25,7 @@ describe('DOM > Feature > Enable and disable default tokens', () => { beforeAll(async () => { web3 = getWeb3() - accounts = await promisify(cb => web3.eth.getAccounts(cb)) + accounts = await web3.eth.getAccounts() firstErc20Token = await getFirstTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0]) // $FlowFixMe diff --git a/src/test/tokens.dom.removing.test.js b/src/test/tokens.dom.removing.test.js index f0be7194..e146e261 100644 --- a/src/test/tokens.dom.removing.test.js +++ b/src/test/tokens.dom.removing.test.js @@ -1,7 +1,6 @@ // @flow import * as TestUtils from 'react-dom/test-utils' import { getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements' import { aNewStore } from '~/store' import { aMinedSafe } from '~/test/builder/safe.redux.builder' @@ -24,7 +23,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => { beforeAll(async () => { web3 = getWeb3() - accounts = await promisify(cb => web3.eth.getAccounts(cb)) + accounts = await web3.eth.getAccounts() firstErc20Token = await getFirstTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0]) diff --git a/src/test/tokens.redux.adding.test.js b/src/test/tokens.redux.adding.test.js index eacba2c9..86be199e 100644 --- a/src/test/tokens.redux.adding.test.js +++ b/src/test/tokens.redux.adding.test.js @@ -1,7 +1,6 @@ // @flow import { getWeb3 } from '~/logic/wallets/getWeb3' import { type Match } from 'react-router-dom' -import { promisify } from '~/utils/promisify' import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements' import { aNewStore } from '~/store' import { aMinedSafe } from '~/test/builder/safe.redux.builder' @@ -24,7 +23,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => { beforeAll(async () => { web3 = getWeb3() - accounts = await promisify(cb => web3.eth.getAccounts(cb)) + accounts = await web3.eth.getAccounts() firstErc20Token = await getFirstTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0]) diff --git a/src/test/tokens.redux.remove.test.js b/src/test/tokens.redux.remove.test.js index 182a66a2..04c75869 100644 --- a/src/test/tokens.redux.remove.test.js +++ b/src/test/tokens.redux.remove.test.js @@ -1,7 +1,6 @@ // @flow import { getWeb3 } from '~/logic/wallets/getWeb3' import { type Match } from 'react-router-dom' -import { promisify } from '~/utils/promisify' import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements' import { aNewStore } from '~/store' import { aMinedSafe } from '~/test/builder/safe.redux.builder' @@ -11,7 +10,12 @@ import { testToken } from '~/test/builder/tokens.dom.utils' import * as fetchTokensModule from '~/routes/tokens/store/actions/fetchTokens' import * as enhancedFetchModule from '~/utils/fetch' import { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage' -import { TOKEN_NAME_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_SYMBOL_PARAM, TOKEN_LOGO_URL_PARAM } from '~/routes/tokens/component/AddToken/SecondPage' +import { + TOKEN_NAME_PARAM, + TOKEN_DECIMALS_PARAM, + TOKEN_SYMBOL_PARAM, + TOKEN_LOGO_URL_PARAM, +} from '~/routes/tokens/component/AddToken/SecondPage' import addToken from '~/routes/tokens/store/actions/addToken' import { addTokenFnc } from '~/routes/tokens/component/AddToken' import { activeTokensSelector, tokenListSelector } from '~/routes/tokens/store/selectors' @@ -27,7 +31,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => { beforeAll(async () => { web3 = getWeb3() - accounts = await promisify(cb => web3.eth.getAccounts(cb)) + accounts = await web3.eth.getAccounts() firstErc20Token = await getFirstTokenContract(web3, accounts[0]) secondErc20Token = await getSecondTokenContract(web3, accounts[0]) diff --git a/src/test/utils/ethereumErrors.js b/src/test/utils/ethereumErrors.js index ba8d874e..e1d10f57 100644 --- a/src/test/utils/ethereumErrors.js +++ b/src/test/utils/ethereumErrors.js @@ -1,7 +1,6 @@ // @flow import { getWeb3 } from '~/logic/wallets/getWeb3' import abi from 'ethereumjs-abi' -import { promisify } from '~/utils/promisify' /* console.log(`to[${to}] \n\n valieInWei[${valueInWei}] \n\n @@ -15,9 +14,12 @@ const err = await getErrorMessage(address, 0, txData, accounts[2]) */ export const getErrorMessage = async (to: string, value: number, data: string, from: string) => { const web3 = getWeb3() - const returnData = await promisify(cb => web3.eth.call({ - to, from, value, data, - }, cb)) + const returnData = await web3.eth.call({ + to, + from, + value, + data, + }) const returnBuffer = Buffer.from(returnData.slice(2), 'hex') return abi.rawDecode(['string'], returnBuffer.slice(4))[0] diff --git a/src/test/utils/tokenMovements.js b/src/test/utils/tokenMovements.js index ec8cbfff..3823eab0 100644 --- a/src/test/utils/tokenMovements.js +++ b/src/test/utils/tokenMovements.js @@ -1,16 +1,15 @@ // @flow import contract from 'truffle-contract' import { getBalanceInEtherOf, getWeb3 } from '~/logic/wallets/getWeb3' -import { promisify } from '~/utils/promisify' import Token from '#/test/TestToken.json' import { ensureOnce } from '~/utils/singleton' import { toNative } from '~/logic/wallets/tokens' export const addEtherTo = async (address: string, eth: string) => { const web3 = getWeb3() - const accounts = await promisify(cb => web3.eth.getAccounts(cb)) - const txData = { from: accounts[0], to: address, value: web3.toWei(eth, 'ether') } - return promisify(cb => web3.eth.sendTransaction(txData, cb)) + const accounts = await web3.eth.getAccounts() + const txData = { from: accounts[0], to: address, value: web3.utils.toWei(eth, 'ether') } + return web3.eth.sendTransaction(txData) } export const checkBalanceOf = async (addressToTest: string, value: string) => { @@ -30,7 +29,7 @@ export const getSecondTokenContract = ensureOnce(createTokenContract) export const addTknTo = async (safe: string, value: number, tokenContract?: any) => { const web3 = getWeb3() - const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb)) + const accounts = await web3.eth.getAccounts() const myToken = tokenContract || await getFirstTokenContract(web3, accounts[0]) const nativeValue = await toNative(value, 18)