@@ -104,7 +104,7 @@ mod test {
104
104
) {
105
105
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
106
106
107
- let update_data = good_update1 ( ) ;
107
+ let update_data = ban_usd_update ( ) ;
108
108
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
109
109
110
110
alice. fund ( update_fee) ;
@@ -116,9 +116,9 @@ mod test {
116
116
117
117
let price_result = pyth_contract
118
118
. sender ( alice)
119
- . get_price_unsafe ( good_update1_feed_id ( ) ) ;
119
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
120
120
assert ! ( price_result. is_ok( ) ) ;
121
- assert_eq ! ( price_result. unwrap( ) , good_update1_results_get_price ( ) ) ;
121
+ assert_eq ! ( price_result. unwrap( ) , ban_usd_results_get_price ( ) ) ;
122
122
}
123
123
124
124
#[ motsu:: test]
@@ -131,7 +131,7 @@ mod test {
131
131
132
132
alice. fund ( U256 :: from ( 200 ) ) ;
133
133
134
- let update_data = good_update1 ( ) ;
134
+ let update_data = ban_usd_update ( ) ;
135
135
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
136
136
let small_update_fee = update_fee / U256 :: from ( 2 ) ;
137
137
@@ -150,10 +150,10 @@ mod test {
150
150
) {
151
151
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
152
152
153
- let update_data1 = good_update1 ( ) ;
153
+ let update_data1 = ban_usd_update ( ) ;
154
154
let update_fee1 = mock_get_update_fee ( update_data1. clone ( ) ) . unwrap ( ) ;
155
155
156
- let update_data2 = good_update2 ( ) ;
156
+ let update_data2 = btc_usd_update ( ) ;
157
157
let update_fee2 = mock_get_update_fee ( update_data2. clone ( ) ) . unwrap ( ) ;
158
158
159
159
alice. fund ( update_fee1 + update_fee2) ;
@@ -170,9 +170,9 @@ mod test {
170
170
171
171
let price_result = pyth_contract
172
172
. sender ( alice)
173
- . get_price_unsafe ( good_update1_feed_id ( ) ) ;
173
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
174
174
assert ! ( price_result. is_ok( ) ) ;
175
- assert_eq ! ( price_result. unwrap( ) , good_update2_results_get_price ( ) ) ;
175
+ assert_eq ! ( price_result. unwrap( ) , ban_usd_results_get_price ( ) ) ;
176
176
}
177
177
178
178
#[ motsu:: test]
@@ -185,7 +185,7 @@ mod test {
185
185
186
186
let price_result = pyth_contract
187
187
. sender ( alice)
188
- . get_price_unsafe ( good_update1_feed_id ( ) ) ;
188
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
189
189
assert ! ( price_result. is_err( ) ) ;
190
190
assert_eq ! (
191
191
price_result. unwrap_err( ) ,
@@ -227,7 +227,7 @@ mod test {
227
227
MockClock :: set_time ( Duration :: from_secs ( 1761573860 ) ) ;
228
228
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
229
229
230
- let update_data = good_update2 ( ) ;
230
+ let update_data = btc_usd_update ( ) ;
231
231
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
232
232
233
233
alice. fund ( update_fee) ;
@@ -239,9 +239,9 @@ mod test {
239
239
240
240
let price_result = pyth_contract
241
241
. sender ( alice)
242
- . get_price_no_older_than ( good_update1_feed_id ( ) , u64:: MAX ) ;
242
+ . get_price_no_older_than ( btc_usd_feed_id ( ) , u64:: MAX ) ;
243
243
assert ! ( price_result. is_ok( ) ) ;
244
- assert_eq ! ( price_result. unwrap( ) , good_update2_results_get_price ( ) ) ;
244
+ assert_eq ! ( price_result. unwrap( ) , btc_usd_results_get_price ( ) ) ;
245
245
}
246
246
247
247
#[ motsu:: test]
@@ -253,7 +253,7 @@ mod test {
253
253
MockClock :: set_time ( Duration :: from_secs ( 1761573860 ) ) ;
254
254
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
255
255
256
- let update_data = good_update2 ( ) ;
256
+ let update_data = btc_usd_update ( ) ;
257
257
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
258
258
259
259
alice. fund ( update_fee) ;
@@ -265,7 +265,8 @@ mod test {
265
265
266
266
let price_result = pyth_contract
267
267
. sender ( alice)
268
- . get_price_no_older_than ( good_update1_feed_id ( ) , 1 ) ;
268
+ . get_price_no_older_than ( btc_usd_feed_id ( ) , 1 ) ;
269
+ println ! ( "Price result: {:?}" , price_result) ;
269
270
assert ! ( price_result. is_err( ) ) ;
270
271
assert_eq ! (
271
272
price_result. unwrap_err( ) ,
@@ -274,14 +275,14 @@ mod test {
274
275
}
275
276
276
277
#[ motsu:: test]
277
- fn test_multiple_updates_in_same_vaa_different_ids_updates_both (
278
+ fn test_multiple_updates_different_ids_updates_both (
278
279
pyth_contract : Contract < PythReceiver > ,
279
280
wormhole_contract : Contract < WormholeContract > ,
280
281
alice : Address ,
281
282
) {
282
283
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
283
284
284
- let update_data = multiple_updates_same_vaa ( ) ;
285
+ let update_data = multiple_updates_diff_vaa ( ) ;
285
286
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
286
287
287
288
alice. fund ( update_fee) ;
@@ -291,41 +292,38 @@ mod test {
291
292
. update_price_feeds ( update_data) ;
292
293
assert ! ( result. is_ok( ) ) ;
293
294
294
- let first_id: [ u8 ; 32 ] = [
295
- 0xe6 , 0x2d , 0xf6 , 0xc8 , 0xb4 , 0xa8 , 0x5f , 0xe1 , 0xa6 , 0x7d , 0xb4 , 0x4d , 0xc1 , 0x2d ,
296
- 0xe5 , 0xdb , 0x33 , 0x0f , 0x7a , 0xc6 , 0x6b , 0x72 , 0xdc , 0x65 , 0x8a , 0xfe , 0xdf , 0x0f ,
297
- 0x4a , 0x41 , 0x5b , 0x43 ,
298
- ] ;
299
- let second_id: [ u8 ; 32 ] = [
300
- 0xff , 0x61 , 0x49 , 0x1a , 0x93 , 0x11 , 0x12 , 0xdd , 0xf1 , 0xbd , 0x81 , 0x47 , 0xcd , 0x1b ,
301
- 0x64 , 0x13 , 0x75 , 0xf7 , 0x9f , 0x58 , 0x25 , 0x12 , 0x6d , 0x66 , 0x54 , 0x80 , 0x87 , 0x46 ,
302
- 0x34 , 0xfd , 0x0a , 0xce ,
303
- ] ;
304
-
305
- let first_price_result = pyth_contract. sender ( alice) . get_price_unsafe ( first_id) ;
295
+ let first_price_result = pyth_contract
296
+ . sender ( alice)
297
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
306
298
assert ! ( first_price_result. is_ok( ) ) ;
307
299
assert_eq ! (
308
300
first_price_result. unwrap( ) ,
309
- multiple_updates_results_get_price ( ) [ 0 ]
301
+ multiple_updates_diff_vaa_results_get_price ( ) [ 0 ]
310
302
) ;
311
303
312
- let second_price_result = pyth_contract. sender ( alice) . get_price_unsafe ( second_id) ;
304
+ let second_price_result = pyth_contract
305
+ . sender ( alice)
306
+ . get_price_unsafe ( btc_usd_feed_id ( ) ) ;
313
307
assert ! ( second_price_result. is_ok( ) ) ;
314
308
assert_eq ! (
315
309
second_price_result. unwrap( ) ,
316
- multiple_updates_results_get_price ( ) [ 1 ]
310
+ multiple_updates_diff_vaa_results_get_price ( ) [ 1 ]
317
311
) ;
318
312
}
319
313
320
314
#[ motsu:: test]
321
- fn test_multiple_updates_different_ids_updates_both (
315
+ fn test_price_feed_exists (
322
316
pyth_contract : Contract < PythReceiver > ,
323
317
wormhole_contract : Contract < WormholeContract > ,
324
318
alice : Address ,
325
319
) {
326
320
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
327
321
328
- let update_data = multiple_updates_diff_vaa ( ) ;
322
+ assert ! ( !pyth_contract
323
+ . sender( alice)
324
+ . price_feed_exists( ban_usd_feed_id( ) ) ) ;
325
+
326
+ let update_data = ban_usd_update ( ) ;
329
327
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
330
328
331
329
alice. fund ( update_fee) ;
@@ -335,35 +333,94 @@ mod test {
335
333
. update_price_feeds ( update_data) ;
336
334
assert ! ( result. is_ok( ) ) ;
337
335
338
- let first_id: [ u8 ; 32 ] = [
339
- 0x3f , 0xa4 , 0x25 , 0x28 , 0x48 , 0xf9 , 0xf0 , 0xa1 , 0x48 , 0x0b , 0xe6 , 0x27 , 0x45 , 0xa4 ,
340
- 0x62 , 0x9d , 0x9e , 0xb1 , 0x32 , 0x2a , 0xeb , 0xab , 0x8a , 0x79 , 0x1e , 0x34 , 0x4b , 0x3b ,
341
- 0x9c , 0x1a , 0xdc , 0xf5 ,
342
- ] ;
343
- let second_id: [ u8 ; 32 ] = TEST_PRICE_ID ;
336
+ assert ! ( pyth_contract
337
+ . sender( alice)
338
+ . price_feed_exists( ban_usd_feed_id( ) ) ) ;
339
+ }
344
340
345
- let first_price_result = pyth_contract. sender ( alice) . get_price_unsafe ( first_id) ;
346
- assert ! ( first_price_result. is_ok( ) ) ;
347
- assert_eq ! (
348
- first_price_result. unwrap( ) ,
349
- multiple_updates_diff_vaa_results_get_price( ) [ 0 ]
350
- ) ;
341
+ #[ motsu:: test]
342
+ fn test_query_price_feed_doesnt_exist (
343
+ pyth_contract : Contract < PythReceiver > ,
344
+ wormhole_contract : Contract < WormholeContract > ,
345
+ alice : Address ,
346
+ ) {
347
+ pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
351
348
352
- let second_price_result = pyth_contract. sender ( alice) . get_price_unsafe ( second_id) ;
353
- assert ! ( second_price_result. is_ok( ) ) ;
349
+ let price_result = pyth_contract
350
+ . sender ( alice)
351
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
352
+
353
+ assert ! ( price_result. is_err( ) ) ;
354
354
assert_eq ! (
355
- second_price_result . unwrap ( ) ,
356
- multiple_updates_diff_vaa_results_get_price ( ) [ 1 ]
355
+ price_result . unwrap_err ( ) ,
356
+ PythReceiverError :: PriceFeedNotFound
357
357
) ;
358
358
}
359
359
360
360
#[ motsu:: test]
361
- fn test_multiple_updates_same_id_updates_latest (
361
+ fn test_query_price_feed_after_one_feed_update (
362
362
pyth_contract : Contract < PythReceiver > ,
363
363
wormhole_contract : Contract < WormholeContract > ,
364
364
alice : Address ,
365
365
) {
366
366
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
367
- alice. fund ( U256 :: from ( 200 ) ) ;
367
+
368
+ let update_data = ban_usd_update ( ) ;
369
+ let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
370
+
371
+ alice. fund ( update_fee) ;
372
+
373
+ let result = pyth_contract
374
+ . sender_and_value ( alice, update_fee)
375
+ . update_price_feeds ( update_data) ;
376
+
377
+ assert ! ( result. is_ok( ) ) ;
378
+
379
+ let price_result = pyth_contract
380
+ . sender ( alice)
381
+ . query_price_feed ( ban_usd_feed_id ( ) ) ;
382
+
383
+ assert ! ( price_result. is_ok( ) ) ;
384
+ assert_eq ! ( price_result. unwrap( ) , ban_usd_results_full( ) ) ;
385
+ }
386
+
387
+ #[ motsu:: test]
388
+ fn test_query_price_feed_after_multiple_updates (
389
+ pyth_contract : Contract < PythReceiver > ,
390
+ wormhole_contract : Contract < WormholeContract > ,
391
+ alice : Address ,
392
+ ) {
393
+ pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
394
+
395
+ let update_data = multiple_updates_diff_vaa ( ) ;
396
+ let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
397
+
398
+ alice. fund ( update_fee) ;
399
+
400
+ let result = pyth_contract
401
+ . sender_and_value ( alice, update_fee)
402
+ . update_price_feeds ( update_data) ;
403
+
404
+ assert ! ( result. is_ok( ) ) ;
405
+
406
+ let price_result1 = pyth_contract
407
+ . sender ( alice)
408
+ . query_price_feed ( ban_usd_feed_id ( ) ) ;
409
+
410
+ assert ! ( price_result1. is_ok( ) ) ;
411
+ assert_eq ! (
412
+ price_result1. unwrap( ) ,
413
+ multiple_updates_diff_vaa_results_full( ) [ 0 ]
414
+ ) ;
415
+
416
+ let price_result2 = pyth_contract
417
+ . sender ( alice)
418
+ . query_price_feed ( btc_usd_feed_id ( ) ) ;
419
+
420
+ assert ! ( price_result2. is_ok( ) ) ;
421
+ assert_eq ! (
422
+ price_result2. unwrap( ) ,
423
+ multiple_updates_diff_vaa_results_full( ) [ 1 ]
424
+ ) ;
368
425
}
369
426
}
0 commit comments