@@ -160,7 +160,89 @@ func (t *BlockTest) TryBlocksInsert(chainManager *core.ChainManager) error {
160160 if b .BlockHeader == nil {
161161 return fmt .Errorf ("Block insertion should have failed" )
162162 }
163+ err = validateBlockHeader (b .BlockHeader , cb .Header ())
164+ if err != nil {
165+ return fmt .Errorf ("Block header validation failed: " , err )
166+ }
167+ }
168+ return nil
169+ }
170+
171+ func validateBlockHeader (h * btHeader , h2 * types.Header ) error {
172+ expectedBloom := mustConvertBytes (h .Bloom )
173+ if ! bytes .Equal (expectedBloom , h2 .Bloom .Bytes ()) {
174+ return fmt .Errorf ("Bloom: expected: %v, decoded: %v" , expectedBloom , h2 .Bloom .Bytes ())
175+ }
176+
177+ expectedCoinbase := mustConvertBytes (h .Coinbase )
178+ if ! bytes .Equal (expectedCoinbase , h2 .Coinbase .Bytes ()) {
179+ return fmt .Errorf ("Coinbase: expected: %v, decoded: %v" , expectedCoinbase , h2 .Coinbase .Bytes ())
180+ }
181+
182+ expectedMixHashBytes := mustConvertBytes (h .MixHash )
183+ if ! bytes .Equal (expectedMixHashBytes , h2 .MixDigest .Bytes ()) {
184+ return fmt .Errorf ("MixHash: expected: %v, decoded: %v" , expectedMixHashBytes , h2 .MixDigest .Bytes ())
185+ }
186+
187+ expectedNonce := mustConvertBytes (h .Nonce )
188+ if ! bytes .Equal (expectedNonce , h2 .Nonce [:]) {
189+ return fmt .Errorf ("Nonce: expected: %v, decoded: %v" , expectedNonce , h2 .Nonce [:])
190+ }
191+
192+ expectedNumber := mustConvertBigInt (h .Number , 16 )
193+ if expectedNumber .Cmp (h2 .Number ) != 0 {
194+ return fmt .Errorf ("Number: expected: %v, decoded: %v" , expectedNumber , h2 .Number )
195+ }
196+
197+ expectedParentHash := mustConvertBytes (h .ParentHash )
198+ if ! bytes .Equal (expectedParentHash , h2 .ParentHash .Bytes ()) {
199+ return fmt .Errorf ("Parent hash: expected: %v, decoded: %v" , expectedParentHash , h2 .ParentHash .Bytes ())
200+ }
201+
202+ expectedReceiptHash := mustConvertBytes (h .ReceiptTrie )
203+ if ! bytes .Equal (expectedReceiptHash , h2 .ReceiptHash .Bytes ()) {
204+ return fmt .Errorf ("Receipt hash: expected: %v, decoded: %v" , expectedReceiptHash , h2 .ReceiptHash .Bytes ())
205+ }
206+
207+ expectedTxHash := mustConvertBytes (h .TransactionsTrie )
208+ if ! bytes .Equal (expectedTxHash , h2 .TxHash .Bytes ()) {
209+ return fmt .Errorf ("Tx hash: expected: %v, decoded: %v" , expectedTxHash , h2 .TxHash .Bytes ())
210+ }
211+
212+ expectedStateHash := mustConvertBytes (h .StateRoot )
213+ if ! bytes .Equal (expectedStateHash , h2 .Root .Bytes ()) {
214+ return fmt .Errorf ("State hash: expected: %v, decoded: %v" , expectedStateHash , h2 .Root .Bytes ())
215+ }
216+
217+ expectedUncleHash := mustConvertBytes (h .UncleHash )
218+ if ! bytes .Equal (expectedUncleHash , h2 .UncleHash .Bytes ()) {
219+ return fmt .Errorf ("Uncle hash: expected: %v, decoded: %v" , expectedUncleHash , h2 .UncleHash .Bytes ())
220+ }
221+
222+ expectedExtraData := mustConvertBytes (h .ExtraData )
223+ if ! bytes .Equal (expectedExtraData , h2 .Extra ) {
224+ return fmt .Errorf ("Extra data: expected: %v, decoded: %v" , expectedExtraData , h2 .Extra )
163225 }
226+
227+ expectedDifficulty := mustConvertBigInt (h .Difficulty , 16 )
228+ if expectedDifficulty .Cmp (h2 .Difficulty ) != 0 {
229+ return fmt .Errorf ("Difficulty: expected: %v, decoded: %v" , expectedDifficulty , h2 .Difficulty )
230+ }
231+
232+ expectedGasLimit := mustConvertBigInt (h .GasLimit , 16 )
233+ if expectedGasLimit .Cmp (h2 .GasLimit ) != 0 {
234+ return fmt .Errorf ("GasLimit: expected: %v, decoded: %v" , expectedGasLimit , h2 .GasLimit )
235+ }
236+ expectedGasUsed := mustConvertBigInt (h .GasUsed , 16 )
237+ if expectedGasUsed .Cmp (h2 .GasUsed ) != 0 {
238+ return fmt .Errorf ("GasUsed: expected: %v, decoded: %v" , expectedGasUsed , h2 .GasUsed )
239+ }
240+
241+ expectedTimestamp := mustConvertUint (h .Timestamp , 16 )
242+ if expectedTimestamp != h2 .Time {
243+ return fmt .Errorf ("Timestamp: expected: %v, decoded: %v" , expectedTimestamp , h2 .Time )
244+ }
245+
164246 return nil
165247}
166248
0 commit comments