diff --git a/contracts/exchange/contracts/src/MixinTransactions.sol b/contracts/exchange/contracts/src/MixinTransactions.sol index c65f97b401..5e2e246283 100644 --- a/contracts/exchange/contracts/src/MixinTransactions.sol +++ b/contracts/exchange/contracts/src/MixinTransactions.sol @@ -99,11 +99,9 @@ contract MixinTransactions is transactionHash ); + // Set the current transaction signer address signerAddress = transaction.signerAddress; - if (signerAddress != msg.sender) { - // Set the current transaction signer - currentContextAddress = signerAddress; - } + _setCurrentContextAddressIfRequired(signerAddress); // Execute transaction transactionsExecuted[transactionHash] = true; @@ -116,9 +114,7 @@ contract MixinTransactions is } // Reset current transaction signer if it was previously updated - if (signerAddress != msg.sender) { - currentContextAddress = address(0); - } + _setCurrentContextAddressIfRequired(address(0)); emit TransactionExecution(transactionHash); @@ -190,6 +186,16 @@ contract MixinTransactions is } } + /// @dev Sets the currentContextAddress if the current context is not msg.sender. + /// @param contextAddress The current context address. + function _setCurrentContextAddressIfRequired(address contextAddress) + internal + { + if (contextAddress != msg.sender) { + currentContextAddress = contextAddress; + } + } + /// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`). /// If calling a fill function, this address will represent the taker. /// If calling a cancel function, this address will represent the maker. diff --git a/contracts/exchange/contracts/test/TestTransactions.sol b/contracts/exchange/contracts/test/TestTransactions.sol index aa5ffb265d..ffb680f788 100644 --- a/contracts/exchange/contracts/test/TestTransactions.sol +++ b/contracts/exchange/contracts/test/TestTransactions.sol @@ -49,6 +49,12 @@ contract TestTransactions is transactionsExecuted[hash] = true; } + function setCurrentContextAddressIfRequired(address context) + external + { + _setCurrentContextAddressIfRequired(context); + } + function getCurrentContextAddress() external view diff --git a/contracts/exchange/test/transactions_unit_tests.ts b/contracts/exchange/test/transactions_unit_tests.ts index bcaf3ca0d5..73cf4cdc84 100644 --- a/contracts/exchange/test/transactions_unit_tests.ts +++ b/contracts/exchange/test/transactions_unit_tests.ts @@ -692,6 +692,22 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef }); }); + describe('setCurrentContextAddressIfRequired', () => { + it('should set the currentContextAddress if not equal to sender', async () => { + const randomAddress = hexRandom(20); + await transactionsContract.setCurrentContextAddressIfRequired.awaitTransactionSuccessAsync(randomAddress); + const currentContextAddress = await transactionsContract.currentContextAddress.callAsync(); + expect(currentContextAddress).to.eq(randomAddress); + }); + it('should not set the currentContextAddress if equal to sender', async () => { + await transactionsContract.setCurrentContextAddressIfRequired.awaitTransactionSuccessAsync(accounts[0], { + from: accounts[0], + }); + const currentContextAddress = await transactionsContract.currentContextAddress.callAsync(); + expect(currentContextAddress).to.eq(constants.NULL_ADDRESS); + }); + }); + describe('getCurrentContext', () => { it('should return the sender address when there is not a saved context address', async () => { const currentContextAddress = await transactionsContract.getCurrentContextAddress.callAsync({