Fixed tests

This commit is contained in:
Matthieu Vachon 2025-02-13 16:54:36 -05:00
parent 9f4c25d3ee
commit 294e2863e6
7 changed files with 39 additions and 27 deletions

View file

@ -465,7 +465,6 @@ func blockEvent(height uint64) tracing.BlockEvent {
Block: types.NewBlock(&types.Header{
Number: big.NewInt(int64(height)),
}, nil, nil, nil),
TD: b(1),
}
}

View file

@ -54,27 +54,39 @@ func runPrestateBlock(t *testing.T, prestatePath string, hooks *tracing.Hooks) {
Transactions: []*types.Transaction{tx},
}, nil, trie.NewStackTrie(nil))
hooks.OnBlockchainInit(prestate.Genesis.Config)
hooks.OnBlockStart(tracing.BlockEvent{
Block: block,
TD: prestate.TotalDifficulty,
})
if hooks.OnBlockchainInit != nil {
hooks.OnBlockchainInit(prestate.Genesis.Config)
}
if hooks.OnBlockStart != nil {
hooks.OnBlockStart(tracing.BlockEvent{
Block: block,
})
}
header := block.Header()
msg, err := core.TransactionToMessage(tx, types.MakeSigner(prestate.Genesis.Config, header.Number, header.Time), header.BaseFee)
require.NoError(t, err)
blockContext := core.NewEVMBlockContext(block.Header(), prestate, &context.Coinbase)
vmenv := vm.NewEVM(blockContext, state.NewHookedState(testState.StateDB, hooks), prestate.Genesis.Config, vm.Config{Tracer: hooks})
usedGas := uint64(0)
_, err := core.ApplyTransaction(
prestate.Genesis.Config,
prestate,
&context.Coinbase,
_, err = core.ApplyTransactionWithEVM(
msg,
new(core.GasPool).AddGas(block.GasLimit()),
testState.StateDB,
block.Header(),
header.Number,
header.Hash(),
tx,
&usedGas,
vm.Config{Tracer: hooks},
vmenv,
)
require.NoError(t, err)
hooks.OnBlockEnd(nil)
if hooks.OnBlockEnd != nil {
hooks.OnBlockEnd(nil)
}
}
func newBlockchain(t *testing.T, alloc types.GenesisAlloc, context vm.BlockContext, tracer *tracing.Hooks) (*core.Genesis, *core.BlockChain) {

View file

@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
)
@ -52,6 +53,11 @@ type prestateData struct {
genesisBlock *types.Block
}
// Config implements core.ChainContext.
func (p *prestateData) Config() *params.ChainConfig {
return p.Genesis.Config
}
// Engine implements core.ChainContext.
func (p *prestateData) Engine() consensus.Engine {
return ethash.NewFullFaker()
@ -100,9 +106,16 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
if genesis.Config.IsLondon(context.BlockNumber) {
context.BaseFee = (*big.Int)(c.BaseFee)
}
if genesis.Config.TerminalTotalDifficulty != nil && genesis.Config.TerminalTotalDifficulty.Sign() == 0 {
context.Random = &genesis.Mixhash
}
if genesis.ExcessBlobGas != nil && genesis.BlobGasUsed != nil {
excessBlobGas := eip4844.CalcExcessBlobGas(*genesis.ExcessBlobGas, *genesis.BlobGasUsed)
context.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas)
header := &types.Header{Number: genesis.Config.LondonBlock, Time: *genesis.Config.CancunTime}
excess := eip4844.CalcExcessBlobGas(genesis.Config, header, genesis.Timestamp)
header.ExcessBlobGas = &excess
context.BlobBaseFee = eip4844.CalcBlobFee(genesis.Config, header)
}
return context
}

View file

@ -13,9 +13,6 @@
"difficulty": {
"bytes": "Ag=="
},
"totalDifficulty": {
"bytes": "Aw=="
},
"number": "1",
"gasLimit": "1000000",
"timestamp": "1970-01-01T00:00:01Z",

View file

@ -13,9 +13,6 @@
"difficulty": {
"bytes": "AA=="
},
"totalDifficulty": {
"bytes": "PGVtIwKasA=="
},
"number": "3727495",
"gasLimit": "30000000",
"timestamp": "2023-06-19T23:23:48Z",

View file

@ -13,9 +13,6 @@
"difficulty": {
"bytes": "AA=="
},
"totalDifficulty": {
"bytes": "PGVtIwKasA=="
},
"number": "3733424",
"gasLimit": "30000000",
"timestamp": "2023-06-20T21:02:36Z",

View file

@ -13,9 +13,6 @@
"difficulty": {
"bytes": "AA=="
},
"totalDifficulty": {
"bytes": "AQ=="
},
"number": "1",
"timestamp": "1970-01-01T00:00:00Z",
"mixHash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",