Skip to content

Commit

Permalink
minor cleanup and adding signature to TestIntegration_MercuryGRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhuie19 committed Jun 11, 2024
1 parent 8610e22 commit e6773d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 9 additions & 0 deletions core/services/ocr2/plugins/mercury/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mercury_test

import (
"context"
"crypto"
"crypto/ed25519"
"encoding/binary"
"errors"
Expand Down Expand Up @@ -576,3 +577,11 @@ chainID = 1337
nativeFeedID,
))
}

func sign(t *testing.T, key csakey.KeyV2, request PbRequest) string {
canonicalRequestString := request.String()
signableKey := ed25519.PrivateKey(key.Raw())
signedBytes, err := signableKey.Sign(nil, []byte(canonicalRequestString), crypto.Hash(0))
require.NoError(t, err)
return fmt.Sprintf("%x", signedBytes)
}
11 changes: 6 additions & 5 deletions core/services/ocr2/plugins/mercury/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ func integration_MercuryV3(t *testing.T, tlsCertFile *string, tlsKeyFile *string
oracle_transmitters[o.OracleIdentity.TransmitAccount] = struct{}{}
}

// feedID: account: count
for req := range reqs {

v := make(map[string]interface{})
Expand Down Expand Up @@ -1069,8 +1068,6 @@ func integration_MercuryV3(t *testing.T, tlsCertFile *string, tlsKeyFile *string
t.Fatalf("FAIL: unexpected report from oracle %s", req.TransmitterID())
}

t.Logf("Oracle %s AKA %s reported for feed %s (0x%x)", req.pk, req.TransmitterID(), feed.name, feed.id)

seen[feedID][req.TransmitterID()] = struct{}{}
if len(seen[feedID]) == n {
t.Logf("all oracles reported for feed %s (0x%x)", feed.name, feed.id)
Expand Down Expand Up @@ -1144,12 +1141,16 @@ func TestIntegration_MercuryGRPC(t *testing.T) {

rawClient := pb.NewMercuryGrpcClient(conn2)

latestReportRequest := pb.LatestReportRequest{
FeedId: []byte("feedId"),
}
latestReportCtx := testutils.Context(t)
kv := make(map[string]string)
kv["csa-key"] = key.PublicKeyString()
kv["signature"] = sign(t, key, &latestReportRequest)
md := metadata.New(kv)
latestReportCtx = metadata.NewOutgoingContext(latestReportCtx, md)
resp2, err := rawClient.LatestReport(latestReportCtx, &pb.LatestReportRequest{})
resp2, err := rawClient.LatestReport(latestReportCtx, &latestReportRequest)
require.NoError(t, err)
t.Logf("LatestReport Response: %v", resp2)

Expand All @@ -1165,7 +1166,7 @@ func TestIntegration_MercuryGRPC(t *testing.T) {
t.Logf("Client name: %v", client.Name())
t.Logf("Client health: %v", client.HealthReport())

resp3, err3 := client.LatestReport(latestReportCtx, &pb.LatestReportRequest{})
resp3, err3 := client.LatestReport(latestReportCtx, &latestReportRequest)
require.NoError(t, err3)

t.Logf("LatestReport Response: %v", resp3)
Expand Down
4 changes: 2 additions & 2 deletions core/services/relay/evm/mercury/wsrpc/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Test_Pool(t *testing.T) {
ctx := testutils.Context(t)

t.Run("Checkout", func(t *testing.T) {
p := &pool {
p := &pool{
lggr: lggr,
}
p.cacheSet = &mockCacheSet{}
Expand Down Expand Up @@ -208,7 +208,7 @@ func Test_Pool(t *testing.T) {
})
})

p := &pool {
p := &pool{
lggr: lggr,
}
p.cacheSet = &mockCacheSet{}
Expand Down

0 comments on commit e6773d3

Please sign in to comment.