Skip to content

Commit

Permalink
update test claimcalldata
Browse files Browse the repository at this point in the history
  • Loading branch information
laisolizq committed Sep 5, 2024
1 parent b7a696f commit cc20697
Show file tree
Hide file tree
Showing 9 changed files with 475 additions and 65 deletions.
232 changes: 227 additions & 5 deletions bridgesync/claimcalldata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/test/contracts/claimmock"
"github.com/0xPolygon/cdk/test/contracts/claimmockcaller"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -57,7 +58,6 @@ func TestClaimCalldata(t *testing.T) {
proofRollup[4] = common.HexToHash("a1fa")
proofRollupH[4] = common.HexToHash("a1fa")
expectedClaim := Claim{
GlobalIndex: big.NewInt(420),
OriginNetwork: 69,
OriginAddress: common.HexToAddress("ffaaffaa"),
DestinationAddress: common.HexToAddress("123456789"),
Expand All @@ -69,9 +69,23 @@ func TestClaimCalldata(t *testing.T) {
DestinationNetwork: 0,
Metadata: []byte{},
}
expectedClaim2 := Claim{
OriginNetwork: 69,
OriginAddress: common.HexToAddress("ffaaffaa"),
DestinationAddress: common.HexToAddress("123456789"),
Amount: big.NewInt(4),
MainnetExitRoot: common.HexToHash("5ca1e"),
RollupExitRoot: common.HexToHash("dead"),
ProofLocalExitRoot: proofLocalH,
ProofRollupExitRoot: proofRollupH,
DestinationNetwork: 0,
Metadata: []byte{},
}
auth.GasLimit = 999999 // for some reason gas estimation fails :(

// direct call claim asset
expectedClaim.GlobalIndex = big.NewInt(421)
expectedClaim.IsMessage = false
tx, err := bridgeContract.ClaimAsset(
auth,
proofLocal,
Expand All @@ -89,7 +103,6 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err := client.TransactionReceipt(ctx, tx.Hash())
expectedClaim.IsMessage = false
testCases = append(testCases, testCase{
description: "direct call to claim asset",
bridgeAddr: bridgeAddr,
Expand All @@ -98,6 +111,8 @@ func TestClaimCalldata(t *testing.T) {
})

// indirect call claim asset
expectedClaim.IsMessage = false
expectedClaim.GlobalIndex = big.NewInt(422)
tx, err = claimCaller.ClaimAsset(
auth,
proofLocal,
Expand All @@ -111,11 +126,11 @@ func TestClaimCalldata(t *testing.T) {
expectedClaim.DestinationAddress,
expectedClaim.Amount,
nil,
false,
)
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
expectedClaim.IsMessage = false
testCases = append(testCases, testCase{
description: "indirect call to claim asset",
bridgeAddr: bridgeAddr,
Expand All @@ -124,6 +139,8 @@ func TestClaimCalldata(t *testing.T) {
})

// direct call claim message
expectedClaim.IsMessage = true
expectedClaim.GlobalIndex = big.NewInt(423)
tx, err = bridgeContract.ClaimMessage(
auth,
proofLocal,
Expand All @@ -141,7 +158,6 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
expectedClaim.IsMessage = true
testCases = append(testCases, testCase{
description: "direct call to claim message",
bridgeAddr: bridgeAddr,
Expand All @@ -150,6 +166,8 @@ func TestClaimCalldata(t *testing.T) {
})

// indirect call claim message
expectedClaim.IsMessage = true
expectedClaim.GlobalIndex = big.NewInt(424)
tx, err = claimCaller.ClaimMessage(
auth,
proofLocal,
Expand All @@ -163,19 +181,223 @@ func TestClaimCalldata(t *testing.T) {
expectedClaim.DestinationAddress,
expectedClaim.Amount,
nil,
false,
)
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
expectedClaim.IsMessage = true
testCases = append(testCases, testCase{
description: "indirect call to claim message",
bridgeAddr: bridgeAddr,
log: *r.Logs[0],
expectedClaim: expectedClaim,
})

reverted := [2]bool{false, false}

// 2 indirect call claim message
expectedClaim.IsMessage = true
expectedClaim.GlobalIndex = big.NewInt(425)
expectedClaim2.IsMessage = true
expectedClaim2.GlobalIndex = big.NewInt(426)
tx, err = claimCaller.ClaimMessage2(
auth,
proofLocal,
proofRollup,
expectedClaim.GlobalIndex,
expectedClaim.MainnetExitRoot,
expectedClaim.RollupExitRoot,
expectedClaim.OriginNetwork,
expectedClaim.OriginAddress,
0,
expectedClaim.DestinationAddress,
expectedClaim.Amount,
nil,
reverted,
)
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
testCases = append(testCases, testCase{
description: "2 indirect call claim message 1",
bridgeAddr: bridgeAddr,
log: *r.Logs[0],
expectedClaim: expectedClaim,
})
testCases = append(testCases, testCase{
description: "2 indirect call claim message 2",
bridgeAddr: bridgeAddr,
log: *r.Logs[1],
expectedClaim: expectedClaim2,
})

reverted = [2]bool{false, true}

// 2 indirect call claim message (1 ok, 1 reverted)
expectedClaim.IsMessage = true
expectedClaim.GlobalIndex = big.NewInt(427)
tx, err = claimCaller.ClaimMessage2(
auth,
proofLocal,
proofRollup,
expectedClaim.GlobalIndex,
expectedClaim.MainnetExitRoot,
expectedClaim.RollupExitRoot,
expectedClaim.OriginNetwork,
expectedClaim.OriginAddress,
0,
expectedClaim.DestinationAddress,
expectedClaim.Amount,
nil,
reverted,
)
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
testCases = append(testCases, testCase{
description: "2 indirect (ok, reverted) call claim message",
bridgeAddr: bridgeAddr,
log: *r.Logs[0],
expectedClaim: expectedClaim,
})

reverted = [2]bool{true, false}

// 2 indirect call claim message (1 reverted, 1 ok)
expectedClaim2.IsMessage = true
expectedClaim.GlobalIndex = big.NewInt(429)
expectedClaim2.GlobalIndex = big.NewInt(430)
tx, err = claimCaller.ClaimMessage2(
auth,
proofLocal,
proofRollup,
expectedClaim.GlobalIndex,
expectedClaim.MainnetExitRoot,
expectedClaim.RollupExitRoot,
expectedClaim.OriginNetwork,
expectedClaim.OriginAddress,
0,
expectedClaim.DestinationAddress,
expectedClaim.Amount,
nil,
reverted,
)
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
testCases = append(testCases, testCase{
description: "2 indirect (reverted,ok) call claim message",
bridgeAddr: bridgeAddr,
log: *r.Logs[0],
expectedClaim: expectedClaim2,
})

reverted = [2]bool{false, false}

// 2 indirect call claim asset
expectedClaim.IsMessage = false
expectedClaim.GlobalIndex = big.NewInt(431)
expectedClaim2.IsMessage = false
expectedClaim2.GlobalIndex = big.NewInt(432)
tx, err = claimCaller.ClaimAsset2(
auth,
proofLocal,
proofRollup,
expectedClaim.GlobalIndex,
expectedClaim.MainnetExitRoot,
expectedClaim.RollupExitRoot,
expectedClaim.OriginNetwork,
expectedClaim.OriginAddress,
0,
expectedClaim.DestinationAddress,
expectedClaim.Amount,
nil,
reverted,
)
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
log.Infof("%+v", r)
testCases = append(testCases, testCase{
description: "2 indirect call claim asset 1",
bridgeAddr: bridgeAddr,
log: *r.Logs[0],
expectedClaim: expectedClaim,
})
testCases = append(testCases, testCase{
description: "2 indirect call claim asset 2",
bridgeAddr: bridgeAddr,
log: *r.Logs[1],
expectedClaim: expectedClaim2,
})

reverted = [2]bool{false, true}

// 2 indirect call claim asset (1 ok, 1 reverted)
expectedClaim.IsMessage = false
expectedClaim.GlobalIndex = big.NewInt(433)
tx, err = claimCaller.ClaimAsset2(
auth,
proofLocal,
proofRollup,
expectedClaim.GlobalIndex,
expectedClaim.MainnetExitRoot,
expectedClaim.RollupExitRoot,
expectedClaim.OriginNetwork,
expectedClaim.OriginAddress,
0,
expectedClaim.DestinationAddress,
expectedClaim.Amount,
nil,
reverted,
)
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
log.Infof("%+v", r)
expectedClaim.IsMessage = false
testCases = append(testCases, testCase{
description: "2 indirect (ok, reverted) call claim asset",
bridgeAddr: bridgeAddr,
log: *r.Logs[0],
expectedClaim: expectedClaim,
})

reverted = [2]bool{true, false}

// 2 indirect call claim asset (1 reverted, 1 ok)
expectedClaim2.IsMessage = false
expectedClaim.GlobalIndex = big.NewInt(435)
expectedClaim2.GlobalIndex = big.NewInt(436)
tx, err = claimCaller.ClaimAsset2(
auth,
proofLocal,
proofRollup,
expectedClaim.GlobalIndex,
expectedClaim.MainnetExitRoot,
expectedClaim.RollupExitRoot,
expectedClaim.OriginNetwork,
expectedClaim.OriginAddress,
0,
expectedClaim.DestinationAddress,
expectedClaim.Amount,
nil,
reverted,
)
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
log.Infof("%+v", r)
expectedClaim2.IsMessage = false
testCases = append(testCases, testCase{
description: "2 indirect (reverted,ok) call claim asset",
bridgeAddr: bridgeAddr,
log: *r.Logs[0],
expectedClaim: expectedClaim2,
})

for _, tc := range testCases {
log.Info(tc.description)
t.Run(tc.description, func(t *testing.T) {
claimEvent, err := bridgeContract.ParseClaimEvent(tc.log)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/abi/claimmockcaller.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"inputs":[{"internalType":"contract IClaimMock","name":"_claimMock","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes32[32]","name":"smtProofLocalExitRoot","type":"bytes32[32]"},{"internalType":"bytes32[32]","name":"smtProofRollupExitRoot","type":"bytes32[32]"},{"internalType":"uint256","name":"globalIndex","type":"uint256"},{"internalType":"bytes32","name":"mainnetExitRoot","type":"bytes32"},{"internalType":"bytes32","name":"rollupExitRoot","type":"bytes32"},{"internalType":"uint32","name":"originNetwork","type":"uint32"},{"internalType":"address","name":"originTokenAddress","type":"address"},{"internalType":"uint32","name":"destinationNetwork","type":"uint32"},{"internalType":"address","name":"destinationAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"metadata","type":"bytes"}],"name":"claimAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[32]","name":"smtProofLocalExitRoot","type":"bytes32[32]"},{"internalType":"bytes32[32]","name":"smtProofRollupExitRoot","type":"bytes32[32]"},{"internalType":"uint256","name":"globalIndex","type":"uint256"},{"internalType":"bytes32","name":"mainnetExitRoot","type":"bytes32"},{"internalType":"bytes32","name":"rollupExitRoot","type":"bytes32"},{"internalType":"uint32","name":"originNetwork","type":"uint32"},{"internalType":"address","name":"originAddress","type":"address"},{"internalType":"uint32","name":"destinationNetwork","type":"uint32"},{"internalType":"address","name":"destinationAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"metadata","type":"bytes"}],"name":"claimMessage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimMock","outputs":[{"internalType":"contract IClaimMock","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
[{"inputs":[{"internalType":"contract IClaimMock","name":"_claimMock","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes32[32]","name":"smtProofLocalExitRoot","type":"bytes32[32]"},{"internalType":"bytes32[32]","name":"smtProofRollupExitRoot","type":"bytes32[32]"},{"internalType":"uint256","name":"globalIndex","type":"uint256"},{"internalType":"bytes32","name":"mainnetExitRoot","type":"bytes32"},{"internalType":"bytes32","name":"rollupExitRoot","type":"bytes32"},{"internalType":"uint32","name":"originNetwork","type":"uint32"},{"internalType":"address","name":"originTokenAddress","type":"address"},{"internalType":"uint32","name":"destinationNetwork","type":"uint32"},{"internalType":"address","name":"destinationAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"metadata","type":"bytes"},{"internalType":"bool","name":"reverted","type":"bool"}],"name":"claimAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[32]","name":"smtProofLocalExitRoot","type":"bytes32[32]"},{"internalType":"bytes32[32]","name":"smtProofRollupExitRoot","type":"bytes32[32]"},{"internalType":"uint256","name":"globalIndex","type":"uint256"},{"internalType":"bytes32","name":"mainnetExitRoot","type":"bytes32"},{"internalType":"bytes32","name":"rollupExitRoot","type":"bytes32"},{"internalType":"uint32","name":"originNetwork","type":"uint32"},{"internalType":"address","name":"originTokenAddress","type":"address"},{"internalType":"uint32","name":"destinationNetwork","type":"uint32"},{"internalType":"address","name":"destinationAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"metadata","type":"bytes"},{"internalType":"bool[2]","name":"reverted","type":"bool[2]"}],"name":"claimAsset2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[32]","name":"smtProofLocalExitRoot","type":"bytes32[32]"},{"internalType":"bytes32[32]","name":"smtProofRollupExitRoot","type":"bytes32[32]"},{"internalType":"uint256","name":"globalIndex","type":"uint256"},{"internalType":"bytes32","name":"mainnetExitRoot","type":"bytes32"},{"internalType":"bytes32","name":"rollupExitRoot","type":"bytes32"},{"internalType":"uint32","name":"originNetwork","type":"uint32"},{"internalType":"address","name":"originAddress","type":"address"},{"internalType":"uint32","name":"destinationNetwork","type":"uint32"},{"internalType":"address","name":"destinationAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"metadata","type":"bytes"},{"internalType":"bool","name":"reverted","type":"bool"}],"name":"claimMessage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[32]","name":"smtProofLocalExitRoot","type":"bytes32[32]"},{"internalType":"bytes32[32]","name":"smtProofRollupExitRoot","type":"bytes32[32]"},{"internalType":"uint256","name":"globalIndex","type":"uint256"},{"internalType":"bytes32","name":"mainnetExitRoot","type":"bytes32"},{"internalType":"bytes32","name":"rollupExitRoot","type":"bytes32"},{"internalType":"uint32","name":"originNetwork","type":"uint32"},{"internalType":"address","name":"originAddress","type":"address"},{"internalType":"uint32","name":"destinationNetwork","type":"uint32"},{"internalType":"address","name":"destinationAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"metadata","type":"bytes"},{"internalType":"bool[2]","name":"reverted","type":"bool[2]"}],"name":"claimMessage2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimMock","outputs":[{"internalType":"contract IClaimMock","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
2 changes: 1 addition & 1 deletion test/contracts/bin/claimmock.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
608060405234801561001057600080fd5b50610240806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063ccaa2d111461003b578063f5efcd791461003b575b600080fd5b61004e610049366004610102565b610050565b005b604080518b815263ffffffff891660208201526001600160a01b0388811682840152861660608201526080810185905290517f1df3f2a973a00d6635911755c260704e95e8a5876997546798770f76396fda4d9181900360a00190a1505050505050505050505050565b8061040081018310156100cc57600080fd5b92915050565b803563ffffffff811681146100e657600080fd5b919050565b80356001600160a01b03811681146100e657600080fd5b6000806000806000806000806000806000806109208d8f03121561012557600080fd5b61012f8e8e6100ba565b9b5061013f8e6104008f016100ba565b9a506108008d013599506108208d013598506108408d013597506101666108608e016100d2565b96506101756108808e016100eb565b95506101846108a08e016100d2565b94506101936108c08e016100eb565b93506108e08d013592506109008d013567ffffffffffffffff808211156101b957600080fd5b818f0191508f601f8301126101cd57600080fd5b80823511156101db57600080fd5b508e6020823583010111156101ef57600080fd5b60208101925080359150509295989b509295989b509295989b56fea2646970667358221220ea3ccb4fef38083776607b84bdd7b00012029d7d1fee9fa7c300663fe761dcac64736f6c63430008120033
6080806040523461001657610235908161001c8239f35b600080fdfe608080604052600436101561001357600080fd5b600090813560e01c908163ccaa2d11146100bb575063f5efcd791461003757600080fd5b346100b8576100453661013d565b505094509750509250935080156100b4576040805193845263ffffffff9490941660208401526001600160a01b039182169383019390935292909216606083015260808201527f1df3f2a973a00d6635911755c260704e95e8a5876997546798770f76396fda4d9060a090a180f35b8580fd5b80fd5b905034610139577f1df3f2a973a00d6635911755c260704e95e8a5876997546798770f76396fda4d8161012e926100f13661013d565b5050968a5263ffffffff90931660208a0152506001600160a01b0390811660408901521660608701525050608084018190529560a0840192509050565b0390a1156100b85780f35b5080fd5b906109206003198301126101fa57610404908282116101fa57600492610804928184116101fa579235916108243591610844359163ffffffff906108643582811681036101fa57926001600160a01b03916108843583811681036101fa57936108a43590811681036101fa57926108c43590811681036101fa57916108e435916109043567ffffffffffffffff928382116101fa57806023830112156101fa57818e01359384116101fa57602484830101116101fa576024019190565b600080fdfea264697066735822122096c60d8b224a7d535ae1b97899c7671e84485ce5288dce7ec93826455adb531364736f6c63430008120033
Loading

0 comments on commit cc20697

Please sign in to comment.