Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Merge 7326c52 into 3c4d52b
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Jun 12, 2020
2 parents 3c4d52b + 7326c52 commit e72a1d1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
1 change: 0 additions & 1 deletion contracts/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ contract Bridge is Pausable, AccessControl {
}
function _setHandlerAddress(address handlerAddress, bytes32 resourceID) internal {
require(_resourceIDToHandlerAddress[resourceID] == address(0), "resourceID already set");
_resourceIDToHandlerAddress[resourceID] = handlerAddress;
}
}
4 changes: 0 additions & 4 deletions contracts/handlers/HandlerHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ contract HandlerHelpers is IERCHandler {
@param contractAddress Address of contract to be called when a deposit is made and a deposited is executed.
*/
function setResource(bytes32 resourceID, address contractAddress) external override onlyBridge {
require(_resourceIDToTokenContractAddress[resourceID] == address(0), "resourceID already has a corresponding contract address");

bytes32 currentResourceID = _tokenContractAddressToResourceID[contractAddress];
require(currentResourceID == bytes32(0), "contract address already has corresponding resourceID");

_setResource(resourceID, contractAddress);
}
Expand Down
42 changes: 34 additions & 8 deletions test/handlers/erc20/setResourceIDAndContractAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,44 @@ contract('ERC20Handler - [setResourceIDAndContractAddress]', async () => {
assert.strictEqual(secondERC20ResourceID.toLowerCase(), retrievedResourceID.toLowerCase());
});

it('should revert because resourceID should already be set', async () => {
await TruffleAssert.reverts(BridgeInstance.adminSetResource(
ERC20HandlerInstance.address, initialResourceIDs[0], ERC20MintableInstance1.address),
"resourceID already has a corresponding contract address");
it('existing resourceID should be updated correctly with new token contract address', async () => {
await BridgeInstance.adminSetResource(ERC20HandlerInstance.address, initialResourceIDs[0], ERC20MintableInstance1.address);

const ERC20MintableInstance2 = await ERC20MintableContract.new("token", "TOK");
await BridgeInstance.adminSetResource(ERC20HandlerInstance.address, initialResourceIDs[0], ERC20MintableInstance2.address);

const retrievedTokenAddress = await ERC20HandlerInstance._resourceIDToTokenContractAddress.call(initialResourceIDs[0]);
assert.strictEqual(ERC20MintableInstance2.address, retrievedTokenAddress);

const retrievedResourceID = await ERC20HandlerInstance._tokenContractAddressToResourceID.call(ERC20MintableInstance2.address);
assert.strictEqual(initialResourceIDs[0].toLowerCase(), retrievedResourceID.toLowerCase());
});

it('existing resourceID should be updated correctly with new handler address', async () => {
await BridgeInstance.adminSetResource(ERC20HandlerInstance.address, initialResourceIDs[0], ERC20MintableInstance1.address);

const ERC20MintableInstance2 = await ERC20MintableContract.new("token", "TOK");
const secondERC20ResourceID = [Ethers.utils.hexZeroPad((ERC20MintableInstance2.address + Ethers.utils.hexlify(chainID).substr(2)), 32)];
ERC20HandlerInstance2 = await ERC20HandlerContract.new(BridgeInstance.address, secondERC20ResourceID, [ERC20MintableInstance2.address], burnableContractAddresses);

await BridgeInstance.adminSetHandlerAddress(ERC20MintableInstance2.address, initialResourceIDs[0]);

const bridgeHandlerAddress = await BridgeInstance._resourceIDToHandlerAddress.call(initialResourceIDs[0]);
assert.strictEqual(bridgeHandlerAddress.toLowerCase(), ERC20MintableInstance2.address.toLowerCase());
});

it('should revert because contract address should already be set', async () => {
it('Existing resourceID should be replaced by new resourceID in handler', async () => {
await BridgeInstance.adminSetResource(ERC20HandlerInstance.address, initialResourceIDs[0], ERC20MintableInstance1.address);

const ERC20MintableInstance2 = await ERC20MintableContract.new("token", "TOK");
const secondERC20ResourceID = Ethers.utils.hexZeroPad((ERC20MintableInstance2.address + Ethers.utils.hexlify(chainID).substr(2)), 32);

await TruffleAssert.reverts(BridgeInstance.adminSetResource(
ERC20HandlerInstance.address, secondERC20ResourceID, ERC20MintableInstance1.address),
'contract address already has corresponding resourceID');
await BridgeInstance.adminSetResource(ERC20HandlerInstance.address, secondERC20ResourceID, ERC20MintableInstance1.address);

const retrievedResourceID = await ERC20HandlerInstance._tokenContractAddressToResourceID.call(ERC20MintableInstance1.address);
assert.strictEqual(secondERC20ResourceID.toLowerCase(), retrievedResourceID.toLowerCase());

const retrievedContractAddress = await ERC20HandlerInstance._resourceIDToTokenContractAddress.call(secondERC20ResourceID);
assert.strictEqual(retrievedContractAddress.toLowerCase(), ERC20MintableInstance1.address.toLowerCase());
});
});

0 comments on commit e72a1d1

Please sign in to comment.