Skip to content

Commit

Permalink
eth/gasprice: avoid modifying TestChainConfig (ethereum#23204)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Lange <fjl@twurst.com>
  • Loading branch information
2 people authored and jagdeep sidhu committed Oct 11, 2021
1 parent 3b6b5d4 commit 8774385
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions eth/gasprice/gasprice_test.go
Expand Up @@ -99,18 +99,14 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
var (
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr = crypto.PubkeyToAddress(key.PublicKey)
config = *params.TestChainConfig // needs copy because it is modified below
gspec = &core.Genesis{
Config: params.TestChainConfig,
Config: &config,
Alloc: core.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}},
}
signer = types.LatestSigner(gspec.Config)
)
if londonBlock != nil {
gspec.Config.LondonBlock = londonBlock
signer = types.LatestSigner(gspec.Config)
} else {
gspec.Config.LondonBlock = nil
}
config.LondonBlock = londonBlock
engine := ethash.NewFaker()
db := rawdb.NewMemoryDatabase()
genesis, _ := gspec.Commit(db)
Expand All @@ -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) {
b.SetCoinbase(common.Address{1})

var tx *types.Transaction
var txdata types.TxData
if londonBlock != nil && b.Number().Cmp(londonBlock) >= 0 {
txdata := &types.DynamicFeeTx{
txdata = &types.DynamicFeeTx{
ChainID: gspec.Config.ChainID,
Nonce: b.TxNonce(addr),
To: &common.Address{},
Expand All @@ -130,28 +126,22 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
GasTipCap: big.NewInt(int64(i+1) * params.GWei),
Data: []byte{},
}
tx = types.NewTx(txdata)
} else {
txdata := &types.LegacyTx{
txdata = &types.LegacyTx{
Nonce: b.TxNonce(addr),
To: &common.Address{},
Gas: 21000,
GasPrice: big.NewInt(int64(i+1) * params.GWei),
Value: big.NewInt(100),
Data: []byte{},
}
tx = types.NewTx(txdata)
}
tx, err := types.SignTx(tx, signer, key)
if err != nil {
t.Fatalf("failed to create tx: %v", err)
}
b.AddTx(tx)
b.AddTx(types.MustSignNewTx(key, signer, txdata))
})
// Construct testing chain
diskdb := rawdb.NewMemoryDatabase()
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 {
t.Fatalf("Failed to create local chain, %v", err)
}
Expand Down

0 comments on commit 8774385

Please sign in to comment.