From 4c5d28db4b9aee2f3f160587f65f08c9f40b2a40 Mon Sep 17 00:00:00 2001 From: apanizo Date: Mon, 4 Jun 2018 17:24:01 +0200 Subject: [PATCH] WA-238 Checking tx receipt status on withdrawn mutlsig txs --- src/routes/open/container/Open.jsx | 2 ++ .../AddTransaction/createTransactions.js | 14 +++++++++----- .../Transactions/processTransactions.js | 10 ++++++---- .../safe/component/Withdrawn/withdrawn.js | 5 +++-- .../Safe.multisig.3owners1threshold.test.js | 2 ++ src/wallets/ethTransactions.js | 19 +++++++++++++++++++ 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/routes/open/container/Open.jsx b/src/routes/open/container/Open.jsx index ea232e7d..009eefa0 100644 --- a/src/routes/open/container/Open.jsx +++ b/src/routes/open/container/Open.jsx @@ -6,6 +6,7 @@ import Page from '~/components/layout/Page' import { getAccountsFrom, getThresholdFrom, getNamesFrom, getSafeNameFrom, getDailyLimitFrom } from '~/routes/open/utils/safeDataExtractor' import { getWeb3 } from '~/wallets/getWeb3' import { getGnosisSafeContract, deploySafeContract, initContracts } from '~/wallets/safeContracts' +import { checkReceiptStatus } from '~/wallets/ethTransactions' import selector from './selector' import actions, { type Actions, type AddSafe } from './actions' import Layout from '../components/Layout' @@ -32,6 +33,7 @@ const createSafe = async (values: Object, userAccount: string, addSafe: AddSafe) await initContracts() const safe = await deploySafeContract(accounts, numConfirmations, dailyLimit, userAccount) + checkReceiptStatus(safe.tx) const param = safe.logs[1].args.proxy const safeContract = GnosisSafe.at(param) diff --git a/src/routes/safe/component/AddTransaction/createTransactions.js b/src/routes/safe/component/AddTransaction/createTransactions.js index 54ca30cd..7ac3956b 100644 --- a/src/routes/safe/component/AddTransaction/createTransactions.js +++ b/src/routes/safe/component/AddTransaction/createTransactions.js @@ -8,7 +8,7 @@ import { getGnosisSafeContract } from '~/wallets/safeContracts' import { getWeb3 } from '~/wallets/getWeb3' import { type Safe } from '~/routes/safe/store/model/safe' import { sameAddress } from '~/wallets/ethAddresses' -import executeTransaction from '~/wallets/ethTransactions' +import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions' export const TX_NAME_PARAM = 'txName' export const TX_DESTINATION_PARAM = 'txDestination' @@ -98,14 +98,18 @@ export const createTransaction = async ( const thresholdIsOne = safe.get('confirmations') === 1 if (hasOneOwner(safe) || thresholdIsOne) { const txConfirmationData = gnosisSafe.contract.execTransactionIfApproved.getData(txDestination, valueInWei, '0x', CALL, nonce) - const txReceipt = await executeTransaction(txConfirmationData, user, safeAddress) + const txHash = await executeTransaction(txConfirmationData, user, safeAddress) + checkReceiptStatus(txHash) + const executedConfirmations: List = buildExecutedConfirmationFrom(safe.get('owners'), user) - return storeTransaction(txName, nonce, txDestination, txValue, user, executedConfirmations, txReceipt, safeAddress, safe.get('confirmations')) + return storeTransaction(txName, nonce, txDestination, txValue, user, executedConfirmations, txHash, safeAddress, safe.get('confirmations')) } const txConfirmationData = gnosisSafe.contract.approveTransactionWithParameters.getData(txDestination, valueInWei, '0x', CALL, nonce) - const txConfirmationReceipt = await executeTransaction(txConfirmationData, user, safeAddress) - const confirmations: List = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationReceipt) + const txConfirmationHash = await executeTransaction(txConfirmationData, user, safeAddress) + checkReceiptStatus(txConfirmationHash) + + const confirmations: List = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash) return storeTransaction(txName, nonce, txDestination, txValue, user, confirmations, '', safeAddress, safe.get('confirmations')) } diff --git a/src/routes/safe/component/Transactions/processTransactions.js b/src/routes/safe/component/Transactions/processTransactions.js index 2e866ce2..dfbc64d2 100644 --- a/src/routes/safe/component/Transactions/processTransactions.js +++ b/src/routes/safe/component/Transactions/processTransactions.js @@ -8,7 +8,7 @@ import { getGnosisSafeContract } from '~/wallets/safeContracts' import { getWeb3 } from '~/wallets/getWeb3' import { sameAddress } from '~/wallets/ethAddresses' import { EXECUTED_CONFIRMATION_HASH } from '~/routes/safe/component/AddTransaction/createTransactions' -import executeTransaction from '~/wallets/ethTransactions' +import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions' export const updateTransaction = ( name: string, @@ -111,11 +111,13 @@ export const processTransaction = async ( const txValue = tx.get('value') const txDestination = tx.get('destination') - const txReceipt = thresholdReached + const txHash = thresholdReached ? await execTransaction(gnosisSafe, txDestination, txValue, nonce, userAddress) : await execConfirmation(gnosisSafe, txDestination, txValue, nonce, userAddress) - const confirmationHash = thresholdReached ? EXECUTED_CONFIRMATION_HASH : txReceipt + checkReceiptStatus(txHash) + + const confirmationHash = thresholdReached ? EXECUTED_CONFIRMATION_HASH : txHash const executedConfirmations: List = updateConfirmations(tx.get('confirmations'), userAddress, confirmationHash) return updateTransaction( @@ -125,7 +127,7 @@ export const processTransaction = async ( txValue, userAddress, executedConfirmations, - thresholdReached ? txReceipt : '', + thresholdReached ? txHash : '', safeAddress, threshold, ) diff --git a/src/routes/safe/component/Withdrawn/withdrawn.js b/src/routes/safe/component/Withdrawn/withdrawn.js index d9f066d0..643b7917 100644 --- a/src/routes/safe/component/Withdrawn/withdrawn.js +++ b/src/routes/safe/component/Withdrawn/withdrawn.js @@ -2,7 +2,7 @@ import { getWeb3 } from '~/wallets/getWeb3' import { getGnosisSafeContract, getCreateDailyLimitExtensionContract } from '~/wallets/safeContracts' import { type DailyLimitProps } from '~/routes/safe/store/model/dailyLimit' -import executeTransaction from '~/wallets/ethTransactions' +import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions' export const LIMIT_POSITION = 0 export const SPENT_TODAY_POS = 1 @@ -45,7 +45,8 @@ const withdrawn = async (values: Object, safeAddress: string, userAccount: strin const dailyLimitData = dailyLimitModule.contract.executeDailyLimit.getData(0, destination, value) - return executeTransaction(dailyLimitData, userAccount, dailyLimitModule.address) + const txHash = await executeTransaction(dailyLimitData, userAccount, dailyLimitModule.address) + checkReceiptStatus(txHash) } export default withdrawn diff --git a/src/routes/safe/test/Safe.multisig.3owners1threshold.test.js b/src/routes/safe/test/Safe.multisig.3owners1threshold.test.js index 6b383e5a..2227b94e 100644 --- a/src/routes/safe/test/Safe.multisig.3owners1threshold.test.js +++ b/src/routes/safe/test/Safe.multisig.3owners1threshold.test.js @@ -9,6 +9,7 @@ import { SAFELIST_ADDRESS } from '~/routes/routes' import AppRoutes from '~/routes' import AddTransactionComponent from '~/routes/safe/component/AddTransaction' import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getTagFromTransaction, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig' +import { sleep } from '~/utils/timer' const renderSafe = localStore => ( TestUtils.renderIntoDocument(( @@ -40,6 +41,7 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 1 thresh await createMultisigTxFilling(SafeDom, AddTransactionComponent, store) await checkBalanceOf(address, '0.09') await listTxsOf(SafeDom) + await sleep(2500) await expandTransactionOf(SafeDom, 3, 1) await confirmOwners(SafeDom, 'Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Not confirmed]', 'Adolfo 3 Eth Account [Not confirmed]') diff --git a/src/wallets/ethTransactions.js b/src/wallets/ethTransactions.js index 47a2dddf..af325c5b 100644 --- a/src/wallets/ethTransactions.js +++ b/src/wallets/ethTransactions.js @@ -5,6 +5,25 @@ import { promisify } from '~/utils/promisify' // const MAINNET_NETWORK = 1 +export const checkReceiptStatus = async (hash: string) => { + if (!hash) { + throw new Error('No valid Tx hash to get receipt from') + } + + const web3 = getWeb3() + const txReceipt = await promisify(cb => web3.eth.getTransactionReceipt(hash, cb)) + + const { status } = txReceipt + if (!status) { + throw new Error('No status found on this transaction receipt') + } + + const hasError = status === '0x0' + if (hasError) { + throw new Error('Obtained a transaction failure in the receipt') + } +} + export const calculateGasPrice = async () => { /* const web3 = getWeb3()