Update tests to use new TransactionInvalidContextError

This commit is contained in:
Amir Bandeali 2019-08-22 15:51:59 -07:00
parent 37cc948741
commit 890bfd18fa
3 changed files with 11 additions and 60 deletions

View File

@ -14,11 +14,11 @@ import * as IExchange from '../generated-artifacts/IExchange.json';
import * as IExchangeCore from '../generated-artifacts/IExchangeCore.json'; import * as IExchangeCore from '../generated-artifacts/IExchangeCore.json';
import * as IMatchOrders from '../generated-artifacts/IMatchOrders.json'; import * as IMatchOrders from '../generated-artifacts/IMatchOrders.json';
import * as ISignatureValidator from '../generated-artifacts/ISignatureValidator.json'; import * as ISignatureValidator from '../generated-artifacts/ISignatureValidator.json';
import * as IsolatedExchange from '../generated-artifacts/IsolatedExchange.json';
import * as ITransactions from '../generated-artifacts/ITransactions.json'; import * as ITransactions from '../generated-artifacts/ITransactions.json';
import * as ITransferSimulator from '../generated-artifacts/ITransferSimulator.json'; import * as ITransferSimulator from '../generated-artifacts/ITransferSimulator.json';
import * as IWallet from '../generated-artifacts/IWallet.json'; import * as IWallet from '../generated-artifacts/IWallet.json';
import * as IWrapperFunctions from '../generated-artifacts/IWrapperFunctions.json'; import * as IWrapperFunctions from '../generated-artifacts/IWrapperFunctions.json';
import * as IsolatedExchange from '../generated-artifacts/IsolatedExchange.json';
import * as LibExchangeRichErrorDecoder from '../generated-artifacts/LibExchangeRichErrorDecoder.json'; import * as LibExchangeRichErrorDecoder from '../generated-artifacts/LibExchangeRichErrorDecoder.json';
import * as MixinAssetProxyDispatcher from '../generated-artifacts/MixinAssetProxyDispatcher.json'; import * as MixinAssetProxyDispatcher from '../generated-artifacts/MixinAssetProxyDispatcher.json';
import * as MixinExchangeCore from '../generated-artifacts/MixinExchangeCore.json'; import * as MixinExchangeCore from '../generated-artifacts/MixinExchangeCore.json';

View File

