Skip to content

Commit

Permalink
Update mock
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Oct 9, 2024
1 parent 13de65e commit ef71d0f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package ocr3captest

type ConsensusInput[T any] struct {
Observation T
Observations []T
}
11 changes: 0 additions & 11 deletions pkg/workflows/sdk/testutils/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/workflows/sdk/testutils/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ef71d0f

Please sign in to comment.