Ensure tests are still working properly

This commit is contained in:
Matthieu Vachon 2025-01-27 14:23:16 -05:00
parent 0435f76787
commit eac7dd4d56
6 changed files with 32 additions and 21 deletions

View file

@ -1675,6 +1675,11 @@ func newBlockHeaderFromChainHeader(hash common.Hash, h *types.Header, td *pbeth.
parentBeaconRootBytes = root.Bytes() parentBeaconRootBytes = root.Bytes()
} }
var requestHashBytes []byte
if hash := h.RequestsHash; hash != nil {
requestHashBytes = hash.Bytes()
}
pbHead := &pbeth.BlockHeader{ pbHead := &pbeth.BlockHeader{
Hash: hash.Bytes(), Hash: hash.Bytes(),
Number: h.Number.Uint64(), Number: h.Number.Uint64(),
@ -1698,6 +1703,7 @@ func newBlockHeaderFromChainHeader(hash common.Hash, h *types.Header, td *pbeth.
BlobGasUsed: h.BlobGasUsed, BlobGasUsed: h.BlobGasUsed,
ExcessBlobGas: h.ExcessBlobGas, ExcessBlobGas: h.ExcessBlobGas,
ParentBeaconRoot: parentBeaconRootBytes, ParentBeaconRoot: parentBeaconRootBytes,
RequestsHash: requestHashBytes,
// Only set on Polygon fork(s) // Only set on Polygon fork(s)
TxDependency: nil, TxDependency: nil,

View file

@ -133,7 +133,7 @@ func Test_TypesHeader_AllConsensusFieldsAreKnown(t *testing.T) {
// When adding support for a new hard-fork that adds new block header fields, it's normal that this value // When adding support for a new hard-fork that adds new block header fields, it's normal that this value
// changes. If you are sure the two struct are the same, then you can update the expected hash below // changes. If you are sure the two struct are the same, then you can update the expected hash below
// to the new value. // to the new value.
expectedHash := common.HexToHash("5341947c531e5c9cf38202784b16ac66484fe1838aa6e825436b22321b927296") expectedHash := common.HexToHash("4ced4916132bbf6a7819a310bbac4abf354062a00efc980ea4f0bab406546ac5")
gethHeaderValue := reflect.New(gethHeaderType) gethHeaderValue := reflect.New(gethHeaderType)
fillAllFieldsWithNonEmptyValues(t, gethHeaderValue, reflect.VisibleFields(gethHeaderType)) fillAllFieldsWithNonEmptyValues(t, gethHeaderValue, reflect.VisibleFields(gethHeaderType))
@ -146,7 +146,7 @@ func Test_TypesHeader_AllConsensusFieldsAreKnown(t *testing.T) {
// actually a computed value based on the other fields in the struct, so if you change any field, // actually a computed value based on the other fields in the struct, so if you change any field,
// the hash will change also. // the hash will change also.
// //
// On hard-fork, it happens that new fields are added, this test serves as a way to "detect" in codde // On hard-fork, it happens that new fields are added, this test serves as a way to "detect" in code
// that the expected fields of `types.Header` changed // that the expected fields of `types.Header` changed
require.Equal(t, expectedHash, gethHeader.Hash(), require.Equal(t, expectedHash, gethHeader.Hash(),
"Geth Header Hash mistmatch, got %q but expecting %q on *types.Header:\n\nGeth Header (from fillNonDefault(new(*types.Header)))\n%s", "Geth Header Hash mistmatch, got %q but expecting %q on *types.Header:\n\nGeth Header (from fillNonDefault(new(*types.Header)))\n%s",
@ -464,7 +464,7 @@ func blockEvent(height uint64) tracing.BlockEvent {
return tracing.BlockEvent{ return tracing.BlockEvent{
Block: types.NewBlock(&types.Header{ Block: types.NewBlock(&types.Header{
Number: big.NewInt(int64(height)), Number: big.NewInt(int64(height)),
}, nil, nil, nil, nil), }, nil, nil, nil),
TD: b(1), TD: b(1),
} }
} }

View file

@ -33,11 +33,13 @@ func runPrestateBlock(t *testing.T, prestatePath string, hooks *tracing.Hooks) {
context := prestate.Context.toBlockContext(prestate.Genesis) context := prestate.Context.toBlockContext(prestate.Genesis)
state := tests.MakePreState(rawdb.NewMemoryDatabase(), prestate.Genesis.Alloc, false, rawdb.HashScheme) testState := tests.MakePreState(rawdb.NewMemoryDatabase(), prestate.Genesis.Alloc, false, rawdb.HashScheme)
defer state.Close() defer testState.Close()
state.StateDB.SetLogger(hooks) state.NewHookedState(testState.StateDB, hooks)
state.StateDB.SetTxContext(tx.Hash(), 0)
// testState.StateDB.SetLogger(hooks)
testState.StateDB.SetTxContext(tx.Hash(), 0)
block := types.NewBlock(&types.Header{ block := types.NewBlock(&types.Header{
ParentHash: prestate.Genesis.ToBlock().Hash(), ParentHash: prestate.Genesis.ToBlock().Hash(),
@ -48,7 +50,9 @@ func runPrestateBlock(t *testing.T, prestatePath string, hooks *tracing.Hooks) {
GasLimit: context.GasLimit, GasLimit: context.GasLimit,
BaseFee: context.BaseFee, BaseFee: context.BaseFee,
ParentBeaconRoot: ptr(common.Hash{}), ParentBeaconRoot: ptr(common.Hash{}),
}, []*types.Transaction{tx}, nil, nil, trie.NewStackTrie(nil)) }, &types.Body{
Transactions: []*types.Transaction{tx},
}, nil, trie.NewStackTrie(nil))
hooks.OnBlockchainInit(prestate.Genesis.Config) hooks.OnBlockchainInit(prestate.Genesis.Config)
hooks.OnBlockStart(tracing.BlockEvent{ hooks.OnBlockStart(tracing.BlockEvent{
@ -62,7 +66,7 @@ func runPrestateBlock(t *testing.T, prestatePath string, hooks *tracing.Hooks) {
prestate, prestate,
&context.Coinbase, &context.Coinbase,
new(core.GasPool).AddGas(block.GasLimit()), new(core.GasPool).AddGas(block.GasLimit()),
state.StateDB, testState.StateDB,
block.Header(), block.Header(),
tx, tx,
&usedGas, &usedGas,
@ -91,7 +95,7 @@ func newBlockchain(t *testing.T, alloc types.GenesisAlloc, context vm.BlockConte
blockchain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), core.DefaultCacheConfigWithScheme(rawdb.HashScheme), genesis, nil, ethash.NewFullFaker(), vm.Config{ blockchain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), core.DefaultCacheConfigWithScheme(rawdb.HashScheme), genesis, nil, ethash.NewFullFaker(), vm.Config{
Tracer: tracer, Tracer: tracer,
}, nil, nil) }, nil)
require.NoError(t, err) require.NoError(t, err)
return genesis, blockchain return genesis, blockchain
@ -126,6 +130,8 @@ func (h *testHasher) Hash() common.Hash {
return common.BytesToHash(h.hasher.Sum(nil)) return common.BytesToHash(h.hasher.Sum(nil))
} }
var _ core.Validator = (*ignoreValidateStateValidator)(nil)
type ignoreValidateStateValidator struct { type ignoreValidateStateValidator struct {
core.Validator core.Validator
} }
@ -134,6 +140,6 @@ func (v ignoreValidateStateValidator) ValidateBody(block *types.Block) error {
return v.Validator.ValidateBody(block) return v.Validator.ValidateBody(block)
} }
func (v ignoreValidateStateValidator) ValidateState(block *types.Block, statedb *state.StateDB, receipts types.Receipts, usedGas uint64) error { func (v ignoreValidateStateValidator) ValidateState(block *types.Block, state *state.StateDB, res *core.ProcessResult, stateless bool) error {
return nil return nil
} }

View file

@ -50,11 +50,11 @@ func TestFirehoseChain(t *testing.T) {
GasLimit: context.GasLimit, GasLimit: context.GasLimit,
BaseFee: context.BaseFee, BaseFee: context.BaseFee,
ParentBeaconRoot: ptr(common.Hash{}), ParentBeaconRoot: ptr(common.Hash{}),
}, nil, nil, nil, trie.NewStackTrie(nil)) }, nil, nil, trie.NewStackTrie(nil))
blockchain.SetBlockValidatorAndProcessorForTesting( blockchain.SetBlockValidatorAndProcessorForTesting(
ignoreValidateStateValidator{core.NewBlockValidator(genesis.Config, blockchain, blockchain.Engine())}, ignoreValidateStateValidator{core.NewBlockValidator(genesis.Config, blockchain)},
core.NewStateProcessor(genesis.Config, blockchain, blockchain.Engine()), core.NewStateProcessor(genesis.Config, blockchain.HeaderChain()),
) )
n, err := blockchain.InsertChain(types.Blocks{block}) n, err := blockchain.InsertChain(types.Blocks{block})
@ -62,7 +62,7 @@ func TestFirehoseChain(t *testing.T) {
require.Equal(t, 1, n) require.Equal(t, 1, n)
genesisLine, blockLines, unknownLines := readTracerFirehoseLines(t, tracer) genesisLine, blockLines, unknownLines := readTracerFirehoseLines(t, tracer)
require.Len(t, unknownLines, 0, "Lines:\n%s", strings.Join(slicesMap(unknownLines, func(l unknwonLine) string { return "- '" + string(l) + "'" }), "\n")) require.Len(t, unknownLines, 0, "Lines:\n%s", strings.Join(slicesMap(unknownLines, func(l unknownLine) string { return "- '" + string(l) + "'" }), "\n"))
require.NotNil(t, genesisLine) require.NotNil(t, genesisLine)
blockLines.assertEquals(t, filepath.Join("testdata", t.Name()), blockLines.assertEquals(t, filepath.Join("testdata", t.Name()),
firehoseBlockLineParams{"1", "8e6ee4b1054d94df1d8a51fb983447dc2e27a854590c3ac0061f994284be8150", "0", "845bad515694a416bab4b8d44e22cf97a8c894a8502110ab807883940e185ce0", "0", "1000000000"}, firehoseBlockLineParams{"1", "8e6ee4b1054d94df1d8a51fb983447dc2e27a854590c3ac0061f994284be8150", "0", "845bad515694a416bab4b8d44e22cf97a8c894a8502110ab807883940e185ce0", "0", "1000000000"},
@ -90,7 +90,7 @@ func TestFirehosePrestate(t *testing.T) {
runPrestateBlock(t, filepath.Join(folder, "prestate.json"), tracers.NewTracingHooksFromFirehose(tracer)) runPrestateBlock(t, filepath.Join(folder, "prestate.json"), tracers.NewTracingHooksFromFirehose(tracer))
genesisLine, blockLines, unknownLines := readTracerFirehoseLines(t, tracer) genesisLine, blockLines, unknownLines := readTracerFirehoseLines(t, tracer)
require.Len(t, unknownLines, 0, "Lines:\n%s", strings.Join(slicesMap(unknownLines, func(l unknwonLine) string { return "- '" + string(l) + "'" }), "\n")) require.Len(t, unknownLines, 0, "Lines:\n%s", strings.Join(slicesMap(unknownLines, func(l unknownLine) string { return "- '" + string(l) + "'" }), "\n"))
require.NotNil(t, genesisLine) require.NotNil(t, genesisLine)
blockLines.assertOnlyBlockEquals(t, folder, 1) blockLines.assertOnlyBlockEquals(t, folder, 1)
}) })

View file

@ -23,7 +23,6 @@ import (
var configByName = map[string]*params.ChainConfig{ var configByName = map[string]*params.ChainConfig{
"mainnet": params.MainnetChainConfig, "mainnet": params.MainnetChainConfig,
"goerli": params.GoerliChainConfig,
"sepolia": params.SepoliaChainConfig, "sepolia": params.SepoliaChainConfig,
"holesky": params.HoleskyChainConfig, "holesky": params.HoleskyChainConfig,
} }

View file

@ -100,9 +100,9 @@ type firehoseBlockLineParams struct {
Time string Time string
} }
type unknwonLine string type unknownLine string
func readTracerFirehoseLines(t *testing.T, tracer *tracers.Firehose) (genesisLine *firehoseInitLine, blockLines firehoseBlockLines, unknownLines []unknwonLine) { func readTracerFirehoseLines(t *testing.T, tracer *tracers.Firehose) (genesisLine *firehoseInitLine, blockLines firehoseBlockLines, unknownLines []unknownLine) {
t.Helper() t.Helper()
lines := bytes.Split(tracer.InternalTestingBuffer().Bytes(), []byte{'\n'}) lines := bytes.Split(tracer.InternalTestingBuffer().Bytes(), []byte{'\n'})
@ -113,7 +113,7 @@ func readTracerFirehoseLines(t *testing.T, tracer *tracers.Firehose) (genesisLin
parts := bytes.Split(line, []byte{' '}) parts := bytes.Split(line, []byte{' '})
if len(parts) == 0 || string(parts[0]) != "FIRE" { if len(parts) == 0 || string(parts[0]) != "FIRE" {
unknownLines = append(unknownLines, unknwonLine(line)) unknownLines = append(unknownLines, unknownLine(line))
continue continue
} }
@ -147,7 +147,7 @@ func readTracerFirehoseLines(t *testing.T, tracer *tracers.Firehose) (genesisLin
}) })
default: default:
unknownLines = append(unknownLines, unknwonLine(line)) unknownLines = append(unknownLines, unknownLine(line))
} }
} }