core/rawdb: improve tests

This commit is contained in:
Gary Rong 2026-03-03 15:09:04 +08:00
parent 07511b5359
commit f7866a0118
2 changed files with 25 additions and 0 deletions

View file

@ -263,6 +263,17 @@ func basicWrite(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
// Write should work after truncating from tail but over the head
db.TruncateTail(200)
head, err := db.Ancients()
if err != nil {
t.Fatalf("Failed to retrieve head ancients %v", err)
}
tail, err := db.Tail()
if err != nil {
t.Fatalf("Failed to retrieve tail ancients %v", err)
}
if head != 200 || tail != 200 {
t.Fatalf("Ancient head and tail are not expected")
}
_, err = db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
offset := uint64(200)
for i := 0; i < 100; i++ {
@ -278,6 +289,17 @@ func basicWrite(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
if err != nil {
t.Fatalf("Failed to write ancient data %v", err)
}
head, err = db.Ancients()
if err != nil {
t.Fatalf("Failed to retrieve head ancients %v", err)
}
tail, err = db.Tail()
if err != nil {
t.Fatalf("Failed to retrieve tail ancients %v", err)
}
if head != 300 || tail != 200 {
t.Fatalf("Ancient head and tail are not expected")
}
}
func nonMutable(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {

View file

@ -397,6 +397,9 @@ func (f *MemoryFreezer) TruncateTail(tail uint64) (uint64, error) {
}
}
f.tail = tail
if f.items < tail {
f.items = tail
}
return old, nil
}