@@ -49,25 +49,11 @@ mod test {
49
49
}
50
50
51
51
#[ cfg( test) ]
52
- fn pyth_wormhole_init (
52
+ fn pyth_init (
53
53
pyth_contract : & Contract < PythReceiver > ,
54
54
wormhole_contract : & Contract < WormholeContract > ,
55
55
alice : & Address ,
56
- ) {
57
- let guardians = current_guardians ( ) ;
58
- let governance_contract =
59
- Address :: from_slice ( & GOVERNANCE_CONTRACT . to_be_bytes :: < 32 > ( ) [ 12 ..32 ] ) ;
60
- wormhole_contract
61
- . sender ( * alice)
62
- . initialize (
63
- guardians,
64
- 4 ,
65
- CHAIN_ID ,
66
- GOVERNANCE_CHAIN_ID ,
67
- governance_contract,
68
- )
69
- . unwrap ( ) ;
70
-
56
+ ) -> Result < ( ) , PythReceiverError > {
71
57
let single_update_fee = SINGLE_UPDATE_FEE_IN_WEI ;
72
58
let valid_time_period = U256 :: from ( 3600u64 ) ;
73
59
@@ -87,7 +73,33 @@ mod test {
87
73
governance_chain_id,
88
74
governance_emitter_address,
89
75
governance_initial_sequence,
90
- ) ;
76
+ ) ?;
77
+
78
+ Ok ( ( ) )
79
+ }
80
+
81
+ #[ cfg( test) ]
82
+ fn pyth_wormhole_init (
83
+ pyth_contract : & Contract < PythReceiver > ,
84
+ wormhole_contract : & Contract < WormholeContract > ,
85
+ alice : & Address ,
86
+ ) -> Result < ( ) , PythReceiverError > {
87
+ let guardians = current_guardians ( ) ;
88
+ let governance_contract =
89
+ Address :: from_slice ( & GOVERNANCE_CONTRACT . to_be_bytes :: < 32 > ( ) [ 12 ..32 ] ) ;
90
+ wormhole_contract
91
+ . sender ( * alice)
92
+ . initialize (
93
+ guardians,
94
+ 4 ,
95
+ CHAIN_ID ,
96
+ GOVERNANCE_CHAIN_ID ,
97
+ governance_contract,
98
+ )
99
+ . unwrap ( ) ;
100
+
101
+ pyth_init ( pyth_contract, wormhole_contract, alice) ?;
102
+ Ok ( ( ) )
91
103
}
92
104
93
105
#[ motsu:: test]
@@ -96,7 +108,7 @@ mod test {
96
108
wormhole_contract : Contract < WormholeContract > ,
97
109
alice : Address ,
98
110
) {
99
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
111
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
100
112
101
113
let update_data = ban_usd_update ( ) ;
102
114
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -121,7 +133,7 @@ mod test {
121
133
wormhole_contract : Contract < WormholeContract > ,
122
134
alice : Address ,
123
135
) {
124
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
136
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
125
137
126
138
alice. fund ( U256 :: from ( 200 ) ) ;
127
139
@@ -142,7 +154,7 @@ mod test {
142
154
wormhole_contract : Contract < WormholeContract > ,
143
155
alice : Address ,
144
156
) {
145
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
157
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
146
158
147
159
let update_data1 = ban_usd_update ( ) ;
148
160
let update_fee1 = mock_get_update_fee ( update_data1. clone ( ) ) . unwrap ( ) ;
@@ -175,7 +187,7 @@ mod test {
175
187
wormhole_contract : Contract < WormholeContract > ,
176
188
alice : Address ,
177
189
) {
178
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
190
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
179
191
180
192
let price_result = pyth_contract
181
193
. sender ( alice)
@@ -194,7 +206,7 @@ mod test {
194
206
alice : Address ,
195
207
) {
196
208
MockClock :: set_time ( Duration :: from_secs ( 1761573860 ) ) ; // less than good_update2().timestamp + 1s
197
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
209
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
198
210
199
211
let random_id: [ u8 ; 32 ] = [
200
212
0x12 , 0x34 , 0x56 , 0x78 , 0x9a , 0xbc , 0xde , 0xf0 , 0x12 , 0x34 , 0x56 , 0x78 , 0x9a , 0xbc ,
@@ -219,7 +231,7 @@ mod test {
219
231
alice : Address ,
220
232
) {
221
233
MockClock :: set_time ( Duration :: from_secs ( 1761573860 ) ) ;
222
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
234
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
223
235
224
236
let update_data = btc_usd_update ( ) ;
225
237
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -245,7 +257,7 @@ mod test {
245
257
alice : Address ,
246
258
) {
247
259
MockClock :: set_time ( Duration :: from_secs ( 1761573860 ) ) ;
248
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
260
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
249
261
250
262
let update_data = btc_usd_update ( ) ;
251
263
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -274,7 +286,7 @@ mod test {
274
286
wormhole_contract : Contract < WormholeContract > ,
275
287
alice : Address ,
276
288
) {
277
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
289
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
278
290
279
291
let update_data = multiple_updates_diff_vaa ( ) ;
280
292
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -311,7 +323,7 @@ mod test {
311
323
wormhole_contract : Contract < WormholeContract > ,
312
324
alice : Address ,
313
325
) {
314
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
326
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
315
327
316
328
assert ! ( !pyth_contract
317
329
. sender( alice)
@@ -338,7 +350,7 @@ mod test {
338
350
wormhole_contract : Contract < WormholeContract > ,
339
351
alice : Address ,
340
352
) {
341
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
353
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
342
354
343
355
let price_result = pyth_contract
344
356
. sender ( alice)
@@ -357,7 +369,7 @@ mod test {
357
369
wormhole_contract : Contract < WormholeContract > ,
358
370
alice : Address ,
359
371
) {
360
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
372
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
361
373
362
374
let update_data = ban_usd_update ( ) ;
363
375
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -384,7 +396,7 @@ mod test {
384
396
wormhole_contract : Contract < WormholeContract > ,
385
397
alice : Address ,
386
398
) {
387
- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
399
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
388
400
389
401
let update_data = multiple_updates_diff_vaa ( ) ;
390
402
let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -417,4 +429,21 @@ mod test {
417
429
multiple_updates_diff_vaa_results_full( ) [ 1 ]
418
430
) ;
419
431
}
432
+
433
+ #[ motsu:: test]
434
+ fn test_double_initialization_reverts (
435
+ pyth_contract : Contract < PythReceiver > ,
436
+ wormhole_contract : Contract < WormholeContract > ,
437
+ alice : Address ,
438
+ ) {
439
+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
440
+
441
+ let double_init = pyth_init ( & pyth_contract, & wormhole_contract, & alice) ;
442
+
443
+ assert ! ( double_init. is_err( ) ) ;
444
+ assert_eq ! (
445
+ double_init. unwrap_err( ) ,
446
+ PythReceiverError :: AlreadyInitialized
447
+ ) ;
448
+ }
420
449
}
0 commit comments