Skip to content

Commit

Permalink
Call GetBridge instead of NewBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
ogtownsend committed Jul 2, 2024
1 parent 347ee53 commit e5e25ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

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

3 changes: 1 addition & 2 deletions core/services/ocr2/plugins/liquiditymanager/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion core/services/ocr2/plugins/liquiditymanager/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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] {
Expand Down

0 comments on commit e5e25ac

Please sign in to comment.