Skip to content

Commit

Permalink
Update deposit to match executeDeposit (#115)
Browse files Browse the repository at this point in the history
* Update deposit to match executeDeposit

* Add constructor tests for mismatched length
  • Loading branch information
spacesailor24 committed May 1, 2020
1 parent 03272f6 commit 06dd995
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
20 changes: 4 additions & 16 deletions contracts/handlers/GenericHandler.sol
Expand Up @@ -127,13 +127,6 @@ contract GenericHandler is IGenericHandler {
_setResource(resourceID, contractAddress, depositFunctionSig, executeFunctionSig);
}

// Initiate a generic deposit. The deposit function associated with the resource ID
// will be called using data as the parameters, if a function signature exists.
//
// resourceID bytes32 bytes 0 - 32
// len(data) uint256 bytes 32 - 64
// data bytes bytes 96 - END

/**
@notice A deposit is initiatied by making a deposit in the Bridge contract.
@param destinationChainID Chain ID deposit is expected to be bridged to.
Expand Down Expand Up @@ -177,8 +170,10 @@ contract GenericHandler is IGenericHandler {
address contractAddress = _resourceIDToContractAddress[resourceID];
require(_contractWhitelist[contractAddress], "provided contractAddress is not whitelisted");

if (_contractAddressToDepositFunctionSignature[contractAddress] != bytes4(0)) {
(bool success,) = contractAddress.call(metadata);
bytes4 sig = _contractAddressToDepositFunctionSignature[contractAddress];
if (sig != bytes4(0)) {
bytes memory callData = abi.encodePacked(sig, metadata);
(bool success,) = contractAddress.call(callData);
require(success, "delegatecall to contractAddress failed");
}

Expand All @@ -190,13 +185,6 @@ contract GenericHandler is IGenericHandler {
);
}

// Execute a generic proposal. The The deposit function associated with the resource ID
// will be called using data as the parameters, if a function signature exists.
//
// resourceID bytes32 bytes 0 - 32
// len(data) uint256 bytes 32 - 64
// data bytes bytes 96 - END

/**
@notice Proposal execution should be initiated when a proposal is finalized in the Bridge contract.
@param data Consists of {resourceID}, {lenMetaData}, and {metaData}.
Expand Down
34 changes: 33 additions & 1 deletion test/handlers/generic/constructor.js
Expand Up @@ -39,7 +39,6 @@ contract('GenericHandler - [constructor]', async () => {
Ethers.utils.hexZeroPad((CentrifugeAssetInstance2.address + Ethers.utils.hexlify(chainID).substr(2)), 32),
Ethers.utils.hexZeroPad((CentrifugeAssetInstance3.address + Ethers.utils.hexlify(chainID).substr(2)), 32)
];
burnableContractAddresses = [];
initialContractAddresses = [CentrifugeAssetInstance1.address, CentrifugeAssetInstance2.address, CentrifugeAssetInstance3.address];

const executeDepositFuncSig = Ethers.utils.keccak256(Ethers.utils.hexlify(Ethers.utils.toUtf8Bytes(centrifugeAssetStoreFuncSig))).substr(0, 10);
Expand All @@ -58,6 +57,39 @@ contract('GenericHandler - [constructor]', async () => {
initialExecuteFunctionSignatures));
});

it('should revert because mismatch length between initialResourceIDs and initialContractAddresses', async () => {
await TruffleAssert.reverts(
GenericHandlerContract.new(
BridgeInstance.address,
[],
initialContractAddresses,
initialDepositFunctionSignatures,
initialExecuteFunctionSignatures),
"mismatch length between initialResourceIDs and initialContractAddresses");
});

it('should revert because mismatch length between provided contract addresses and function signatures', async () => {
await TruffleAssert.reverts(
GenericHandlerContract.new(
BridgeInstance.address,
initialResourceIDs,
initialContractAddresses,
[],
initialExecuteFunctionSignatures),
"mismatch length between provided contract addresses and function signatures");
});

it('should revert because mismatch length between provided deposit and execute function signatures', async () => {
await TruffleAssert.reverts(
GenericHandlerContract.new(
BridgeInstance.address,
initialResourceIDs,
initialContractAddresses,
initialDepositFunctionSignatures,
[]),
"mismatch length between provided deposit and execute function signatures");
});

it('contract mappings were set with expected values', async () => {
const GenericHandlerInstance = await GenericHandlerContract.new(
BridgeInstance.address,
Expand Down

0 comments on commit 06dd995

Please sign in to comment.