Skip to content

Commit 9f3d809

Browse files
committed
set up integration tests
1 parent 2c77720 commit 9f3d809

File tree

4 files changed

+63
-42
lines changed

4 files changed

+63
-42
lines changed

target_chains/stylus/contracts/pyth-receiver/src/integration_tests.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ mod test {
114114
.update_price_feeds(update_data);
115115
assert!(result.is_ok());
116116

117-
let price_result = pyth_contract.sender(alice).get_price_unsafe(TEST_PRICE_ID);
117+
let price_result = pyth_contract
118+
.sender(alice)
119+
.get_price_unsafe(good_update1_feed_id());
118120
assert!(price_result.is_ok());
119121
assert_eq!(price_result.unwrap(), good_update1_results());
120122
}
@@ -166,7 +168,9 @@ mod test {
166168
.update_price_feeds(update_data2);
167169
assert!(result2.is_ok());
168170

169-
let price_result = pyth_contract.sender(alice).get_price_unsafe(TEST_PRICE_ID);
171+
let price_result = pyth_contract
172+
.sender(alice)
173+
.get_price_unsafe(good_update1_feed_id());
170174
assert!(price_result.is_ok());
171175
assert_eq!(price_result.unwrap(), good_update2_results());
172176
}
@@ -179,7 +183,9 @@ mod test {
179183
) {
180184
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice);
181185

