1717package tests
1818
1919import (
20- "bytes"
2120 "encoding/hex"
2221 "encoding/json"
2322 "fmt"
2423 "math/big"
25- "reflect"
2624 "strings"
2725
2826 "github.com/ethereum/go-ethereum/common"
@@ -33,8 +31,10 @@ import (
3331 "github.com/ethereum/go-ethereum/core/types"
3432 "github.com/ethereum/go-ethereum/core/vm"
3533 "github.com/ethereum/go-ethereum/crypto"
34+ "github.com/ethereum/go-ethereum/crypto/sha3"
3635 "github.com/ethereum/go-ethereum/ethdb"
3736 "github.com/ethereum/go-ethereum/params"
37+ "github.com/ethereum/go-ethereum/rlp"
3838)
3939
4040// StateTest checks transaction processing without block context.
@@ -63,7 +63,7 @@ type stJSON struct {
6363
6464type stPostState struct {
6565 Root common.UnprefixedHash `json:"hash"`
66- Logs * [] stLog `json:"logs"`
66+ Logs common. UnprefixedHash `json:"logs"`
6767 Indexes struct {
6868 Data int `json:"data"`
6969 Gas int `json:"gas"`
@@ -108,21 +108,6 @@ type stTransactionMarshaling struct {
108108 PrivateKey hexutil.Bytes
109109}
110110
111- //go:generate gencodec -type stLog -field-override stLogMarshaling -out gen_stlog.go
112-
113- type stLog struct {
114- Address common.Address `json:"address"`
115- Data []byte `json:"data"`
116- Topics []common.Hash `json:"topics"`
117- Bloom string `json:"bloom"`
118- }
119-
120- type stLogMarshaling struct {
121- Address common.UnprefixedAddress
122- Data hexutil.Bytes
123- Topics []common.UnprefixedHash
124- }
125-
126111// Subtests returns all valid subtests of the test.
127112func (t * StateTest ) Subtests () []StateSubtest {
128113 var sub []StateSubtest
@@ -159,10 +144,8 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) error {
159144 if _ , _ , _ , err := core .ApplyMessage (evm , msg , gaspool ); err != nil {
160145 statedb .RevertToSnapshot (snapshot )
161146 }
162- if post .Logs != nil {
163- if err := checkLogs (statedb .Logs (), * post .Logs ); err != nil {
164- return err
165- }
147+ if logs := rlpHash (statedb .Logs ()); logs != common .Hash (post .Logs ) {
148+ return fmt .Errorf ("post state logs hash mismatch: got %x, want %x" , logs , post .Logs )
166149 }
167150 root , _ := statedb .CommitTo (db , config .IsEIP158 (block .Number ()))
168151 if root != common .Hash (post .Root ) {
@@ -254,28 +237,9 @@ func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) {
254237 return msg , nil
255238}
256239
257- func checkLogs (have []* types.Log , want []stLog ) error {
258- if len (have ) != len (want ) {
259- return fmt .Errorf ("logs length mismatch: got %d, want %d" , len (have ), len (want ))
260- }
261- for i := range have {
262- if have [i ].Address != want [i ].Address {
263- return fmt .Errorf ("log address %d: got %x, want %x" , i , have [i ].Address , want [i ].Address )
264- }
265- if ! bytes .Equal (have [i ].Data , want [i ].Data ) {
266- return fmt .Errorf ("log data %d: got %x, want %x" , i , have [i ].Data , want [i ].Data )
267- }
268- if ! reflect .DeepEqual (have [i ].Topics , want [i ].Topics ) {
269- return fmt .Errorf ("log topics %d:\n got %x\n want %x" , i , have [i ].Topics , want [i ].Topics )
270- }
271- genBloom := math .PaddedBigBytes (types .LogsBloom ([]* types.Log {have [i ]}), 256 )
272- var wantBloom types.Bloom
273- if err := hexutil .UnmarshalFixedUnprefixedText ("Bloom" , []byte (want [i ].Bloom ), wantBloom [:]); err != nil {
274- return fmt .Errorf ("test log %d has invalid bloom: %v" , i , err )
275- }
276- if ! bytes .Equal (genBloom , wantBloom [:]) {
277- return fmt .Errorf ("bloom mismatch" )
278- }
279- }
280- return nil
240+ func rlpHash (x interface {}) (h common.Hash ) {
241+ hw := sha3 .NewKeccak256 ()
242+ rlp .Encode (hw , x )
243+ hw .Sum (h [:0 ])
244+ return h
281245}
0 commit comments