From 8a728c2988ed5cb753ef26f47150dba0c0fb3201 Mon Sep 17 00:00:00 2001 From: JukLee0ira Date: Sat, 13 Jul 2024 14:03:04 +0800 Subject: [PATCH] core: cleanup tests (#25641) --- core/chain_makers.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/chain_makers.go b/core/chain_makers.go index 15e87c88378d3..7a4012945f7d0 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -244,6 +244,19 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse return blocks, receipts } +// GenerateChainWithGenesis is a wrapper of GenerateChain which will initialize +// genesis block to database first according to the provided genesis specification +// then generate chain on top. +func GenerateChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int, gen func(int, *BlockGen)) (ethdb.Database, []*types.Block, []types.Receipts) { + db := rawdb.NewMemoryDatabase() + _, err := genesis.Commit(db) + if err != nil { + panic(err) + } + blocks, receipts := GenerateChain(genesis.Config, genesis.ToBlock(nil), engine, db, n, gen) + return db, blocks, receipts +} + func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.StateDB, engine consensus.Engine) *types.Header { var time *big.Int if parent.Time() == nil {