Skip to content

Commit

Permalink
core: uncomment TestCorruptedJournal test
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjunLi committed Apr 9, 2024
1 parent 9039fcb commit 6013cb3
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions triedb/pathdb/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"bytes"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/log"
"math/rand"
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -527,36 +529,36 @@ func TestJournal(t *testing.T) {
}
}

//func TestCorruptedJournal(t *testing.T) {
// tester := newTester(t, 0)
// defer tester.release()
// log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true)))
//
// if err := tester.db.Journal(tester.lastHash()); err != nil {
// t.Errorf("Failed to journal, err: %v", err)
// }
// tester.db.Close()
// _, root := rawdb.ReadAccountTrieNode(tester.db.diskdb, nil)
//
// // Mutate the journal in disk, it should be regarded as invalid
// blob := rawdb.ReadTrieJournal(tester.db.diskdb)
// blob[0] = 1
// rawdb.WriteTrieJournal(tester.db.diskdb, blob)
//
// // Verify states, all not-yet-written states should be discarded
// tester.db = New(tester.db.diskdb, nil)
// for i := 0; i < len(tester.roots); i++ {
// if tester.roots[i] == root {
// if err := tester.verifyState(root); err != nil {
// t.Fatalf("Disk state is corrupted, err: %v", err)
// }
// continue
// }
// if err := tester.verifyState(tester.roots[i]); err == nil {
// t.Fatal("Unexpected state")
// }
// }
//}
func TestCorruptedJournal(t *testing.T) {
tester := newTester(t, 0)
defer tester.release()
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true)))

if err := tester.db.Journal(tester.lastHash()); err != nil {
t.Errorf("Failed to journal, err: %v", err)
}
tester.db.Close()
_, root := rawdb.ReadAccountTrieNode(tester.db.diskdb, nil)

// Mutate the journal in disk, it should be regarded as invalid
blob := rawdb.ReadTrieJournal(tester.db.diskdb)
blob[0] = 1
rawdb.WriteTrieJournal(tester.db.diskdb, blob)

// Verify states, all not-yet-written states should be discarded
tester.db = New(tester.db.diskdb, nil)
for i := 0; i < len(tester.roots); i++ {
if tester.roots[i] == root {
if err := tester.verifyState(root); err != nil {
t.Fatalf("Disk state is corrupted, err: %v", err)
}
continue
}
if err := tester.verifyState(tester.roots[i]); err == nil {
t.Fatal("Unexpected state")
}
}
}

// TestTailTruncateHistory function is designed to test a specific edge case where,
// when history objects are removed from the end, it should trigger a state flush
Expand Down

0 comments on commit 6013cb3

Please sign in to comment.