@@ -33,14 +33,34 @@ func TestChainIterator(t *testing.T) {
3333
3434 var block * types.Block
3535 var txs []* types.Transaction
36- for i := uint64 (0 ); i <= 10 ; i ++ {
37- if i == 0 {
38- block = types .NewBlock (& types.Header {Number : big .NewInt (int64 (i ))}, nil , nil , nil , newHasher ()) // Empty genesis block
36+ to := common .BytesToAddress ([]byte {0x11 })
37+ block = types .NewBlock (& types.Header {Number : big .NewInt (int64 (0 ))}, nil , nil , nil , newHasher ()) // Empty genesis block
38+ WriteBlock (chainDb , block )
39+ WriteCanonicalHash (chainDb , block .Hash (), block .NumberU64 ())
40+ for i := uint64 (1 ); i <= 10 ; i ++ {
41+ var tx * types.Transaction
42+ if i % 2 == 0 {
43+ tx = types .NewTx (& types.LegacyTx {
44+ Nonce : i ,
45+ GasPrice : big .NewInt (11111 ),
46+ Gas : 1111 ,
47+ To : & to ,
48+ Value : big .NewInt (111 ),
49+ Data : []byte {0x11 , 0x11 , 0x11 },
50+ })
3951 } else {
40- tx := types .NewTransaction (i , common .BytesToAddress ([]byte {0x11 }), big .NewInt (111 ), 1111 , big .NewInt (11111 ), []byte {0x11 , 0x11 , 0x11 })
41- txs = append (txs , tx )
42- block = types .NewBlock (& types.Header {Number : big .NewInt (int64 (i ))}, []* types.Transaction {tx }, nil , nil , newHasher ())
52+ tx = types .NewTx (& types.AccessListTx {
53+ ChainID : big .NewInt (1337 ),
54+ Nonce : i ,
55+ GasPrice : big .NewInt (11111 ),
56+ Gas : 1111 ,
57+ To : & to ,
58+ Value : big .NewInt (111 ),
59+ Data : []byte {0x11 , 0x11 , 0x11 },
60+ })
4361 }
62+ txs = append (txs , tx )
63+ block = types .NewBlock (& types.Header {Number : big .NewInt (int64 (i ))}, []* types.Transaction {tx }, nil , nil , newHasher ())
4464 WriteBlock (chainDb , block )
4565 WriteCanonicalHash (chainDb , block .Hash (), block .NumberU64 ())
4666 }
@@ -66,7 +86,7 @@ func TestChainIterator(t *testing.T) {
6686 numbers = append (numbers , int (h .number ))
6787 if len (h .hashes ) > 0 {
6888 if got , exp := h .hashes [0 ], txs [h .number - 1 ].Hash (); got != exp {
69- t .Fatalf ("hash wrong, got %x exp %x" , got , exp )
89+ t .Fatalf ("block %d: hash wrong, got %x exp %x" , h . number , got , exp )
7090 }
7191 }
7292 }
@@ -88,14 +108,37 @@ func TestIndexTransactions(t *testing.T) {
88108
89109 var block * types.Block
90110 var txs []* types.Transaction
91- for i := uint64 (0 ); i <= 10 ; i ++ {
92- if i == 0 {
93- block = types .NewBlock (& types.Header {Number : big .NewInt (int64 (i ))}, nil , nil , nil , newHasher ()) // Empty genesis block
111+ to := common .BytesToAddress ([]byte {0x11 })
112+
113+ // Write empty genesis block
114+ block = types .NewBlock (& types.Header {Number : big .NewInt (int64 (0 ))}, nil , nil , nil , newHasher ())
115+ WriteBlock (chainDb , block )
116+ WriteCanonicalHash (chainDb , block .Hash (), block .NumberU64 ())
117+
118+ for i := uint64 (1 ); i <= 10 ; i ++ {
119+ var tx * types.Transaction
120+ if i % 2 == 0 {
121+ tx = types .NewTx (& types.LegacyTx {
122+ Nonce : i ,
123+ GasPrice : big .NewInt (11111 ),
124+ Gas : 1111 ,
125+ To : & to ,
126+ Value : big .NewInt (111 ),
127+ Data : []byte {0x11 , 0x11 , 0x11 },
128+ })
94129 } else {
95- tx := types .NewTransaction (i , common .BytesToAddress ([]byte {0x11 }), big .NewInt (111 ), 1111 , big .NewInt (11111 ), []byte {0x11 , 0x11 , 0x11 })
96- txs = append (txs , tx )
97- block = types .NewBlock (& types.Header {Number : big .NewInt (int64 (i ))}, []* types.Transaction {tx }, nil , nil , newHasher ())
130+ tx = types .NewTx (& types.AccessListTx {
131+ ChainID : big .NewInt (1337 ),
132+ Nonce : i ,
133+ GasPrice : big .NewInt (11111 ),
134+ Gas : 1111 ,
135+ To : & to ,
136+ Value : big .NewInt (111 ),
137+ Data : []byte {0x11 , 0x11 , 0x11 },
138+ })
98139 }
140+ txs = append (txs , tx )
141+ block = types .NewBlock (& types.Header {Number : big .NewInt (int64 (i ))}, []* types.Transaction {tx }, nil , nil , newHasher ())
99142 WriteBlock (chainDb , block )
100143 WriteCanonicalHash (chainDb , block .Hash (), block .NumberU64 ())
101144 }
@@ -108,10 +151,10 @@ func TestIndexTransactions(t *testing.T) {
108151 }
109152 number := ReadTxLookupEntry (chainDb , txs [i - 1 ].Hash ())
110153 if exist && number == nil {
111- t .Fatalf ("Transaction indice missing" )
154+ t .Fatalf ("Transaction index %d missing" , i )
112155 }
113156 if ! exist && number != nil {
114- t .Fatalf ("Transaction indice is not deleted" )
157+ t .Fatalf ("Transaction index %d is not deleted" , i )
115158 }
116159 }
117160 number := ReadTxIndexTail (chainDb )
0 commit comments