Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 1 addition & 70 deletions pkg/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,66 +357,6 @@ type TriggerEvent struct {

// Trigger-specific payload for no DAG workflows
Payload *anypb.Any

// Deprecated: use Outputs instead
// TODO: remove after core services are updated (pending https://github.com/smartcontractkit/chainlink/pull/16950)
OCREvent *OCRTriggerEvent
}

type OCRTriggerEvent struct {
ConfigDigest []byte
SeqNr uint64
Report []byte // marshaled pb.OCRTriggerReport
Sigs []OCRAttributedOnchainSignature
}

// DO NOT change this. it is in the encoding of [TriggerEvent].Outputs
//
// TODO: a more sophisticated way to handle this would be to have add this const
// in the protobuf definition of the TriggerEvent struct.
const ocrTriggerEventOutputKey = "OCRTriggerEvent"

func (e *OCRTriggerEvent) topLevelKey() string {
return ocrTriggerEventOutputKey
}

// ToMap converts the OCRTriggerEvent to a map.
// This is useful serialization purposes with the [TriggerEvent] struct.
func (e *OCRTriggerEvent) ToMap() (*values.Map, error) {
x, err := values.Wrap(e)
if err != nil {
return nil, fmt.Errorf("failed to wrap OCRTriggerEvent: %w", err)
}
return values.NewMap(map[string]any{
e.topLevelKey(): x,
})
}

// FromMap converts a map to an OCRTriggerEvent.
// This is useful deserialization purposes with the [TriggerEvent] struct.
func (e *OCRTriggerEvent) FromMap(m *values.Map) error {
if m == nil {
return errors.New("nil map")
}
if m.Underlying == nil {
return errors.New("nil underlying map")
}
val, ok := m.Underlying[e.topLevelKey()]
if !ok {
return fmt.Errorf("missing key: %s", e.topLevelKey())
}
var unwrapped OCRTriggerEvent
err := val.UnwrapTo(&unwrapped)
if err != nil {
return fmt.Errorf("failed to unwrap OCRTriggerEvent: %w", err)
}
*e = unwrapped
return nil
}

type OCRAttributedOnchainSignature struct {
Signature []byte
Signer uint32 // oracle ID (0,1,...,N-1)
}

type TriggerExecutable interface {
Expand Down Expand Up @@ -652,13 +592,7 @@ type RemoteTriggerConfig struct {
BatchCollectionPeriod time.Duration
}

type RemoteTargetConfig struct { // deprecated - v1 only
RequestHashExcludedAttributes []string
}

type RemoteExecutableConfig struct {
RequestHashExcludedAttributes []string // deprecated - v1 only

// Fields below are used only by v2 capabilities
TransmissionSchedule TransmissionSchedule
DeltaStage time.Duration
Expand Down Expand Up @@ -742,10 +676,7 @@ type CapabilityConfiguration struct {
RestrictedKeys []string
// RestrictedConfig is configuration that can only be set by us; this
// takes precedence over any user-provided config.
RestrictedConfig *values.Map
Comment thread
bolekk marked this conversation as resolved.
RemoteTriggerConfig *RemoteTriggerConfig
RemoteTargetConfig *RemoteTargetConfig
RemoteExecutableConfig *RemoteExecutableConfig
RestrictedConfig *values.Map

// v2 / "NoDAG" capabilities - config for Don2Don framework.
CapabilityMethodConfig map[string]CapabilityMethodConfig
Expand Down
118 changes: 0 additions & 118 deletions pkg/capabilities/capabilities_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package capabilities

import (
"bytes"
"context"
"encoding/hex"
"errors"
Expand Down Expand Up @@ -161,123 +160,6 @@ func Test_RemoteExecutableConfig_ApplyDefaults(t *testing.T) {
assert.Equal(t, DefaultServerMaxParallelRequests, rec.ServerMaxParallelRequests)
}

func TestOCRTriggerEvent_ToMapFromMap(t *testing.T) {
// Create test signatures
sigs := []OCRAttributedOnchainSignature{
{
Signature: []byte("first_signature_data"),
Signer: 1,
},
{
Signature: []byte("second_signature_data"),
Signer: 2,
},
{
Signature: []byte("third_signature_data"),
Signer: 3,
},
}

testCases := []struct {
name string
event *OCRTriggerEvent
}{
{
name: "typical event with all fields populated",
event: &OCRTriggerEvent{
ConfigDigest: []byte("test_config_digest_data"),
SeqNr: 123456789,
Report: []byte("marshaled_report_payload_data"),
Sigs: sigs,
},
},

{
name: "event with empty slices",
event: &OCRTriggerEvent{
ConfigDigest: []byte{},
SeqNr: 987654321,
Report: []byte{},
Sigs: []OCRAttributedOnchainSignature{},
},
},
{
name: "event with nil slices",
event: &OCRTriggerEvent{
ConfigDigest: nil,
SeqNr: 555555,
Report: nil,
Sigs: nil,
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Convert the original event to a values.Map
valueMap, err := tc.event.ToMap()
require.NoError(t, err, "ToMap should not error")
require.NotNil(t, valueMap, "ToMap should return a non-nil map")

// Create a new empty event
reconstructedEvent := &OCRTriggerEvent{}

// Convert the values.Map back to an event
err = reconstructedEvent.FromMap(valueMap)
require.NoError(t, err, "FromMap should not error")

// Validate that the reconstructed event matches the original
assert.Equal(t, tc.event.SeqNr, reconstructedEvent.SeqNr, "SeqNr should match")

// Compare byte slices
assert.True(t, bytes.Equal(tc.event.ConfigDigest, reconstructedEvent.ConfigDigest),
"ConfigDigest should match")
assert.True(t, bytes.Equal(tc.event.Report, reconstructedEvent.Report),
"Report should match")

// Compare signatures
assert.Len(t, reconstructedEvent.Sigs, len(tc.event.Sigs),
"Number of signatures should match")

for i := 0; i < len(tc.event.Sigs); i++ {
if i < len(reconstructedEvent.Sigs) {
assert.Equal(t, tc.event.Sigs[i].Signer, reconstructedEvent.Sigs[i].Signer,
"Signature signer should match at index %d", i)
assert.True(t, bytes.Equal(tc.event.Sigs[i].Signature, reconstructedEvent.Sigs[i].Signature),
"Signature data should match at index %d", i)
}
}
})
}

// Test error handling

t.Run("invalid map missing key", func(t *testing.T) {
invalidMap, err := values.NewMap(map[string]any{
"WrongKey": "value",
})
require.NoError(t, err)

event := &OCRTriggerEvent{}
err = event.FromMap(invalidMap)
assert.Error(t, err)
assert.Contains(t, err.Error(), "missing key")
})

t.Run("nil map", func(t *testing.T) {
event := &OCRTriggerEvent{}
err := event.FromMap(nil)
assert.ErrorContains(t, err, "nil map")
})
t.Run("nil underlying map", func(t *testing.T) {
event := &OCRTriggerEvent{}
err := event.FromMap(&values.Map{
Underlying: nil,
})
assert.ErrorContains(t, err, "nil underlying map")
})
}

func TestParseID(t *testing.T) {
for _, tc := range []struct {
id string
Expand Down
Loading
Loading