Skip to content

Commit

Permalink
tests: update for London (ethereum#22976)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Sep 6, 2024
1 parent c97ea29 commit ed91fbf
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 57 deletions.
8 changes: 8 additions & 0 deletions core/gen_genesis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/gen_genesis_account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Genesis struct {
Number uint64 `json:"number"`
GasUsed uint64 `json:"gasUsed"`
ParentHash common.Hash `json:"parentHash"`
BaseFee *big.Int `json:"baseFee"`
}

// GenesisAlloc specifies the initial state that is part of the genesis block.
Expand Down Expand Up @@ -265,7 +266,11 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
head.Difficulty = params.GenesisDifficulty
}
if g.Config != nil && g.Config.IsEIP1559(common.Big0) {
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
if g.BaseFee != nil {
head.BaseFee = g.BaseFee
} else {
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
}
}
statedb.Commit(false)
statedb.Database().TrieDB().Commit(root, true)
Expand Down
58 changes: 33 additions & 25 deletions tests/block_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"

"github.com/XinFinOrg/XDPoSChain/core/rawdb"
"os"

"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
"github.com/XinFinOrg/XDPoSChain/common/math"
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
"github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/state"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/core/vm"
Expand All @@ -58,9 +57,10 @@ type btJSON struct {
}

type btBlock struct {
BlockHeader *btHeader
Rlp string
UncleHeaders []*btHeader
BlockHeader *btHeader
ExpectException string
Rlp string
UncleHeaders []*btHeader
}

//go:generate gencodec -type btHeader -field-override btHeaderMarshaling -out gen_btheader.go
Expand All @@ -82,6 +82,7 @@ type btHeader struct {
GasLimit uint64
GasUsed uint64
Timestamp *big.Int
BaseFee *big.Int
}

type btHeaderMarshaling struct {
Expand All @@ -91,6 +92,7 @@ type btHeaderMarshaling struct {
GasLimit math.HexOrDecimal64
GasUsed math.HexOrDecimal64
Timestamp *math.HexOrDecimal256
BaseFee *math.HexOrDecimal256
}

func (t *BlockTest) Run() error {
Expand Down Expand Up @@ -149,6 +151,7 @@ func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis {
Mixhash: t.json.Genesis.MixHash,
Coinbase: t.json.Genesis.Coinbase,
Alloc: t.json.Pre,
BaseFee: t.json.Genesis.BaseFee,
}
}

Expand All @@ -168,13 +171,13 @@ See https://github.com/ethereum/tests/wiki/Blockchain-Tests-II
func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error) {
validBlocks := make([]btBlock, 0)
// insert the test blocks, which will execute all transactions
for _, b := range t.json.Blocks {
for bi, b := range t.json.Blocks {
cb, err := b.decode()
if err != nil {
if b.BlockHeader == nil {
continue // OK - block is supposed to be invalid, continue with next block
} else {
return nil, fmt.Errorf("Block RLP decoding failed when expected to succeed: %v", err)
return nil, fmt.Errorf("block RLP decoding failed when expected to succeed: %v", err)
}
}
// RLP decoding worked, try to insert into chain:
Expand All @@ -184,16 +187,21 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
if b.BlockHeader == nil {
continue // OK - block is supposed to be invalid, continue with next block
} else {
return nil, fmt.Errorf("Block #%v insertion into chain failed: %v", blocks[i].Number(), err)
return nil, fmt.Errorf("block #%v insertion into chain failed: %v", blocks[i].Number(), err)
}
}
if b.BlockHeader == nil {
return nil, errors.New("Block insertion should have failed")
if data, err := json.MarshalIndent(cb.Header(), "", " "); err == nil {
fmt.Fprintf(os.Stderr, "block (index %d) insertion should have failed due to: %v:\n%v\n",
bi, b.ExpectException, string(data))
}
return nil, fmt.Errorf("block (index %d) insertion should have failed due to: %v",
bi, b.ExpectException)
}

// validate RLP decoding by checking all values against test file JSON
if err = validateHeader(b.BlockHeader, cb.Header()); err != nil {
return nil, fmt.Errorf("Deserialised block header validation failed: %v", err)
return nil, fmt.Errorf("deserialised block header validation failed: %v", err)
}
validBlocks = append(validBlocks, b)
}
Expand All @@ -202,49 +210,49 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)

