Skip to content

Commit 6a56b15

Browse files
committed
tests: update tests, use blockchain test "network" field
Blockchain tests now include the "network" which determines the chain config to use. Remove config matching based on test name and share the name-to-config index with state tests. Byzantium/Constantinople tests are still skipped because most of them fail anyway.
1 parent 17ce0a3 commit 6a56b15

6 files changed

Lines changed: 111 additions & 85 deletions

File tree

‎tests/block_test.go‎

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
package tests
1818

1919
import (
20-
"math/big"
2120
"testing"
22-
23-
"github.com/ethereum/go-ethereum/params"
2421
)
2522

2623
func TestBlockchain(t *testing.T) {
@@ -30,51 +27,19 @@ func TestBlockchain(t *testing.T) {
3027
// General state tests are 'exported' as blockchain tests, but we can run them natively.
3128
bt.skipLoad(`^GeneralStateTests/`)
3229
// Skip random failures due to selfish mining test.
33-
bt.skipLoad(`bcForkUncle\.json/ForkUncle`)
34-
bt.skipLoad(`^bcMultiChainTest\.json/ChainAtoChainB_blockorder`)
35-
bt.skipLoad(`^bcTotalDifficultyTest\.json/(lotsOfLeafs|lotsOfBranches|sideChainWithMoreTransactions)$`)
36-
bt.skipLoad(`^bcMultiChainTest\.json/CallContractFromNotBestBlock`)
30+
bt.skipLoad(`^bcForgedTest/bcForkUncle\.json`)
31+
bt.skipLoad(`^bcMultiChainTest/(ChainAtoChainB_blockorder|CallContractFromNotBestBlock)`)
32+
bt.skipLoad(`^bcTotalDifficultyTest/(lotsOfLeafs|lotsOfBranches|sideChainWithMoreTransactions)`)
33+
// Constantinople is not implemented yet.
34+
bt.skipLoad(`(?i)(constantinople)`)
3735
// Expected failures:
38-
bt.fails(`(?i)metropolis`, "metropolis is not supported yet")
39-
bt.fails(`^TestNetwork/bcTheDaoTest\.json/(DaoTransactions$|DaoTransactions_UncleExtradata$)`, "issue in test")
40-
41-
bt.config(`^TestNetwork/`, params.ChainConfig{
42-
HomesteadBlock: big.NewInt(5),
43-
DAOForkBlock: big.NewInt(8),
44-
DAOForkSupport: true,
45-
EIP150Block: big.NewInt(10),
46-
EIP155Block: big.NewInt(10),
47-
EIP158Block: big.NewInt(14),
48-
// MetropolisBlock: big.NewInt(16),
49-
})
50-
bt.config(`^RandomTests/.*EIP150`, params.ChainConfig{
51-
HomesteadBlock: big.NewInt(0),
52-
EIP150Block: big.NewInt(0),
53-
})
54-
bt.config(`^RandomTests/.*EIP158`, params.ChainConfig{
55-
HomesteadBlock: big.NewInt(0),
56-
EIP150Block: big.NewInt(0),
57-
EIP155Block: big.NewInt(0),
58-
EIP158Block: big.NewInt(0),
59-
})
60-
bt.config(`^RandomTests/`, params.ChainConfig{
61-
HomesteadBlock: big.NewInt(0),
62-
EIP150Block: big.NewInt(10),
63-
})
64-
bt.config(`^Homestead/`, params.ChainConfig{
65-
HomesteadBlock: big.NewInt(0),
66-
})
67-
bt.config(`^EIP150/`, params.ChainConfig{
68-
HomesteadBlock: big.NewInt(0),
69-
EIP150Block: big.NewInt(0),
70-
})
71-
bt.config(`^[^/]+\.json`, params.ChainConfig{
72-
HomesteadBlock: big.NewInt(1000000),
73-
})
36+
bt.fails("^TransitionTests/bcEIP158ToByzantium", "byzantium not supported")
37+
bt.fails(`^TransitionTests/bcHomesteadToDao/DaoTransactions(|_UncleExtradata|_EmptyTransactionAndForkBlocksAhead)\.json`, "issue in test")
38+
bt.fails(`^bc(Exploit|Fork|Gas|Multi|Total|State|Random|Uncle|Valid|Wallet).*_Byzantium$`, "byzantium not supported")
39+
bt.fails(`^bcBlockGasLimitTest/(BlockGasLimit2p63m1|TransactionGasHigherThanLimit2p63m1|SuicideTransaction|GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideFirst|TransactionGasHigherThanLimit2p63m1_2).*_Byzantium$`, "byzantium not supported")
7440

7541
bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
76-
cfg := bt.findConfig(name)
77-
if err := bt.checkFailure(t, name, test.Run(cfg)); err != nil {
42+
if err := bt.checkFailure(t, name, test.Run()); err != nil {
7843
t.Error(err)
7944
}
8045
})

‎tests/block_test_util.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type btJSON struct {
5353
Pre core.GenesisAlloc `json:"pre"`
5454
Post core.GenesisAlloc `json:"postState"`
5555
BestBlock common.UnprefixedHash `json:"lastblockhash"`
56+
Network string `json:"network"`
5657
}
5758

5859
type btBlock struct {
@@ -91,7 +92,12 @@ type btHeaderMarshaling struct {
9192
Timestamp *math.HexOrDecimal256
9293
}
9394

94-
func (t *BlockTest) Run(config *params.ChainConfig) error {
95+
func (t *BlockTest) Run() error {
96+
config, ok := Forks[t.json.Network]
97+
if !ok {
98+
return UnsupportedForkError{t.json.Network}
99+
}
100+
95101
// import pre accounts & construct test genesis block & state root
96102
db, _ := ethdb.NewMemDatabase()
97103
gblock, err := t.genesis(config).Commit(db)

‎tests/init.go‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2017 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package tests
18+
19+
import (
20+
"fmt"
21+
"math/big"
22+
23+
"github.com/ethereum/go-ethereum/params"
24+
)
25+
26+
// This table defines supported forks and their chain config.
27+
var Forks = map[string]*params.ChainConfig{
28+
"Frontier": &params.ChainConfig{
29+
ChainId: big.NewInt(1),
30+
},
31+
"Homestead": &params.ChainConfig{
32+
ChainId: big.NewInt(1),
33+
HomesteadBlock: big.NewInt(0),
34+
},
35+
"EIP150": &params.ChainConfig{
36+
ChainId: big.NewInt(1),
37+
HomesteadBlock: big.NewInt(0),
38+
EIP150Block: big.NewInt(0),
39+
},
40+
"EIP158": &params.ChainConfig{
41+
ChainId: big.NewInt(1),
42+
HomesteadBlock: big.NewInt(0),
43+
EIP150Block: big.NewInt(0),
44+
EIP155Block: big.NewInt(0),
45+
EIP158Block: big.NewInt(0),
46+
},
47+
"Byzantium": &params.ChainConfig{
48+
ChainId: big.NewInt(1),
49+
HomesteadBlock: big.NewInt(0),
50+
EIP150Block: big.NewInt(0),
51+
EIP155Block: big.NewInt(0),
52+
EIP158Block: big.NewInt(0),
53+
DAOForkBlock: big.NewInt(0),
54+
MetropolisBlock: big.NewInt(0),
55+
},
56+
"FrontierToHomesteadAt5": &params.ChainConfig{
57+
ChainId: big.NewInt(1),
58+
HomesteadBlock: big.NewInt(5),
59+
},
60+
"HomesteadToEIP150At5": &params.ChainConfig{
61+
ChainId: big.NewInt(1),
62+
HomesteadBlock: big.NewInt(0),
63+
EIP150Block: big.NewInt(5),
64+
},
65+
"HomesteadToDaoAt5": &params.ChainConfig{
66+
ChainId: big.NewInt(1),
67+
HomesteadBlock: big.NewInt(0),
68+
DAOForkBlock: big.NewInt(5),
69+
DAOForkSupport: true,
70+
},
71+
"EIP158ToByzantiumAt5": &params.ChainConfig{
72+
ChainId: big.NewInt(1),
73+
HomesteadBlock: big.NewInt(0),
74+
EIP150Block: big.NewInt(0),
75+
EIP155Block: big.NewInt(0),
76+
EIP158Block: big.NewInt(0),
77+
MetropolisBlock: big.NewInt(5),
78+
},
79+
}
80+
81+
// UnsupportedForkError is returned when a test requests a fork that isn't implemented.
82+
type UnsupportedForkError struct {
83+
Name string
84+
}
85+
86+
func (e UnsupportedForkError) Error() string {
87+
return fmt.Sprintf("unsupported fork %q", e.Name)
88+
}

‎tests/state_test.go‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ func TestState(t *testing.T) {
3333
st.skipShortMode(`^stQuadraticComplexityTest/`)
3434
// Broken tests:
3535
st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) // gasLimit > 256 bits
36-
st.skipLoad(`^stStackTests/shallowStackOK\.json`) // bad hex encoding
3736
st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) // EIP-86 is not supported yet
3837
// Expected failures:
39-
st.fails(`^stCallCreateCallCodeTest/createJS_ExampleContract\.json`, "bug in test")
40-
st.fails(`^stCodeSizeLimit/codesizeOOGInvalidSize\.json/(Frontier|Homestead)`,
38+
st.fails(`^stCodeSizeLimit/codesizeOOGInvalidSize\.json/(Frontier|Homestead|EIP150)`,
4139
"code size limit implementation is not conditional on fork")
4240
st.fails(`^stRevertTest/RevertDepthCreateAddressCollision\.json/EIP15[08]/[67]`, "bug in test")
4341
st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test")
@@ -49,8 +47,8 @@ func TestState(t *testing.T) {
4947
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
5048
name := name + "/" + key
5149
t.Run(key, func(t *testing.T) {
52-
if subtest.Fork == "Metropolis" {
53-
t.Skip("metropolis not supported yet")
50+
if subtest.Fork == "Constantinople" || subtest.Fork == "Byzantium" {
51+
t.Skip("constantinople, byzantium not supported yet")
5452
}
5553
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
5654
return st.checkFailure(t, name, test.Run(subtest, vmconfig))

‎tests/state_test_util.go‎

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,6 @@ import (
3737
"github.com/ethereum/go-ethereum/params"
3838
)
3939

40-
// This table defines supported forks and their chain config.
41-
var stateTestForks = map[string]*params.ChainConfig{
42-
"Frontier": &params.ChainConfig{
43-
ChainId: big.NewInt(1),
44-
},
45-
"Homestead": &params.ChainConfig{
46-
HomesteadBlock: big.NewInt(0),
47-
ChainId: big.NewInt(1),
48-
},
49-
"EIP150": &params.ChainConfig{
50-
HomesteadBlock: big.NewInt(0),
51-
EIP150Block: big.NewInt(0),
52-
ChainId: big.NewInt(1),
53-
},
54-
"EIP158": &params.ChainConfig{
55-
HomesteadBlock: big.NewInt(0),
56-
EIP150Block: big.NewInt(0),
57-
EIP155Block: big.NewInt(0),
58-
EIP158Block: big.NewInt(0),
59-
ChainId: big.NewInt(1),
60-
},
61-
"Metropolis": &params.ChainConfig{
62-
HomesteadBlock: big.NewInt(0),
63-
EIP150Block: big.NewInt(0),
64-
EIP155Block: big.NewInt(0),
65-
EIP158Block: big.NewInt(0),
66-
MetropolisBlock: big.NewInt(0),
67-
ChainId: big.NewInt(1),
68-
},
69-
}
70-
7140
// StateTest checks transaction processing without block context.
7241
// See https://github.com/ethereum/EIPs/issues/176 for the test format specification.
7342
type StateTest struct {
@@ -167,9 +136,9 @@ func (t *StateTest) Subtests() []StateSubtest {
167136

168137
// Run executes a specific subtest.
169138
func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) error {
170-
config, ok := stateTestForks[subtest.Fork]
139+
config, ok := Forks[subtest.Fork]
171140
if !ok {
172-
return fmt.Errorf("no config for fork %q", subtest.Fork)
141+
return UnsupportedForkError{subtest.Fork}
173142
}
174143
block, _ := t.genesis(config).ToBlock()
175144
db, _ := ethdb.NewMemDatabase()

‎tests/testdata‎

Submodule testdata updated 8311 files

0 commit comments

Comments
 (0)