Skip to content

Commit

Permalink
ethclient/simulated: fix failing test due the min tip change
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Feb 6, 2024
1 parent 27f7023 commit 264bfaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ethclient/simulated/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {

// create a signed transaction to send
head, _ := client.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei))
addr := crypto.PubkeyToAddress(key.PublicKey)
chainid, _ := client.ChainID(context.Background())
nonce, err := client.PendingNonceAt(context.Background(), addr)
Expand All @@ -62,7 +62,7 @@ func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: chainid,
Nonce: nonce,
GasTipCap: big.NewInt(1),
GasTipCap: big.NewInt(params.GWei),
GasFeeCap: gasPrice,
Gas: 21000,
To: &addr,
Expand Down
16 changes: 16 additions & 0 deletions ethclient/simulated/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package simulated

import (
"math/big"

"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/node"
)
Expand All @@ -37,3 +39,17 @@ func WithCallGasLimit(gaslimit uint64) func(nodeConf *node.Config, ethConf *ethc
ethConf.RPCGasCap = gaslimit
}
}

// WithMinerMinTip configures the simulated backend to require a specific minimum
// gas tip for a transaction to be included.
//
// 0 is not possible as a live Geth node would reject that due to DoS protection,
// so the simulated backend will replicate that behavior for consisntency.
func WithMinerMinTip(tip *big.Int) func(nodeConf *node.Config, ethConf *ethconfig.Config) {
if tip == nil || tip.Cmp(new(big.Int)) <= 0 {
panic("invalid miner minimum tip")
}
return func(nodeConf *node.Config, ethConf *ethconfig.Config) {
ethConf.Miner.GasPrice = tip
}
}

0 comments on commit 264bfaf

Please sign in to comment.