github.com/ethereum-optimism/optimism@v1.7.2/op-node/rollup/derive/test/random.go (about) 1 package test 2 3 import ( 4 "math/big" 5 "math/rand" 6 7 "github.com/ethereum-optimism/optimism/op-node/rollup" 8 "github.com/ethereum-optimism/optimism/op-node/rollup/derive" 9 "github.com/ethereum-optimism/optimism/op-service/eth" 10 "github.com/ethereum-optimism/optimism/op-service/testutils" 11 "github.com/ethereum/go-ethereum/core/types" 12 "github.com/ethereum/go-ethereum/trie" 13 ) 14 15 // RandomL2Block returns a random block whose first transaction is a random pre-Ecotone upgrade 16 // L1 Info Deposit transaction. 17 func RandomL2Block(rng *rand.Rand, txCount int) (*types.Block, []*types.Receipt) { 18 l1Block := types.NewBlock(testutils.RandomHeader(rng), 19 nil, nil, nil, trie.NewStackTrie(nil)) 20 rollupCfg := rollup.Config{} 21 if testutils.RandomBool(rng) { 22 t := uint64(0) 23 rollupCfg.RegolithTime = &t 24 } 25 l1InfoTx, err := derive.L1InfoDeposit(&rollupCfg, eth.SystemConfig{}, 0, eth.BlockToInfo(l1Block), 0) 26 if err != nil { 27 panic("L1InfoDeposit: " + err.Error()) 28 } 29 return testutils.RandomBlockPrependTxs(rng, txCount, types.NewTx(l1InfoTx)) 30 } 31 32 func RandomL2BlockWithChainId(rng *rand.Rand, txCount int, chainId *big.Int) *types.Block { 33 signer := types.NewLondonSigner(chainId) 34 block, _ := RandomL2Block(rng, 0) 35 txs := []*types.Transaction{block.Transactions()[0]} // L1 info deposit TX 36 for i := 0; i < txCount; i++ { 37 txs = append(txs, testutils.RandomTx(rng, big.NewInt(int64(rng.Uint32())), signer)) 38 } 39 return block.WithBody(txs, nil) 40 }