@@ -464,6 +464,48 @@ func TestAncientStorage(t *testing.T) {
464
464
}
465
465
}
466
466
467
+ func TestWriteAncientHeaderChain (t * testing.T ) {
468
+ db , err := NewDatabaseWithFreezer (NewMemoryDatabase (), t .TempDir (), "" , false )
469
+ if err != nil {
470
+ t .Fatalf ("failed to create database with ancient backend" )
471
+ }
472
+ defer db .Close ()
473
+
474
+ // Create a test block
475
+ var headers []* types.Header
476
+ headers = append (headers , & types.Header {
477
+ Number : big .NewInt (0 ),
478
+ Extra : []byte ("test block" ),
479
+ UncleHash : types .EmptyUncleHash ,
480
+ TxHash : types .EmptyTxsHash ,
481
+ ReceiptHash : types .EmptyReceiptsHash ,
482
+ })
483
+ headers = append (headers , & types.Header {
484
+ Number : big .NewInt (1 ),
485
+ Extra : []byte ("test block" ),
486
+ UncleHash : types .EmptyUncleHash ,
487
+ TxHash : types .EmptyTxsHash ,
488
+ ReceiptHash : types .EmptyReceiptsHash ,
489
+ })
490
+ // Write and verify the header in the database
491
+ WriteAncientHeaderChain (db , headers )
492
+
493
+ for _ , header := range headers {
494
+ if blob := ReadHeaderRLP (db , header .Hash (), header .Number .Uint64 ()); len (blob ) == 0 {
495
+ t .Fatalf ("no header returned" )
496
+ }
497
+ if h := ReadCanonicalHash (db , header .Number .Uint64 ()); h != header .Hash () {
498
+ t .Fatalf ("no canonical hash returned" )
499
+ }
500
+ if blob := ReadBodyRLP (db , header .Hash (), header .Number .Uint64 ()); len (blob ) != 0 {
501
+ t .Fatalf ("unexpected body returned" )
502
+ }
503
+ if blob := ReadReceiptsRLP (db , header .Hash (), header .Number .Uint64 ()); len (blob ) != 0 {
504
+ t .Fatalf ("unexpected body returned" )
505
+ }
506
+ }
507
+ }
508
+
467
509
func TestCanonicalHashIteration (t * testing.T ) {
468
510
var cases = []struct {
469
511
from , to uint64
0 commit comments