mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
Create database_test.go
This commit is contained in:
parent
521b277b63
commit
6bba367f8b
1 changed files with 36 additions and 0 deletions
36
triedb/hashdb/database_test.go
Normal file
36
triedb/hashdb/database_test.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package hashdb
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/triedb/rawdb"
|
||||
)
|
||||
|
||||
func TestCleanerDelete(t *testing.T) {
|
||||
// Create a new database with clean cache enabled
|
||||
db := New(rawdb.NewMemoryDatabase(), &Config{CleanCacheSize: 256 * 1024})
|
||||
defer db.Close()
|
||||
|
||||
// Create a test node and add it to clean cache
|
||||
hash := common.HexToHash("0x1234")
|
||||
testData := []byte("test data")
|
||||
db.cleans.Set(hash[:], testData)
|
||||
|
||||
// Create cleaner and delete the node
|
||||
c := &cleaner{db: db}
|
||||
if err := c.Delete(hash[:]); err != nil {
|
||||
t.Fatalf("failed to delete node: %v", err)
|
||||
}
|
||||
|
||||
// Verify node was deleted from clean cache
|
||||
if data := db.cleans.Get(nil, hash[:]); data != nil {
|
||||
t.Error("node was not deleted from clean cache")
|
||||
}
|
||||
|
||||
// Test delete with nil clean cache
|
||||
db.cleans = nil
|
||||
if err := c.Delete(hash[:]); err != nil {
|
||||
t.Fatalf("failed to handle nil clean cache: %v", err)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue