Skip to content

Commit

Permalink
updated existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silaslenihan committed Mar 25, 2024
1 parent 4971c26 commit 4a0d405
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
4 changes: 2 additions & 2 deletions core/chains/evm/gas/block_history_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (b *BlockHistoryEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLim
gasPrice = b.eConfig.PriceDefault()
}
gasPrice = capGasPrice(gasPrice, maxGasPriceWei, b.eConfig.PriceMax())
chainSpecificGasLimit, err = commonfee.ApplyMultiplier(gasLimit, b.eConfig.LimitMultiplier())
chainSpecificGasLimit = gasLimit
return
}

Expand Down Expand Up @@ -396,7 +396,7 @@ func (b *BlockHistoryEstimator) GetDynamicFee(_ context.Context, gasLimit uint64
var feeCap *assets.Wei
var tipCap *assets.Wei
ok := b.IfStarted(func() {
chainSpecificGasLimit, err = commonfee.ApplyMultiplier(gasLimit, b.eConfig.LimitMultiplier())
chainSpecificGasLimit = gasLimit
if err != nil {
return
}
Expand Down
15 changes: 3 additions & 12 deletions core/chains/evm/gas/fixed_price_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ func (f *fixedPriceEstimator) Start(context.Context) error {

func (f *fixedPriceEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLimit uint64, maxGasPriceWei *assets.Wei, _ ...feetypes.Opt) (*assets.Wei, uint64, error) {
gasPrice := commonfee.CalculateFee(f.config.PriceDefault().ToInt(), maxGasPriceWei.ToInt(), f.config.PriceMax().ToInt())
chainSpecificGasLimit, err := commonfee.ApplyMultiplier(gasLimit, f.config.LimitMultiplier())
if err != nil {
return nil, 0, err
}
chainSpecificGasLimit := gasLimit
return assets.NewWei(gasPrice), chainSpecificGasLimit, nil
}

Expand All @@ -88,10 +85,7 @@ func (f *fixedPriceEstimator) BumpLegacyGas(
return nil, 0, err
}

chainSpecificGasLimit, err := commonfee.ApplyMultiplier(originalGasLimit, f.config.LimitMultiplier())
if err != nil {
return nil, 0, err
}
chainSpecificGasLimit := originalGasLimit
return assets.NewWei(gasPrice), chainSpecificGasLimit, err
}

Expand All @@ -101,10 +95,7 @@ func (f *fixedPriceEstimator) GetDynamicFee(_ context.Context, originalGasLimit
if gasTipCap == nil {
return d, 0, pkgerrors.New("cannot calculate dynamic fee: EthGasTipCapDefault was not set")
}
chainSpecificGasLimit, err = commonfee.ApplyMultiplier(originalGasLimit, f.config.LimitMultiplier())
if err != nil {
return d, 0, err
}
chainSpecificGasLimit = originalGasLimit

var feeCap *assets.Wei
if f.config.BumpThreshold() == 0 {
Expand Down
23 changes: 9 additions & 14 deletions core/chains/evm/gas/fixed_price_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,47 @@ func Test_FixedPriceEstimator(t *testing.T) {
t.Parallel()
maxGasPrice := assets.NewWeiI(1000000)

t.Run("GetLegacyGas returns EvmGasPriceDefault from config, with multiplier applied", func(t *testing.T) {
t.Run("GetLegacyGas returns EvmGasPriceDefault from config", func(t *testing.T) {
config := &gas.MockGasEstimatorConfig{}
f := gas.NewFixedPriceEstimator(config, &blockHistoryConfig{}, logger.Test(t))

config.PriceDefaultF = assets.NewWeiI(42)
config.LimitMultiplierF = float32(1.1)
config.PriceMaxF = maxGasPrice

gasPrice, gasLimit, err := f.GetLegacyGas(testutils.Context(t), nil, 100000, maxGasPrice)
require.NoError(t, err)
assert.Equal(t, 110000, int(gasLimit))
assert.Equal(t, 100000, int(gasLimit))
assert.Equal(t, assets.NewWeiI(42), gasPrice)
})

t.Run("GetLegacyGas returns user specified maximum gas price", func(t *testing.T) {
config := &gas.MockGasEstimatorConfig{}
config.PriceDefaultF = assets.NewWeiI(42)
config.LimitMultiplierF = float32(1.1)
config.PriceMaxF = assets.NewWeiI(35)
f := gas.NewFixedPriceEstimator(config, &blockHistoryConfig{}, logger.Test(t))

gasPrice, gasLimit, err := f.GetLegacyGas(testutils.Context(t), nil, 100000, assets.NewWeiI(30))
require.NoError(t, err)
assert.Equal(t, 110000, int(gasLimit))
assert.Equal(t, 100000, int(gasLimit))
assert.Equal(t, assets.NewWeiI(30), gasPrice)
})

t.Run("GetLegacyGas returns global maximum gas price", func(t *testing.T) {
config := &gas.MockGasEstimatorConfig{}
config.PriceDefaultF = assets.NewWeiI(42)
config.LimitMultiplierF = float32(1.1)
config.PriceMaxF = assets.NewWeiI(20)

f := gas.NewFixedPriceEstimator(config, &blockHistoryConfig{}, logger.Test(t))
gasPrice, gasLimit, err := f.GetLegacyGas(testutils.Context(t), nil, 100000, assets.NewWeiI(30))
require.NoError(t, err)
assert.Equal(t, 110000, int(gasLimit))
assert.Equal(t, 100000, int(gasLimit))
assert.Equal(t, assets.NewWeiI(20), gasPrice)
})

t.Run("BumpLegacyGas calls BumpLegacyGasPriceOnly", func(t *testing.T) {
config := &gas.MockGasEstimatorConfig{}
config.PriceDefaultF = assets.NewWeiI(42)
config.LimitMultiplierF = float32(1.1)
config.LimitMultiplierF = float32(1.0)
config.PriceMaxF = maxGasPrice
config.BumpPercentF = uint16(10)
config.BumpMinF = assets.NewWeiI(150)
Expand All @@ -85,9 +82,8 @@ func Test_FixedPriceEstimator(t *testing.T) {
assert.Equal(t, expectedGasPrice, gasPrice)
})

t.Run("GetDynamicFee returns defaults from config, with multiplier applied", func(t *testing.T) {
t.Run("GetDynamicFee returns defaults from config", func(t *testing.T) {
config := &gas.MockGasEstimatorConfig{}
config.LimitMultiplierF = float32(1.1)
config.PriceMaxF = maxGasPrice
config.TipCapDefaultF = assets.NewWeiI(52)
config.FeeCapDefaultF = assets.NewWeiI(100)
Expand All @@ -98,7 +94,7 @@ func Test_FixedPriceEstimator(t *testing.T) {

fee, gasLimit, err := f.GetDynamicFee(testutils.Context(t), 100000, maxGasPrice)
require.NoError(t, err)
assert.Equal(t, 110000, int(gasLimit))
assert.Equal(t, 100000, int(gasLimit))

assert.Equal(t, assets.NewWeiI(52), fee.TipCap)
assert.Equal(t, assets.NewWeiI(100), fee.FeeCap)
Expand All @@ -108,23 +104,22 @@ func Test_FixedPriceEstimator(t *testing.T) {

fee, gasLimit, err = f.GetDynamicFee(testutils.Context(t), 100000, maxGasPrice)
require.NoError(t, err)
assert.Equal(t, 110000, int(gasLimit))
assert.Equal(t, 100000, int(gasLimit))

assert.Equal(t, assets.NewWeiI(52), fee.TipCap)
assert.Equal(t, maxGasPrice, fee.FeeCap)

// override max gas price
fee, gasLimit, err = f.GetDynamicFee(testutils.Context(t), 100000, assets.NewWeiI(10))
require.NoError(t, err)
assert.Equal(t, 110000, int(gasLimit))
assert.Equal(t, 100000, int(gasLimit))

assert.Equal(t, assets.NewWeiI(52), fee.TipCap)
assert.Equal(t, assets.NewWeiI(10), fee.FeeCap)
})

t.Run("BumpDynamicFee calls BumpDynamicFeeOnly", func(t *testing.T) {
config := &gas.MockGasEstimatorConfig{}
config.LimitMultiplierF = float32(1.1)
config.PriceMaxF = maxGasPrice
config.TipCapDefaultF = assets.NewWeiI(52)
config.BumpMinF = assets.NewWeiI(150)
Expand Down

0 comments on commit 4a0d405

Please sign in to comment.