Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed Feb 27, 2023
1 parent dd078be commit 68f7dad
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 19 deletions.
137 changes: 137 additions & 0 deletions core/chains/evm/gas/mocks/fee_estimator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions core/chains/evm/gas/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type EvmFee struct {
Dynamic *DynamicFee
}

// Estimator provides an interface that wraps the EVM specific dynamic and legacy estimators into one estimator
//
//go:generate mockery --quiet --name FeeEstimator --output ./mocks/ --case=underscore
type FeeEstimator interface {
OnNewLongestChain(context.Context, *evmtypes.Head)
Start(context.Context) error
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/txmgr/eth_broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi
chStartEstimate := make(chan struct{})
chBlock := make(chan struct{})

estimator := gasmocks.NewEstimator(t)
estimator.On("GetLegacyGas", mock.Anything, mock.Anything, mock.Anything, evmcfg.KeySpecificMaxGasPriceWei(fromAddress)).Return(assets.GWei(32), uint32(500), nil).Run(func(_ mock.Arguments) {
estimator := gasmocks.NewFeeEstimator(t)
estimator.On("GetFee", mock.Anything, mock.Anything, mock.Anything, evmcfg.KeySpecificMaxGasPriceWei(fromAddress)).Return(gas.EvmFee{Legacy: assets.GWei(32)}, uint32(500), nil).Run(func(_ mock.Arguments) {
close(chStartEstimate)
<-chBlock
})
Expand Down Expand Up @@ -1140,7 +1140,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) {
t.Cleanup(func() { assert.NoError(t, eventBroadcaster.Close()) })
lggr := logger.TestLogger(t)
eb := txmgr.NewEthBroadcaster(db, ethClient, evmcfg, ethKeyStore, eventBroadcaster,
[]ethkey.State{keyState}, gas.NewFixedPriceEstimator(evmcfg, lggr), fn, lggr,
[]ethkey.State{keyState}, gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(evmcfg, lggr), evmcfg), fn, lggr,
&testCheckerFactory{}, false)

{
Expand Down Expand Up @@ -1887,7 +1887,7 @@ func TestEthBroadcaster_SyncNonce(t *testing.T) {
sub.On("Events").Return(make(<-chan pg.Event))
sub.On("Close")
eventBroadcaster.On("Subscribe", "insert_on_eth_txes", "").Return(sub, nil)
estimator := gas.NewFixedPriceEstimator(evmcfg, lggr)
estimator := gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(evmcfg, lggr), evmcfg)
checkerFactory := &testCheckerFactory{}

t.Run("does nothing if nonce sync is disabled", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/eth_confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type EthConfirmer struct {
}

// NewEthConfirmer instantiates a new eth confirmer
func NewEthConfirmer(orm ORM ethClient evmclient.Client, config Config, keystore KeyStore,
func NewEthConfirmer(orm ORM, ethClient evmclient.Client, config Config, keystore KeyStore,
keyStates []ethkey.State, estimator gas.FeeEstimator, resumeCallback ResumeCallback, lggr logger.Logger) *EthConfirmer {

ctx, cancel := context.WithCancel(context.Background())
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/txmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func newMockConfig(t *testing.T) *txmmocks.Config {
cfg.On("BlockHistoryEstimatorBlockHistorySize").Return(uint16(42)).Maybe().Once()
cfg.On("BlockHistoryEstimatorEIP1559FeeCapBufferBlocks").Return(uint16(42)).Maybe().Once()
cfg.On("BlockHistoryEstimatorTransactionPercentile").Return(uint16(42)).Maybe().Once()
cfg.On("EvmEIP1559DynamicFees").Return(false).Maybe().Once()
cfg.On("EvmEIP1559DynamicFees").Return(false).Maybe().Twice()
cfg.On("EvmGasBumpPercent").Return(uint16(42)).Maybe().Once()
cfg.On("EvmGasBumpThreshold").Return(uint64(42)).Maybe()
cfg.On("EvmGasBumpWei").Return(assets.NewWeiI(42)).Maybe().Once()
Expand Down
4 changes: 2 additions & 2 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func NewEthBroadcaster(t testing.TB, db *sqlx.DB, ethClient evmclient.Client, ke
t.Cleanup(func() { assert.NoError(t, eventBroadcaster.Close()) })
lggr := logger.TestLogger(t)
return txmgr.NewEthBroadcaster(db, ethClient, config, keyStore, eventBroadcaster,
keyStates, gas.NewFixedPriceEstimator(config, lggr), nil, lggr,
keyStates, gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(config, lggr), config), nil, lggr,
checkerFactory, nonceAutoSync)
}

Expand All @@ -221,7 +221,7 @@ func NewEthConfirmer(t testing.TB, orm txmgr.ORM, ethClient evmclient.Client, co
t.Helper()
lggr := logger.TestLogger(t)
ec := txmgr.NewEthConfirmer(orm, ethClient, config, ks, keyStates,
gas.NewFixedPriceEstimator(config, lggr), fn, lggr)
gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(config, lggr), config), fn, lggr)
return ec
}

Expand Down
8 changes: 4 additions & 4 deletions core/internal/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,10 +1379,10 @@ func TestIntegration_BlockHistoryEstimator(t *testing.T) {

chain := evmtest.MustGetDefaultChain(t, cc)
estimator := chain.TxManager().GetGasEstimator()
gasPrice, gasLimit, err := estimator.GetLegacyGas(testutils.Context(t), nil, 500_000, maxGasPrice)
gasPrice, gasLimit, err := estimator.GetFee(testutils.Context(t), nil, 500_000, maxGasPrice)
require.NoError(t, err)
assert.Equal(t, uint32(500000), gasLimit)
assert.Equal(t, "41.5 gwei", gasPrice.String())
assert.Equal(t, "41.5 gwei", gasPrice.Legacy.String())
assert.Equal(t, initialDefaultGasPrice, chain.Config().EvmGasPriceDefault().Int64()) // unchanged

// BlockHistoryEstimator new blocks
Expand All @@ -1401,9 +1401,9 @@ func TestIntegration_BlockHistoryEstimator(t *testing.T) {
newHeads.TrySend(cltest.Head(43))

gomega.NewWithT(t).Eventually(func() string {
gasPrice, _, err := estimator.GetLegacyGas(testutils.Context(t), nil, 500000, maxGasPrice)
gasPrice, _, err := estimator.GetFee(testutils.Context(t), nil, 500000, maxGasPrice)
require.NoError(t, err)
return gasPrice.String()
return gasPrice.Legacy.String()
}, testutils.WaitTimeout(t), cltest.DBPollingInterval).Should(gomega.Equal("45 gwei"))
}

Expand Down
15 changes: 8 additions & 7 deletions core/services/keeper/upkeep_executer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ func newHead() evmtypes.Head {
return evmtypes.NewHead(big.NewInt(20), utils.NewHash(), utils.NewHash(), 1000, utils.NewBigI(0))
}

func mockEstimator(t *testing.T) (estimator *gasmocks.Estimator) {
estimator = gasmocks.NewEstimator(t)
estimator.On("GetLegacyGas", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe().Return(assets.GWei(60), uint32(0), nil)
estimator.On("GetDynamicFee", mock.Anything, mock.Anything, mock.Anything).Maybe().Return(gas.DynamicFee{
FeeCap: assets.GWei(60),
TipCap: assets.GWei(60),
func mockEstimator(t *testing.T) (estimator *gasmocks.FeeEstimator) {
// note: estimator will only return 1 of legacy or dynamic fees (not both)
// assumed to call legacy estimator only
estimator = gasmocks.NewFeeEstimator(t)
estimator.On("GetFee", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe().Return(gas.EvmFee{
Legacy: assets.GWei(60),
Dynamic: nil,
}, uint32(60), nil)
return
}

func setup(t *testing.T, estimator *gasmocks.Estimator, overrideFn func(c *chainlink.Config, s *chainlink.Secrets)) (
func setup(t *testing.T, estimator *gasmocks.FeeEstimator, overrideFn func(c *chainlink.Config, s *chainlink.Secrets)) (
*sqlx.DB,
config.GeneralConfig,
*evmmocks.Client,
Expand Down

0 comments on commit 68f7dad

Please sign in to comment.