Skip to content

Commit d50bc52

Browse files
tests: extend test case util with RANDOM support
1 parent 4a75f92 commit d50bc52

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type ommer struct {
6666
type stEnv struct {
6767
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
6868
Difficulty *big.Int `json:"currentDifficulty"`
69+
Random *big.Int `json:"currentRandom"`
6970
ParentDifficulty *big.Int `json:"parentDifficulty"`
7071
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
7172
Number uint64 `json:"currentNumber" gencodec:"required"`
@@ -80,6 +81,7 @@ type stEnv struct {
8081
type stEnvMarshaling struct {
8182
Coinbase common.UnprefixedAddress
8283
Difficulty *math.HexOrDecimal256
84+
Random *math.HexOrDecimal256
8385
ParentDifficulty *math.HexOrDecimal256
8486
GasLimit math.HexOrDecimal64
8587
Number math.HexOrDecimal64

cmd/evm/internal/t8ntool/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.

core/genesis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
294294
if g.GasLimit == 0 {
295295
head.GasLimit = params.GenesisGasLimit
296296
}
297-
if g.Difficulty == nil {
297+
emptyHash := common.Hash{}
298+
if g.Difficulty == nil && bytes.Equal(g.Mixhash[:], emptyHash[:]) {
298299
head.Difficulty = params.GenesisDifficulty
299300
}
300301
if g.Config != nil && g.Config.IsLondon(common.Big0) {

tests/gen_stenv.go

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

tests/state_test_util.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ type stPostState struct {
8080

8181
type stEnv struct {
8282
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
83-
Difficulty *big.Int `json:"currentDifficulty" gencodec:"required"`
83+
Difficulty *big.Int `json:"currentDifficulty" gencodec:"optional"`
84+
Random *big.Int `json:"currentRandom" gencodec:"optional"`
8485
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
8586
Number uint64 `json:"currentNumber" gencodec:"required"`
8687
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
@@ -90,6 +91,7 @@ type stEnv struct {
9091
type stEnvMarshaling struct {
9192
Coinbase common.UnprefixedAddress
9293
Difficulty *math.HexOrDecimal256
94+
Random *math.HexOrDecimal256
9395
GasLimit math.HexOrDecimal64
9496
Number math.HexOrDecimal64
9597
Timestamp math.HexOrDecimal64
@@ -218,8 +220,11 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
218220
context := core.NewEVMBlockContext(block.Header(), nil, &t.json.Env.Coinbase)
219221
context.GetHash = vmTestBlockHash
220222
context.BaseFee = baseFee
223+
if t.json.Env.Random != nil {
224+
context.Random = common.BigToHash(t.json.Env.Random)
225+
context.Difficulty = nil
226+
}
221227
evm := vm.NewEVM(context, txContext, statedb, config, vmconfig)
222-
223228
// Execute the message.
224229
snapshot := statedb.Snapshot()
225230
gaspool := new(core.GasPool)
@@ -268,7 +273,7 @@ func MakePreState(db ethdb.Database, accounts core.GenesisAlloc, snapshotter boo
268273
}
269274

270275
func (t *StateTest) genesis(config *params.ChainConfig) *core.Genesis {
271-
return &core.Genesis{
276+
genesis := &core.Genesis{
272277
Config: config,
273278
Coinbase: t.json.Env.Coinbase,
274279
Difficulty: t.json.Env.Difficulty,
@@ -277,6 +282,12 @@ func (t *StateTest) genesis(config *params.ChainConfig) *core.Genesis {
277282
Timestamp: t.json.Env.Timestamp,
278283
Alloc: t.json.Pre,
279284
}
285+
if t.json.Env.Random != nil {
286+
// Post-Merge
287+
genesis.Mixhash = common.BigToHash(t.json.Env.Random)
288+
genesis.Difficulty = nil
289+
}
290+
return genesis
280291
}
281292

282293
func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (core.Message, error) {

tests/testdata

Submodule testdata updated 163 files

0 commit comments

Comments
 (0)