From e6773d3bc858563da2822ededc24f4fb55f149e6 Mon Sep 17 00:00:00 2001 From: patrickhuie19 Date: Wed, 24 Apr 2024 12:52:42 -0400 Subject: [PATCH] minor cleanup and adding signature to TestIntegration_MercuryGRPC --- core/services/ocr2/plugins/mercury/helpers_test.go | 9 +++++++++ .../services/ocr2/plugins/mercury/integration_test.go | 11 ++++++----- core/services/relay/evm/mercury/wsrpc/pool_test.go | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/services/ocr2/plugins/mercury/helpers_test.go b/core/services/ocr2/plugins/mercury/helpers_test.go index 3752fd1ecfb..08cf956f1c5 100644 --- a/core/services/ocr2/plugins/mercury/helpers_test.go +++ b/core/services/ocr2/plugins/mercury/helpers_test.go @@ -2,6 +2,7 @@ package mercury_test import ( "context" + "crypto" "crypto/ed25519" "encoding/binary" "errors" @@ -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) +} diff --git a/core/services/ocr2/plugins/mercury/integration_test.go b/core/services/ocr2/plugins/mercury/integration_test.go index 67390e52dd9..75ea8616208 100644 --- a/core/services/ocr2/plugins/mercury/integration_test.go +++ b/core/services/ocr2/plugins/mercury/integration_test.go @@ -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{}) @@ -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) @@ -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) @@ -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) diff --git a/core/services/relay/evm/mercury/wsrpc/pool_test.go b/core/services/relay/evm/mercury/wsrpc/pool_test.go index b99daad4708..fd4df5cd16c 100644 --- a/core/services/relay/evm/mercury/wsrpc/pool_test.go +++ b/core/services/relay/evm/mercury/wsrpc/pool_test.go @@ -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{} @@ -208,7 +208,7 @@ func Test_Pool(t *testing.T) { }) }) - p := &pool { + p := &pool{ lggr: lggr, } p.cacheSet = &mockCacheSet{}