diff --git a/pkg/loop/internal/relayer.go b/pkg/loop/internal/relayer.go index 86824d559..c0287ef87 100644 --- a/pkg/loop/internal/relayer.go +++ b/pkg/loop/internal/relayer.go @@ -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()}) +} diff --git a/pkg/loop/standalone_provider.go b/pkg/loop/standalone_provider.go new file mode 100644 index 000000000..2c9ebb5e6 --- /dev/null +++ b/pkg/loop/standalone_provider.go @@ -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) + } +} diff --git a/pkg/loop/standalone_provider_test.go b/pkg/loop/standalone_provider_test.go new file mode 100644 index 000000000..fc0021daf --- /dev/null +++ b/pkg/loop/standalone_provider_test.go @@ -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) +}