Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Jul 24, 2024
1 parent 39246c1 commit b624b38
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
6 changes: 2 additions & 4 deletions pkg/capabilities/consensus/ocr3/reporting_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ func TestReportingPlugin_Reports_ShouldReportFalse(t *testing.T) {
assert.Len(t, gotRep.Report, 0)

ib := gotRep.Info
info := &pbtypes.ReportInfo{}
err = proto.Unmarshal(ib, info)
info, err := extractReportInfo(ib)
require.NoError(t, err)

assert.EqualExportedValues(t, info.Id, id)
Expand Down Expand Up @@ -397,8 +396,7 @@ func TestReportingPlugin_Reports_ShouldReportTrue(t *testing.T) {
require.Equal(t, nm, fp)

ib := gotRep.Info
info := &pbtypes.ReportInfo{}
err = proto.Unmarshal(ib, info)
info, err := extractReportInfo(ib)
require.NoError(t, err)

assert.EqualExportedValues(t, info.Id, id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
},
"request_timeout_ms": {
"type": "integer"
},
"key_id": {
"type": "string"
}
},
"additionalProperties": false,
Expand All @@ -53,7 +56,8 @@
"encoder",
"encoder_config",
"report_id",
"request_timeout_ms"
"request_timeout_ms",
"key_id"
]
},
"inputs": {
Expand Down
15 changes: 9 additions & 6 deletions pkg/capabilities/consensus/ocr3/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package ocr3

import (
"context"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"

"github.com/smartcontractkit/libocr/offchainreporting2/types"
Expand Down Expand Up @@ -41,21 +43,22 @@ func extractReportInfo(data []byte) (*pbtypes.ReportInfo, error) {

im := info.AsMap()
ri, ok := im["reportInfo"]
if ok {
return nil, err
if !ok {
return nil, errors.New("could not fetch reportInfo from structpb")
}

rib, ok := ri.([]byte)
ris, ok := ri.(string)
if !ok {
return nil, err
return nil, errors.New("reportInfo is not bytes")
}

reportInfo := &pbtypes.ReportInfo{}
err = proto.Unmarshal(rib, reportInfo)
rib, err := base64.StdEncoding.DecodeString(ris)
if err != nil {
return nil, err
}

reportInfo := &pbtypes.ReportInfo{}
err = proto.Unmarshal([]byte(rib), reportInfo)
return reportInfo, err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/capabilities/consensus/ocr3/transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestTransmitter(t *testing.T) {
},
ShouldReport: true,
}
infob, err := proto.Marshal(info)
infob, err := marshalReportInfo(info, "evm")
require.NoError(t, err)

sp := values.Proto(values.NewString("hello"))
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestTransmitter_ShouldReportFalse(t *testing.T) {
},
ShouldReport: false,
}
infob, err := proto.Marshal(info)
infob, err := marshalReportInfo(info, "evm")
require.NoError(t, err)

sp := values.Proto(values.NewString("hello"))
Expand Down

0 comments on commit b624b38

Please sign in to comment.