Quellcode durchsuchen

pushing temp changes.

Ayush Suresh vor 4 Monaten
Ursprung
Commit
c1e6badc2e

+ 32 - 19
target_chains/stylus/contracts/pyth-receiver/src/lib.rs

@@ -530,6 +530,7 @@ impl PythReceiver {
     ) -> Result<(), PythReceiverError> {
         let wormhole: IWormholeContract = IWormholeContract::new(self.wormhole.get());
         let config = Call::new();
+
         wormhole
             .parse_and_verify_vm(config, Vec::from(data.clone()))
             .map_err(|_| PythReceiverError::InvalidWormholeMessage)?;
@@ -619,10 +620,13 @@ impl PythReceiver {
         let new_valid_period = U256::from(valid_time_period_seconds);
         self.valid_time_period_seconds.set(new_valid_period);
 
-        log(self.vm(), ValidPeriodSet {
-            old_valid_period,
-            new_valid_period,
-        });
+        log(
+            self.vm(),
+            ValidPeriodSet {
+                old_valid_period,
+                new_valid_period,
+            },
+        );
     }
 
     fn set_wormhole_address(
@@ -725,13 +729,16 @@ impl PythReceiver {
         self.last_executed_governance_sequence
             .set(U64::from(last_executed_governance_sequence));
 
-        log(self.vm(), GovernanceDataSourceSet {
-            old_chain_id: current_index as u16,
-            old_emitter_address: self.governance_data_source_emitter_address.get(),
-            new_chain_id: claim_vm.body.emitter_chain,
-            new_emitter_address: FixedBytes::from(emitter_bytes),
-            initial_sequence: last_executed_governance_sequence,
-        });
+        log(
+            self.vm(),
+            GovernanceDataSourceSet {
+                old_chain_id: current_index as u16,
+                old_emitter_address: self.governance_data_source_emitter_address.get(),
+                new_chain_id: claim_vm.body.emitter_chain,
+                new_emitter_address: FixedBytes::from(emitter_bytes),
+                initial_sequence: last_executed_governance_sequence,
+            },
+        );
 
         Ok(())
     }
@@ -762,10 +769,13 @@ impl PythReceiver {
             .transfer_eth(target_address, fee_to_withdraw)
             .map_err(|_| PythReceiverError::InsufficientFee)?;
 
-        log(self.vm(), FeeWithdrawn {
-            target_address,
-            fee_amount: fee_to_withdraw,
-        });
+        log(
+            self.vm(),
+            FeeWithdrawn {
+                target_address,
+                fee_amount: fee_to_withdraw,
+            },
+        );
 
         Ok(())
     }
@@ -835,8 +845,11 @@ fn set_data_sources(receiver: &mut PythReceiver, data_sources: Vec<DataSource>)
         receiver.is_valid_data_source.setter(data_source).set(true);
     }
 
-    log(receiver.vm(), DataSourcesSet {
-        old_data_sources,
-        new_data_sources,
-    });
+    log(
+        receiver.vm(),
+        DataSourcesSet {
+            old_data_sources,
+            new_data_sources,
+        },
+    );
 }

+ 27 - 20
target_chains/stylus/contracts/pyth-receiver/src/pyth_governance_test.rs

