Skip to content

Commit 9a11387

Browse files
fix: tests
1 parent 38edf01 commit 9a11387

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

bridgesync/processor.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,13 +1669,21 @@ func (p *processor) deleteBridgesAbove(ctx context.Context, tx dbtypes.Txer, dep
16691669

16701670
// sanityCheckLatestLER checks if the provided local exit root matches the latest one in the exit tree
16711671
func (p *processor) sanityCheckLatestLER(tx dbtypes.Txer, ler common.Hash) error {
1672+
var lastRootHash common.Hash
1673+
16721674
root, err := p.exitTree.GetLastRoot(tx)
16731675
if err != nil {
1674-
return fmt.Errorf("failed to get last root from exit tree: %w", err)
1676+
// if there is no root yet, we consider the zero hash as the last root
1677+
if !errors.Is(err, db.ErrNotFound) {
1678+
return fmt.Errorf("failed to get last root from exit tree: %w", err)
1679+
}
1680+
} else {
1681+
lastRootHash = root.Hash
16751682
}
1676-
if root.Hash != ler {
1683+
1684+
if lastRootHash != ler {
16771685
return fmt.Errorf("local exit root mismatch: expected %s, got %s",
1678-
ler.String(), root.Hash.String())
1686+
ler.String(), lastRootHash.String())
16791687
}
16801688
return nil
16811689
}

bridgesync/processor_forward_let_test.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,7 @@ func TestHandleForwardLETEvent(t *testing.T) {
243243
// Don't set Source - bridge_archive table doesn't have this column
244244
}
245245
// Insert manually to avoid Source field
246-
_, err = tx.Exec(`
247-
INSERT INTO bridge_archive (
248-
block_num, block_pos, leaf_type, origin_network, origin_address,
249-
destination_network, destination_address, amount, metadata, deposit_count,
250-
tx_hash, block_timestamp, from_address, txn_sender
251-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, 0, $12, $13)
252-
`, archivedBridge.BlockNum, archivedBridge.BlockPos, archivedBridge.LeafType,
253-
archivedBridge.OriginNetwork, archivedBridge.OriginAddress,
254-
archivedBridge.DestinationNetwork, archivedBridge.DestinationAddress,
255-
archivedBridge.Amount.String(), archivedBridge.Metadata, archivedBridge.DepositCount,
256-
archivedBridge.TxHash.Hex(), archivedBridge.FromAddress.Hex(), archivedBridge.TxnSender.Hex())
246+
err = meddler.Insert(tx, "bridge_archive", archivedBridge)
257247
require.NoError(t, err)
258248

259249
// Create forward LET event with matching leaf
@@ -371,17 +361,7 @@ func TestHandleForwardLETEvent(t *testing.T) {
371361

372362
// Insert both archived bridges manually (to avoid Source column)
373363
for _, archived := range []*Bridge{archivedBridge1, archivedBridge2} {
374-
_, err = tx.Exec(`
375-
INSERT INTO bridge_archive (
376-
block_num, block_pos, leaf_type, origin_network, origin_address,
377-
destination_network, destination_address, amount, metadata, deposit_count,
378-
tx_hash, block_timestamp, from_address, txn_sender
379-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, 0, $12, $13)
380-
`, archived.BlockNum, archived.BlockPos, archived.LeafType,
381-
archived.OriginNetwork, archived.OriginAddress,
382-
archived.DestinationNetwork, archived.DestinationAddress,
383-
archived.Amount.String(), archived.Metadata, archived.DepositCount,
384-
archived.TxHash.Hex(), archived.FromAddress.Hex(), archived.TxnSender.Hex())
364+
err = meddler.Insert(tx, "bridge_archive", archived)
385365
require.NoError(t, err)
386366
}
387367

bridgesync/processor_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5424,6 +5424,8 @@ func TestProcessor_BackwardLET(t *testing.T) {
54245424
BlockPos: 0,
54255425
PreviousDepositCount: big.NewInt(3),
54265426
NewDepositCount: big.NewInt(2),
5427+
PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"),
5428+
NewRoot: common.HexToHash("0xa9d31ebbb97c7cd7c7103bee8af7d0b4c83771939baba0b415b0f94c4c39fd84"),
54275429
}},
54285430
},
54295431
})
@@ -5445,6 +5447,8 @@ func TestProcessor_BackwardLET(t *testing.T) {
54455447
BlockPos: 0,
54465448
PreviousDepositCount: big.NewInt(6),
54475449
NewDepositCount: big.NewInt(0),
5450+
PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"),
5451+
NewRoot: common.HexToHash("0x283c52c3d10a22d01f95f5bcab5e823675c9855bd40b1e82f32b0437b3b6a446"),
54485452
}},
54495453
},
54505454
})
@@ -5466,6 +5470,8 @@ func TestProcessor_BackwardLET(t *testing.T) {
54665470
BlockPos: 0,
54675471
PreviousDepositCount: big.NewInt(6),
54685472
NewDepositCount: big.NewInt(5),
5473+
PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"),
5474+
NewRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"),
54695475
}},
54705476
},
54715477
}
@@ -5488,6 +5494,8 @@ func TestProcessor_BackwardLET(t *testing.T) {
54885494
BlockPos: 0,
54895495
PreviousDepositCount: big.NewInt(5),
54905496
NewDepositCount: big.NewInt(2),
5497+
PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"),
5498+
NewRoot: common.HexToHash("0xa9d31ebbb97c7cd7c7103bee8af7d0b4c83771939baba0b415b0f94c4c39fd84"),
54915499
}},
54925500
},
54935501
}
@@ -5512,6 +5520,8 @@ func TestProcessor_BackwardLET(t *testing.T) {
55125520
BlockPos: 0,
55135521
PreviousDepositCount: big.NewInt(6),
55145522
NewDepositCount: big.NewInt(3),
5523+
PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"),
5524+
NewRoot: common.HexToHash("0x7533c9ef58edd0bea7959a20c33ed47e5548d35f4ff140c5c915740fe6800fb8"),
55155525
}},
55165526
},
55175527
})
@@ -5524,6 +5534,8 @@ func TestProcessor_BackwardLET(t *testing.T) {
55245534
BlockPos: 0,
55255535
PreviousDepositCount: big.NewInt(4),
55265536
NewDepositCount: big.NewInt(3),
5537+
PreviousRoot: common.HexToHash("0x7533c9ef58edd0bea7959a20c33ed47e5548d35f4ff140c5c915740fe6800fb8"),
5538+
NewRoot: common.HexToHash("0x7533c9ef58edd0bea7959a20c33ed47e5548d35f4ff140c5c915740fe6800fb8"),
55275539
}},
55285540
},
55295541
})
@@ -5602,6 +5614,8 @@ func TestProcessor_BackwardLET(t *testing.T) {
56025614
BlockPos: 0,
56035615
PreviousDepositCount: big.NewInt(5),
56045616
NewDepositCount: big.NewInt(2),
5617+
PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"),
5618+
NewRoot: common.HexToHash("0xa9d31ebbb97c7cd7c7103bee8af7d0b4c83771939baba0b415b0f94c4c39fd84"),
56055619
}},
56065620
},
56075621
}
@@ -5626,6 +5640,8 @@ func TestProcessor_BackwardLET(t *testing.T) {
56265640
BlockPos: 0,
56275641
PreviousDepositCount: big.NewInt(5),
56285642
NewDepositCount: big.NewInt(2),
5643+
PreviousRoot: common.HexToHash("0x9ba667158a062be548e5c1b2e8a9a2ad03b693e562535b0723880627c6664b02"),
5644+
NewRoot: common.HexToHash("0xa9d31ebbb97c7cd7c7103bee8af7d0b4c83771939baba0b415b0f94c4c39fd84"),
56295645
}},
56305646
},
56315647
}

0 commit comments

Comments
 (0)