@@ -9,11 +9,6 @@ mod test {
9
9
use pythnet_sdk:: wire:: v1:: { AccumulatorUpdateData , Proof } ;
10
10
use std:: time:: Duration ;
11
11
use wormhole_contract:: WormholeContract ;
12
- const TEST_PRICE_ID : [ u8 ; 32 ] = [
13
- 0xe6 , 0x2d , 0xf6 , 0xc8 , 0xb4 , 0xa8 , 0x5f , 0xe1 , 0xa6 , 0x7d , 0xb4 , 0x4d , 0xc1 , 0x2d , 0xe5 ,
14
- 0xdb , 0x33 , 0x0f , 0x7a , 0xc6 , 0x6b , 0x72 , 0xdc , 0x65 , 0x8a , 0xfe , 0xdf , 0x0f , 0x4a , 0x41 ,
15
- 0x5b , 0x43 ,
16
- ] ;
17
12
18
13
const PYTHNET_CHAIN_ID : u16 = 26 ;
19
14
const PYTHNET_EMITTER_ADDRESS : [ u8 ; 32 ] = [
@@ -102,7 +97,7 @@ mod test {
102
97
) {
103
98
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
104
99
105
- let update_data = good_update1 ( ) ;
100
+ let update_data = ban_usd_update ( ) ;
106
101
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
107
102
108
103
alice. fund ( update_fee) ;
@@ -112,9 +107,11 @@ mod test {
112
107
. update_price_feeds ( update_data) ;
113
108
assert ! ( result. is_ok( ) ) ;
114
109
115
- let price_result = pyth_contract. sender ( alice) . get_price_unsafe ( TEST_PRICE_ID ) ;
110
+ let price_result = pyth_contract
111
+ . sender ( alice)
112
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
116
113
assert ! ( price_result. is_ok( ) ) ;
117
- assert_eq ! ( price_result. unwrap( ) , good_update1_results ( ) ) ;
114
+ assert_eq ! ( price_result. unwrap( ) , ban_usd_results_get_price ( ) ) ;
118
115
}
119
116
120
117
#[ motsu:: test]
@@ -127,7 +124,7 @@ mod test {
127
124
128
125
alice. fund ( U256 :: from ( 200 ) ) ;
129
126
130
- let update_data = good_update1 ( ) ;
127
+ let update_data = ban_usd_update ( ) ;
131
128
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
132
129
let small_update_fee = update_fee / U256 :: from ( 2 ) ;
133
130
@@ -146,10 +143,10 @@ mod test {
146
143
) {
147
144
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
148
145
149
- let update_data1 = good_update1 ( ) ;
146
+ let update_data1 = ban_usd_update ( ) ;
150
147
let update_fee1 = mock_get_update_fee ( update_data1. clone ( ) ) . unwrap ( ) ;
151
148
152
- let update_data2 = good_update2 ( ) ;
149
+ let update_data2 = btc_usd_update ( ) ;
153
150
let update_fee2 = mock_get_update_fee ( update_data2. clone ( ) ) . unwrap ( ) ;
154
151
155
152
alice. fund ( update_fee1 + update_fee2) ;
@@ -164,9 +161,11 @@ mod test {
164
161
. update_price_feeds ( update_data2) ;
165
162
assert ! ( result2. is_ok( ) ) ;
166
163
167
- let price_result = pyth_contract. sender ( alice) . get_price_unsafe ( TEST_PRICE_ID ) ;
164
+ let price_result = pyth_contract
165
+ . sender ( alice)
166
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
168
167
assert ! ( price_result. is_ok( ) ) ;
169
- assert_eq ! ( price_result. unwrap( ) , good_update2_results ( ) ) ;
168
+ assert_eq ! ( price_result. unwrap( ) , ban_usd_results_get_price ( ) ) ;
170
169
}
171
170
172
171
#[ motsu:: test]
@@ -177,7 +176,9 @@ mod test {
177
176
) {
178
177
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
179
178
180
- let price_result = pyth_contract. sender ( alice) . get_price_unsafe ( TEST_PRICE_ID ) ;
179
+ let price_result = pyth_contract
180
+ . sender ( alice)
181
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
181
182
assert ! ( price_result. is_err( ) ) ;
182
183
assert_eq ! (
183
184
price_result. unwrap_err( ) ,
@@ -219,7 +220,7 @@ mod test {
219
220
MockClock :: set_time ( Duration :: from_secs ( 1761573860 ) ) ;
220
221
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
221
222
222
- let update_data = good_update2 ( ) ;
223
+ let update_data = btc_usd_update ( ) ;
223
224
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
224
225
225
226
alice. fund ( update_fee) ;
@@ -231,9 +232,9 @@ mod test {
231
232
232
233
let price_result = pyth_contract
233
234
. sender ( alice)
234
- . get_price_no_older_than ( TEST_PRICE_ID , u64:: MAX ) ;
235
+ . get_price_no_older_than ( btc_usd_feed_id ( ) , u64:: MAX ) ;
235
236
assert ! ( price_result. is_ok( ) ) ;
236
- assert_eq ! ( price_result. unwrap( ) , good_update2_results ( ) ) ;
237
+ assert_eq ! ( price_result. unwrap( ) , btc_usd_results_get_price ( ) ) ;
237
238
}
238
239
239
240
#[ motsu:: test]
@@ -245,7 +246,7 @@ mod test {
245
246
MockClock :: set_time ( Duration :: from_secs ( 1761573860 ) ) ;
246
247
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
247
248
248
- let update_data = good_update2 ( ) ;
249
+ let update_data = btc_usd_update ( ) ;
249
250
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
250
251
251
252
alice. fund ( update_fee) ;
@@ -257,7 +258,8 @@ mod test {
257
258
258
259
let price_result = pyth_contract
259
260
. sender ( alice)
260
- . get_price_no_older_than ( TEST_PRICE_ID , 1 ) ;
261
+ . get_price_no_older_than ( btc_usd_feed_id ( ) , 1 ) ;
262
+ println ! ( "Price result: {:?}" , price_result) ;
261
263
assert ! ( price_result. is_err( ) ) ;
262
264
assert_eq ! (
263
265
price_result. unwrap_err( ) ,
@@ -266,14 +268,14 @@ mod test {
266
268
}
267
269
268
270
#[ motsu:: test]
269
- fn test_multiple_updates_in_same_vaa_different_ids_updates_both (
271
+ fn test_multiple_updates_different_ids_updates_both (
270
272
pyth_contract : Contract < PythReceiver > ,
271
273
wormhole_contract : Contract < WormholeContract > ,
272
274
alice : Address ,
273
275
) {
274
276
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
275
277
276
- let update_data = multiple_updates_same_vaa ( ) ;
278
+ let update_data = multiple_updates_diff_vaa ( ) ;
277
279
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
278
280
279
281
alice. fund ( update_fee) ;
@@ -283,35 +285,38 @@ mod test {
283
285
. update_price_feeds ( update_data) ;
284
286
assert ! ( result. is_ok( ) ) ;
285
287
286
- let first_id: [ u8 ; 32 ] = [
287
- 0xe6 , 0x2d , 0xf6 , 0xc8 , 0xb4 , 0xa8 , 0x5f , 0xe1 , 0xa6 , 0x7d , 0xb4 , 0x4d , 0xc1 , 0x2d ,
288
- 0xe5 , 0xdb , 0x33 , 0x0f , 0x7a , 0xc6 , 0x6b , 0x72 , 0xdc , 0x65 , 0x8a , 0xfe , 0xdf , 0x0f ,
289
- 0x4a , 0x41 , 0x5b , 0x43 ,
290
- ] ;
291
- let second_id: [ u8 ; 32 ] = [
292
- 0xff , 0x61 , 0x49 , 0x1a , 0x93 , 0x11 , 0x12 , 0xdd , 0xf1 , 0xbd , 0x81 , 0x47 , 0xcd , 0x1b ,
293
- 0x64 , 0x13 , 0x75 , 0xf7 , 0x9f , 0x58 , 0x25 , 0x12 , 0x6d , 0x66 , 0x54 , 0x80 , 0x87 , 0x46 ,
294
- 0x34 , 0xfd , 0x0a , 0xce ,
295
- ] ;
296
-
297
- let first_price_result = pyth_contract. sender ( alice) . get_price_unsafe ( first_id) ;
288
+ let first_price_result = pyth_contract
289
+ . sender ( alice)
290
+ . get_price_unsafe ( ban_usd_feed_id ( ) ) ;
298
291
assert ! ( first_price_result. is_ok( ) ) ;
299
- assert_eq ! ( first_price_result. unwrap( ) , multiple_updates_results( ) [ 0 ] ) ;
292
+ assert_eq ! (
293
+ first_price_result. unwrap( ) ,
294
+ multiple_updates_diff_vaa_results_get_price( ) [ 0 ]
295
+ ) ;
300
296
301
- let second_price_result = pyth_contract. sender ( alice) . get_price_unsafe ( second_id) ;
297
+ let second_price_result = pyth_contract
298
+ . sender ( alice)
299
+ . get_price_unsafe ( btc_usd_feed_id ( ) ) ;
302
300
assert ! ( second_price_result. is_ok( ) ) ;
303
- assert_eq ! ( second_price_result. unwrap( ) , multiple_updates_results( ) [ 1 ] ) ;
301
+ assert_eq ! (
302
+ second_price_result. unwrap( ) ,
303
+ multiple_updates_diff_vaa_results_get_price( ) [ 1 ]
304
+ ) ;
304
305
}
305
306
306
307
#[ motsu:: test]
307
- fn test_multiple_updates_different_ids_updates_both (
308
+ fn test_price_feed_exists (
308
309
pyth_contract : Contract < PythReceiver > ,
309
310
wormhole_contract : Contract < WormholeContract > ,
310
311
alice : Address ,
311
312
) {
312
313
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
313
314
314
- let update_data = multiple_updates_diff_vaa ( ) ;
315
+ assert ! ( !pyth_contract
316
+ . sender( alice)
317
+ . price_feed_exists( ban_usd_feed_id( ) ) ) ;
318
+
319
+ let update_data = ban_usd_update ( ) ;
315
320
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
316
321
317
322
alice. fund ( update_fee) ;
@@ -321,35 +326,94 @@ mod test {
321
326
. update_price_feeds ( update_data) ;
322
327
assert ! ( result. is_ok( ) ) ;
323
328
324
- let first_id: [ u8 ; 32 ] = [
325
- 0x3f , 0xa4 , 0x25 , 0x28 , 0x48 , 0xf9 , 0xf0 , 0xa1 , 0x48 , 0x0b , 0xe6 , 0x27 , 0x45 , 0xa4 ,
326
- 0x62 , 0x9d , 0x9e , 0xb1 , 0x32 , 0x2a , 0xeb , 0xab , 0x8a , 0x79 , 0x1e , 0x34 , 0x4b , 0x3b ,
327
- 0x9c , 0x1a , 0xdc , 0xf5 ,
328
- ] ;
329
- let second_id: [ u8 ; 32 ] = TEST_PRICE_ID ;
329
+ assert ! ( pyth_contract
330
+ . sender( alice)
331
+ . price_feed_exists( ban_usd_feed_id( ) ) ) ;
332
+ }
330
333
331
- let first_price_result = pyth_contract. sender ( alice) . get_price_unsafe ( first_id) ;
332
- assert ! ( first_price_result. is_ok( ) ) ;
333
- assert_eq ! (
334
- first_price_result. unwrap( ) ,
335
- multiple_updates_diff_vaa_results( ) [ 0 ]
336
- ) ;
334
+ #[ motsu:: test]
335
+ fn test_query_price_feed_doesnt_exist (
336
+ pyth_contract : Contract < PythReceiver > ,
337
+ wormhole_contract : Contract < WormholeContract > ,
338
+ alice : Address ,
339
+ ) {
340
+ pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
337
341
338
- let second_price_result = pyth_contract. sender ( alice) . get_price_unsafe ( second_id) ;
339
- assert ! ( second_price_result. is_ok( ) ) ;
342
+ let price_result = pyth_contract
343
+ . sender ( alice)
344
+ . query_price_feed ( ban_usd_feed_id ( ) ) ;
345
+
346
+ assert ! ( price_result. is_err( ) ) ;
340
347
assert_eq ! (
341
- second_price_result . unwrap ( ) ,
342
- multiple_updates_diff_vaa_results ( ) [ 1 ]
348
+ price_result . unwrap_err ( ) ,
349
+ PythReceiverError :: PriceFeedNotFound
343
350
) ;
344
351
}
345
352
346
353
#[ motsu:: test]
347
- fn test_multiple_updates_same_id_updates_latest (
354
+ fn test_query_price_feed_after_one_feed_update (
348
355
pyth_contract : Contract < PythReceiver > ,
349
356
wormhole_contract : Contract < WormholeContract > ,
350
357
alice : Address ,
351
358
) {
352
359
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
353
- alice. fund ( U256 :: from ( 200 ) ) ;
360
+
361
+ let update_data = ban_usd_update ( ) ;
362
+ let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
363
+
364
+ alice. fund ( update_fee) ;
365
+
366
+ let result = pyth_contract
367
+ . sender_and_value ( alice, update_fee)
368
+ . update_price_feeds ( update_data) ;
369
+
370
+ assert ! ( result. is_ok( ) ) ;
371
+
372
+ let price_result = pyth_contract
373
+ . sender ( alice)
374
+ . query_price_feed ( ban_usd_feed_id ( ) ) ;
375
+
376
+ assert ! ( price_result. is_ok( ) ) ;
377
+ assert_eq ! ( price_result. unwrap( ) , ban_usd_results_full( ) ) ;
378
+ }
379
+
380
+ #[ motsu:: test]
381
+ fn test_query_price_feed_after_multiple_updates (
382
+ pyth_contract : Contract < PythReceiver > ,
383
+ wormhole_contract : Contract < WormholeContract > ,
384
+ alice : Address ,
385
+ ) {
386
+ pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
387
+
388
+ let update_data = multiple_updates_diff_vaa ( ) ;
389
+ let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
390
+
391
+ alice. fund ( update_fee) ;
392
+
393
+ let result = pyth_contract
394
+ . sender_and_value ( alice, update_fee)
395
+ . update_price_feeds ( update_data) ;
396
+
397
+ assert ! ( result. is_ok( ) ) ;
398
+
399
+ let price_result1 = pyth_contract
400
+ . sender ( alice)
401
+ . query_price_feed ( ban_usd_feed_id ( ) ) ;
402
+
403
+ assert ! ( price_result1. is_ok( ) ) ;
404
+ assert_eq ! (
405
+ price_result1. unwrap( ) ,
406
+ multiple_updates_diff_vaa_results_full( ) [ 0 ]
407
+ ) ;
408
+
409
+ let price_result2 = pyth_contract
410
+ . sender ( alice)
411
+ . query_price_feed ( btc_usd_feed_id ( ) ) ;
412
+
413
+ assert ! ( price_result2. is_ok( ) ) ;
414
+ assert_eq ! (
415
+ price_result2. unwrap( ) ,
416
+ multiple_updates_diff_vaa_results_full( ) [ 1 ]
417
+ ) ;
354
418
}
355
419
}
0 commit comments