11package rfq
22
33import (
4+ "bytes"
45 "context"
56 "fmt"
67 "net"
@@ -43,6 +44,11 @@ func (p *mockRpcPriceOracleServer) QueryRateTick(_ context.Context,
4344 ExpiryTimestamp : uint64 (expiry ),
4445 }
4546
47+ err := validateRateTickRequest (req )
48+ if err != nil {
49+ return nil , err
50+ }
51+
4652 // If a rate tick hint is provided, return it as the rate tick.
4753 if req .RateTickHint != nil {
4854 rateTick .Rate = req .RateTickHint .Rate
@@ -58,6 +64,32 @@ func (p *mockRpcPriceOracleServer) QueryRateTick(_ context.Context,
5864 }, nil
5965}
6066
67+ // validateRateTickRequest validates the given rate tick request.
68+ func validateRateTickRequest (req * priceoraclerpc.QueryRateTickRequest ) error {
69+ var zeroAssetID [32 ]byte
70+ if req .SubjectAsset == nil {
71+ return fmt .Errorf ("subject asset must be specified" )
72+ }
73+ if len (req .SubjectAsset .GetAssetId ()) != 32 {
74+ return fmt .Errorf ("invalid subject asset ID length" )
75+ }
76+ if bytes .Equal (req .SubjectAsset .GetAssetId (), zeroAssetID [:]) {
77+ return fmt .Errorf ("subject asset ID must NOT be all zero" )
78+ }
79+
80+ if req .PaymentAsset == nil {
81+ return fmt .Errorf ("payment asset must be specified" )
82+ }
83+ if len (req .PaymentAsset .GetAssetId ()) != 32 {
84+ return fmt .Errorf ("invalid payment asset ID length" )
85+ }
86+ if ! bytes .Equal (req .PaymentAsset .GetAssetId (), zeroAssetID [:]) {
87+ return fmt .Errorf ("payment asset ID must be all zero" )
88+ }
89+
90+ return nil
91+ }
92+
6193// startBackendRPC starts the given RPC server and blocks until the server is
6294// shut down.
6395func startBackendRPC (grpcServer * grpc.Server ) error {
@@ -95,7 +127,7 @@ func runQueryAskPriceTest(t *testing.T, tc *testCaseQueryAskPrice) {
95127 defer backendService .Stop ()
96128
97129 // Wait for the server to start.
98- time .Sleep (2 * time .Second )
130+ time .Sleep (200 * time .Millisecond )
99131
100132 // Create a new RPC price oracle client and connect to the mock service.
101133 serviceAddr := fmt .Sprintf ("rfqrpc://%s" , testServiceAddress )
0 commit comments