tests: update (#26548)

This updates the reference tests to the latest version.

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Martin Holst Swende 2023-02-06 14:52:51 -05:00 committed by GitHub
parent 37e3208e33
commit 91cb6f863a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 7 deletions

@ -50,11 +50,13 @@ func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engin
// header's transaction and uncle roots. The headers are assumed to be already
// validated at this point.
func (v *BlockValidator) ValidateBody(block *types.Block) error {
// Check whether the block's known, and if not, that it's linkable
// Check whether the block is already imported.
if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) {
return ErrKnownBlock
}
// Header validity is known at this point, check the uncles and transactions
// Header validity is known at this point. Here we verify that uncles, transactions
// and withdrawals given in the block body match the header.
header := block.Header()
if err := v.engine.VerifyUncles(v.bc, block); err != nil {
return err
@ -65,11 +67,17 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
if hash := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil)); hash != header.TxHash {
return fmt.Errorf("transaction root hash mismatch (header value %x, calculated %x)", header.TxHash, hash)
}
// Withdrawals are present after the Shanghai fork.
if header.WithdrawalsHash != nil {
// Withdrawals list must be present in body after Shanghai.
if block.Withdrawals() == nil {
return fmt.Errorf("missing withdrawals in block body")
}
if hash := types.DeriveSha(block.Withdrawals(), trie.NewStackTrie(nil)); hash != *header.WithdrawalsHash {
return fmt.Errorf("withdrawals root hash mismatch (header value %x, calculated %x)", *header.WithdrawalsHash, hash)
}
}
if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) {
return consensus.ErrUnknownAncestor

@ -423,5 +423,8 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
}
header.Root = common.BytesToHash(hasher.Sum(nil))
// Assemble and return the final block for sealing
if config.IsShanghai(header.Time) {
return types.NewBlockWithWithdrawals(header, txs, nil, receipts, []*types.Withdrawal{}, trie.NewStackTrie(nil))
}
return types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil))
}

@ -24,6 +24,7 @@ import (
"fmt"
"math/big"
"os"
"reflect"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
@ -87,6 +88,7 @@ type btHeader struct {
GasUsed uint64
Timestamp uint64
BaseFeePerGas *big.Int
WithdrawalsRoot *common.Hash
}
type btHeaderMarshaling struct {
@ -275,6 +277,12 @@ func validateHeader(h *btHeader, h2 *types.Header) error {
if h.Timestamp != h2.Time {
return fmt.Errorf("timestamp: want: %v have: %v", h.Timestamp, h2.Time)
}
if !reflect.DeepEqual(h.BaseFeePerGas, h2.BaseFee) {
return fmt.Errorf("baseFeePerGas: want: %v have: %v", h.BaseFeePerGas, h2.BaseFee)
}
if !reflect.DeepEqual(h.WithdrawalsRoot, h2.WithdrawalsHash) {
return fmt.Errorf("withdrawalsRoot: want: %v have: %v", h.WithdrawalsRoot, h2.WithdrawalsHash)
}
return nil
}

@ -34,6 +34,7 @@ func (b btHeader) MarshalJSON() ([]byte, error) {
GasUsed math.HexOrDecimal64
Timestamp math.HexOrDecimal64
BaseFeePerGas *math.HexOrDecimal256
WithdrawalsRoot *common.Hash
}
var enc btHeader
enc.Bloom = b.Bloom
@ -53,6 +54,7 @@ func (b btHeader) MarshalJSON() ([]byte, error) {
enc.GasUsed = math.HexOrDecimal64(b.GasUsed)
enc.Timestamp = math.HexOrDecimal64(b.Timestamp)
enc.BaseFeePerGas = (*math.HexOrDecimal256)(b.BaseFeePerGas)
enc.WithdrawalsRoot = b.WithdrawalsRoot
return json.Marshal(&enc)
}
@ -76,6 +78,7 @@ func (b *btHeader) UnmarshalJSON(input []byte) error {
GasUsed *math.HexOrDecimal64
Timestamp *math.HexOrDecimal64
BaseFeePerGas *math.HexOrDecimal256
WithdrawalsRoot *common.Hash
}
var dec btHeader
if err := json.Unmarshal(input, &dec); err != nil {
@ -132,5 +135,8 @@ func (b *btHeader) UnmarshalJSON(input []byte) error {
if dec.BaseFeePerGas != nil {
b.BaseFeePerGas = (*big.Int)(dec.BaseFeePerGas)
}
if dec.WithdrawalsRoot != nil {
b.WithdrawalsRoot = dec.WithdrawalsRoot
}
return nil
}

@ -268,6 +268,24 @@ var Forks = map[string]*params.ChainConfig{
TerminalTotalDifficulty: big.NewInt(0),
ShanghaiTime: u64(0),
},
"MergeToShanghaiAtTime15k": {
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
ShanghaiTime: u64(15_000),
},
}
// AvailableForks returns the set of defined fork names

@ -56,11 +56,11 @@ func TestState(t *testing.T) {
// Uses 1GB RAM per tested fork
st.skipLoad(`^stStaticCall/static_Call1MB`)
// Not yet supported TODO
st.skipLoad(`^stEIP3540/`)
st.skipLoad(`^stEIP3860/`)
// Broken tests:
//
// The stEOF tests are generated with EOF as part of Shanghai, which
// is erroneous. Therefore, these tests are skipped.
st.skipLoad(`^EIPTests/stEOF/`)
// Expected failures:
// For Istanbul, older tests were moved into LegacyTests

@ -1 +1 @@
Subproject commit 24fa31adb30f71ee700b27decb5204e53a11d9f3
Subproject commit bac70c50a579197af68af5fc6d8c7b6163b92c52