mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
test for eas going backward
This commit is contained in:
@@ -49,7 +49,7 @@ func (s *Store) UpdateCustodyInfo(ctx context.Context, earliestAvailableSlot pri
|
||||
// When increasing custody group count, prevent earliestAvailableSlot from going backward.
|
||||
if storedEarliestAvailableSlot != 0 && earliestAvailableSlot < storedEarliestAvailableSlot {
|
||||
return errors.Errorf(
|
||||
"cannot decrease earliest available slot from %d to %d when increasing custody group count from %d to %d. ",
|
||||
"cannot decrease earliest available slot from %d to %d when increasing custody group count from %d to %d",
|
||||
storedEarliestAvailableSlot, earliestAvailableSlot, storedGroupCount, custodyGroupCount,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -134,6 +134,31 @@ func TestUpdateCustodyInfo(t *testing.T) {
|
||||
require.Equal(t, initialSlot, storedSlot)
|
||||
require.Equal(t, initialCount, storedCount)
|
||||
})
|
||||
|
||||
t.Run("prevent earliest available slot from going backward when increasing group count", func(t *testing.T) {
|
||||
const (
|
||||
initialSlot = primitives.Slot(200)
|
||||
initialCount = uint64(5)
|
||||
newSlot = primitives.Slot(100) // Lower than initial - should be rejected
|
||||
newCount = uint64(10) // Higher than initial - would trigger update
|
||||
)
|
||||
|
||||
db := setupDB(t)
|
||||
|
||||
// Initialize custody info with slot 200 and group count 5
|
||||
_, _, err := db.UpdateCustodyInfo(ctx, initialSlot, initialCount)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Try to increase group count (5 -> 10) but with a lower earliest slot (200 -> 100)
|
||||
// This should fail because we can't move earliest available slot backward when increasing custody
|
||||
_, _, err = db.UpdateCustodyInfo(ctx, newSlot, newCount)
|
||||
require.ErrorContains(t, "cannot decrease earliest available slot", err)
|
||||
|
||||
// Verify the database wasn't updated
|
||||
storedSlot, storedCount := getCustodyInfoFromDB(t, db)
|
||||
require.Equal(t, initialSlot, storedSlot)
|
||||
require.Equal(t, initialCount, storedCount)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdateEarliestAvailableSlot(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user