From 3e993ff64a9c2e9651fae11aaee55032cd6b0c3e Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 8 Aug 2019 11:07:23 +0200 Subject: Eip 1884 v3 (#19743) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * core/vm, tests: implement EIP 1884, add support for feature-tests * core/vm: 1884-changes to extcodehash, move selfbalance opcode * tests: fix statetests * core/vm: move constants, address review concerns * core/vm: word formatting Co-Authored-By: Péter Szilágyi --- tests/state_test_util.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 0b78f26ed..c6341e524 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "math/big" + "strconv" "strings" "github.com/ethereum/go-ethereum/common" @@ -109,6 +110,29 @@ type stTransactionMarshaling struct { PrivateKey hexutil.Bytes } +// getVMConfig takes a fork definition and returns a chain config. +// The fork definition can be +// - a plain forkname, e.g. `Byzantium`, +// - a fork basename, and a list of EIPs to enable; e.g. `Byzantium+1884+1283`. +func getVMConfig(forkString string) (baseConfig *params.ChainConfig, eips []int, err error) { + var ( + splitForks = strings.Split(forkString, "+") + ok bool + baseName, eipsStrings = splitForks[0], splitForks[1:] + ) + if baseConfig, ok = Forks[baseName]; !ok { + return nil, nil, UnsupportedForkError{baseName} + } + for _, eip := range eipsStrings { + if eipNum, err := strconv.Atoi(eip); err != nil { + return nil, nil, fmt.Errorf("syntax error, invalid eip number %v", eipNum) + } else { + eips = append(eips, eipNum) + } + } + return baseConfig, eips, nil +} + // Subtests returns all valid subtests of the test. func (t *StateTest) Subtests() []StateSubtest { var sub []StateSubtest @@ -122,10 +146,11 @@ func (t *StateTest) Subtests() []StateSubtest { // Run executes a specific subtest. func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, error) { - config, ok := Forks[subtest.Fork] - if !ok { + config, eips, err := getVMConfig(subtest.Fork) + if err != nil { return nil, UnsupportedForkError{subtest.Fork} } + vmconfig.ExtraEips = eips block := t.genesis(config).ToBlock(nil) statedb := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre) -- cgit v1.2.3