Browse Source

Update test_set_wormhole_address with wormhole_contract_2 parameter and initialization

- Add wormhole_contract_2: Contract<WormholeContract> parameter to function signature
- Add wormhole_contract_2.initialize() call before hex_str format
- Update VAA to use wormhole_contract_2.address() as the address being submitted
- Uncomment the test

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
Devin AI 4 months ago
parent
commit
2441d0a804

+ 41 - 30
target_chains/stylus/contracts/pyth-receiver/src/pyth_governance_test.rs

@@ -182,38 +182,49 @@ mod test {
         );
     }
 
-    // This test is commented out because it requires an already deployed new Wormhole contract.
-    // This function demonstrates the usage of this instruction, however.
-    /*
-        #[motsu::test]
-        fn test_set_wormhole_address(
-            pyth_contract: Contract<PythReceiver>,
-            wormhole_contract: Contract<WormholeContract>,
-            alice: Address,
-        ) {
-            pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
-
-            let hex_str = "010000000001001daf08e5e3799cbc6096a90c2361e43220325418f377620a7a73d6bece18322679f6ada9725d9081743805efb8bccecd51098f1d76f34cba8b835fae643bbd9c000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010600027e5f4552091a69125d5dfcb7b8c2659029395bdf";
-            let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
-
-            let result = pyth_contract
-                .sender(alice)
-                .execute_governance_instruction(bytes.clone());
-            if result.is_err() {
-                println!(
-                    "SetWormholeAddress Error: {:?}",
-                    result.as_ref().unwrap_err()
-                );
-            }
-            assert!(result.is_ok());
-
-            let result2 = pyth_contract
-                .sender(alice)
-                .execute_governance_instruction(bytes.clone());
-            assert!(result2.is_err(), "Second execution should fail due to sequence number check");
+    #[motsu::test]
+    fn test_set_wormhole_address(
+        pyth_contract: Contract<PythReceiver>,
+        wormhole_contract: Contract<WormholeContract>,
+        wormhole_contract_2: Contract<WormholeContract>,
+        alice: Address,
+    ) {
+        pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
+
+        let guardians = vec![address!("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf")];
+        let governance_contract =
+            Address::from_slice(&GOVERNANCE_CONTRACT.to_be_bytes::<32>()[12..32]);
+        wormhole_contract_2
+            .sender(alice)
+            .initialize(
+                guardians,
+                0,
+                CHAIN_ID,
+                GOVERNANCE_CHAIN_ID,
+                governance_contract,
+            )
+            .unwrap();
+
+        let hex_str = format!("010000000001001daf08e5e3799cbc6096a90c2361e43220325418f377620a7a73d6bece18322679f6ada9725d9081743805efb8bccecd51098f1d76f34cba8b835fae643bbd9c000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d01060002{:040x}", wormhole_contract_2.address());
+        let bytes = Vec::from_hex(&hex_str).expect("Invalid hex string");
 
+        let result = pyth_contract
+            .sender(alice)
+            .execute_governance_instruction(bytes.clone());
+        if result.is_err() {
+            println!(
+                "SetWormholeAddress Error: {:?}",
+                result.as_ref().unwrap_err()
+            );
         }
-    */
+        assert!(result.is_ok());
+
+        let result2 = pyth_contract
+            .sender(alice)
+            .execute_governance_instruction(bytes.clone());
+        assert!(result2.is_err(), "Second execution should fail due to sequence number check");
+
+    }
     #[motsu::test]
     fn test_authorize_governance_data_source_transfer(
         pyth_contract: Contract<PythReceiver>,