Skip to content

Commit

Permalink
Stand alone median provider (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
george-dorin authored Nov 8, 2023
1 parent 6de9cc4 commit 37dec77
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/loop/internal/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,15 @@ func healthReport(s map[string]string) (hr map[string]error) {
}
return hr
}

// RegisterStandAloneMedianProvider register the servers needed for a median plugin provider,
// this is a workaround to test the Node API on EVM until the EVM relayer is loopifyed
func RegisterStandAloneMedianProvider(s *grpc.Server, p types.MedianProvider) {
pb.RegisterServiceServer(s, &serviceServer{srv: p})
pb.RegisterOffchainConfigDigesterServer(s, &offchainConfigDigesterServer{impl: p.OffchainConfigDigester()})
pb.RegisterContractConfigTrackerServer(s, &contractConfigTrackerServer{impl: p.ContractConfigTracker()})
pb.RegisterContractTransmitterServer(s, &contractTransmitterServer{impl: p.ContractTransmitter()})
pb.RegisterReportCodecServer(s, &reportCodecServer{impl: p.ReportCodec()})
pb.RegisterMedianContractServer(s, &medianContractServer{impl: p.MedianContract()})
pb.RegisterOnchainConfigCodecServer(s, &onchainConfigCodecServer{impl: p.OnchainConfigCodec()})
}
26 changes: 26 additions & 0 deletions pkg/loop/standalone_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package loop

import (
"fmt"

"google.golang.org/grpc"

"github.com/smartcontractkit/chainlink-relay/pkg/loop/internal"
"github.com/smartcontractkit/chainlink-relay/pkg/types"
)

// RegisterStandAloneProvider register the servers needed for a plugin provider,
// this is a workaround to test the Node API medianpoc on EVM until the EVM relayer is loopifyed
func RegisterStandAloneProvider(s *grpc.Server, p types.PluginProvider, pType types.OCR2PluginType) error {
switch pType {
case types.Median:
mp, ok := p.(types.MedianProvider)
if !ok {
return fmt.Errorf("expected median provider got %T", p)
}
internal.RegisterStandAloneMedianProvider(s, mp)
return nil
default:
return fmt.Errorf("stand alone provider only supports median, got %q", pType)
}
}
28 changes: 28 additions & 0 deletions pkg/loop/standalone_provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package loop_test

import (
"testing"

"github.com/stretchr/testify/require"
"google.golang.org/grpc"

"github.com/smartcontractkit/chainlink-relay/pkg/loop"
"github.com/smartcontractkit/chainlink-relay/pkg/loop/internal/test"
)

func TestRegisterStandAloneProvider(t *testing.T) {
s := grpc.NewServer()

p := test.StaticPluginProvider{}
err := loop.RegisterStandAloneProvider(s, p, "some-type-we-do-not-support")
require.ErrorContains(t, err, "stand alone provider only supports median")

err = loop.RegisterStandAloneProvider(s, p, "median")
require.ErrorContains(t, err, "expected median provider got")

stopCh := newStopCh(t)
pr := newPluginRelayerExec(t, stopCh)
mp := newMedianProvider(t, pr)
err = loop.RegisterStandAloneProvider(s, mp, "median")
require.NoError(t, err)
}

0 comments on commit 37dec77

Please sign in to comment.