Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deposit to match executeDeposit #115

Merged
merged 2 commits into from May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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