@@ -49,25 +49,11 @@ mod test {
4949 }
5050
5151 #[ cfg( test) ]
52- fn pyth_wormhole_init (
52+ fn pyth_init (
5353 pyth_contract : & Contract < PythReceiver > ,
5454 wormhole_contract : & Contract < WormholeContract > ,
5555 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 > {
7157 let single_update_fee = SINGLE_UPDATE_FEE_IN_WEI ;
7258 let valid_time_period = U256 :: from ( 3600u64 ) ;
7359
@@ -87,7 +73,33 @@ mod test {
8773 governance_chain_id,
8874 governance_emitter_address,
8975 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 ( ( ) )
91103 }
92104
93105 #[ motsu:: test]
@@ -96,7 +108,7 @@ mod test {
96108 wormhole_contract : Contract < WormholeContract > ,
97109 alice : Address ,
98110 ) {
99- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
111+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
100112
101113 let update_data = ban_usd_update ( ) ;
102114 let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -121,7 +133,7 @@ mod test {
121133 wormhole_contract : Contract < WormholeContract > ,
122134 alice : Address ,
123135 ) {
124- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
136+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
125137
126138 alice. fund ( U256 :: from ( 200 ) ) ;
127139
@@ -142,7 +154,7 @@ mod test {
142154 wormhole_contract : Contract < WormholeContract > ,
143155 alice : Address ,
144156 ) {
145- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
157+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
146158
147159 let update_data1 = ban_usd_update ( ) ;
148160 let update_fee1 = mock_get_update_fee ( update_data1. clone ( ) ) . unwrap ( ) ;
@@ -175,7 +187,7 @@ mod test {
175187 wormhole_contract : Contract < WormholeContract > ,
176188 alice : Address ,
177189 ) {
178- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
190+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
179191
180192 let price_result = pyth_contract
181193 . sender ( alice)
@@ -194,7 +206,7 @@ mod test {
194206 alice : Address ,
195207 ) {
196208 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) ;
198210
199211 let random_id: [ u8 ; 32 ] = [
200212 0x12 , 0x34 , 0x56 , 0x78 , 0x9a , 0xbc , 0xde , 0xf0 , 0x12 , 0x34 , 0x56 , 0x78 , 0x9a , 0xbc ,
@@ -219,7 +231,7 @@ mod test {
219231 alice : Address ,
220232 ) {
221233 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) ;
223235
224236 let update_data = btc_usd_update ( ) ;
225237 let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -245,7 +257,7 @@ mod test {
245257 alice : Address ,
246258 ) {
247259 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) ;
249261
250262 let update_data = btc_usd_update ( ) ;
251263 let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -274,7 +286,7 @@ mod test {
274286 wormhole_contract : Contract < WormholeContract > ,
275287 alice : Address ,
276288 ) {
277- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
289+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
278290
279291 let update_data = multiple_updates_diff_vaa ( ) ;
280292 let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -311,7 +323,7 @@ mod test {
311323 wormhole_contract : Contract < WormholeContract > ,
312324 alice : Address ,
313325 ) {
314- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
326+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
315327
316328 assert ! ( !pyth_contract
317329 . sender( alice)
@@ -338,7 +350,7 @@ mod test {
338350 wormhole_contract : Contract < WormholeContract > ,
339351 alice : Address ,
340352 ) {
341- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
353+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
342354
343355 let price_result = pyth_contract
344356 . sender ( alice)
@@ -357,7 +369,7 @@ mod test {
357369 wormhole_contract : Contract < WormholeContract > ,
358370 alice : Address ,
359371 ) {
360- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
372+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
361373
362374 let update_data = ban_usd_update ( ) ;
363375 let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -384,7 +396,7 @@ mod test {
384396 wormhole_contract : Contract < WormholeContract > ,
385397 alice : Address ,
386398 ) {
387- pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
399+ let _ = pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
388400
389401 let update_data = multiple_updates_diff_vaa ( ) ;
390402 let update_fee = mock_get_update_fee ( update_data. clone ( ) ) . unwrap ( ) ;
@@ -417,4 +429,21 @@ mod test {
417429 multiple_updates_diff_vaa_results_full( ) [ 1 ]
418430 ) ;
419431 }
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+ }
420449}
0 commit comments