Skip to content

Commit

Permalink
Fix mercury v0.3 decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
infiloop2 committed Sep 26, 2023
1 parent eef6160 commit 4bc94ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
7 changes: 4 additions & 3 deletions core/services/ocr2/plugins/ocr2keeper/evm21/streams_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ type MercuryV03Response struct {
}

type MercuryV03Report struct {
FeedID []byte `json:"feedID"` // feed id in hex
FeedID string `json:"feedID"` // feed id in hex encoded
ValidFromTimestamp uint32 `json:"validFromTimestamp"`
ObservationsTimestamp uint32 `json:"observationsTimestamp"`
FullReport []byte `json:"fullReport"` // the actual mercury report of this feed, can be sent to verifier
FullReport string `json:"fullReport"` // the actual hex encoded mercury report of this feed, can be sent to verifier
}

type MercuryData struct {
Expand Down Expand Up @@ -533,7 +533,8 @@ func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryDa
}
var reportBytes [][]byte
for _, rsp := range response.Reports {
reportBytes = append(reportBytes, rsp.FullReport)
b, _ := hexutil.Decode(rsp.FullReport)
reportBytes = append(reportBytes, b)
}
ch <- MercuryData{
Index: 0,
Expand Down
31 changes: 16 additions & 15 deletions core/services/ocr2/plugins/ocr2keeper/evm21/streams_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,16 +681,16 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) {
response: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: hexutil.MustDecode("0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: hexutil.MustDecode("0xab2123dc00000012"),
FullReport: "0xab2123dc00000012",
},
{
FeedID: hexutil.MustDecode("0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123458,
ObservationsTimestamp: 123458,
FullReport: hexutil.MustDecode("0xab2123dc00000016"),
FullReport: "0xab2123dc00000016",
},
},
},
Expand All @@ -711,16 +711,16 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) {
response: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: hexutil.MustDecode("0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: hexutil.MustDecode("0xab2123dc00000012"),
FullReport: "0xab2123dc00000012",
},
{
FeedID: hexutil.MustDecode("0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123458,
ObservationsTimestamp: 123458,
FullReport: hexutil.MustDecode("0xab2123dc00000019"),
FullReport: "0xab2123dc00000019",
},
},
},
Expand Down Expand Up @@ -789,26 +789,26 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) {
firstResponse: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: hexutil.MustDecode("0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: hexutil.MustDecode("0xab2123dc00000012"),
FullReport: "0xab2123dc00000012",
},
},
},
response: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: hexutil.MustDecode("0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: hexutil.MustDecode("0xab2123dc00000012"),
FullReport: "0xab2123dc00000012",
},
{
FeedID: hexutil.MustDecode("0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123458,
ObservationsTimestamp: 123458,
FullReport: hexutil.MustDecode("0xab2123dc00000019"),
FullReport: "0xab2123dc00000019",
},
},
},
Expand Down Expand Up @@ -880,7 +880,8 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) {
assert.Nil(t, m.Error)
var reports [][]byte
for _, rsp := range tt.response.Reports {
reports = append(reports, rsp.FullReport)
b, _ := hexutil.Decode(rsp.FullReport)
reports = append(reports, b)
}
assert.Equal(t, reports, m.Bytes)
}
Expand Down

0 comments on commit 4bc94ba

Please sign in to comment.