@@ -43,11 +43,9 @@ func randomTrienodes(n int) (map[common.Hash]map[string][]byte, common.Hash) {
4343 nodes [owner ] = make (map [string ][]byte )
4444
4545 for j := 0 ; j < 10 ; j ++ {
46- pathLen := rand .Intn (10 )
47- path := testrand .Bytes (pathLen )
46+ path := testrand .Bytes (rand .Intn (10 ))
4847 for z := 0 ; z < len (path ); z ++ {
49- valLen := rand .Intn (128 )
50- nodes [owner ][string (path [:z ])] = testrand .Bytes (valLen )
48+ nodes [owner ][string (path [:z ])] = testrand .Bytes (rand .Intn (128 ))
5149 }
5250 }
5351 // zero-size trie node, representing it was non-existent before
@@ -65,7 +63,7 @@ func randomTrienodes(n int) (map[common.Hash]map[string][]byte, common.Hash) {
6563 return nodes , root
6664}
6765
68- func makeTrinodeHistory () * trienodeHistory {
66+ func makeTrienodeHistory () * trienodeHistory {
6967 nodes , root := randomTrienodes (10 )
7068 return newTrienodeHistory (root , common.Hash {}, 1 , nodes )
7169}
@@ -86,7 +84,7 @@ func makeTrienodeHistories(n int) []*trienodeHistory {
8684func TestEncodeDecodeTrienodeHistory (t * testing.T ) {
8785 var (
8886 dec trienodeHistory
89- obj = makeTrinodeHistory ()
87+ obj = makeTrienodeHistory ()
9088 )
9189 header , keySection , valueSection , err := obj .encode ()
9290 if err != nil {
@@ -108,6 +106,21 @@ func TestEncodeDecodeTrienodeHistory(t *testing.T) {
108106 if ! compareMapSet (dec .nodes , obj .nodes ) {
109107 t .Fatal ("trienode content is mismatched" )
110108 }
109+
110+ // Re-encode again, ensuring the encoded blob still match
111+ header2 , keySection2 , valueSection2 , err := dec .encode ()
112+ if err != nil {
113+ t .Fatalf ("Failed to encode trienode history: %v" , err )
114+ }
115+ if ! bytes .Equal (header , header2 ) {
116+ t .Fatal ("re-encoded header is mismatched" )
117+ }
118+ if ! bytes .Equal (keySection , keySection2 ) {
119+ t .Fatal ("re-encoded key section is mismatched" )
120+ }
121+ if ! bytes .Equal (valueSection , valueSection2 ) {
122+ t .Fatal ("re-encoded value section is mismatched" )
123+ }
111124}
112125
113126func TestTrienodeHistoryReader (t * testing.T ) {
@@ -280,7 +293,7 @@ func TestNilNodeValues(t *testing.T) {
280293
281294// TestCorruptedHeader tests error handling for corrupted header data
282295func TestCorruptedHeader (t * testing.T ) {
283- h := makeTrinodeHistory ()
296+ h := makeTrienodeHistory ()
284297 header , keySection , valueSection , _ := h .encode ()
285298
286299 // Test corrupted version
@@ -311,7 +324,7 @@ func TestCorruptedHeader(t *testing.T) {
311324
312325// TestCorruptedKeySection tests error handling for corrupted key section data
313326func TestCorruptedKeySection (t * testing.T ) {
314- h := makeTrinodeHistory ()
327+ h := makeTrienodeHistory ()
315328 header , keySection , valueSection , _ := h .encode ()
316329
317330 // Test empty key section when header indicates data
@@ -345,7 +358,7 @@ func TestCorruptedKeySection(t *testing.T) {
345358
346359// TestCorruptedValueSection tests error handling for corrupted value section data
347360func TestCorruptedValueSection (t * testing.T ) {
348- h := makeTrinodeHistory ()
361+ h := makeTrienodeHistory ()
349362 header , keySection , valueSection , _ := h .encode ()
350363
351364 // Test truncated value section
@@ -368,7 +381,7 @@ func TestCorruptedValueSection(t *testing.T) {
368381
369382// TestInvalidOffsets tests error handling for invalid offsets in encoded data
370383func TestInvalidOffsets (t * testing.T ) {
371- h := makeTrinodeHistory ()
384+ h := makeTrienodeHistory ()
372385 header , keySection , valueSection , _ := h .encode ()
373386
374387 // Corrupt key offset in header (make it larger than key section)
@@ -395,7 +408,7 @@ func TestInvalidOffsets(t *testing.T) {
395408// TestTrienodeHistoryReaderNonExistentPath tests reading non-existent paths
396409func TestTrienodeHistoryReaderNonExistentPath (t * testing.T ) {
397410 var (
398- h = makeTrinodeHistory ()
411+ h = makeTrienodeHistory ()
399412 freezer , _ = rawdb .NewTrienodeFreezer (t .TempDir (), false , false )
400413 )
401414 defer freezer .Close ()
@@ -523,7 +536,7 @@ func TestTrienodeHistoryReaderNilKey(t *testing.T) {
523536
524537// TestTrienodeHistoryReaderIterator tests the iterator functionality
525538func TestTrienodeHistoryReaderIterator (t * testing.T ) {
526- h := makeTrinodeHistory ()
539+ h := makeTrienodeHistory ()
527540
528541 // Count expected entries
529542 expectedCount := 0
@@ -614,7 +627,7 @@ func TestSharedLen(t *testing.T) {
614627// TestDecodeHeaderCorruptedData tests decodeHeader with corrupted data
615628func TestDecodeHeaderCorruptedData (t * testing.T ) {
616629 // Create valid header data first
617- h := makeTrinodeHistory ()
630+ h := makeTrienodeHistory ()
618631 header , _ , _ , _ := h .encode ()
619632
620633 // Test with empty header
@@ -661,7 +674,7 @@ func TestDecodeHeaderCorruptedData(t *testing.T) {
661674
662675// TestDecodeSingleCorruptedData tests decodeSingle with corrupted data
663676func TestDecodeSingleCorruptedData (t * testing.T ) {
664- h := makeTrinodeHistory ()
677+ h := makeTrienodeHistory ()
665678 _ , keySection , _ , _ := h .encode ()
666679
667680 // Test with empty key section
0 commit comments