eth/gasprice: avoid modifying TestChainConfig (#23204)

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
aaronbuchwald 2021-10-10 19:52:30 -04:00 committed by GitHub
parent 84bccd0900
commit bcbd700367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -99,18 +99,14 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
var ( var (
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr = crypto.PubkeyToAddress(key.PublicKey) addr = crypto.PubkeyToAddress(key.PublicKey)
config = *params.TestChainConfig // needs copy because it is modified below
gspec = &core.Genesis{ gspec = &core.Genesis{
Config: params.TestChainConfig, Config: &config,
Alloc: core.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}}, Alloc: core.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}},
} }
signer = types.LatestSigner(gspec.Config) signer = types.LatestSigner(gspec.Config)
) )
if londonBlock != nil { config.LondonBlock = londonBlock
gspec.Config.LondonBlock = londonBlock
signer = types.LatestSigner(gspec.Config)
} else {
gspec.Config.LondonBlock = nil
}
engine := ethash.NewFaker() engine := ethash.NewFaker()
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
genesis, _ := gspec.Commit(db) genesis, _ := gspec.Commit(db)
@ -119,9 +115,9 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
blocks, _ := core.GenerateChain(gspec.Config, genesis, engine, db, testHead+1, func(i int, b *core.BlockGen) { blocks, _ := core.GenerateChain(gspec.Config, genesis, engine, db, testHead+1, func(i int, b *core.BlockGen) {
b.SetCoinbase(common.Address{1}) b.SetCoinbase(common.Address{1})
var tx *types.Transaction var txdata types.TxData
if londonBlock != nil && b.Number().Cmp(londonBlock) >= 0 { if londonBlock != nil && b.Number().Cmp(londonBlock) >= 0 {
txdata := &types.DynamicFeeTx{ txdata = &types.DynamicFeeTx{
ChainID: gspec.Config.ChainID, ChainID: gspec.Config.ChainID,
Nonce: b.TxNonce(addr), Nonce: b.TxNonce(addr),
To: &common.Address{}, To: &common.Address{},
@ -130,9 +126,8 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
GasTipCap: big.NewInt(int64(i+1) * params.GWei), GasTipCap: big.NewInt(int64(i+1) * params.GWei),
Data: []byte{}, Data: []byte{},
} }
tx = types.NewTx(txdata)
} else { } else {
txdata := &types.LegacyTx{ txdata = &types.LegacyTx{
Nonce: b.TxNonce(addr), Nonce: b.TxNonce(addr),
To: &common.Address{}, To: &common.Address{},
Gas: 21000, Gas: 21000,
@ -140,18 +135,13 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
Value: big.NewInt(100), Value: big.NewInt(100),
Data: []byte{}, Data: []byte{},
} }
tx = types.NewTx(txdata)
} }
tx, err := types.SignTx(tx, signer, key) b.AddTx(types.MustSignNewTx(key, signer, txdata))
if err != nil {
t.Fatalf("failed to create tx: %v", err)
}
b.AddTx(tx)
}) })
// Construct testing chain // Construct testing chain
diskdb := rawdb.NewMemoryDatabase() diskdb := rawdb.NewMemoryDatabase()
gspec.Commit(diskdb) gspec.Commit(diskdb)
chain, err := core.NewBlockChain(diskdb, &core.CacheConfig{TrieCleanNoPrefetch: true}, gspec.Config, engine, vm.Config{}, nil, nil) chain, err := core.NewBlockChain(diskdb, &core.CacheConfig{TrieCleanNoPrefetch: true}, &config, engine, vm.Config{}, nil, nil)
if err != nil { if err != nil {
t.Fatalf("Failed to create local chain, %v", err) t.Fatalf("Failed to create local chain, %v", err)
} }