Skip to content

Commit

Permalink
Move KeySpecific field (#9694)
Browse files Browse the repository at this point in the history
* Move KeySpecific field

* Fix test

* Fix test

* Change KeySpecificMaxPrice to MaxPriceKey

* Change MaxPriceKey to PriceMaxKey
  • Loading branch information
george-dorin committed Jul 10, 2023
1 parent b698a3f commit ea29e8f
Show file tree
Hide file tree
Showing 23 changed files with 470 additions and 182 deletions.
3 changes: 2 additions & 1 deletion core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type EVM interface {
ChainType() config.ChainType
FinalityDepth() uint32
FlagsContractAddress() string
KeySpecificMaxGasPriceWei(addr gethcommon.Address) *assets.Wei
LinkContractAddress() string
LogBackfillBatchSize() uint32
LogKeepBlocksDepth() uint32
Expand Down Expand Up @@ -74,6 +73,7 @@ type Transactions interface {
MaxQueued() uint64
}

//go:generate mockery --quiet --name GasEstimator --output ./mocks/ --case=underscore
type GasEstimator interface {
BlockHistory() BlockHistory
LimitJobType() LimitJobType
Expand All @@ -94,6 +94,7 @@ type GasEstimator interface {
PriceMax() *assets.Wei
PriceMin() *assets.Wei
Mode() string
PriceMaxKey(gethcommon.Address) *assets.Wei
}

type LimitJobType interface {
Expand Down
18 changes: 9 additions & 9 deletions core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestChainScopedConfig(t *testing.T) {
})
})

t.Run("KeySpecificMaxGasPriceWei", func(t *testing.T) {
t.Run("PriceMaxKey", func(t *testing.T) {
addr := testutils.NewAddress()
randomOtherAddr := testutils.NewAddress()
gcfg2 := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
Expand All @@ -97,7 +97,7 @@ func TestChainScopedConfig(t *testing.T) {
cfg2 := evmtest.NewChainScopedConfig(t, gcfg2)

t.Run("uses chain-specific default value when nothing is set", func(t *testing.T) {
assert.Equal(t, assets.NewWeiI(100000000000000), cfg2.EVM().KeySpecificMaxGasPriceWei(addr))
assert.Equal(t, assets.NewWeiI(100000000000000), cfg2.EVM().GasEstimator().PriceMaxKey(addr))
})

t.Run("uses chain-specific override value when that is set", func(t *testing.T) {
Expand All @@ -107,7 +107,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, val.String(), cfg3.EVM().KeySpecificMaxGasPriceWei(addr).String())
assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses key-specific override value when set", func(t *testing.T) {
val := assets.GWei(250)
Expand All @@ -122,7 +122,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, val.String(), cfg3.EVM().KeySpecificMaxGasPriceWei(addr).String())
assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses key-specific override value when set and lower than chain specific config", func(t *testing.T) {
keySpecificPrice := assets.GWei(900)
Expand All @@ -139,7 +139,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, keySpecificPrice.String(), cfg3.EVM().KeySpecificMaxGasPriceWei(addr).String())
assert.Equal(t, keySpecificPrice.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses chain-specific value when higher than key-specific value", func(t *testing.T) {
keySpecificPrice := assets.GWei(1400)
Expand All @@ -156,7 +156,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, chainSpecificPrice.String(), cfg3.EVM().KeySpecificMaxGasPriceWei(addr).String())
assert.Equal(t, chainSpecificPrice.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses key-specific override value when set and lower than global config", func(t *testing.T) {
keySpecificPrice := assets.GWei(900)
Expand All @@ -171,7 +171,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, keySpecificPrice.String(), cfg3.EVM().KeySpecificMaxGasPriceWei(addr).String())
assert.Equal(t, keySpecificPrice.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses global value when higher than key-specific value", func(t *testing.T) {
keySpecificPrice := assets.GWei(1400)
Expand All @@ -188,7 +188,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, chainSpecificPrice.String(), cfg3.EVM().KeySpecificMaxGasPriceWei(addr).String())
assert.Equal(t, chainSpecificPrice.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses global value when there is no key-specific price", func(t *testing.T) {
val := assets.NewWeiI(rand.Int63())
Expand All @@ -198,7 +198,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, val.String(), cfg3.EVM().KeySpecificMaxGasPriceWei(unsetAddr).String())
assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().PriceMaxKey(unsetAddr).String())
})
})

Expand Down
Loading

0 comments on commit ea29e8f

Please sign in to comment.