@@ -16,17 +16,17 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds success", () => {
16
16
let pricesUpdates = pyth . buildPriceUpdateBatch ( [
17
17
[ pyth . BtcPriceIdentifier ] ,
18
18
[ pyth . StxPriceIdentifier ] ,
19
- [ pyth . BatPriceIdentifer ] ,
20
- [ pyth . DaiPriceIdentifer ] ,
21
- [ pyth . TbtcPriceIdentifer ] ,
22
- [ pyth . UsdcPriceIdentifer ] ,
23
- [ pyth . UsdtPriceIdentifer ] ,
24
- [ pyth . WbtcPriceIdentifer ] ,
19
+ [ pyth . BatPriceIdentifier ] ,
20
+ [ pyth . DaiPriceIdentifier ] ,
21
+ [ pyth . TbtcPriceIdentifier ] ,
22
+ [ pyth . UsdcPriceIdentifier ] ,
23
+ [ pyth . UsdtPriceIdentifier ] ,
24
+ [ pyth . WbtcPriceIdentifier ] ,
25
25
] ) ;
26
26
let pricesUpdatesToSubmit = [
27
27
pyth . BtcPriceIdentifier ,
28
28
pyth . StxPriceIdentifier ,
29
- pyth . UsdcPriceIdentifer ,
29
+ pyth . UsdcPriceIdentifier ,
30
30
] ;
31
31
let pricesUpdatesVaaPayload = pyth . buildAuwvVaaPayload ( pricesUpdates ) ;
32
32
@@ -137,17 +137,17 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
137
137
let pricesUpdates = pyth . buildPriceUpdateBatch ( [
138
138
[ pyth . BtcPriceIdentifier ] ,
139
139
[ pyth . StxPriceIdentifier ] ,
140
- [ pyth . BatPriceIdentifer ] ,
141
- [ pyth . DaiPriceIdentifer ] ,
142
- [ pyth . TbtcPriceIdentifer ] ,
143
- [ pyth . UsdcPriceIdentifer ] ,
144
- [ pyth . UsdtPriceIdentifer ] ,
145
- [ pyth . WbtcPriceIdentifer ] ,
140
+ [ pyth . BatPriceIdentifier ] ,
141
+ [ pyth . DaiPriceIdentifier ] ,
142
+ [ pyth . TbtcPriceIdentifier ] ,
143
+ [ pyth . UsdcPriceIdentifier ] ,
144
+ [ pyth . UsdtPriceIdentifier ] ,
145
+ [ pyth . WbtcPriceIdentifier ] ,
146
146
] ) ;
147
147
let pricesUpdatesToSubmit = [
148
148
pyth . BtcPriceIdentifier ,
149
149
pyth . StxPriceIdentifier ,
150
- pyth . UsdcPriceIdentifer ,
150
+ pyth . UsdcPriceIdentifier ,
151
151
] ;
152
152
let pricesUpdatesVaaPayload = pyth . buildAuwvVaaPayload ( pricesUpdates ) ;
153
153
let executionPlan = Cl . tuple ( {
@@ -194,6 +194,16 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
194
194
3n ,
195
195
) ;
196
196
197
+ pyth . applyStalePriceThresholdUpdate (
198
+ { threshold : 10800n } ,
199
+ pyth . DefaultGovernanceDataSource ,
200
+ guardianSet ,
201
+ sender ,
202
+ pythGovernanceContractName ,
203
+ wormholeCoreContractName ,
204
+ 4n ,
205
+ ) ;
206
+
197
207
let payload = pyth . serializeAuwvVaaPayloadToBuffer ( pricesUpdatesVaaPayload ) ;
198
208
let vaaBody = wormhole . buildValidVaaBodySpecs ( {
199
209
payload,
@@ -211,14 +221,53 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
211
221
pricesUpdatesToSubmit,
212
222
} ) ;
213
223
214
- pricesUpdates . decoded [ 0 ] ;
215
-
216
- simnet . callPublicFn (
224
+ let res = simnet . callPublicFn (
217
225
pythOracleContractName ,
218
226
"verify-and-update-price-feeds" ,
219
227
[ Cl . buffer ( pnau ) , executionPlan ] ,
220
228
sender ,
221
229
) ;
230
+
231
+ expect ( res . result ) . toBeOk (
232
+ Cl . list ( [
233
+ Cl . tuple ( {
234
+ "price-identifier" : Cl . buffer ( pyth . BtcPriceIdentifier ) ,
235
+ price : Cl . int ( pricesUpdates . decoded [ 0 ] . price ) ,
236
+ conf : Cl . uint ( pricesUpdates . decoded [ 0 ] . conf ) ,
237
+ "ema-conf" : Cl . uint ( pricesUpdates . decoded [ 0 ] . emaConf ) ,
238
+ "ema-price" : Cl . int ( pricesUpdates . decoded [ 0 ] . emaPrice ) ,
239
+ expo : Cl . int ( pricesUpdates . decoded [ 0 ] . expo ) ,
240
+ "prev-publish-time" : Cl . uint (
241
+ pricesUpdates . decoded [ 0 ] . prevPublishTime ,
242
+ ) ,
243
+ "publish-time" : Cl . uint ( pricesUpdates . decoded [ 0 ] . publishTime ) ,
244
+ } ) ,
245
+ Cl . tuple ( {
246
+ "price-identifier" : Cl . buffer ( pyth . StxPriceIdentifier ) ,
247
+ price : Cl . int ( pricesUpdates . decoded [ 1 ] . price ) ,
248
+ conf : Cl . uint ( pricesUpdates . decoded [ 1 ] . conf ) ,
249
+ "ema-conf" : Cl . uint ( pricesUpdates . decoded [ 1 ] . emaConf ) ,
250
+ "ema-price" : Cl . int ( pricesUpdates . decoded [ 1 ] . emaPrice ) ,
251
+ expo : Cl . int ( pricesUpdates . decoded [ 1 ] . expo ) ,
252
+ "prev-publish-time" : Cl . uint (
253
+ pricesUpdates . decoded [ 1 ] . prevPublishTime ,
254
+ ) ,
255
+ "publish-time" : Cl . uint ( pricesUpdates . decoded [ 1 ] . publishTime ) ,
256
+ } ) ,
257
+ Cl . tuple ( {
258
+ "price-identifier" : Cl . buffer ( pyth . UsdcPriceIdentifier ) ,
259
+ price : Cl . int ( pricesUpdates . decoded [ 2 ] . price ) ,
260
+ conf : Cl . uint ( pricesUpdates . decoded [ 2 ] . conf ) ,
261
+ "ema-conf" : Cl . uint ( pricesUpdates . decoded [ 2 ] . emaConf ) ,
262
+ "ema-price" : Cl . int ( pricesUpdates . decoded [ 2 ] . emaPrice ) ,
263
+ expo : Cl . int ( pricesUpdates . decoded [ 2 ] . expo ) ,
264
+ "prev-publish-time" : Cl . uint (
265
+ pricesUpdates . decoded [ 2 ] . prevPublishTime ,
266
+ ) ,
267
+ "publish-time" : Cl . uint ( pricesUpdates . decoded [ 2 ] . publishTime ) ,
268
+ } ) ,
269
+ ] ) ,
270
+ ) ;
222
271
} ) ;
223
272
224
273
it ( "should succeed updating prices once" , ( ) => {
@@ -248,12 +297,12 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
248
297
let outdatedPricesUpdates = pyth . buildPriceUpdateBatch ( [
249
298
[ pyth . BtcPriceIdentifier , { price : 0n , publishTime : 9999999n } ] ,
250
299
[ pyth . StxPriceIdentifier ] ,
251
- [ pyth . BatPriceIdentifer ] ,
252
- [ pyth . DaiPriceIdentifer ] ,
253
- [ pyth . TbtcPriceIdentifer ] ,
254
- [ pyth . UsdcPriceIdentifer ] ,
255
- [ pyth . UsdtPriceIdentifer ] ,
256
- [ pyth . WbtcPriceIdentifer ] ,
300
+ [ pyth . BatPriceIdentifier ] ,
301
+ [ pyth . DaiPriceIdentifier ] ,
302
+ [ pyth . TbtcPriceIdentifier ] ,
303
+ [ pyth . UsdcPriceIdentifier ] ,
304
+ [ pyth . UsdtPriceIdentifier ] ,
305
+ [ pyth . WbtcPriceIdentifier ] ,
257
306
] ) ;
258
307
let outdatedPricesUpdatesVaaPayload = pyth . buildAuwvVaaPayload (
259
308
outdatedPricesUpdates ,
@@ -310,12 +359,12 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
310
359
let actualPricesUpdates = pyth . buildPriceUpdateBatch ( [
311
360
[ pyth . BtcPriceIdentifier ] ,
312
361
[ pyth . StxPriceIdentifier ] ,
313
- [ pyth . BatPriceIdentifer ] ,
314
- [ pyth . DaiPriceIdentifer ] ,
315
- [ pyth . TbtcPriceIdentifer ] ,
316
- [ pyth . UsdcPriceIdentifer ] ,
317
- [ pyth . UsdtPriceIdentifer ] ,
318
- [ pyth . WbtcPriceIdentifer ] ,
362
+ [ pyth . BatPriceIdentifier ] ,
363
+ [ pyth . DaiPriceIdentifier ] ,
364
+ [ pyth . TbtcPriceIdentifier ] ,
365
+ [ pyth . UsdcPriceIdentifier ] ,
366
+ [ pyth . UsdtPriceIdentifier ] ,
367
+ [ pyth . WbtcPriceIdentifier ] ,
319
368
] ) ;
320
369
let actualPricesUpdatesVaaPayload =
321
370
pyth . buildAuwvVaaPayload ( actualPricesUpdates ) ;
@@ -622,13 +671,16 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
622
671
expect ( res . result ) . toBeErr ( Cl . uint ( 2008 ) ) ;
623
672
} ) ;
624
673
625
- it ( "should fail if the price is above stale threshold" , ( ) => {
674
+ it ( "should fail if the price is below stale threshold" , ( ) => {
675
+ // Everytime a simnet block is being mined, we add 1500s to the initial genesis time - usually bringing us to the future.
676
+ let onChainTime = pyth . timestampNow ( ) + 1500n * BigInt ( simnet . blockHeight ) ;
677
+ simnet . mineEmptyBlocks ( 7 ) ; // stale threshold set to 10800 (3 hours), so by mining 7 blocks (1800s), we are advancing enough
626
678
let actualPricesUpdates = pyth . buildPriceUpdateBatch ( [
627
679
[
628
680
pyth . BtcPriceIdentifier ,
629
681
{
630
682
price : 100n ,
631
- publishTime : pyth . timestampNow ( ) - ( 5n * 365n * 60n * 60n + 1n ) ,
683
+ publishTime : onChainTime ,
632
684
} ,
633
685
] ,
634
686
] ) ;
@@ -663,16 +715,24 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
663
715
} ) ;
664
716
665
717
it ( "should only return validated prices and filter invalid prices" , ( ) => {
718
+ // Everytime a simnet block is being mined, we add 1500s to the initial genesis time - usually bringing us to the future.
719
+ let previousOnChainTime =
720
+ pyth . timestampNow ( ) + 1500n * BigInt ( simnet . blockHeight ) ;
721
+ simnet . mineEmptyBlocks ( 7 ) ; // stale threshold set to 10800 (3 hours), so by mining 7 blocks (1800s), we are advancing enough
722
+ let newOnChainTime =
723
+ pyth . timestampNow ( ) + 1500n * BigInt ( simnet . blockHeight ) ;
666
724
let actualPricesUpdates = pyth . buildPriceUpdateBatch ( [
667
725
[
668
726
pyth . BtcPriceIdentifier ,
669
727
{
670
728
price : 100n ,
671
- publishTime : pyth . timestampNow ( ) - ( 5n * 365n * 60n * 60n + 1n ) ,
729
+ publishTime : previousOnChainTime ,
672
730
} ,
673
731
] ,
674
- [ pyth . StxPriceIdentifier , { price : 100n } ] ,
732
+ [ pyth . StxPriceIdentifier , { price : 100n , publishTime : newOnChainTime } ] ,
733
+ [ pyth . UsdcPriceIdentifier , { price : 100n , publishTime : newOnChainTime } ] ,
675
734
] ) ;
735
+
676
736
let actualPricesUpdatesVaaPayload =
677
737
pyth . buildAuwvVaaPayload ( actualPricesUpdates ) ;
678
738
let payload = pyth . serializeAuwvVaaPayloadToBuffer (
@@ -714,6 +774,18 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
714
774
) ,
715
775
"publish-time" : Cl . uint ( actualPricesUpdates . decoded [ 1 ] . publishTime ) ,
716
776
} ) ,
777
+ Cl . tuple ( {
778
+ "price-identifier" : Cl . buffer ( pyth . UsdcPriceIdentifier ) ,
779
+ price : Cl . int ( actualPricesUpdates . decoded [ 2 ] . price ) ,
780
+ conf : Cl . uint ( actualPricesUpdates . decoded [ 2 ] . conf ) ,
781
+ "ema-conf" : Cl . uint ( actualPricesUpdates . decoded [ 2 ] . emaConf ) ,
782
+ "ema-price" : Cl . int ( actualPricesUpdates . decoded [ 2 ] . emaPrice ) ,
783
+ expo : Cl . int ( actualPricesUpdates . decoded [ 2 ] . expo ) ,
784
+ "prev-publish-time" : Cl . uint (
785
+ actualPricesUpdates . decoded [ 2 ] . prevPublishTime ,
786
+ ) ,
787
+ "publish-time" : Cl . uint ( actualPricesUpdates . decoded [ 2 ] . publishTime ) ,
788
+ } ) ,
717
789
] ) ,
718
790
) ;
719
791
} ) ;
0 commit comments