Skip to content

Commit 0e9c7d5

Browse files
authored
tests: update for London (#22976)
This updates the tests submodule to the London fork tests, and also updates the test runner to support the new EIP-1559 fields in test JSON.
1 parent 08379b5 commit 0e9c7d5

File tree

11 files changed

+130
-44
lines changed

11 files changed

+130
-44
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type ExecutionResult struct {
5252
LogsHash common.Hash `json:"logsHash"`
5353
Bloom types.Bloom `json:"logsBloom" gencodec:"required"`
5454
Receipts types.Receipts `json:"receipts"`
55-
Rejected []int `json:"rejected,omitempty"`
55+
Rejected []*rejectedTx `json:"rejected,omitempty"`
5656
}
5757

5858
type ommer struct {
@@ -81,6 +81,11 @@ type stEnvMarshaling struct {
8181
BaseFee *math.HexOrDecimal256
8282
}
8383

84+
type rejectedTx struct {
85+
Index int `json:"index"`
86+
Err string `json:"error"`
87+
}
88+
8489
// Apply applies a set of transactions to a pre-state
8590
func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
8691
txs types.Transactions, miningReward int64,
@@ -105,7 +110,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
105110
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number))
106111
gaspool = new(core.GasPool)
107112
blockHash = common.Hash{0x13, 0x37}
108-
rejectedTxs []int
113+
rejectedTxs []*rejectedTx
109114
includedTxs types.Transactions
110115
gasUsed = uint64(0)
111116
receipts = make(types.Receipts, 0)
@@ -137,8 +142,8 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
137142
for i, tx := range txs {
138143
msg, err := tx.AsMessage(signer, pre.Env.BaseFee)
139144
if err != nil {
140-
log.Info("rejected tx", "index", i, "hash", tx.Hash(), "error", err)
141-
rejectedTxs = append(rejectedTxs, i)
145+
log.Warn("rejected tx", "index", i, "hash", tx.Hash(), "error", err)
146+
rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()})
142147
continue
143148
}
144149
tracer, err := getTracerFn(txIndex, tx.Hash())
@@ -157,7 +162,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
157162
if err != nil {
158163
statedb.RevertToSnapshot(snapshot)
159164
log.Info("rejected tx", "index", i, "hash", tx.Hash(), "from", msg.From(), "error", err)
160-
rejectedTxs = append(rejectedTxs, i)
165+
rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()})
161166
continue
162167
}
163168
includedTxs = append(includedTxs, tx)

core/gen_genesis.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/gen_genesis_account.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/genesis.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Genesis struct {
6262
Number uint64 `json:"number"`
6363
GasUsed uint64 `json:"gasUsed"`
6464
ParentHash common.Hash `json:"parentHash"`
65+
BaseFee *big.Int `json:"baseFee"`
6566
}
6667

6768
// GenesisAlloc specifies the initial state that is part of the genesis block.
@@ -292,7 +293,11 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
292293
head.Difficulty = params.GenesisDifficulty
293294
}
294295
if g.Config != nil && g.Config.IsLondon(common.Big0) {
295-
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
296+
if g.BaseFee != nil {
297+
head.BaseFee = g.BaseFee
298+
} else {
299+
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
300+
}
296301
}
297302
statedb.Commit(false)
298303
statedb.Database().TrieDB().Commit(root, true, nil)

tests/block_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func TestBlockchain(t *testing.T) {
4343

4444
// Very slow test
4545
bt.skipLoad(`.*/stTimeConsuming/.*`)
46-
4746
// test takes a lot for time and goes easily OOM because of sha3 calculation on a huge range,
4847
// using 4.6 TGas
4948
bt.skipLoad(`.*randomStatetest94.json.*`)

tests/block_test_util.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"encoding/json"
2424
"fmt"
2525
"math/big"
26+
"os"
2627

2728
"github.com/ethereum/go-ethereum/common"
2829
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -59,9 +60,10 @@ type btJSON struct {
5960
}
6061

6162
type btBlock struct {
62-
BlockHeader *btHeader
63-
Rlp string
64-
UncleHeaders []*btHeader
63+
BlockHeader *btHeader
64+
ExpectException string
65+
Rlp string
66+
UncleHeaders []*btHeader
6567
}
6668

6769
//go:generate gencodec -type btHeader -field-override btHeaderMarshaling -out gen_btheader.go
@@ -83,6 +85,7 @@ type btHeader struct {
8385
GasLimit uint64
8486
GasUsed uint64
8587
Timestamp uint64
88+
BaseFee *big.Int
8689
}
8790

8891
type btHeaderMarshaling struct {
@@ -92,6 +95,7 @@ type btHeaderMarshaling struct {
9295
GasLimit math.HexOrDecimal64
9396
GasUsed math.HexOrDecimal64
9497
Timestamp math.HexOrDecimal64
98+
BaseFee *math.HexOrDecimal256
9599
}
96100

97101
func (t *BlockTest) Run(snapshotter bool) error {
@@ -166,6 +170,7 @@ func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis {
166170
Mixhash: t.json.Genesis.MixHash,
167171
Coinbase: t.json.Genesis.Coinbase,
168172
Alloc: t.json.Pre,
173+
BaseFee: t.json.Genesis.BaseFee,
169174
}
170175
}
171176

@@ -184,7 +189,7 @@ func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis {
184189
func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error) {
185190
validBlocks := make([]btBlock, 0)
186191
// insert the test blocks, which will execute all transactions
187-
for _, b := range t.json.Blocks {
192+
for bi, b := range t.json.Blocks {
188193
cb, err := b.decode()
189194
if err != nil {
190195
if b.BlockHeader == nil {
@@ -204,7 +209,12 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
204209
}
205210
}
206211
if b.BlockHeader == nil {
207-
return nil, fmt.Errorf("block insertion should have failed")
212+
if data, err := json.MarshalIndent(cb.Header(), "", " "); err == nil {
213+
fmt.Fprintf(os.Stderr, "block (index %d) insertion should have failed due to: %v:\n%v\n",
214+
bi, b.ExpectException, string(data))
215+
}
216+
return nil, fmt.Errorf("block (index %d) insertion should have failed due to: %v",
217+
bi, b.ExpectException)
208218
}
209219

210220
// validate RLP decoding by checking all values against test file JSON

tests/gen_btheader.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/gen_stenv.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/gen_sttransaction.go

Lines changed: 28 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)