1
- use std:: time:: Duration ;
2
1
use crate :: router:: { Channel , Price , PriceFeedId , Rate , TimestampUs } ;
3
- use serde:: { Deserialize , Serialize } ;
4
2
use crate :: symbol_state:: SymbolState ;
3
+ use serde:: { Deserialize , Serialize } ;
4
+ use std:: time:: Duration ;
5
5
6
6
#[ derive( Serialize , Deserialize , Debug , Eq , PartialEq ) ]
7
7
pub struct PythLazerAgentJrpcV1 {
@@ -91,6 +91,7 @@ pub enum JrpcError {
91
91
InternalError ,
92
92
}
93
93
94
+ // note: error codes can be found in the rfc https://www.jsonrpc.org/specification#error_object
94
95
impl From < JrpcError > for JrpcErrorObject {
95
96
fn from ( error : JrpcError ) -> Self {
96
97
match error {
@@ -128,9 +129,8 @@ pub struct SymbolMetadata {
128
129
129
130
#[ cfg( test) ]
130
131
mod tests {
132
+ use super :: * ;
131
133
use crate :: jrpc:: JrpcCall :: { GetMetadata , PushUpdate } ;
132
- use crate :: jrpc:: { FeedUpdateParams , Filter , GetMetadataParams , JrpcErrorObject , JrpcErrorResponse , JrpcSuccessResponse , JsonRpcVersion , PythLazerAgentJrpcV1 , UpdateParams } ;
133
- use crate :: router:: { Price , PriceFeedId , Rate , TimestampUs } ;
134
134
135
135
#[ test]
136
136
fn test_push_update_price ( ) {
@@ -218,8 +218,8 @@ mod tests {
218
218
"jsonrpc": "2.0",
219
219
"method": "get_metadata",
220
220
"params": {
221
- "names": ["BTC/USD"],
222
- "asset_types": ["crypto"]
221
+ "names": ["BTC/USD"],
222
+ "asset_types": ["crypto"]
223
223
},
224
224
"id": 1
225
225
}
@@ -253,7 +253,10 @@ mod tests {
253
253
254
254
let expected = PythLazerAgentJrpcV1 {
255
255
jsonrpc : JsonRpcVersion :: V2 ,
256
- params : GetMetadata ( GetMetadataParams { names : None , asset_types : None } ) ,
256
+ params : GetMetadata ( GetMetadataParams {
257
+ names : None ,
258
+ asset_types : None ,
259
+ } ) ,
257
260
id : 1 ,
258
261
} ;
259
262
@@ -275,18 +278,22 @@ mod tests {
275
278
"code": -32603
276
279
}
277
280
}
278
- "#
279
- ) . unwrap ( ) ;
281
+ "# ,
282
+ )
283
+ . unwrap ( ) ;
280
284
281
- assert_eq ! ( response, JrpcErrorResponse {
282
- jsonrpc: JsonRpcVersion :: V2 ,
283
- error: JrpcErrorObject {
284
- code: -32603 ,
285
- message: "Internal error" . to_string( ) ,
286
- data: None ,
287
- } ,
288
- id: Some ( 2 ) ,
289
- } ) ;
285
+ assert_eq ! (
286
+ response,
287
+ JrpcErrorResponse {
288
+ jsonrpc: JsonRpcVersion :: V2 ,
289
+ error: JrpcErrorObject {
290
+ code: -32603 ,
291
+ message: "Internal error" . to_string( ) ,
292
+ data: None ,
293
+ } ,
294
+ id: Some ( 2 ) ,
295
+ }
296
+ ) ;
290
297
}
291
298
292
299
#[ test]
@@ -298,13 +305,17 @@ mod tests {
298
305
"id": 2,
299
306
"result": "success"
300
307
}
301
- "#
302
- ) . unwrap ( ) ;
308
+ "# ,
309
+ )
310
+ . unwrap ( ) ;
303
311
304
- assert_eq ! ( response, JrpcSuccessResponse :: <String > {
305
- jsonrpc: JsonRpcVersion :: V2 ,
306
- result: "success" . to_string( ) ,
307
- id: 2 ,
308
- } ) ;
312
+ assert_eq ! (
313
+ response,
314
+ JrpcSuccessResponse :: <String > {
315
+ jsonrpc: JsonRpcVersion :: V2 ,
316
+ result: "success" . to_string( ) ,
317
+ id: 2 ,
318
+ }
319
+ ) ;
309
320
}
310
321
}
0 commit comments