diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-24 17:26:06 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-08-24 22:16:39 +0800 |
commit | b872961ec82ec88a7ac6ef331cfb3eb685ce2c00 (patch) | |
tree | 652d5bc27e4f95809637e6f76f6db3162b2e435e /tests | |
parent | 3c48a25762dfab9382791c33a2f5832466077ac3 (diff) | |
download | dexon-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.tar.gz dexon-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.tar.zst dexon-b872961ec82ec88a7ac6ef331cfb3eb685ce2c00.zip |
consensus, core, tests: implement Metropolis EIP 649
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gen_stlog.go | 61 | ||||
-rw-r--r-- | tests/state_test_util.go | 56 | ||||
m--------- | tests/testdata | 0 | ||||
-rw-r--r-- | tests/vm_test.go | 4 | ||||
-rw-r--r-- | tests/vm_test_util.go | 21 |
5 files changed, 26 insertions, 116 deletions
diff --git a/tests/gen_stlog.go b/tests/gen_stlog.go deleted file mode 100644 index 4f7ebc966..000000000 --- a/tests/gen_stlog.go +++ /dev/null @@ -1,61 +0,0 @@ -// Code generated by github.com/fjl/gencodec. DO NOT EDIT. - -package tests - -import ( - "encoding/json" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" -) - -var _ = (*stLogMarshaling)(nil) - -func (s stLog) MarshalJSON() ([]byte, error) { - type stLog struct { - Address common.UnprefixedAddress `json:"address"` - Data hexutil.Bytes `json:"data"` - Topics []common.UnprefixedHash `json:"topics"` - Bloom string `json:"bloom"` - } - var enc stLog - enc.Address = common.UnprefixedAddress(s.Address) - enc.Data = s.Data - if s.Topics != nil { - enc.Topics = make([]common.UnprefixedHash, len(s.Topics)) - for k, v := range s.Topics { - enc.Topics[k] = common.UnprefixedHash(v) - } - } - enc.Bloom = s.Bloom - return json.Marshal(&enc) -} - -func (s *stLog) UnmarshalJSON(input []byte) error { - type stLog struct { - Address *common.UnprefixedAddress `json:"address"` - Data hexutil.Bytes `json:"data"` - Topics []common.UnprefixedHash `json:"topics"` - Bloom *string `json:"bloom"` - } - var dec stLog - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.Address != nil { - s.Address = common.Address(*dec.Address) - } - if dec.Data != nil { - s.Data = dec.Data - } - if dec.Topics != nil { - s.Topics = make([]common.Hash, len(dec.Topics)) - for k, v := range dec.Topics { - s.Topics[k] = common.Hash(v) - } - } - if dec.Bloom != nil { - s.Bloom = *dec.Bloom - } - return nil -} diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 0eb85ab28..ecaa6c668 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -17,12 +17,10 @@ package tests import ( - "bytes" "encoding/hex" "encoding/json" "fmt" "math/big" - "reflect" "strings" "github.com/ethereum/go-ethereum/common" @@ -33,8 +31,10 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/rlp" ) // StateTest checks transaction processing without block context. @@ -63,7 +63,7 @@ type stJSON struct { type stPostState struct { Root common.UnprefixedHash `json:"hash"` - Logs *[]stLog `json:"logs"` + Logs common.UnprefixedHash `json:"logs"` Indexes struct { Data int `json:"data"` Gas int `json:"gas"` @@ -108,21 +108,6 @@ type stTransactionMarshaling struct { PrivateKey hexutil.Bytes } -//go:generate gencodec -type stLog -field-override stLogMarshaling -out gen_stlog.go - -type stLog struct { - Address common.Address `json:"address"` - Data []byte `json:"data"` - Topics []common.Hash `json:"topics"` - Bloom string `json:"bloom"` -} - -type stLogMarshaling struct { - Address common.UnprefixedAddress - Data hexutil.Bytes - Topics []common.UnprefixedHash -} - // Subtests returns all valid subtests of the test. func (t *StateTest) Subtests() []StateSubtest { var sub []StateSubtest @@ -159,10 +144,8 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) error { if _, _, _, err := core.ApplyMessage(evm, msg, gaspool); err != nil { statedb.RevertToSnapshot(snapshot) } - if post.Logs != nil { - if err := checkLogs(statedb.Logs(), *post.Logs); err != nil { - return err - } + if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) { + return fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs) } root, _ := statedb.CommitTo(db, config.IsEIP158(block.Number())) if root != common.Hash(post.Root) { @@ -254,28 +237,9 @@ func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) { return msg, nil } -func checkLogs(have []*types.Log, want []stLog) error { - if len(have) != len(want) { - return fmt.Errorf("logs length mismatch: got %d, want %d", len(have), len(want)) - } - for i := range have { - if have[i].Address != want[i].Address { - return fmt.Errorf("log address %d: got %x, want %x", i, have[i].Address, want[i].Address) - } - if !bytes.Equal(have[i].Data, want[i].Data) { - return fmt.Errorf("log data %d: got %x, want %x", i, have[i].Data, want[i].Data) - } - if !reflect.DeepEqual(have[i].Topics, want[i].Topics) { - return fmt.Errorf("log topics %d:\ngot %x\nwant %x", i, have[i].Topics, want[i].Topics) - } - genBloom := math.PaddedBigBytes(types.LogsBloom([]*types.Log{have[i]}), 256) - var wantBloom types.Bloom - if err := hexutil.UnmarshalFixedUnprefixedText("Bloom", []byte(want[i].Bloom), wantBloom[:]); err != nil { - return fmt.Errorf("test log %d has invalid bloom: %v", i, err) - } - if !bytes.Equal(genBloom, wantBloom[:]) { - return fmt.Errorf("bloom mismatch") - } - } - return nil +func rlpHash(x interface{}) (h common.Hash) { + hw := sha3.NewKeccak256() + rlp.Encode(hw, x) + hw.Sum(h[:0]) + return h } diff --git a/tests/testdata b/tests/testdata -Subproject 70e5862eb267226ca89fb9f395c97be1fdf6923 +Subproject cd2c3f1b3acb98c0d1501b06a4a54629d8794d7 diff --git a/tests/vm_test.go b/tests/vm_test.go index 5289ba355..f35abeb11 100644 --- a/tests/vm_test.go +++ b/tests/vm_test.go @@ -26,6 +26,10 @@ func TestVM(t *testing.T) { t.Parallel() vmt := new(testMatcher) vmt.fails("^vmSystemOperationsTest.json/createNameRegistrator$", "fails without parallel execution") + + vmt.skipLoad(`^vmPerformanceTest.json`) // log format broken + vmt.skipLoad(`^vmInputLimits(Light)?.json`) // log format broken + vmt.skipShortMode("^vmPerformanceTest.json") vmt.skipShortMode("^vmInputLimits(Light)?.json") diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index afdd896c3..0aa37955c 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -44,14 +44,14 @@ func (t *VMTest) UnmarshalJSON(data []byte) error { } type vmJSON struct { - Env stEnv `json:"env"` - Exec vmExec `json:"exec"` - Logs []stLog `json:"logs"` - GasRemaining *math.HexOrDecimal64 `json:"gas"` - Out hexutil.Bytes `json:"out"` - Pre core.GenesisAlloc `json:"pre"` - Post core.GenesisAlloc `json:"post"` - PostStateRoot common.Hash `json:"postStateRoot"` + Env stEnv `json:"env"` + Exec vmExec `json:"exec"` + Logs common.UnprefixedHash `json:"logs"` + GasRemaining *math.HexOrDecimal64 `json:"gas"` + Out hexutil.Bytes `json:"out"` + Pre core.GenesisAlloc `json:"pre"` + Post core.GenesisAlloc `json:"post"` + PostStateRoot common.Hash `json:"postStateRoot"` } //go:generate gencodec -type vmExec -field-override vmExecMarshaling -out gen_vmexec.go @@ -109,7 +109,10 @@ func (t *VMTest) Run(vmconfig vm.Config) error { // if root := statedb.IntermediateRoot(false); root != t.json.PostStateRoot { // return fmt.Errorf("post state root mismatch, got %x, want %x", root, t.json.PostStateRoot) // } - return checkLogs(statedb.Logs(), t.json.Logs) + if logs := rlpHash(statedb.Logs()); logs != common.Hash(t.json.Logs) { + return fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, t.json.Logs) + } + return nil } func (t *VMTest) exec(statedb *state.StateDB, vmconfig vm.Config) ([]byte, uint64, error) { |