Skip to content

Commit c1e6bad

Browse files
committed
pushing temp changes.
1 parent a6c588d commit c1e6bad

File tree

2 files changed

+59
-39
lines changed

2 files changed

+59
-39
lines changed

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ impl PythReceiver {
530530
) -> Result<(), PythReceiverError> {
531531
let wormhole: IWormholeContract = IWormholeContract::new(self.wormhole.get());
532532
let config = Call::new();
533+
533534
wormhole
534535
.parse_and_verify_vm(config, Vec::from(data.clone()))
535536
.map_err(|_| PythReceiverError::InvalidWormholeMessage)?;
@@ -619,10 +620,13 @@ impl PythReceiver {
619620
let new_valid_period = U256::from(valid_time_period_seconds);
620621
self.valid_time_period_seconds.set(new_valid_period);
621622

622-
log(self.vm(), ValidPeriodSet {
623-
old_valid_period,
624-
new_valid_period,
625-
});
623+
log(
624+
self.vm(),
625+
ValidPeriodSet {
626+
old_valid_period,
627+
new_valid_period,
628+
},
629+
);
626630
}
627631

628632
fn set_wormhole_address(
@@ -725,13 +729,16 @@ impl PythReceiver {
725729
self.last_executed_governance_sequence
726730
.set(U64::from(last_executed_governance_sequence));
727731

728-
log(self.vm(), GovernanceDataSourceSet {
729-
old_chain_id: current_index as u16,
730-
old_emitter_address: self.governance_data_source_emitter_address.get(),
731-
new_chain_id: claim_vm.body.emitter_chain,
732-
new_emitter_address: FixedBytes::from(emitter_bytes),
733-
initial_sequence: last_executed_governance_sequence,
734-
});
732+
log(
733+
self.vm(),
734+
GovernanceDataSourceSet {
735+
old_chain_id: current_index as u16,
736+
old_emitter_address: self.governance_data_source_emitter_address.get(),
737+
new_chain_id: claim_vm.body.emitter_chain,
738+
new_emitter_address: FixedBytes::from(emitter_bytes),
739+
initial_sequence: last_executed_governance_sequence,
740+
},
741+
);
735742

736743
Ok(())
737744
}
@@ -762,10 +769,13 @@ impl PythReceiver {
762769
.transfer_eth(target_address, fee_to_withdraw)
763770
.map_err(|_| PythReceiverError::InsufficientFee)?;
764771

765-
log(self.vm(), FeeWithdrawn {
766-
target_address,
767-
fee_amount: fee_to_withdraw,
768-
});
772+
log(
773+
self.vm(),
774+
FeeWithdrawn {
775+
target_address,
776+
fee_amount: fee_to_withdraw,
777+
},
778+
);
769779

770780
Ok(())
771781
}
@@ -835,8 +845,11 @@ fn set_data_sources(receiver: &mut PythReceiver, data_sources: Vec<DataSource>)
835845
receiver.is_valid_data_source.setter(data_source).set(true);
836846
}
837847

838-
log(receiver.vm(), DataSourcesSet {
839-
old_data_sources,
840-
new_data_sources,
841-
});
848+
log(
849+
receiver.vm(),
850+
DataSourcesSet {
851+
old_data_sources,
852+
new_data_sources,
853+
},
854+
);
842855
}

