-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add tests #1448
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
feat: add tests #1448
Changes from 75 commits
38c00a1
e9834af
003112a
c3dbef4
928cf5f
c72e102
aea7e8f
6ae4adb
b2dccc5
aa2cd0c
a9c7035
44774fa
275aed8
4d4d220
ecc3ded
f98e350
a74ca6e
b2035c2
38f1fbe
752f986
7c941ab
7ffebfd
2b1ce28
ba08508
e4c8f62
3600cd6
dba8654
c900f0a
2e39f39
72fa419
a6ac3d8
39c37b3
4b8235f
04f3b2e
e8dc5e0
d24339d
b093169
3d9814f
3eeb0b9
60e78cc
5ffbd31
c40e7ac
a7390c2
8eae344
1f4efd4
2289565
96c5bce
02a966d
cfcd7eb
243cead
75f7c5d
935dda1
37f4c01
e6ec119
45aed70
2bde87b
318e673
faf64b8
f86ed29
4bbb46e
d314b70
a99a644
dd35682
360f5ac
169f914
78e7dbc
7065643
d45d26a
49c68b3
9102012
933f3cc
afca6a5
82b9c89
65a195a
b7600ba
3b3aa60
dc758c7
1e64edb
825293b
ccd81db
aabeb3b
7ff6314
d700fd8
0656fbb
bd49e83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1405,12 +1405,12 @@ func (p *processor) restoreBackwardLETBridges(tx dbtypes.Txer, backwardLETs []*B | |||||||
| ` | ||||||||
|
|
||||||||
| for _, backwardLET := range backwardLETs { | ||||||||
| prev, err := aggkitcommon.SafeUint64(backwardLET.PreviousDepositCount) | ||||||||
| prev, err := aggkitcommon.SafeUint64(new(big.Int).Sub(backwardLET.PreviousDepositCount, big.NewInt(1))) | ||||||||
| if err != nil { | ||||||||
| return fmt.Errorf("invalid previous deposit count: %w", err) | ||||||||
| } | ||||||||
|
|
||||||||
| next, err := aggkitcommon.SafeUint64(backwardLET.NewDepositCount) | ||||||||
| next, err := aggkitcommon.SafeUint64(new(big.Int).Sub(backwardLET.NewDepositCount, big.NewInt(1))) | ||||||||
|
Comment on lines
+1408
to
+1413
|
||||||||
| if err != nil { | ||||||||
| return fmt.Errorf("invalid new deposit count: %w", err) | ||||||||
| } | ||||||||
|
|
@@ -1590,7 +1590,8 @@ func (p *processor) ProcessBlock(ctx context.Context, block sync.Block) error { | |||||||
| return err | ||||||||
| } | ||||||||
|
|
||||||||
| newDepositCount, leafIndex, err := normalizeDepositCount(event.BackwardLET.NewDepositCount) | ||||||||
| adjustedCount := new(big.Int).Sub(event.BackwardLET.NewDepositCount, big.NewInt(1)) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the If that's the case, would it make more sense if we would delete all the nodes that has the index greater than or equal to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so basically what smart contract emits is deposit count which is 1 indexed (starts from 1 and not 0) |
||||||||
| newDepositCount, leafIndex, err := normalizeDepositCount(adjustedCount) | ||||||||
|
Comment on lines
+1593
to
+1594
|
||||||||
| adjustedCount := new(big.Int).Sub(event.BackwardLET.NewDepositCount, big.NewInt(1)) | |
| newDepositCount, leafIndex, err := normalizeDepositCount(adjustedCount) | |
| newDepositCount, leafIndex, err := normalizeDepositCount(event.BackwardLET.NewDepositCount) |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from uint32(event.PreviousDepositCount.Uint64()) + 1 to uint32(event.PreviousDepositCount.Uint64()) appears to change the semantics of how deposit counts are interpreted. This is a critical change that affects how bridges are indexed. The PreviousDepositCount now directly becomes the newDepositCount, rather than being incremented. Ensure this is the correct interpretation according to the contract's event semantics and that all consumers of this field are aware of this change in behavior.
| newDepositCount := uint32(event.PreviousDepositCount.Uint64()) | |
| newDepositCount := uint32(event.PreviousDepositCount.Uint64()) + 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ import ( | |
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "math" | ||
| "math/big" | ||
| "os" | ||
| "path" | ||
|
|
@@ -487,8 +486,8 @@ var ( | |
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: 5, | ||
| BlockPos: 4, | ||
| PreviousDepositCount: big.NewInt(3), | ||
| NewDepositCount: big.NewInt(2), | ||
| PreviousDepositCount: big.NewInt(4), | ||
| NewDepositCount: big.NewInt(3), | ||
| PreviousRoot: common.HexToHash("0x15cd4b94cacc2cf50d055e1adb5fbfe5cd95485e121a5c411d73e263f2a66685"), | ||
| NewRoot: common.HexToHash("0xa03113d9ce128863f29479689c82d0b37ebc9432c569c3a57f22d6c008256c5b"), | ||
| }}, | ||
|
|
@@ -5447,8 +5446,8 @@ func TestProcessor_BackwardLET(t *testing.T) { | |
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: uint64(len(blocks) + 1), | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(3), | ||
| NewDepositCount: big.NewInt(2), | ||
| PreviousDepositCount: big.NewInt(4), | ||
| NewDepositCount: big.NewInt(3), | ||
| PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"), | ||
| NewRoot: common.HexToHash("0xa9d31ebbb97c7cd7c7103bee8af7d0b4c83771939baba0b415b0f94c4c39fd84"), | ||
| }}, | ||
|
|
@@ -5471,8 +5470,8 @@ func TestProcessor_BackwardLET(t *testing.T) { | |
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: uint64(len(blocks) + 1), | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(5), | ||
| NewDepositCount: big.NewInt(0), | ||
| PreviousDepositCount: big.NewInt(6), | ||
| NewDepositCount: big.NewInt(1), | ||
| PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"), | ||
| NewRoot: common.HexToHash("0x283c52c3d10a22d01f95f5bcab5e823675c9855bd40b1e82f32b0437b3b6a446"), | ||
| }}, | ||
|
|
@@ -5495,8 +5494,8 @@ func TestProcessor_BackwardLET(t *testing.T) { | |
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: uint64(len(blocks) + 1), | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(5), | ||
| NewDepositCount: big.NewInt(4), | ||
| PreviousDepositCount: big.NewInt(6), | ||
| NewDepositCount: big.NewInt(5), | ||
| PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"), | ||
| NewRoot: common.HexToHash("0x44e1bf8449ecec2b8b1d123fab00d33c9acb308e590605adf5f6e2de4d1c1133"), | ||
| }}, | ||
|
|
@@ -5520,8 +5519,8 @@ func TestProcessor_BackwardLET(t *testing.T) { | |
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: uint64(len(blocks) + 1), | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(5), | ||
| NewDepositCount: big.NewInt(2), | ||
| PreviousDepositCount: big.NewInt(6), | ||
| NewDepositCount: big.NewInt(3), | ||
| PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"), | ||
| NewRoot: common.HexToHash("0xa9d31ebbb97c7cd7c7103bee8af7d0b4c83771939baba0b415b0f94c4c39fd84"), | ||
| }}, | ||
|
|
@@ -5536,44 +5535,6 @@ func TestProcessor_BackwardLET(t *testing.T) { | |
| skipBlocks: []uint64{2, 3}, // all the bridges from these blocks were backwarded | ||
| archivedDepositCounts: []uint32{3, 4, 5}, | ||
| }, | ||
|
||
| { | ||
| name: "overlapping backward let events", | ||
| setupBlocks: func() []sync.Block { | ||
| blocks := buildBlocksWithSequentialBridges(3, 2, 0, 0) | ||
| blocks = append(blocks, sync.Block{ | ||
| Num: uint64(len(blocks) + 1), | ||
| Hash: common.HexToHash(fmt.Sprintf("0x%x", len(blocks)+1)), | ||
| Events: []any{ | ||
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: uint64(len(blocks) + 1), | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(5), | ||
| NewDepositCount: big.NewInt(3), | ||
| PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"), | ||
| NewRoot: common.HexToHash("0x7533c9ef58edd0bea7959a20c33ed47e5548d35f4ff140c5c915740fe6800fb8"), | ||
| }}, | ||
| }, | ||
| }) | ||
| blocks = append(blocks, sync.Block{ | ||
| Num: uint64(len(blocks) + 2), | ||
| Hash: common.HexToHash(fmt.Sprintf("0x%x", len(blocks)+2)), | ||
| Events: []any{ | ||
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: uint64(len(blocks) + 2), | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(4), | ||
| NewDepositCount: big.NewInt(3), | ||
| PreviousRoot: common.HexToHash("0x7533c9ef58edd0bea7959a20c33ed47e5548d35f4ff140c5c915740fe6800fb8"), | ||
| NewRoot: common.HexToHash("0x7533c9ef58edd0bea7959a20c33ed47e5548d35f4ff140c5c915740fe6800fb8"), | ||
| }}, | ||
| }, | ||
| }) | ||
|
|
||
| return blocks | ||
| }, | ||
| targetDepositCount: 3, | ||
| archivedDepositCounts: []uint32{4, 5}, | ||
| }, | ||
| { | ||
| name: "backward let on empty bridge table", | ||
| setupBlocks: func() []sync.Block { | ||
|
|
@@ -5585,52 +5546,14 @@ func TestProcessor_BackwardLET(t *testing.T) { | |
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: 1, | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(6), | ||
| NewDepositCount: big.NewInt(3), | ||
| PreviousDepositCount: big.NewInt(7), | ||
| NewDepositCount: big.NewInt(4), | ||
| }}, | ||
| }, | ||
| }} | ||
| }, | ||
| targetDepositCount: 0, | ||
| }, | ||
| { | ||
| name: "backward let invalid new deposit count (outside of uint64 range)", | ||
| setupBlocks: func() []sync.Block { | ||
| return []sync.Block{ | ||
| { | ||
| Num: 1, | ||
| Hash: common.HexToHash("0x1"), | ||
| Events: []any{ | ||
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: 1, | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(0), | ||
| NewDepositCount: big.NewInt(-3), | ||
| }}, | ||
| }, | ||
| }} | ||
| }, | ||
| processBlockErrMsg: "invalid deposit count: value=-3 does not fit in uint64", | ||
| }, | ||
| { | ||
| name: "backward let invalid new deposit count (outside of uint32 range)", | ||
| setupBlocks: func() []sync.Block { | ||
| return []sync.Block{ | ||
| { | ||
| Num: 1, | ||
| Hash: common.HexToHash("0x1"), | ||
| Events: []any{ | ||
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: 1, | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(0), | ||
| NewDepositCount: new(big.Int).SetUint64(uint64(math.MaxUint32) + 1), | ||
| }}, | ||
| }, | ||
| }} | ||
| }, | ||
| processBlockErrMsg: "invalid deposit count: value=4294967296 exceeds uint32 max", | ||
| }, | ||
| { | ||
|
||
| name: "backward let after a couple of bridges + reorg backward let", | ||
| setupBlocks: func() []sync.Block { | ||
|
|
@@ -5642,8 +5565,8 @@ func TestProcessor_BackwardLET(t *testing.T) { | |
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: 4, | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(5), | ||
| NewDepositCount: big.NewInt(2), | ||
| PreviousDepositCount: big.NewInt(6), | ||
| NewDepositCount: big.NewInt(3), | ||
| PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"), | ||
| NewRoot: common.HexToHash("0xa9d31ebbb97c7cd7c7103bee8af7d0b4c83771939baba0b415b0f94c4c39fd84"), | ||
| }}, | ||
|
|
@@ -5668,8 +5591,8 @@ func TestProcessor_BackwardLET(t *testing.T) { | |
| Event{BackwardLET: &BackwardLET{ | ||
| BlockNum: uint64(len(blocks) + 1), | ||
| BlockPos: 0, | ||
| PreviousDepositCount: big.NewInt(5), | ||
| NewDepositCount: big.NewInt(2), | ||
| PreviousDepositCount: big.NewInt(6), | ||
| NewDepositCount: big.NewInt(3), | ||
| PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"), | ||
| NewRoot: common.HexToHash("0xa9d31ebbb97c7cd7c7103bee8af7d0b4c83771939baba0b415b0f94c4c39fd84"), | ||
| }}, | ||
|
|
@@ -5888,7 +5811,7 @@ func TestHandleForwardLETEvent(t *testing.T) { | |
| BlockPos: 5, | ||
| BlockTimestamp: 1234567890, | ||
| TxnHash: common.HexToHash("0xabc123"), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount)), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
| PreviousRoot: initialRoot, | ||
| NewDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
|
temaniarpit27 marked this conversation as resolved.
|
||
| NewLeaves: encodedLeaves, | ||
|
|
@@ -5993,7 +5916,7 @@ func TestHandleForwardLETEvent(t *testing.T) { | |
| BlockPos: 10, | ||
| BlockTimestamp: 1234567900, | ||
| TxnHash: common.HexToHash("0xdef456"), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount)), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
| PreviousRoot: initialRoot, | ||
| NewDepositCount: big.NewInt(int64(initialDepositCount + uint32(len(leaves)))), | ||
|
temaniarpit27 marked this conversation as resolved.
|
||
| NewLeaves: encodedLeaves, | ||
|
|
@@ -6092,7 +6015,7 @@ func TestHandleForwardLETEvent(t *testing.T) { | |
| BlockPos: 20, | ||
| BlockTimestamp: 1234567950, | ||
| TxnHash: common.HexToHash("0xforward789"), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount)), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
| PreviousRoot: initialRoot, | ||
| NewDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
|
temaniarpit27 marked this conversation as resolved.
|
||
| NewLeaves: encodedLeaves, | ||
|
|
@@ -6201,7 +6124,7 @@ func TestHandleForwardLETEvent(t *testing.T) { | |
| BlockPos: 30, | ||
| BlockTimestamp: 1234567999, | ||
| TxnHash: common.HexToHash("0xforward999"), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount)), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
| PreviousRoot: initialRoot, | ||
| NewDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
|
temaniarpit27 marked this conversation as resolved.
|
||
| NewLeaves: encodedLeaves, | ||
|
|
@@ -6262,7 +6185,7 @@ func TestHandleForwardLETEvent(t *testing.T) { | |
| BlockPos: 5, | ||
| BlockTimestamp: 1234567890, | ||
| TxnHash: common.HexToHash("0xabc123"), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount)), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
|
temaniarpit27 marked this conversation as resolved.
|
||
| PreviousRoot: common.HexToHash("0xWRONG"), // Wrong root | ||
| NewDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
| NewRoot: common.HexToHash("0x999"), | ||
|
|
@@ -6319,7 +6242,7 @@ func TestHandleForwardLETEvent(t *testing.T) { | |
| BlockPos: 5, | ||
| BlockTimestamp: 1234567890, | ||
| TxnHash: common.HexToHash("0xabc123"), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount)), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
|
temaniarpit27 marked this conversation as resolved.
|
||
| PreviousRoot: initialRoot, | ||
| NewDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
| NewRoot: common.HexToHash("0xWRONG"), // Wrong new root | ||
|
|
@@ -6352,7 +6275,7 @@ func TestHandleForwardLETEvent(t *testing.T) { | |
| BlockPos: 5, | ||
| BlockTimestamp: 1234567890, | ||
| TxnHash: common.HexToHash("0xabc123"), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount)), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
| PreviousRoot: initialRoot, | ||
| NewDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
|
temaniarpit27 marked this conversation as resolved.
|
||
| NewRoot: common.Hash{}, | ||
|
|
@@ -6407,7 +6330,7 @@ func TestHandleForwardLETEvent(t *testing.T) { | |
| BlockPos: 5, | ||
| BlockTimestamp: 1234567890, | ||
| TxnHash: common.HexToHash("0xabc123"), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount)), | ||
| PreviousDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
| PreviousRoot: initialRoot, | ||
| NewDepositCount: big.NewInt(int64(initialDepositCount + 1)), | ||
|
temaniarpit27 marked this conversation as resolved.
|
||
| NewLeaves: encodedLeaves, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.