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

add more tests claimtest #96

Merged
merged 1 commit into from
Sep 30, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
948 changes: 947 additions & 1 deletion bridgesync/claimcalldata_test.go

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions bridgesync/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ func setClaimCalldata(client EthClienter, bridge common.Address, txHash common.H
}

// find the claim linked to the event using DFS
// TODO: take into account potential reverts that may be found on the path,
// and other edge cases
callStack := stack.New()
callStack.Push(*c)
for {
Expand Down
1 change: 1 addition & 0 deletions test/contracts/abi/claimmocktest.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"contract IClaimMock","name":"_claimMock","type":"address"},{"internalType":"contract IClaimMockCaller","name":"_claimMockCaller","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes","name":"claim1","type":"bytes"},{"internalType":"bytes","name":"claim2","type":"bytes"},{"internalType":"bool[2]","name":"reverted","type":"bool[2]"}],"name":"claim2TestInternal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"claim1","type":"bytes"},{"internalType":"bytes","name":"claim2","type":"bytes"},{"internalType":"bytes","name":"claim3","type":"bytes"},{"internalType":"bool[3]","name":"reverted","type":"bool[3]"}],"name":"claim3TestInternal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimMock","outputs":[{"internalType":"contract IClaimMock","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimMockCaller","outputs":[{"internalType":"contract IClaimMockCaller","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"claim","type":"bytes"},{"internalType":"bool","name":"reverted","type":"bool"}],"name":"claimTestInternal","outputs":[],"stateMutability":"nonpayable","type":"function"}]
1 change: 1 addition & 0 deletions test/contracts/bin/claimmocktest.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60c0346100a157601f61072e38819003918201601f19168301916001600160401b038311848410176100a65780849260409485528339810103126100a15780516001600160a01b039182821682036100a1576020015191821682036100a15760a05260805260405161067190816100bd82396080518181816102d5015281816103870152818161046a015261054e015260a05181818161031a01526105c20152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604052600436101561001257600080fd5b6000803560e01c90816348f0c6801461006a575080636e53085414610065578063837a84701461006057806383f5b0061461005b57639bee34681461005657600080fd5b610349565b610304565b6102bf565b610217565b346100f45760c03660031901126100f45767ffffffffffffffff6004358181116100f05761009c903690600401610142565b6024358281116100ec576100b4903690600401610142565b916044359081116100ec576100cd903690600401610142565b36608312156100ec576100e9926100e3366101c6565b92610533565b80f35b8380fd5b8280fd5b80fd5b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161012157604052565b6100f7565b6040810190811067ffffffffffffffff82111761012157604052565b81601f820112156101a55780359067ffffffffffffffff928383116101215760405193601f8401601f19908116603f011685019081118582101761012157604052828452602083830101116101a557816000926020809301838601378301015290565b600080fd5b6024359081151582036101a557565b359081151582036101a557565b90604051916060830183811067ffffffffffffffff821117610121576040528260c49182116101a5576064905b8282106101ff57505050565b6020809161020c846101b9565b8152019101906101f3565b346101a55760803660031901126101a55767ffffffffffffffff6004358181116101a557610249903690600401610142565b906024359081116101a557610262903690600401610142565b36606312156101a5576040519061027882610126565b819260843681116101a5576044945b81861061029c57505061029a9350610467565b005b602080916102a9886101b9565b815201950194610287565b60009103126101a557565b346101a55760003660031901126101a5576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b346101a55760003660031901126101a5576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b346101a557600060403660031901126100f45760043567ffffffffffffffff81116103f75761037c903690600401610142565b816103856101aa565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b156100f0576103d793836040518096819582946327e3584360e01b84526004840161043b565b03925af180156103f2576103e9575080f35b6100e99061010d565b61045b565b5080fd5b919082519283825260005b848110610427575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201610406565b906104536020919493946040845260408401906103fb565b931515910152565b6040513d6000823e3d90fd5b917f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031691823b156101a557604051631cf865cf60e01b815260806004820152938492916104d6916104c49060848601906103fb565b848103600319016024860152906103fb565b90600090604484015b60028310610517575050509181600081819503925af180156103f2576105025750565b8061050f6105159261010d565b806102b4565b565b81511515815286945060019290920191602091820191016104df565b91926000906020810151610632575b80516001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081169490911515853b156101a557600061059d91604051809381926327e3584360e01b9b8c84526004840161043b565b0381838a5af19283156103f25760409560208094610aac9460009761061f575b5001917f0000000000000000000000000000000000000000000000000000000000000000165af1500151151590803b156101a55761060e93600080946040519687958694859384526004840161043b565b03925af180156103f2576105025750565b8061050f61062c9261010d565b386105bd565b6001915061054256fea264697066735822122091357ca0b4807d5579dc633a7d2a9263efbfe31944c644c21b7ccf83594a9e2c64736f6c63430008120033
3 changes: 2 additions & 1 deletion test/contracts/bind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ gen() {

gen verifybatchesmock
gen claimmock
gen claimmockcaller
gen claimmockcaller
gen claimmocktest
53 changes: 53 additions & 0 deletions test/contracts/claimmocktest/ClaimMockTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: AGPL-3.0

pragma solidity 0.8.18;

interface IClaimMock {
event ClaimEvent(uint256 globalIndex, uint32 originNetwork, address originAddress, address destinationAddress, uint256 amount);
function claimAsset(bytes32[32] calldata smtProofLocalExitRoot,bytes32[32] calldata smtProofRollupExitRoot,uint256 globalIndex,bytes32 mainnetExitRoot,bytes32 rollupExitRoot,uint32 originNetwork,address originTokenAddress,uint32 destinationNetwork,address destinationAddress,uint256 amount,bytes calldata metadata) external;
function claimMessage(bytes32[32] calldata smtProofLocalExitRoot,bytes32[32] calldata smtProofRollupExitRoot,uint256 globalIndex,bytes32 mainnetExitRoot,bytes32 rollupExitRoot,uint32 originNetwork,address originAddress,uint32 destinationNetwork,address destinationAddress,uint256 amount,bytes calldata metadata) external;
}

interface IClaimMockCaller {
function claimAsset(bytes32[32] calldata smtProofLocalExitRoot, bytes32[32] calldata smtProofRollupExitRoot, uint256 globalIndex, bytes32 mainnetExitRoot, bytes32 rollupExitRoot, uint32 originNetwork, address originTokenAddress, uint32 destinationNetwork, address destinationAddress, uint256 amount, bytes calldata metadata, bool reverted) external;
function claimMessage(bytes32[32] calldata smtProofLocalExitRoot, bytes32[32] calldata smtProofRollupExitRoot, uint256 globalIndex, bytes32 mainnetExitRoot, bytes32 rollupExitRoot, uint32 originNetwork, address originAddress, uint32 destinationNetwork, address destinationAddress, uint256 amount, bytes calldata metadata, bool reverted) external;
function claimBytes(bytes memory claim, bool reverted) external;
function claim2Bytes(bytes memory claim1, bytes memory claim2, bool[2] memory reverted) external;
}

contract ClaimMockTest {
IClaimMockCaller public immutable claimMockCaller;
IClaimMock public immutable claimMock;

uint8 constant _DEPOSIT_CONTRACT_TREE_DEPTH = 32;

constructor(
IClaimMock _claimMock,
IClaimMockCaller _claimMockCaller
) {
claimMock = _claimMock;
claimMockCaller = _claimMockCaller;
}

function claimTestInternal(bytes memory claim, bool reverted) external {
claimMockCaller.claimBytes(claim, reverted);
}

function claim2TestInternal(bytes memory claim1, bytes memory claim2, bool[2] memory reverted) external {
claimMockCaller.claim2Bytes(claim1, claim2, reverted);
}

function claim3TestInternal(bytes memory claim1, bytes memory claim2, bytes memory claim3, bool[3] memory reverted) external {
address addr = address(claimMock);
uint256 value1 = 0;
if(reverted[1]) {
value1 = 1;
}
claimMockCaller.claimBytes(claim1, reverted[0]);
assembly {
let success1 := call(gas(), addr, value1, add(claim2, 32), 0xaac, 0x20, 0)
}
claimMockCaller.claimBytes(claim3, reverted[2]);
}

}
Loading
Loading