target_chains/stylus/contracts/pyth-receiver/src/pyth_governance_test.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#[cfg(test)]
22
mod test {
3+
use crate::error::PythReceiverError;
4+
use crate::test_data::*;
35
use crate::PythReceiver;
46
use alloy_primitives::{Address, U256};
7+
use mock_instant::global::MockClock;
58
use motsu::prelude::*;
9+
use pythnet_sdk::wire::v1::{AccumulatorUpdateData, Proof};
10+
use std::time::Duration;
611
use hex::FromHex;
712
use wormhole_contract::WormholeContract;
813
use wormhole_vaas::{Vaa, Readable, Writeable};
@@ -18,11 +23,25 @@ mod test {
1823
const GOVERNANCE_CONTRACT: U256 = U256::from_limbs([4, 0, 0, 0]);
1924

2025
const SINGLE_UPDATE_FEE_IN_WEI: U256 = U256::from_limbs([100, 0, 0, 0]);
26+
const TRANSACTION_FEE_IN_WEI: U256 = U256::from_limbs([32, 0, 0, 0]);
27+
28+
const TEST_SIGNER1: Address = Address::new([
29+
0xbe, 0xFA, 0x42, 0x9d, 0x57, 0xcD, 0x18, 0xb7, 0xF8, 0xA4, 0xd9, 0x1A, 0x2d, 0xa9, 0xAB, 0x4A, 0xF0, 0x5d, 0x0F, 0xBe
30+
]);
31+
const TEST_SIGNER2: Address = Address::new([
32+
0x4b, 0xa0, 0xC2, 0xdb, 0x9A, 0x26, 0x20, 0x8b, 0x3b, 0xB1, 0xa5, 0x0B, 0x01, 0xb1, 0x69, 0x41, 0xc1, 0x0D, 0x76, 0xdb
33+
]);
2134
const GOVERNANCE_CHAIN_ID: u16 = 1;
2235
const GOVERNANCE_EMITTER: [u8; 32] = [
2336
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2437
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11
2538
];
39+
const TEST_PYTH2_WORMHOLE_CHAIN_ID: u16 = 1;
40+
const TEST_PYTH2_WORMHOLE_EMITTER: [u8; 32] = [
41+
0x71, 0xf8, 0xdc, 0xb8, 0x63, 0xd1, 0x76, 0xe2, 0xc4, 0x20, 0xad, 0x66, 0x10, 0xcf, 0x68, 0x73,
42+
0x59, 0x61, 0x2b, 0x6f, 0xb3, 0x92, 0xe0, 0x64, 0x2b, 0x0c, 0xa6, 0xb1, 0xf1, 0x86, 0xaa, 0x3b
43+
];
44+
const TARGET_CHAIN_ID: u16 = 2;
2645

2746
#[cfg(test)]
2847
fn pyth_wormhole_init(
@@ -35,13 +54,14 @@ mod test {
3554
Address::new([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02]),
3655
Address::new([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03]),
3756
];
57+
3858
let governance_contract =
3959
Address::from_slice(&GOVERNANCE_CONTRACT.to_be_bytes::<32>()[12..32]);
4060
wormhole_contract
4161
.sender(*alice)
4262
.initialize(
4363
guardians,
44-
0, // guardian set index 0
64+
4,
4565
CHAIN_ID,
4666
GOVERNANCE_CHAIN_ID,
4767
governance_contract,
@@ -77,29 +97,16 @@ mod test {
7797
) {
7898
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice);
7999

80-
81100
let hex_str = "01000000000100a53d7675143a514fa10756ef19e1281648aec03be2ea071c139f241839cb01206ce5c7f3673fc446a045cab2d4f97ef0de01de70269ab2678bba76b41c3a60ce010000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010200020100010000000000000000000000000000000000000000000000000000000000001111";
82101
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
83102

84-
use wormhole_vaas::Vaa;
85-
let vm = Vaa::read(&mut bytes.as_slice()).expect("Failed to parse VAA");
86-
let instruction = crate::governance_structs::parse_instruction(vm.body.payload.to_vec())
87-
.expect("Failed to parse governance instruction");
88-
89-
match instruction.payload {
90-
crate::governance_structs::GovernancePayload::SetDataSources(payload) => {
91-
assert_eq!(payload.sources.len(), 1);
92-
let expected_source = &payload.sources[0];
93-
assert_eq!(expected_source.chain_id.to::<u16>(), 1);
94-
assert_eq!(expected_source.emitter_address.as_slice(), &[
95-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11
97-
]);
98-
println!("Successfully parsed SetDataSources governance instruction with {} data sources", payload.sources.len());
99-
}
100-
_ => panic!("Expected SetDataSources governance instruction"),
103+
let result = pyth_contract.sender(alice).execute_governance_instruction(bytes.clone());
104+
if let Err(e) = &result {
105+
println!("Governance instruction failed with error: {:?}", e);
101106
}
102-
107+
108+
println!("{:?}", result);
109+
assert!(result.is_ok());
103110
}
104111

105112
}

0 commit comments

Comments
 (0)