1+ #![ cfg_attr( not( feature = "std" ) , no_std, no_main) ]
12extern crate alloc;
23
4+ #[ cfg( not( feature = "std" ) ) ]
35#[ global_allocator]
46static ALLOC : mini_alloc:: MiniAlloc = mini_alloc:: MiniAlloc :: INIT ;
57
8+ #[ cfg( not( feature = "std" ) ) ]
9+ #[ panic_handler]
10+ fn panic ( _info : & core:: panic:: PanicInfo ) -> ! {
11+ loop { }
12+ }
13+
614
715use alloc:: { vec, vec:: Vec } ;
816use stylus_sdk:: {
@@ -58,8 +66,8 @@ pub enum WormholeError {
5866}
5967
6068impl core:: fmt:: Debug for WormholeError {
61- fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
62- f . write_str ( "" )
69+ fn fmt ( & self , _ : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
70+ Ok ( ( ) )
6371 }
6472}
6573
@@ -486,28 +494,31 @@ mod tests {
486494 use core:: str:: FromStr ;
487495 use k256:: ecdsa:: SigningKey ;
488496 use stylus_sdk:: alloy_primitives:: keccak256;
497+
498+ #[ cfg( test) ]
489499 use base64:: engine:: general_purpose;
500+ #[ cfg( test) ]
490501 use base64:: Engine ;
491502
492503 const CHAIN_ID : u16 = 60051 ;
493504 const GOVERNANCE_CHAIN_ID : u16 = 1 ;
494505 const GOVERNANCE_CONTRACT : U256 = U256 :: from_limbs ( [ 4 , 0 , 0 , 0 ] ) ;
495506
507+ #[ cfg( test) ]
496508 fn test_wormhole_vaa ( ) -> Vec < u8 > {
497- let vaa_raw_base64 = "AQAAAAQNAKPLun8KH+IfCb2c9rlKrXV8wDcZUeMtLeoxoJLHAu7kH40xE1IY5uaJLT4PRsWDDv+7GHNT8rDP+4hUaJNHMtkBAvbQ7aUofV+VAoXjfqrU+V4Vzgvkpwuowaj0BMzNTSp2PkKz5BsnfvC7cxVwOw9sJnQfPvN8KrmhA0IXgQdkQDIBA/0sVNcwZm1oic2G6r7c3x5DyEO9sRF2sTDyM4nuiOtaWPb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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMMN2oOke3QAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABu3yoHkAEAAAAAAAAAAAAAAAAPpLFVLLUvQgzfCF8uDxxgOpZXNaAAAAAAAAAAAAAAAAegpThHd29+lMw1dClxrLIhew24EAAAAAAAAAAAAAAAB6ClOEd3b36UzDV0KXGssiF7DbgQAAAAAAAAAAAAAAACdCjdLT3TKk1/fEl+qqIxMNiUkRAA==" ;
498- let vaa_bytes = general_purpose:: STANDARD . decode ( vaa_raw_base64) . unwrap ( ) ;
499- let vaa: Vec < u8 > = vaa_bytes;
500- vaa
509+ general_purpose:: STANDARD . decode ( "AQAAAAQNAKPLun8KH+IfCb2c9rlKrXV8wDcZUeMtLeoxoJLHAu7kH40xE1IY5uaJLT4PRsWDDv+7GHNT8rDP+4hUaJNHMtkBAvbQ7aUofV+VAoXjfqrU+V4Vzgvkpwuowaj0BMzNTSp2PkKz5BsnfvC7cxVwOw9sJnQfPvN8KrmhA0IXgQdkQDIBA/0sVNcwZm1oic2G6r7c3x5DyEO9sRF2sTDyM4nuiOtaWPbgolaK6iU3yTx2bEzjdKsdVD2z3qs/QReV8ZxtA5MBBKSm2RKacsgdvwwNZPB3Ifw3P2niCAhZA435PkYeZpDBd8GQ4hALy+42lffR+AXJu19pNs+thWSxq7GRxF5oKz8BBYYS1n9/PJOybDhuWS+PI6YU0CFVTC9pTFSFTlMcEpjsUbT+cUKYCcFU63YaeVGUEPmhFYKeUeRhhQ5g2cCPIegABqts6uHMo5hrdXujJHVEqngLCSaQpB2W9I32LcIvKBfxLcx9IZTjxJ36tyNo7VJ6Fu1FbXnLW0lzaSIbmVmlGukABzpn+9z3bHT6g16HeroSW/YWNlZD5Jo6Zuw9/LT4VD0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T3TKk1/fEl+qqIxMNiUkRAA==" ) . unwrap ( )
501510 }
502511
512+ #[ cfg( test) ]
503513 fn create_vaa_bytes ( input_string : & str ) -> Vec < u8 > {
504514 let vaa_bytes = general_purpose:: STANDARD
505515 . decode ( input_string)
506- . expect ( "dec" ) ;
516+ . unwrap ( ) ;
507517 let vaa: Vec < u8 > = vaa_bytes;
508518 vaa
509519 }
510520
521+ #[ cfg( test) ]
511522 fn test_guardian_secret1 ( ) -> [ u8 ; 32 ] {
512523 [
513524 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 ,
@@ -517,6 +528,7 @@ mod tests {
517528 ]
518529 }
519530
531+ #[ cfg( test) ]
520532 fn test_guardian_secret2 ( ) -> [ u8 ; 32 ] {
521533 [
522534 0x21 , 0x22 , 0x23 , 0x24 , 0x25 , 0x26 , 0x27 , 0x28 ,
@@ -526,6 +538,7 @@ mod tests {
526538 ]
527539 }
528540
541+ #[ cfg( test) ]
529542 fn test_guardian_address1 ( ) -> Address {
530543 let secret = test_guardian_secret1 ( ) ;
531544 let signing_key = SigningKey :: from_bytes ( & secret. into ( ) ) . expect ( "key" ) ;
@@ -538,6 +551,7 @@ mod tests {
538551 }
539552
540553
554+ #[ cfg( test) ]
541555 fn test_guardian_address2 ( ) -> Address {
542556 let secret = test_guardian_secret2 ( ) ;
543557 let signing_key = SigningKey :: from_bytes ( & secret. into ( ) ) . expect ( "key" ) ;
@@ -549,18 +563,20 @@ mod tests {
549563 Address :: from ( address_bytes)
550564 }
551565
566+ #[ cfg( test) ]
552567 fn deploy_with_test_guardian ( ) -> WormholeContract {
553568 let mut contract = WormholeContract :: default ( ) ;
554569 let guardians = vec ! [ test_guardian_address1( ) ] ;
555570 let governance_contract = Address :: from_slice ( & GOVERNANCE_CONTRACT . to_be_bytes :: < 32 > ( ) [ 12 ..32 ] ) ;
556571 match contract. store_gs ( 0 , guardians. clone ( ) , 0 ) {
557572 Ok ( _) => { }
558- Err ( _) => panic ! ( "s" ) ,
573+ Err ( _) => unreachable ! ( ) ,
559574 }
560575 contract. initialize ( guardians, CHAIN_ID , GOVERNANCE_CHAIN_ID , governance_contract) . unwrap ( ) ;
561576 contract
562577 }
563578
579+ #[ cfg( test) ]
564580 fn deploy_with_current_guardians ( ) -> WormholeContract {
565581 let mut contract = WormholeContract :: default ( ) ;
566582 let guardians = mock_guardian_set13 ( ) ;
@@ -570,6 +586,7 @@ mod tests {
570586 contract
571587 }
572588
589+ #[ cfg( test) ]
573590 fn deploy_with_mainnet_guardian_set0 ( ) -> WormholeContract {
574591 let mut contract = WormholeContract :: default ( ) ;
575592 let guardians = guardian_set0 ( ) ;
@@ -580,6 +597,7 @@ mod tests {
580597
581598
582599
600+ #[ cfg( test) ]
583601 fn deploy_with_mainnet_guardians ( ) -> WormholeContract {
584602 let mut contract = WormholeContract :: default ( ) ;
585603 let guardians = guardian_set4 ( ) ;
@@ -588,10 +606,12 @@ mod tests {
588606 contract
589607 }
590608
609+ #[ cfg( test) ]
591610 fn guardian_set0 ( ) -> Vec < Address > {
592611 vec ! [ Address :: from_str( "0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5" ) . unwrap( ) ]
593612 }
594613
614+ #[ cfg( test) ]
595615 fn guardian_set4 ( ) -> Vec < Address > {
596616 vec ! [
597617 Address :: from_str( "0x5893B5A76c3f739645648885bDCcC06cd70a3Cd3" ) . unwrap( ) ,
@@ -600,13 +620,15 @@ mod tests {
600620 ]
601621 }
602622
623+ #[ cfg( test) ]
603624 fn mock_guardian_set13 ( ) -> Vec < Address > {
604625 vec ! [
605626 Address :: from( [ 0x58 , 0x93 , 0xB5 , 0xA7 , 0x6c , 0x3f , 0x73 , 0x96 , 0x45 , 0x64 , 0x88 , 0x85 , 0xbD , 0xCc , 0xC0 , 0x6c , 0xd7 , 0x0a , 0x3C , 0xd3 ] ) ,
606627 Address :: from( [ 0xff , 0x6C , 0xB9 , 0x52 , 0x58 , 0x9B , 0xDE , 0x86 , 0x2c , 0x25 , 0xEf , 0x43 , 0x92 , 0x13 , 0x2f , 0xb9 , 0xD4 , 0xA4 , 0x21 , 0x57 ] ) ,
607628 ]
608629 }
609630
631+ #[ cfg( test) ]
610632 fn corrupted_vaa ( mut real_data : Vec < u8 > , pos : usize , random1 : u8 , random2 : u8 ) -> Vec < u8 > {
611633 if real_data. len ( ) < 2 {
612634 return real_data;
@@ -680,6 +702,7 @@ mod tests {
680702 } )
681703 }
682704
705+ #[ cfg( test) ]
683706 fn create_guardian_signature ( guardian_index : u8 ) -> GuardianSignature {
684707 GuardianSignature {
685708 guardian_index,
@@ -703,7 +726,7 @@ mod tests {
703726 let vaa_vec = test_wormhole_vaa ( ) ;
704727 let result = match WormholeContract :: parse_vm_static ( & vaa_vec) {
705728 Ok ( vaa) => vaa,
706- Err ( _) => panic ! ( "p" ) ,
729+ Err ( _) => unreachable ! ( ) ,
707730 } ;
708731 assert_eq ! ( result. signatures. len( ) , 13 )
709732 }
@@ -767,7 +790,7 @@ mod tests {
767790 ] ;
768791 match contract. store_gs ( 0 , guardians. clone ( ) , 0 ) {
769792 Ok ( _) => { } ,
770- Err ( _) => panic ! ( "s" ) ,
793+ Err ( _) => unreachable ! ( ) ,
771794 }
772795
773796 let signatures = vec ! [
@@ -877,7 +900,7 @@ mod tests {
877900 let i_u8: u8 = match i. try_into ( ) {
878901 Ok ( val) => val,
879902 Err ( _) => {
880- panic ! ( "i" ) ;
903+ unreachable ! ( ) ;
881904 }
882905 } ;
883906 let corrupted_data = corrupted_vaa ( vec ! [ 1 , 0 , 0 , 1 , 0 , 0 ] , i, i_u8, i_u8 * 2 ) ;
@@ -894,7 +917,7 @@ mod tests {
894917 let i_u8: u8 = match i. try_into ( ) {
895918 Ok ( val) => val,
896919 Err ( _) => {
897- panic ! ( "i" ) ;
920+ unreachable ! ( ) ;
898921 }
899922 } ;
900923 let base_vaa = vec ! [ 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
@@ -954,15 +977,15 @@ mod tests {
954977
955978 contract
956979 . store_gs ( 0 , guardian_set0 ( ) , 0 )
957- . unwrap_or_else ( |_| panic ! ( "sf" ) ) ;
980+ . unwrap ( ) ;
958981 contract
959982 . store_gs ( 4 , guardian_set4 ( ) , 0 )
960- . unwrap_or_else ( |_| panic ! ( "sf" ) ) ;
983+ . unwrap ( ) ;
961984
962985 let set0 = contract. get_gs_internal ( 0 )
963- . unwrap_or_else ( || panic ! ( "gf" ) ) ;
986+ . unwrap ( ) ;
964987 let set4 = contract. get_gs_internal ( 4 )
965- . unwrap_or_else ( || panic ! ( "gf" ) ) ;
988+ . unwrap ( ) ;
966989
967990 assert_eq ! ( set0. keys, guardian_set0( ) ) ;
968991 assert_eq ! ( set4. keys, guardian_set4( ) ) ;
@@ -977,7 +1000,7 @@ mod tests {
9771000 ] ;
9781001 match contract. store_gs ( 0 , guardians. clone ( ) , 0 ) {
9791002 Ok ( ( ) ) => ( ) ,
980- Err ( _) => panic ! ( "s" ) ,
1003+ Err ( _) => unreachable ! ( ) ,
9811004 }
9821005 let hash = FixedBytes :: < 32 > :: from ( [ 0x42u8 ; 32 ] ) ;
9831006
0 commit comments