182-
let price_result = pyth_contract.sender(alice).get_price_unsafe(TEST_PRICE_ID);
186+
let price_result = pyth_contract
187+
.sender(alice)
188+
.get_price_unsafe(good_update1_feed_id());
183189
assert!(price_result.is_err());
184190
assert_eq!(
185191
price_result.unwrap_err(),
@@ -233,7 +239,7 @@ mod test {
233239

234240
let price_result = pyth_contract
235241
.sender(alice)
236-
.get_price_no_older_than(TEST_PRICE_ID, u64::MAX);
242+
.get_price_no_older_than(good_update1_feed_id(), u64::MAX);
237243
assert!(price_result.is_ok());
238244
assert_eq!(price_result.unwrap(), good_update2_results());
239245
}
@@ -259,7 +265,7 @@ mod test {
259265

260266
let price_result = pyth_contract
261267
.sender(alice)
262-
.get_price_no_older_than(TEST_PRICE_ID, 1);
268+
.get_price_no_older_than(good_update1_feed_id(), 1);
263269
assert!(price_result.is_err());
264270
assert_eq!(
265271
price_result.unwrap_err(),

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use pythnet_sdk::{
3939
},
4040
},
4141
};
42-
use structs::{DataSource, DataSourceStorage, PriceInfoReturn, PriceInfoStorage};
42+
use structs::{DataSource, DataSourceStorage, PriceFeedReturn, PriceInfoStorage};
4343
use wormhole_vaas::{Readable, Vaa, Writeable};
4444

4545
sol_interface! {
@@ -111,7 +111,7 @@ impl PythReceiver {
111111
}
112112
}
113113

114-
pub fn get_price_unsafe(&self, id: [u8; 32]) -> Result<PriceInfoReturn, PythReceiverError> {
114+
pub fn get_price_unsafe(&self, id: [u8; 32]) -> Result<PriceFeedReturn, PythReceiverError> {
115115
let id_fb = FixedBytes::<32>::from(id);
116116

117117
let price_info = self.latest_price_info.get(id_fb);
@@ -134,15 +134,15 @@ impl PythReceiver {
134134
&self,
135135
id: [u8; 32],
136136
age: u64,
137-
) -> Result<PriceInfoReturn, PythReceiverError> {
137+
) -> Result<PriceFeedReturn, PythReceiverError> {
138138
let price_info = self.get_price_unsafe(id)?;
139139
if !self.is_no_older_than(price_info.0, age) {
140140
return Err(PythReceiverError::NewPriceUnavailable);
141141
}
142142
Ok(price_info)
143143
}
144144

145-
pub fn get_ema_price_unsafe(&self, id: [u8; 32]) -> Result<PriceInfoReturn, PythReceiverError> {
145+
pub fn get_ema_price_unsafe(&self, id: [u8; 32]) -> Result<PriceFeedReturn, PythReceiverError> {
146146
let id_fb = FixedBytes::<32>::from(id);
147147
let price_info = self.latest_price_info.get(id_fb);
148148

@@ -164,7 +164,7 @@ impl PythReceiver {
164164
&self,
165165
id: [u8; 32],
166166
age: u64,
167-
) -> Result<PriceInfoReturn, PythReceiverError> {
167+
) -> Result<PriceFeedReturn, PythReceiverError> {
168168
let price_info = self.get_ema_price_unsafe(id)?;
169169
if !self.is_no_older_than(price_info.0, age) {
170170
return Err(PythReceiverError::NewPriceUnavailable);
@@ -204,7 +204,7 @@ impl PythReceiver {
204204
}
205205

206206
for i in 0..price_ids.len() {
207-
if (self.latest_price_info_publish_time(price_ids[i]) < publish_times[i]) {
207+
if self.latest_price_info_publish_time(price_ids[i]) < publish_times[i] {
208208
self.update_price_feeds(update_data.clone())?;
209209
return Ok(());
210210
}
@@ -226,7 +226,7 @@ impl PythReceiver {
226226
min_publish_time: u64,
227227
max_publish_time: u64,
228228
_unique: bool,
229-
) -> Result<Vec<([u8; 32], PriceInfoReturn)>, PythReceiverError> {
229+
) -> Result<Vec<([u8; 32], PriceFeedReturn)>, PythReceiverError> {
230230
let price_pairs = self.parse_price_feed_updates_internal(
231231
update_data,
232232
min_publish_time,
@@ -285,7 +285,7 @@ impl PythReceiver {
285285
price_ids: Vec<[u8; 32]>,
286286
min_publish_time: u64,
287287
max_publish_time: u64,
288-
) -> Result<Vec<PriceInfoReturn>, PythReceiverError> {
288+
) -> Result<Vec<PriceFeedReturn>, PythReceiverError> {
289289
let price_feeds = self.parse_price_feed_updates_with_config(
290290
vec![update_data],
291291
price_ids,
@@ -307,7 +307,7 @@ impl PythReceiver {
307307
check_uniqueness: bool,
308308
check_update_data_is_minimal: bool,
309309
store_updates_if_fresh: bool,
310-
) -> Result<Vec<PriceInfoReturn>, PythReceiverError> {
310+
) -> Result<Vec<PriceFeedReturn>, PythReceiverError> {
311311
let mut all_parsed_price_pairs = Vec::new();
312312
for data in &update_data {
313313
if store_updates_if_fresh {
@@ -332,8 +332,8 @@ impl PythReceiver {
332332
return Err(PythReceiverError::InvalidUpdateData);
333333
}
334334

335-
let mut result: Vec<PriceInfoReturn> = Vec::with_capacity(price_ids.len());
336-
let mut price_map: BTreeMap<[u8; 32], PriceInfoReturn> = BTreeMap::new();
335+
let mut result: Vec<PriceFeedReturn> = Vec::with_capacity(price_ids.len());
336+
let mut price_map: BTreeMap<[u8; 32], PriceFeedReturn> = BTreeMap::new();
337337

338338
for (price_id, price_info) in all_parsed_price_pairs {
339339
if !price_map.contains_key(&price_id) {
@@ -358,7 +358,7 @@ impl PythReceiver {
358358
min_allowed_publish_time: u64,
359359
max_allowed_publish_time: u64,
360360
check_uniqueness: bool,
361-
) -> Result<Vec<([u8; 32], PriceInfoReturn)>, PythReceiverError> {
361+
) -> Result<Vec<([u8; 32], PriceFeedReturn)>, PythReceiverError> {
362362
let update_data_array: &[u8] = &update_data;
363363
// Check the first 4 bytes of the update_data_array for the magic header
364364
if update_data_array.len() < 4 {
@@ -375,7 +375,7 @@ impl PythReceiver {
375375
let accumulator_update = AccumulatorUpdateData::try_from_slice(&update_data_array)
376376
.map_err(|_| PythReceiverError::InvalidAccumulatorMessage)?;
377377

378-
let mut price_feeds: BTreeMap<[u8; 32], PriceInfoReturn> = BTreeMap::new();
378+
let mut price_feeds: BTreeMap<[u8; 32], PriceFeedReturn> = BTreeMap::new();
379379

380380
match accumulator_update.proof {
381381
Proof::WormholeMerkle { vaa, updates } => {
@@ -469,7 +469,7 @@ impl PythReceiver {
469469
&mut self,
470470
_update_data: Vec<Vec<u8>>,
471471
_price_ids: Vec<[u8; 32]>,
472-
) -> Vec<PriceInfoReturn> {
472+
) -> Vec<PriceFeedReturn> {
473473
Vec::new()
474474
}
475475

@@ -479,7 +479,7 @@ impl PythReceiver {
479479
price_ids: Vec<[u8; 32]>,
480480
min_publish_time: u64,
481481
max_publish_time: u64,
482-
) -> Result<Vec<PriceInfoReturn>, PythReceiverError> {
482+
) -> Result<Vec<PriceFeedReturn>, PythReceiverError> {
483483
let price_feeds = self.parse_price_feed_updates_with_config(
484484
update_data,
485485
price_ids,

target_chains/stylus/contracts/pyth-receiver/src/structs.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ pub struct PriceInfoStorage {
4646
}
4747

4848
// Addressing nit -- running into some versioning issues that preclude me
49-
// from returning the PriceInfo struct directly. Need to figure that out.
49+
// from returning the PriceFeed struct directly. Need to figure that out.
5050

51-
// pub struct PriceInfo {
51+
// pub struct PriceFeed {
5252
// pub publish_time: U64,
5353
// pub expo: I32,
5454
// pub price: I64,
@@ -57,7 +57,9 @@ pub struct PriceInfoStorage {
5757
// pub ema_conf: U64,
5858
// }
5959

60-
pub type PriceInfoReturn = (U64, I32, I64, U64, I64, U64);
60+
pub type PriceFeedReturn = (U64, I32, I64, U64, I64, U64);
61+
62+
pub type PriceReturn = ([u8; 32], U64, I32, I64, U64, I64, U64);
6163

6264
#[cfg(test)]
6365
mod tests {

0 commit comments

Comments
 (0)