From f52621c20b60175cde17fd972b75a6716cd05a80 Mon Sep 17 00:00:00 2001 From: Oliver Townsend Date: Thu, 27 Jun 2024 11:52:18 -0700 Subject: [PATCH] Call GetBridge instead of NewBridge --- .../plugins/liquiditymanager/bridge/bridge.go | 1 + .../bridge/mocks/bridge_factory_mock.go | 30 +++++++++++++++++++ .../ocr2/plugins/liquiditymanager/plugin.go | 3 +- .../plugins/liquiditymanager/plugin_test.go | 3 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/core/services/ocr2/plugins/liquiditymanager/bridge/bridge.go b/core/services/ocr2/plugins/liquiditymanager/bridge/bridge.go index 1085ca59765..24af25c48e7 100644 --- a/core/services/ocr2/plugins/liquiditymanager/bridge/bridge.go +++ b/core/services/ocr2/plugins/liquiditymanager/bridge/bridge.go @@ -61,6 +61,7 @@ type Bridge interface { //go:generate mockery --name Factory --output ./mocks --filename bridge_factory_mock.go --case=underscore type Factory interface { NewBridge(ctx context.Context, source, dest models.NetworkSelector) (Bridge, error) + GetBridge(source, dest models.NetworkSelector) (Bridge, error) } type Opt func(c *factory) diff --git a/core/services/ocr2/plugins/liquiditymanager/bridge/mocks/bridge_factory_mock.go b/core/services/ocr2/plugins/liquiditymanager/bridge/mocks/bridge_factory_mock.go index 32b2d823778..53f1bf86cd2 100644 --- a/core/services/ocr2/plugins/liquiditymanager/bridge/mocks/bridge_factory_mock.go +++ b/core/services/ocr2/plugins/liquiditymanager/bridge/mocks/bridge_factory_mock.go @@ -17,6 +17,36 @@ type Factory struct { mock.Mock } +// GetBridge provides a mock function with given fields: source, dest +func (_m *Factory) GetBridge(source models.NetworkSelector, dest models.NetworkSelector) (bridge.Bridge, error) { + ret := _m.Called(source, dest) + + if len(ret) == 0 { + panic("no return value specified for GetBridge") + } + + var r0 bridge.Bridge + var r1 error + if rf, ok := ret.Get(0).(func(models.NetworkSelector, models.NetworkSelector) (bridge.Bridge, error)); ok { + return rf(source, dest) + } + if rf, ok := ret.Get(0).(func(models.NetworkSelector, models.NetworkSelector) bridge.Bridge); ok { + r0 = rf(source, dest) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(bridge.Bridge) + } + } + + if rf, ok := ret.Get(1).(func(models.NetworkSelector, models.NetworkSelector) error); ok { + r1 = rf(source, dest) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // NewBridge provides a mock function with given fields: ctx, source, dest func (_m *Factory) NewBridge(ctx context.Context, source models.NetworkSelector, dest models.NetworkSelector) (bridge.Bridge, error) { ret := _m.Called(ctx, source, dest) diff --git a/core/services/ocr2/plugins/liquiditymanager/plugin.go b/core/services/ocr2/plugins/liquiditymanager/plugin.go index a2ef60744b5..99171960618 100644 --- a/core/services/ocr2/plugins/liquiditymanager/plugin.go +++ b/core/services/ocr2/plugins/liquiditymanager/plugin.go @@ -607,8 +607,7 @@ func (p *Plugin) computeResolvedTransfersQuorum(observations []models.Observatio } medianizedNativeFee := rebalcalc.BigIntSortedMiddle(bridgeFees) medianizedDateUnix := rebalcalc.BigIntSortedMiddle(datesUnix) - // TODO (ogtownsend): should we set an explicit timeout on this context? - bridge, err := p.bridgeFactory.NewBridge(context.Background(), k.From, k.To) + bridge, err := p.bridgeFactory.GetBridge(k.From, k.To) if err != nil { return nil, fmt.Errorf("init bridge: %w", err) } diff --git a/core/services/ocr2/plugins/liquiditymanager/plugin_test.go b/core/services/ocr2/plugins/liquiditymanager/plugin_test.go index 90727270f7a..aeb05010839 100644 --- a/core/services/ocr2/plugins/liquiditymanager/plugin_test.go +++ b/core/services/ocr2/plugins/liquiditymanager/plugin_test.go @@ -660,7 +660,7 @@ func TestPlugin_Outcome(t *testing.T) { for sourceDest, bridgeFn := range tc.bridges { br, err := bridgeFn(t) p.bridgeFactory. - On("NewBridge", mock.Anything /* cancelContext */, sourceDest[0], sourceDest[1]). + On("GetBridge", sourceDest[0], sourceDest[1]). Return(br, err) } @@ -1136,6 +1136,7 @@ func TestPlugin_E2EWithMocks(t *testing.T) { br, ok := n.bridges[[2]models.NetworkSelector{edge.Source, edge.Dest}] require.True(t, ok, "the test case is wrong, bridge is not defined %d->%d", edge.Source, edge.Dest) n.bridgeFactory.On("NewBridge", mock.Anything /* cancelContext */, edge.Source, edge.Dest).Return(br, nil).Maybe() + n.bridgeFactory.On("GetBridge", edge.Source, edge.Dest).Return(br, nil).Maybe() pendingTransfers := make([]models.PendingTransfer, 0) for _, tr := range round.pendingTransfersPerNode[i] {