@ -43,7 +43,7 @@ import {
const artifacts = { ...erc20Artifacts, ...localArtifacts }; const artifacts = { ...erc20Artifacts, ...localArtifacts };
// tslint:disable:no-unnecessary-type-assertion // tslint:disable:no-unnecessary-type-assertion
blockchainTests.resets('Exchange transactions', env => { blockchainTests.resets.only('Exchange transactions', env => {
let chainId: number; let chainId: number;
let senderAddress: string; let senderAddress: string;
let owner: string; let owner: string;
@ -349,9 +349,9 @@ blockchainTests.resets('Exchange transactions', env => {
const recursiveTransactionHashHex = transactionHashUtils.getTransactionHashHex( const recursiveTransactionHashHex = transactionHashUtils.getTransactionHashHex(
recursiveTransaction, recursiveTransaction,
); );
const noReentrancyError = new ExchangeRevertErrors.TransactionError( const noReentrancyError = new ExchangeRevertErrors.TransactionInvalidContextError(
ExchangeRevertErrors.TransactionErrorCode.NoReentrancy,
transactionHashHex, transactionHashHex,
transaction.signerAddress,
).encode(); ).encode();
const expectedError = new ExchangeRevertErrors.TransactionExecutionError( const expectedError = new ExchangeRevertErrors.TransactionExecutionError(
recursiveTransactionHashHex, recursiveTransactionHashHex,

View File

@ -357,28 +357,6 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
}); });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
// FIXME - This should be unskipped when the contracts have been updated to fix this problem.
it.skip('should revert if reentrancy occurs in the middle of an executeTransaction call and msg.sender == signer for both calls', async () => {
const validSignature = randomSignature();
const transaction1 = await generateZeroExTransactionAsync({ signerAddress: accounts[0] });
const transactionHash1 = transactionHashUtils.getTransactionHashHex(transaction1);
const transaction2 = await generateZeroExTransactionAsync({
signerAddress: accounts[0],
callData: getExecuteTransactionCallData(transaction1, validSignature),
returnData: '0xdeadbeef',
});
const transactionHash2 = transactionHashUtils.getTransactionHashHex(transaction2);
const abiEncoder = AbiEncoder.createMethod('TransactionError', ['uint8', 'bytes32']);
const errorData = abiEncoder.encode([
ExchangeRevertErrors.TransactionErrorCode.NoReentrancy,
transactionHash1,
]);
const expectedError = new ExchangeRevertErrors.TransactionExecutionError(transactionHash2, errorData);
const tx = transactionsContract.executeTransaction.sendTransactionAsync(transaction2, validSignature, {
from: accounts[0],
});
return expect(tx).to.revertWith(expectedError);
});
it('should revert if reentrancy occurs in the middle of an executeTransaction call and msg.sender != signer for both calls', async () => { it('should revert if reentrancy occurs in the middle of an executeTransaction call and msg.sender != signer for both calls', async () => {
const validSignature = randomSignature(); const validSignature = randomSignature();
const transaction1 = await generateZeroExTransactionAsync({ signerAddress: accounts[0] }); const transaction1 = await generateZeroExTransactionAsync({ signerAddress: accounts[0] });
@ -389,11 +367,10 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
returnData: '0xdeadbeef', returnData: '0xdeadbeef',
}); });
const transactionHash2 = transactionHashUtils.getTransactionHashHex(transaction2); const transactionHash2 = transactionHashUtils.getTransactionHashHex(transaction2);
const abiEncoder = AbiEncoder.createMethod('TransactionError', ['uint8', 'bytes32']); const errorData = new ExchangeRevertErrors.TransactionInvalidContextError(
const errorData = abiEncoder.encode([
ExchangeRevertErrors.TransactionErrorCode.NoReentrancy,
transactionHash1, transactionHash1,
]); accounts[0],
).encode();
const expectedError = new ExchangeRevertErrors.TransactionExecutionError(transactionHash2, errorData); const expectedError = new ExchangeRevertErrors.TransactionExecutionError(transactionHash2, errorData);
const tx = transactionsContract.executeTransaction.sendTransactionAsync(transaction2, validSignature, { const tx = transactionsContract.executeTransaction.sendTransactionAsync(transaction2, validSignature, {
from: accounts[1], // Different then the signing addresses from: accounts[1], // Different then the signing addresses
@ -410,33 +387,10 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
returnData: '0xdeadbeef', returnData: '0xdeadbeef',
}); });
const transactionHash2 = transactionHashUtils.getTransactionHashHex(transaction2); const transactionHash2 = transactionHashUtils.getTransactionHashHex(transaction2);
const abiEncoder = AbiEncoder.createMethod('TransactionError', ['uint8', 'bytes32']); const errorData = new ExchangeRevertErrors.TransactionInvalidContextError(
const errorData = abiEncoder.encode([
ExchangeRevertErrors.TransactionErrorCode.NoReentrancy,
transactionHash1, transactionHash1,
]); accounts[0],
const expectedError = new ExchangeRevertErrors.TransactionExecutionError(transactionHash2, errorData); ).encode();
const tx = transactionsContract.executeTransaction.sendTransactionAsync(transaction2, validSignature, {
from: accounts[1], // Different then the signing addresses
});
return expect(tx).to.revertWith(expectedError);
});
// FIXME - This should be unskipped when the contracts have been updated to fix this problem.
it.skip('should revert if reentrancy occurs in the middle of an executeTransaction call and msg.sender == signer and then msg.sender != sender', async () => {
const validSignature = randomSignature();
const transaction1 = await generateZeroExTransactionAsync({ signerAddress: accounts[0] });
const transactionHash1 = transactionHashUtils.getTransactionHashHex(transaction1);
const transaction2 = await generateZeroExTransactionAsync({
signerAddress: accounts[0],
callData: getExecuteTransactionCallData(transaction1, validSignature),
returnData: '0xdeadbeef',
});
const transactionHash2 = transactionHashUtils.getTransactionHashHex(transaction2);
const abiEncoder = AbiEncoder.createMethod('TransactionError', ['uint8', 'bytes32']);
const errorData = abiEncoder.encode([
ExchangeRevertErrors.TransactionErrorCode.NoReentrancy,
transactionHash1,
]);
const expectedError = new ExchangeRevertErrors.TransactionExecutionError(transactionHash2, errorData); const expectedError = new ExchangeRevertErrors.TransactionExecutionError(transactionHash2, errorData);
const tx = transactionsContract.executeTransaction.sendTransactionAsync(transaction2, validSignature, { const tx = transactionsContract.executeTransaction.sendTransactionAsync(transaction2, validSignature, {
from: accounts[1], // Different then the signing addresses from: accounts[1], // Different then the signing addresses
@ -598,10 +552,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
await transactionsContract.setCurrentContextAddress.awaitTransactionSuccessAsync(accounts[0]); await transactionsContract.setCurrentContextAddress.awaitTransactionSuccessAsync(accounts[0]);
const transaction = await generateZeroExTransactionAsync(); const transaction = await generateZeroExTransactionAsync();
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction); const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
const expectedError = new ExchangeRevertErrors.TransactionError( const expectedError = new ExchangeRevertErrors.TransactionInvalidContextError(transactionHash, accounts[0]);
ExchangeRevertErrors.TransactionErrorCode.NoReentrancy,
transactionHash,
);
expect( expect(
transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature()), transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature()),
).to.revertWith(expectedError); ).to.revertWith(expectedError);