Skip to content

Commit

Permalink
Merge branch 'main' into BCFR-967
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 authored Nov 7, 2024
2 parents add2419 + 3b320ad commit c9ac222
Show file tree
Hide file tree
Showing 21 changed files with 667 additions and 16 deletions.
25 changes: 25 additions & 0 deletions pkg/capabilities/consensus/ocr3/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestOCR3Capability(t *testing.T) {
"encoder_config": map[string]any{},
"encoder": "evm",
"report_id": "ffff",
"key_id": "evm",
},
)
require.NoError(t, err)
Expand Down Expand Up @@ -164,6 +165,7 @@ func TestOCR3Capability_Eviction(t *testing.T) {
"encoder_config": map[string]any{},
"encoder": "evm",
"report_id": "aaaa",
"key_id": "evm",
},
)
require.NoError(t, err)
Expand Down Expand Up @@ -231,6 +233,7 @@ func TestOCR3Capability_EvictionUsingConfig(t *testing.T) {
"encoder_config": map[string]any{},
"encoder": "evm",
"report_id": "aaaa",
"key_id": "evm",
"request_timeout_ms": 10000,
},
)
Expand Down Expand Up @@ -296,6 +299,7 @@ func TestOCR3Capability_Registration(t *testing.T) {
"encoder": "",
"encoder_config": map[string]any{},
"report_id": "000f",
"key_id": "evm",
})
require.NoError(t, err)

Expand Down Expand Up @@ -342,6 +346,7 @@ func TestOCR3Capability_ValidateConfig(t *testing.T) {
"encoder": "",
"encoder_config": map[string]any{},
"report_id": "aaaa",
"key_id": "evm",
})
require.NoError(t, err)

Expand All @@ -354,6 +359,7 @@ func TestOCR3Capability_ValidateConfig(t *testing.T) {
config, err := values.NewMap(map[string]any{
"aggregation_method": "data_feeds",
"report_id": "aaaa",
"key_id": "evm",
})
require.NoError(t, err)

Expand All @@ -370,6 +376,7 @@ func TestOCR3Capability_ValidateConfig(t *testing.T) {
"encoder": "",
"encoder_config": map[string]any{},
"report_id": "aa",
"key_id": "evm",
})
require.NoError(t, err)

Expand All @@ -378,6 +385,22 @@ func TestOCR3Capability_ValidateConfig(t *testing.T) {
assert.Contains(t, err.Error(), "does not match pattern") // taken from the error json schema error message
require.Nil(t, c)
})

t.Run("InvalidConfig no key_id", func(t *testing.T) {
config, err := values.NewMap(map[string]any{
"aggregation_method": "data_feeds",
"aggregation_config": map[string]any{},
"encoder": "",
"encoder_config": map[string]any{},
"report_id": "aaaa",
})
require.NoError(t, err)

c, err := o.ValidateConfig(config)
require.Error(t, err)
assert.Contains(t, err.Error(), "missing properties: 'key_id'") // taken from the error json schema error message
require.Nil(t, c)
})
}

func TestOCR3Capability_RespondsToLateRequest(t *testing.T) {
Expand All @@ -399,6 +422,7 @@ func TestOCR3Capability_RespondsToLateRequest(t *testing.T) {
"encoder_config": map[string]any{},
"encoder": "evm",
"report_id": "ffff",
"key_id": "evm",
},
)
require.NoError(t, err)
Expand Down Expand Up @@ -458,6 +482,7 @@ func TestOCR3Capability_RespondingToLateRequestDoesNotBlockOnSlowResponseConsume
"encoder_config": map[string]any{},
"encoder": "evm",
"report_id": "ffff",
"key_id": "evm",
},
)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/capabilities/consensus/ocr3/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type config struct {
ReportID string `mapstructure:"report_id" json:"report_id" jsonschema:"required,pattern=^[a-f0-9]{4}$"`
RequestTimeoutMS int64 `mapstructure:"request_timeout_ms" json:"request_timeout_ms"`

KeyID string `mapstructure:"key_id" json:"key_id"`
KeyID string `mapstructure:"key_id" json:"key_id,omitempty" jsonschema:"required"`
}

type inputs struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
"type": "object",
"additionalProperties": true
},
"key_id" : {
"type": "string",
"examples": [
"evm"
]
},
"report_id" : {
"type": "string",
"pattern": "^[a-f0-9]{4}$",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
"encoder_config": {
"$ref": "ocr3cap_common-schema.json#/$defs/encoder_config"
},
"key_id": {
"$ref": "ocr3cap_common-schema.json#/$defs/key_id"
},
"report_id": {
"$ref": "ocr3cap_common-schema.json#/$defs/report_id"
}
Expand All @@ -78,6 +81,7 @@
"aggregation_config",
"encoder",
"encoder_config",
"key_id",
"report_id"
]
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/capabilities/consensus/ocr3/transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestTransmitter(t *testing.T) {
"encoder": "",
"encoder_config": map[string]any{},
"report_id": hex.EncodeToString(repID),
"key_id": "evm",
})
require.NoError(t, err)

