From ef71d0f9ffaf553722c65b80f6cb6efc1c20c345 Mon Sep 17 00:00:00 2001 From: Cedric Cordenier Date: Wed, 9 Oct 2024 19:12:40 +0100 Subject: [PATCH] Update mock --- .../ocr3cap/ocr3captest/identical_consensus.go | 14 +++----------- .../ocr3/ocr3cap/ocr3captest/observations.go | 2 +- pkg/workflows/sdk/testutils/runner.go | 11 ----------- pkg/workflows/sdk/testutils/runner_test.go | 2 +- 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/pkg/capabilities/consensus/ocr3/ocr3cap/ocr3captest/identical_consensus.go b/pkg/capabilities/consensus/ocr3/ocr3cap/ocr3captest/identical_consensus.go index b20e25962..b5a3420c6 100644 --- a/pkg/capabilities/consensus/ocr3/ocr3cap/ocr3captest/identical_consensus.go +++ b/pkg/capabilities/consensus/ocr3/ocr3cap/ocr3captest/identical_consensus.go @@ -3,6 +3,7 @@ package ocr3captest import ( "google.golang.org/protobuf/proto" + "github.com/smartcontractkit/chainlink-common/pkg/capabilities" "github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/ocr3cap" "github.com/smartcontractkit/chainlink-common/pkg/values" "github.com/smartcontractkit/chainlink-common/pkg/values/pb" @@ -30,7 +31,7 @@ func IdenticalConsensusForStep[T any](runner *testutils.Runner, step string) *Id } func identicalConsensus[T any](inputs ConsensusInput[T]) (ocr3cap.SignedReport, error) { - wrapped, err := values.Wrap(inputs.Observation) + wrapped, err := values.Wrap(inputs.Observations[0]) if err != nil { return ocr3cap.SignedReport{}, err } @@ -55,16 +56,7 @@ type IdenticalConsensusMock[T any] struct { *testutils.Mock[ConsensusInput[T], ocr3cap.SignedReport] } -var _ testutils.ConsensusMock = &IdenticalConsensusMock[struct{}]{} - -func (c *IdenticalConsensusMock[T]) SingleToManyObservations(input values.Value) (*values.Map, error) { - tmp := ConsensusInput[T]{} - if err := input.UnwrapTo(&tmp); err != nil { - return nil, err - } - - return values.CreateMapFromStruct(tmp) -} +var _ capabilities.ConsensusCapability = &IdenticalConsensusMock[struct{}]{} func (c *IdenticalConsensusMock[T]) GetStepDecoded(ref string) testutils.StepResults[ConsensusInput[T], T] { step := c.GetStep(ref) diff --git a/pkg/capabilities/consensus/ocr3/ocr3cap/ocr3captest/observations.go b/pkg/capabilities/consensus/ocr3/ocr3cap/ocr3captest/observations.go index ef6d1b118..a136d9cd9 100644 --- a/pkg/capabilities/consensus/ocr3/ocr3cap/ocr3captest/observations.go +++ b/pkg/capabilities/consensus/ocr3/ocr3cap/ocr3captest/observations.go @@ -1,5 +1,5 @@ package ocr3captest type ConsensusInput[T any] struct { - Observation T + Observations []T } diff --git a/pkg/workflows/sdk/testutils/runner.go b/pkg/workflows/sdk/testutils/runner.go index 125b666bb..aa3c7c35a 100644 --- a/pkg/workflows/sdk/testutils/runner.go +++ b/pkg/workflows/sdk/testutils/runner.go @@ -25,11 +25,6 @@ func NewRunner(ctx context.Context) *Runner { } } -type ConsensusMock interface { - capabilities.ConsensusCapability - SingleToManyObservations(value values.Value) (*values.Map, error) -} - type Runner struct { RawConfig []byte // Context is held in this runner because it's for testing and capability calls are made by it. @@ -173,12 +168,6 @@ func (r *Runner) walk(spec sdk.WorkflowSpec, ref string) error { return err } - if c, ok := mock.(ConsensusMock); ok { - if request.Inputs, err = c.SingleToManyObservations(request.Inputs); err != nil { - return err - } - } - results, err := mock.Execute(r.ctx, request) if err != nil { return err diff --git a/pkg/workflows/sdk/testutils/runner_test.go b/pkg/workflows/sdk/testutils/runner_test.go index 69ab73230..555e1f5c7 100644 --- a/pkg/workflows/sdk/testutils/runner_test.go +++ b/pkg/workflows/sdk/testutils/runner_test.go @@ -54,7 +54,7 @@ func TestRunner(t *testing.T) { assert.True(t, helper.transformTriggerCalled) consensus := consensusMock.GetStepDecoded("consensus") assert.Equal(t, "it was true", consensus.Output.AdaptedThing) - require.NotNil(t, consensus.Input.Observation) + require.NotNil(t, consensus.Input.Observations[0]) rawConsensus := consensusMock.GetStep("consensus") target := targetMock.GetAllWrites()