func validateHeader(h *btHeader, h2 *types.Header) error {
if h.Bloom != h2.Bloom {
return fmt.Errorf("Bloom: want: %x have: %x", h.Bloom, h2.Bloom)
return fmt.Errorf("bloom: want: %x have: %x", h.Bloom, h2.Bloom)
}
if h.Coinbase != h2.Coinbase {
return fmt.Errorf("Coinbase: want: %x have: %x", h.Coinbase, h2.Coinbase)
return fmt.Errorf("coinbase: want: %x have: %x", h.Coinbase, h2.Coinbase)
}
if h.MixHash != h2.MixDigest {
return fmt.Errorf("MixHash: want: %x have: %x", h.MixHash, h2.MixDigest)
}
if h.Nonce != h2.Nonce {
return fmt.Errorf("Nonce: want: %x have: %x", h.Nonce, h2.Nonce)
return fmt.Errorf("nonce: want: %x have: %x", h.Nonce, h2.Nonce)
}
if h.Number.Cmp(h2.Number) != 0 {
return fmt.Errorf("Number: want: %v have: %v", h.Number, h2.Number)
return fmt.Errorf("number: want: %v have: %v", h.Number, h2.Number)
}
if h.ParentHash != h2.ParentHash {
return fmt.Errorf("Parent hash: want: %x have: %x", h.ParentHash, h2.ParentHash)
return fmt.Errorf("parent hash: want: %x have: %x", h.ParentHash, h2.ParentHash)
}
if h.ReceiptTrie != h2.ReceiptHash {
return fmt.Errorf("Receipt hash: want: %x have: %x", h.ReceiptTrie, h2.ReceiptHash)
return fmt.Errorf("receipt hash: want: %x have: %x", h.ReceiptTrie, h2.ReceiptHash)
}
if h.TransactionsTrie != h2.TxHash {
return fmt.Errorf("Tx hash: want: %x have: %x", h.TransactionsTrie, h2.TxHash)
return fmt.Errorf("tx hash: want: %x have: %x", h.TransactionsTrie, h2.TxHash)
}
if h.StateRoot != h2.Root {
return fmt.Errorf("State hash: want: %x have: %x", h.StateRoot, h2.Root)
return fmt.Errorf("state hash: want: %x have: %x", h.StateRoot, h2.Root)
}
if h.UncleHash != h2.UncleHash {
return fmt.Errorf("Uncle hash: want: %x have: %x", h.UncleHash, h2.UncleHash)
return fmt.Errorf("uncle hash: want: %x have: %x", h.UncleHash, h2.UncleHash)
}
if !bytes.Equal(h.ExtraData, h2.Extra) {
return fmt.Errorf("Extra data: want: %x have: %x", h.ExtraData, h2.Extra)
return fmt.Errorf("extra data: want: %x have: %x", h.ExtraData, h2.Extra)
}
if h.Difficulty.Cmp(h2.Difficulty) != 0 {
return fmt.Errorf("Difficulty: want: %v have: %v", h.Difficulty, h2.Difficulty)
return fmt.Errorf("difficulty: want: %v have: %v", h.Difficulty, h2.Difficulty)
}
if h.GasLimit != h2.GasLimit {
return fmt.Errorf("GasLimit: want: %d have: %d", h.GasLimit, h2.GasLimit)
return fmt.Errorf("gasLimit: want: %d have: %d", h.GasLimit, h2.GasLimit)
}
if h.GasUsed != h2.GasUsed {
return fmt.Errorf("GasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
return fmt.Errorf("gasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
}
if h.Timestamp.Cmp(h2.Time) != 0 {
return fmt.Errorf("Timestamp: want: %v have: %v", h.Timestamp, h2.Time)
return fmt.Errorf("timestamp: want: %v have: %v", h.Timestamp, h2.Time)
}
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions tests/gen_btheader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/gen_stenv.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 28 additions & 16 deletions tests/gen_sttransaction.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ed91fbf

Please sign in to comment.