Skip to content

Commit 103690f

Browse files
committed
fix types
1 parent 61906e1 commit 103690f

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lazer/sdk/rust/protocol/src/metadata.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::time::{DurationUs, TimestampUs};
44
use crate::FeedKind;
5-
use crate::{symbol_state::SymbolState, PriceFeedId, SymbolV3};
5+
use crate::{symbol_state::SymbolState, PriceFeedId};
66
use serde::{Deserialize, Serialize};
77

88
/// The pricing context or type of instrument for a feed.
@@ -59,7 +59,7 @@ pub struct FeedResponseV3 {
5959
/// Unique human-readable identifier for a feed.
6060
/// Format: `source.instrument_type.base/quote`
6161
/// Examples: `"pyth.spot.btc/usd"`, `"pyth.redemptionrate.alp/usd"`, `"binance.fundingrate.btc/usdt"`, `"pyth.future.emz5/usd"`
62-
pub symbol: SymbolV3,
62+
pub symbol: String,
6363
/// Description of the feed pair.
6464
/// Example: `"Pyth Network Aggregate Price for spot BTC/USD"`
6565
pub description: String,
@@ -143,10 +143,14 @@ pub struct AssetResponseV3 {
143143

144144
#[cfg(test)]
145145
mod tests {
146+
use std::str::FromStr;
147+
148+
use crate::SymbolV3;
149+
146150
use super::*;
147151

148152
#[test]
149-
fn test_feed_response_v3_roundtrip() {
153+
fn test_feed_response_v3_json_serde_roundtrip() {
150154
use crate::{symbol_state::SymbolState, FeedKind, PriceFeedId};
151155

152156
let symbol = SymbolV3::new(
@@ -159,7 +163,7 @@ mod tests {
159163
let feed_response = FeedResponseV3 {
160164
id: PriceFeedId(1),
161165
name: "Bitcoin / US Dollar".to_string(),
162-
symbol,
166+
symbol: symbol.as_string(),
163167
description: "Pyth Network Aggregate Price for spot BTC/USD".to_string(),
164168
base_asset_id: "BTC".to_string(),
165169
quote_asset_id: Some("USD".to_string()),
@@ -182,18 +186,25 @@ mod tests {
182186
// Test JSON serialization
183187
let json =
184188
serde_json::to_string(&feed_response).expect("Failed to serialize FeedResponseV3");
185-
assert!(json.contains("\"symbol\":\"pyth.spot.btc/usd\""));
189+
let expected_json = r#"{"id":1,"name":"Bitcoin / US Dollar","symbol":"pyth.spot.btc/usd","description":"Pyth Network Aggregate Price for spot BTC/USD","base_asset_id":"BTC","quote_asset_id":"USD","instrument_type":"spot","source":"pyth","schedule":"America/New_York;O,O,O,O,O,O,O;","exponent":-8,"update_interval":10000000,"min_publishers":3,"state":"stable","asset_type":"crypto","cmc_id":1,"pythnet_id":"e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43","feed_kind":"price"}"#;
190+
assert_eq!(
191+
json, expected_json,
192+
"Serialized JSON does not match expected output"
193+
);
186194

187195
// Test JSON deserialization
188196
let deserialized: FeedResponseV3 =
189197
serde_json::from_str(&json).expect("Failed to deserialize FeedResponseV3");
190-
assert_eq!(deserialized.symbol.as_string(), "pyth.spot.btc/usd");
191-
assert_eq!(deserialized.symbol.source, "pyth");
192-
assert_eq!(deserialized.symbol.instrument_type, "spot");
193-
assert_eq!(deserialized.symbol.base, "btc");
194-
assert_eq!(deserialized.symbol.quote, Some("usd".to_string()));
195198

196199
// Ensure the entire structure matches
197200
assert_eq!(deserialized, feed_response);
201+
202+
// Test SymbolV3 deserialization
203+
assert_eq!(deserialized.symbol, "pyth.spot.btc/usd");
204+
let symbol = SymbolV3::from_str(&deserialized.symbol).unwrap();
205+
assert_eq!(symbol.source, "pyth");
206+
assert_eq!(symbol.instrument_type, "spot");
207+
assert_eq!(symbol.base, "btc");
208+
assert_eq!(symbol.quote, Some("usd".to_string()));
198209
}
199210
}

0 commit comments

Comments
 (0)