Skip to content

Commit

Permalink
Add standalone plugin provider (#350)
Browse files Browse the repository at this point in the history
* Add standalone plugin provider

* -Clean up PR
-Add test

---------

Co-authored-by: george-dorin <[email protected]>
  • Loading branch information
cedric-cordenier and george-dorin authored Feb 19, 2024
1 parent 17b9ec0 commit 85226a0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
11 changes: 11 additions & 0 deletions pkg/loop/internal/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,14 @@ func RegisterStandAloneMedianProvider(s *grpc.Server, p types.MedianProvider) {
pb.RegisterMedianContractServer(s, &medianContractServer{impl: p.MedianContract()})
pb.RegisterOnchainConfigCodecServer(s, &onchainConfigCodecServer{impl: p.OnchainConfigCodec()})
}

// RegisterStandAlonePluginProvider register the servers needed for a generic plugin provider,
// this is a workaround to test the Node API on EVM until the EVM relayer is loopifyed
func RegisterStandAlonePluginProvider(s *grpc.Server, p types.PluginProvider) {
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.RegisterChainReaderServer(s, &chainReaderServer{impl: p.ChainReader()})
pb.RegisterCodecServer(s, &codecServer{impl: p.Codec()})
}
13 changes: 13 additions & 0 deletions pkg/loop/plugin_median_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,16 @@ func newMedianProvider(t *testing.T, pr loop.PluginRelayer) types.MedianProvider
servicetest.Run(t, mp)
return mp
}

func newGenericPluginProvider(t *testing.T, pr loop.PluginRelayer) types.PluginProvider {
ctx := context.Background()
r, err := pr.NewRelayer(ctx, test.ConfigTOML, test.StaticKeystore{})
require.NoError(t, err)
servicetest.Run(t, r)
ra := test.RelayArgs
ra.ProviderType = string(types.GenericPlugin)
p, err := r.NewPluginProvider(ctx, ra, test.PluginArgs)
require.NoError(t, err)
servicetest.Run(t, p)
return p
}
11 changes: 7 additions & 4 deletions pkg/loop/standalone_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import (
)

// 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
// this is a workaround to test the Node API POCs 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)
provider, ok := p.(types.MedianProvider)
if !ok {
return fmt.Errorf("expected median provider got %T", p)
}
internal.RegisterStandAloneMedianProvider(s, mp)
internal.RegisterStandAloneMedianProvider(s, provider)
return nil
case types.GenericPlugin:
internal.RegisterStandAlonePluginProvider(s, p)
return nil
default:
return fmt.Errorf("stand alone provider only supports median, got %q", pType)
return fmt.Errorf("unsupported stand alone provider: %q", pType)
}
}
14 changes: 12 additions & 2 deletions pkg/loop/standalone_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/test"
)

func TestRegisterStandAloneProvider(t *testing.T) {
func TestRegisterStandAloneProvider_Median(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")
require.ErrorContains(t, err, "unsupported stand alone provider")

err = loop.RegisterStandAloneProvider(s, p, "median")
require.ErrorContains(t, err, "expected median provider got")
Expand All @@ -26,3 +26,13 @@ func TestRegisterStandAloneProvider(t *testing.T) {
err = loop.RegisterStandAloneProvider(s, mp, "median")
require.NoError(t, err)
}

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

stopCh := newStopCh(t)
pr := newPluginRelayerExec(t, false, stopCh)
gp := newGenericPluginProvider(t, pr)
err := loop.RegisterStandAloneProvider(s, gp, "plugin")
require.NoError(t, err)
}

0 comments on commit 85226a0

Please sign in to comment.