Expand Down Expand Up @@ -145,6 +146,7 @@ func TestTransmitter_ShouldReportFalse(t *testing.T) {
"encoder": "",
"encoder_config": map[string]any{},
"report_id": "aaff",
"key_id": "evm",
})
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions pkg/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func validate(v reflect.Value, checkInterface bool) (err error) {
for iter.Next() {
mk := iter.Key()
mv := iter.Value()
if !v.CanInterface() {
if !mv.CanInterface() {
continue
}
if mv.Kind() == reflect.Ptr && mv.IsNil() {
Expand All @@ -92,7 +92,7 @@ func validate(v reflect.Value, checkInterface bool) (err error) {
case reflect.Slice, reflect.Array:
for i := 0; i < v.Len(); i++ {
iv := v.Index(i)
if !v.CanInterface() {
if !iv.CanInterface() {
continue
}
if iv.Kind() == reflect.Ptr && iv.IsNil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,11 @@ func convertLimitAndSortToProto(limitAndSort query.LimitAndSort) (*pb.LimitAndSo
var tp pb.SortType

switch sort := sortBy.(type) {
case query.SortByBlock:
case query.SortByBlock, *query.SortByBlock:
tp = pb.SortType_SortBlock
case query.SortByTimestamp:
case query.SortByTimestamp, *query.SortByTimestamp:
tp = pb.SortType_SortTimestamp
case query.SortBySequence:
case query.SortBySequence, *query.SortBySequence:
tp = pb.SortType_SortSequence
default:
return &pb.LimitAndSort{}, status.Errorf(codes.InvalidArgument, "Unknown sort by type: %T", sort)
Expand Down Expand Up @@ -902,5 +902,7 @@ func convertSequencesFromProto(pbSequences []*pb.Sequence, sequenceDataType any)
}

func RegisterContractReaderService(s *grpc.Server, contractReader types.ContractReader) {
pb.RegisterServiceServer(s, &goplugin.ServiceServer{Srv: contractReader})
service := goplugin.ServiceServer{Srv: contractReader}
pb.RegisterServiceServer(s, &service)
pb.RegisterContractReaderServer(s, NewServer(contractReader))
}
5 changes: 5 additions & 0 deletions pkg/workflows/sdk/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type ModifiedConfig struct {
DefaultDeviation string `yaml:"default_deviation" json:"default_deviation"`
FeedInfo []FeedInfo `yaml:"feed_info" json:"feed_info"`
ReportID ocr3.ReportId `yaml:"report_id" json:"report_id"`
KeyID ocr3.KeyId `yaml:"key_id" json:"key_id"`
Encoder ocr3.Encoder
EncoderConfig ocr3.EncoderConfig `yaml:"encoder_config" json:"encoder_config"`
ChainWriter *chainwriter.TargetConfig
Expand All @@ -87,6 +88,7 @@ func NewWorkflowRemapped(rawConfig []byte) (*sdk.WorkflowSpecFactory, error) {
Encoder: conf.Encoder,
EncoderConfig: conf.EncoderConfig,
ReportId: conf.ReportID,
KeyId: conf.KeyID,
AggregationConfig: ocr3.DataFeedsConsensusConfigAggregationConfig{
AllowedPartialStaleness: conf.AllowedPartialStaleness,
},
Expand Down Expand Up @@ -167,6 +169,7 @@ func NewWorkflowSpecFromPrimitives(rawConfig []byte) (*sdk.WorkflowSpecFactory,
Encoder: conf.Ocr.Encoder,
EncoderConfig: conf.Ocr.EncoderConfig,
ReportId: conf.Ocr.ReportID,
KeyId: conf.Ocr.KeyID,
}

consensus := ocrConfig.New(workflow, "data-feeds-report", ocr3.DataFeedsConsensusInput{
Expand Down Expand Up @@ -263,6 +266,7 @@ func TestBuilder_ValidSpec(t *testing.T) {
"Abi": "(bytes32 FeedID, uint224 Price, uint32 Timestamp)[] Reports",
},
"report_id": "0001",
"key_id": "evm",
},
CapabilityType: capabilities.CapabilityTypeConsensus,
},
Expand Down Expand Up @@ -676,6 +680,7 @@ type ModifiedConsensusConfig struct {
Encoder ocr3.Encoder `json:"encoder" yaml:"encoder" mapstructure:"encoder"`
EncoderConfig ocr3.EncoderConfig `json:"encoder_config" yaml:"encoder_config" mapstructure:"encoder_config"`
ReportID ocr3.ReportId `json:"report_id" yaml:"report_id" mapstructure:"report_id"`
KeyID ocr3.KeyId `json:"key_id" yaml:"key_id" mapstructure:"key_id"`
}

func UnmarshalYaml[T any](raw []byte) (*T, error) {
Expand Down
Loading

0 comments on commit c9ac222

Please sign in to comment.