tests: update tests and implement general state tests (#14734)

Tests are now included as a submodule. This should make updating easier
and removes ~60MB of JSON data from the working copy.

State tests are replaced by General State Tests, which run the same test
with multiple fork configurations.

With the new test runner, consensus tests are run as subtests by walking
json files. Many hex issues have been fixed upstream since the last
update and most custom parsing code is replaced by existing JSON hex
types. Tests can now be marked as 'expected failures', ensuring that
fixes for those tests will trigger an update to test configuration. The
new test runner also supports parallel execution and the -short flag.
This commit is contained in:
Felix Lange
2017-07-11 13:49:14 +02:00
committed by GitHub
parent bd01cd7183
commit 225de7ca0a
903 changed files with 1630 additions and 2505463 deletions

View File

@ -13,24 +13,27 @@ import (
"github.com/ethereum/go-ethereum/params"
)
var _ = (*genesisSpecMarshaling)(nil)
func (g Genesis) MarshalJSON() ([]byte, error) {
type Genesis struct {
Config *params.ChainConfig `json:"config"`
Nonce math.HexOrDecimal64 `json:"nonce"`
Timestamp math.HexOrDecimal64 `json:"timestamp"`
ParentHash common.Hash `json:"parentHash"`
ExtraData hexutil.Bytes `json:"extraData"`
GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash common.Hash `json:"mixHash"`
Coinbase common.Address `json:"coinbase"`
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"`
Number uint64 `json:"number"`
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
ParentHash common.Hash `json:"parentHash"`
}
var enc Genesis
enc.Config = g.Config
enc.Nonce = math.HexOrDecimal64(g.Nonce)
enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
enc.ParentHash = g.ParentHash
enc.ExtraData = g.ExtraData
enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
@ -42,6 +45,9 @@ func (g Genesis) MarshalJSON() ([]byte, error) {
enc.Alloc[common.UnprefixedAddress(k)] = v
}
}
enc.Number = g.Number
enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
enc.ParentHash = g.ParentHash
return json.Marshal(&enc)
}
@ -50,13 +56,15 @@ func (g *Genesis) UnmarshalJSON(input []byte) error {
Config *params.ChainConfig `json:"config"`
Nonce *math.HexOrDecimal64 `json:"nonce"`
Timestamp *math.HexOrDecimal64 `json:"timestamp"`
ParentHash *common.Hash `json:"parentHash"`
ExtraData hexutil.Bytes `json:"extraData"`
GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash *common.Hash `json:"mixHash"`
Coinbase *common.Address `json:"coinbase"`
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"`
Number *uint64 `json:"number"`
GasUsed *math.HexOrDecimal64 `json:"gasUsed"`
ParentHash *common.Hash `json:"parentHash"`
}
var dec Genesis
if err := json.Unmarshal(input, &dec); err != nil {
@ -71,9 +79,6 @@ func (g *Genesis) UnmarshalJSON(input []byte) error {
if dec.Timestamp != nil {
g.Timestamp = uint64(*dec.Timestamp)
}
if dec.ParentHash != nil {
g.ParentHash = *dec.ParentHash
}
if dec.ExtraData != nil {
g.ExtraData = dec.ExtraData
}
@ -98,5 +103,14 @@ func (g *Genesis) UnmarshalJSON(input []byte) error {
for k, v := range dec.Alloc {
g.Alloc[common.Address(k)] = v
}
if dec.Number != nil {
g.Number = *dec.Number
}
if dec.GasUsed != nil {
g.GasUsed = uint64(*dec.GasUsed)
}
if dec.ParentHash != nil {
g.ParentHash = *dec.ParentHash
}
return nil
}