@@ -1,8 +1,13 @@
 #[cfg(test)]
 mod test {
+    use crate::error::PythReceiverError;
+    use crate::test_data::*;
     use crate::PythReceiver;
     use alloy_primitives::{Address, U256};
+    use mock_instant::global::MockClock;
     use motsu::prelude::*;
+    use pythnet_sdk::wire::v1::{AccumulatorUpdateData, Proof};
+    use std::time::Duration;
     use hex::FromHex;
     use wormhole_contract::WormholeContract;
     use wormhole_vaas::{Vaa, Readable, Writeable};
@@ -18,11 +23,25 @@ mod test {
     const GOVERNANCE_CONTRACT: U256 = U256::from_limbs([4, 0, 0, 0]);
 
     const SINGLE_UPDATE_FEE_IN_WEI: U256 = U256::from_limbs([100, 0, 0, 0]);
+    const TRANSACTION_FEE_IN_WEI: U256 = U256::from_limbs([32, 0, 0, 0]);
+    
+    const TEST_SIGNER1: Address = Address::new([
+        0xbe, 0xFA, 0x42, 0x9d, 0x57, 0xcD, 0x18, 0xb7, 0xF8, 0xA4, 0xd9, 0x1A, 0x2d, 0xa9, 0xAB, 0x4A, 0xF0, 0x5d, 0x0F, 0xBe
+    ]);
+    const TEST_SIGNER2: Address = Address::new([
+        0x4b, 0xa0, 0xC2, 0xdb, 0x9A, 0x26, 0x20, 0x8b, 0x3b, 0xB1, 0xa5, 0x0B, 0x01, 0xb1, 0x69, 0x41, 0xc1, 0x0D, 0x76, 0xdb
+    ]);
     const GOVERNANCE_CHAIN_ID: u16 = 1;
     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
     ];
+    const TEST_PYTH2_WORMHOLE_CHAIN_ID: u16 = 1;
+    const TEST_PYTH2_WORMHOLE_EMITTER: [u8; 32] = [
+        0x71, 0xf8, 0xdc, 0xb8, 0x63, 0xd1, 0x76, 0xe2, 0xc4, 0x20, 0xad, 0x66, 0x10, 0xcf, 0x68, 0x73,
+        0x59, 0x61, 0x2b, 0x6f, 0xb3, 0x92, 0xe0, 0x64, 0x2b, 0x0c, 0xa6, 0xb1, 0xf1, 0x86, 0xaa, 0x3b
+    ];
+    const TARGET_CHAIN_ID: u16 = 2;
 
     #[cfg(test)]
     fn pyth_wormhole_init(
@@ -35,13 +54,14 @@ mod test {
             Address::new([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02]),
             Address::new([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03]),
         ];
+        
         let governance_contract =
             Address::from_slice(&GOVERNANCE_CONTRACT.to_be_bytes::<32>()[12..32]);
         wormhole_contract
             .sender(*alice)
             .initialize(
                 guardians,
-                0, // guardian set index 0
+                4,
                 CHAIN_ID,
                 GOVERNANCE_CHAIN_ID,
                 governance_contract,
@@ -77,29 +97,16 @@ mod test {
     ) {
         pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice);
 
-
         let hex_str = "01000000000100a53d7675143a514fa10756ef19e1281648aec03be2ea071c139f241839cb01206ce5c7f3673fc446a045cab2d4f97ef0de01de70269ab2678bba76b41c3a60ce010000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010200020100010000000000000000000000000000000000000000000000000000000000001111";
         let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
 
-        use wormhole_vaas::Vaa;
-        let vm = Vaa::read(&mut bytes.as_slice()).expect("Failed to parse VAA");
-        let instruction = crate::governance_structs::parse_instruction(vm.body.payload.to_vec())
-            .expect("Failed to parse governance instruction");
-        
-        match instruction.payload {
-            crate::governance_structs::GovernancePayload::SetDataSources(payload) => {
-                assert_eq!(payload.sources.len(), 1);
-                let expected_source = &payload.sources[0];
-                assert_eq!(expected_source.chain_id.to::<u16>(), 1);
-                assert_eq!(expected_source.emitter_address.as_slice(), &[
-                    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
-                ]);
-                println!("Successfully parsed SetDataSources governance instruction with {} data sources", payload.sources.len());
-            }
-            _ => panic!("Expected SetDataSources governance instruction"),
+        let result = pyth_contract.sender(alice).execute_governance_instruction(bytes.clone());
+        if let Err(e) = &result {
+            println!("Governance instruction failed with error: {:?}", e);
         }
-
+        
+        println!("{:?}", result);
+        assert!(result.is_ok());
     }
 
 }