Ayush Suresh 4 months ago
parent
commit
1e6251e19d

+ 23 - 40
target_chains/stylus/contracts/pyth-receiver/src/pyth_governance_test.rs

@@ -31,7 +31,7 @@ mod test {
     const GOVERNANCE_EMITTER: [u8; 32] = [
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x11,
+        0x11, 0x11,
     ];
     const TEST_PYTH2_WORMHOLE_CHAIN_ID: u16 = 1;
     const TEST_PYTH2_WORMHOLE_EMITTER: [u8; 32] = [
@@ -69,7 +69,7 @@ mod test {
         let data_source_chain_ids = vec![PYTHNET_CHAIN_ID];
         let data_source_emitter_addresses = vec![PYTHNET_EMITTER_ADDRESS];
 
-        let governance_chain_id = 1u16;
+        let governance_chain_id = 2u16;
         let governance_initial_sequence = 0u64;
 
         pyth_contract.sender(*alice).initialize(
@@ -92,17 +92,21 @@ mod test {
     ) {
         pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
 
-        let sources = vec![(1u16, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11])];
+        let sources = vec![(
+            1u16,
+            [
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x11, 0x11,
+            ],
+        )];
         let bytes = crate::test_utils::create_set_data_sources_vaa(sources);
 
         let result = pyth_contract
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
         if result.is_err() {
-            println!(
-                "SetDataSources Error: {:?}",
-                result.as_ref().unwrap_err()
-            );
+            println!("SetDataSources Error: {:?}", result.as_ref().unwrap_err());
         }
         assert!(result.is_ok());
 
@@ -143,10 +147,12 @@ mod test {
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
 
-        assert!(result.is_ok(), "SetValidPeriod governance instruction should succeed");
+        assert!(
+            result.is_ok(),
+            "SetValidPeriod governance instruction should succeed"
+        );
     }
 
-
     #[motsu::test]
     fn test_set_fee(
         pyth_contract: Contract<PythReceiver>,
@@ -231,8 +237,7 @@ mod test {
         alice: Address,
     ) {
         pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
-
-        let hex_str = "010000000001006fc27ac424b300c23a564bcabe1d7888a898cba92b8aec62468c35025baaf4a87056c50d443fbc172c3caa30d28ec57cefc0bbabf4590ffe98c44dff040d0e02000000000100000000000200000000000000000000000000000000000000000000000000000000000011110000000000000001005054474d0105000200000001";
+        let hex_str = "010000000001006fc27ac424b300c23a564bcabe1d7888a898cba92b8aec62468c35025baaf4a87056c50d443fbc172c3caa30d28ec57cefc0bbabf4590ffe98c44dff040d0e020000000001000000000002000000000000000000000000000000000000000000000000000000000000111100000000000001015054474d01010002010000000001006fc27ac424b300c23a564bcabe1d7888a898cba92b8aec62468c35025baaf4a87056c50d443fbc172c3caa30d28ec57cefc0bbabf4590ffe98c44dff040d0e02000000000100000000000200000000000000000000000000000000000000000000000000000000000011110000000000000001005054474d0105000200000001";
         let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
 
         let result = pyth_contract
@@ -341,10 +346,7 @@ mod test {
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
 
-        assert!(
-            result.is_err(),
-            "Invalid VAA should revert the transaction"
-        );
+        assert!(result.is_err(), "Invalid VAA should revert the transaction");
     }
 
     #[motsu::test]
@@ -363,10 +365,7 @@ mod test {
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
 
-        assert!(
-            result.is_err(),
-            "Invalid VAA should revert the transaction"
-        );
+        assert!(result.is_err(), "Invalid VAA should revert the transaction");
     }
 
     #[motsu::test]
@@ -384,10 +383,7 @@ mod test {
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
 
-        assert!(
-            result.is_err(),
-            "Invalid VAA should revert the transaction"
-        );
+        assert!(result.is_err(), "Invalid VAA should revert the transaction");
     }
 
     #[motsu::test]
@@ -406,10 +402,7 @@ mod test {
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
 
-        assert!(
-            result.is_err(),
-            "Invalid VAA should revert the transaction"
-        );
+        assert!(result.is_err(), "Invalid VAA should revert the transaction");
     }
 
     #[motsu::test]
@@ -428,10 +421,7 @@ mod test {
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
 
-        assert!(
-            result.is_err(),
-            "Invalid VAA should revert the transaction"
-        );
+        assert!(result.is_err(), "Invalid VAA should revert the transaction");
     }
 
     #[motsu::test]
@@ -450,10 +440,7 @@ mod test {
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
 
-        assert!(
-            result.is_err(),
-            "Invalid VAA should revert the transaction"
-        );
+        assert!(result.is_err(), "Invalid VAA should revert the transaction");
     }
 
     #[motsu::test]
@@ -471,10 +458,7 @@ mod test {
             .sender(alice)
             .execute_governance_instruction(bytes.clone());
 
-        assert!(
-            result.is_ok(),
-            "This is a valid VAA, should go through"
-        );
+        assert!(result.is_ok(), "This is a valid VAA, should go through");
 
         let result = pyth_contract
             .sender(alice)
@@ -529,5 +513,4 @@ mod test {
             "Wrong action expected should lead to bad parsing"
         );
     }
-
 }

+ 20 - 6
target_chains/stylus/contracts/pyth-receiver/src/test_utils.rs

@@ -1,5 +1,3 @@
-
-
 use alloc::vec::Vec;
 use hex::FromHex;
 use stylus_sdk::alloy_primitives::Address;
@@ -15,8 +13,15 @@ pub fn create_authorize_governance_data_source_transfer_vaa(_claim_vaa: Vec<u8>)
 }
 
 pub fn create_set_data_sources_vaa(sources: Vec<(u16, [u8; 32])>) -> Vec<u8> {
-    let expected_source = (1u16, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11]);
-    
+    let expected_source = (
+        1u16,
+        [
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x11, 0x11,
+        ],
+    );
+
     if sources.len() == 1 && sources[0] == expected_source {
         let hex_str = "0100000000010069825ef00344cf745b6e72a41d4f869d4e90de517849360c72bf94efc97681671d826e484747b21a80c8f1e7816021df9f55e458a6e7a717cb2bd2a1e85fd57100499602d200000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010200020100010000000000000000000000000000000000000000000000000000000000001111";
         Vec::from_hex(hex_str).expect("Invalid hex string")
@@ -35,7 +40,9 @@ pub fn create_set_valid_period_vaa(_valid_time_period_seconds: u64) -> Vec<u8> {
     Vec::from_hex(hex_str).expect("Invalid hex string")
 }
 
-pub fn create_request_governance_data_source_transfer_vaa(_governance_data_source_index: u32) -> Vec<u8> {
+pub fn create_request_governance_data_source_transfer_vaa(
+    _governance_data_source_index: u32,
+) -> Vec<u8> {
     let hex_str = "01000000000100b2e15dd5ef41b800ec5ec10f61c6415f706a769f459757f43be78a8fd9f1f6e104e909239fe73b4d8652f7aa1a07825e3230d01a0a7bd6efa0be2e7e72377d71010000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010500020000000000000000";
     Vec::from_hex(hex_str).expect("Invalid hex string")
 }
@@ -86,7 +93,14 @@ mod tests {
 
     #[test]
     fn test_create_set_data_sources_vaa() {
-        let sources = vec![(1u16, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11])];
+        let sources = vec![(
+            1u16,
+            [
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x11, 0x11,
+            ],
+        )];
         let vaa = create_set_data_sources_vaa(sources);
         assert!(!vaa.is_empty());
         let hex_str = hex::encode(&vaa);