Fix _setCurrentContextAddressIfRequired
This commit is contained in:
@@ -101,7 +101,7 @@ contract MixinTransactions is
|
||||
|
||||
// Set the current transaction signer
|
||||
address signerAddress = transaction.signerAddress;
|
||||
_setCurrentContextAddressIfRequired(signerAddress);
|
||||
_setCurrentContextAddressIfRequired(signerAddress, signerAddress);
|
||||
|
||||
// Execute transaction
|
||||
transactionsExecuted[transactionHash] = true;
|
||||
@@ -114,7 +114,7 @@ contract MixinTransactions is
|
||||
}
|
||||
|
||||
// Reset current transaction signer if it was previously updated
|
||||
_setCurrentContextAddressIfRequired(address(0));
|
||||
_setCurrentContextAddressIfRequired(signerAddress, address(0));
|
||||
|
||||
emit TransactionExecution(transactionHash);
|
||||
|
||||
@@ -187,11 +187,15 @@ contract MixinTransactions is
|
||||
}
|
||||
|
||||
/// @dev Sets the currentContextAddress if the current context is not msg.sender.
|
||||
/// @param signerAddress Address of the transaction signer.
|
||||
/// @param contextAddress The current context address.
|
||||
function _setCurrentContextAddressIfRequired(address contextAddress)
|
||||
function _setCurrentContextAddressIfRequired(
|
||||
address signerAddress,
|
||||
address contextAddress
|
||||
)
|
||||
internal
|
||||
{
|
||||
if (contextAddress != msg.sender) {
|
||||
if (signerAddress != msg.sender) {
|
||||
currentContextAddress = contextAddress;
|
||||
}
|
||||
}
|
||||
|
@@ -49,10 +49,10 @@ contract TestTransactions is
|
||||
transactionsExecuted[hash] = true;
|
||||
}
|
||||
|
||||
function setCurrentContextAddressIfRequired(address context)
|
||||
function setCurrentContextAddressIfRequired(address signerAddress, address context)
|
||||
external
|
||||
{
|
||||
_setCurrentContextAddressIfRequired(context);
|
||||
_setCurrentContextAddressIfRequired(signerAddress, context);
|
||||
}
|
||||
|
||||
function getCurrentContextAddress()
|
||||
|
@@ -693,16 +693,24 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
});
|
||||
|
||||
describe('setCurrentContextAddressIfRequired', () => {
|
||||
it('should set the currentContextAddress if not equal to sender', async () => {
|
||||
it('should set the currentContextAddress if signer not equal to sender', async () => {
|
||||
const randomAddress = hexRandom(20);
|
||||
await transactionsContract.setCurrentContextAddressIfRequired.awaitTransactionSuccessAsync(randomAddress);
|
||||
await transactionsContract.setCurrentContextAddressIfRequired.awaitTransactionSuccessAsync(
|
||||
randomAddress,
|
||||
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],
|
||||
});
|
||||
it('should not set the currentContextAddress if signer equal to sender', async () => {
|
||||
const randomAddress = hexRandom(20);
|
||||
await transactionsContract.setCurrentContextAddressIfRequired.awaitTransactionSuccessAsync(
|
||||
accounts[0],
|
||||
randomAddress,
|
||||
{
|
||||
from: accounts[0],
|
||||
},
|
||||
);
|
||||
const currentContextAddress = await transactionsContract.currentContextAddress.callAsync();
|
||||
expect(currentContextAddress).to.eq(constants.NULL_ADDRESS);
|
||||
});
|
||||
|
Reference in New Issue
Block a user