Skip to content

Commit 2082a85

Browse files
Implement event assertions in pyth_governance_test.rs
- Add event type imports (FeeSet, TransactionFeeSet, DataSourcesSet, GovernanceDataSourceSet) - Update test_set_data_sources to assert DataSourcesSet event emission - Update test_set_fee to assert FeeSet event with correct old/new fee values - Update test_authorize_governance_data_source_transfer to assert GovernanceDataSourceSet event - Update test_set_transaction_fee to assert TransactionFeeSet event - Use motsu Contract::emitted() method for event verification - All governance tests now verify correct event emission and data Co-Authored-By: [email protected] <[email protected]>
1 parent c7be32b commit 2082a85

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(test)]
22
mod test {
3-
use crate::PythReceiver;
4-
use alloy_primitives::{address, Address, U256};
3+
use crate::{PythReceiver, FeeSet, TransactionFeeSet, DataSourcesSet, GovernanceDataSourceSet};
4+
use alloy_primitives::{address, Address, U256, FixedBytes};
55
use hex::FromHex;
66
use motsu::prelude::*;
77
use wormhole_contract::WormholeContract;
@@ -100,6 +100,17 @@ mod test {
100100
.execute_governance_instruction(bytes.clone());
101101
assert!(result.is_ok());
102102

103+
104+
let expected_event = DataSourcesSet {
105+
old_data_sources: vec![FixedBytes::from(PYTHNET_EMITTER_ADDRESS)],
106+
new_data_sources: vec![FixedBytes::from([
107+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109+
0x11, 0x11
110+
])],
111+
};
112+
assert!(pyth_contract.emitted(&expected_event), "DataSourcesSet event should be emitted");
113+
103114
let result2 = pyth_contract
104115
.sender(alice)
105116
.execute_governance_instruction(bytes.clone());
@@ -145,6 +156,13 @@ mod test {
145156

146157
assert!(result.is_ok());
147158

159+
let expected_new_fee = U256::from(5000);
160+
let expected_event = FeeSet {
161+
old_fee: SINGLE_UPDATE_FEE_IN_WEI,
162+
new_fee: expected_new_fee,
163+
};
164+
assert!(pyth_contract.emitted(&expected_event), "FeeSet event should be emitted");
165+
148166
let result2 = pyth_contract
149167
.sender(alice)
150168
.execute_governance_instruction(bytes.clone());
@@ -245,6 +263,15 @@ mod test {
245263
);
246264
}
247265
assert!(result.is_ok());
266+
267+
let expected_event = GovernanceDataSourceSet {
268+
old_chain_id: 0, // Initial governance_data_source_index
269+
old_emitter_address: FixedBytes::from(GOVERNANCE_EMITTER), // Initial governance emitter from pyth_wormhole_init
270+
new_chain_id: 1, // claim_vm.body.emitter_chain from the VAA
271+
new_emitter_address: FixedBytes::from(GOVERNANCE_EMITTER), // emitter_bytes from the VAA
272+
initial_sequence: 100, // claim_vm.body.sequence from the VAA (0x64 = 100)
273+
};
274+
assert!(pyth_contract.emitted(&expected_event), "GovernanceDataSourceSet event should be emitted");
248275
}
249276

250277
#[motsu::test]
@@ -269,6 +296,13 @@ mod test {
269296
}
270297
assert!(result.is_ok());
271298

299+
let expected_new_fee = U256::from(100000);
300+
let expected_event = TransactionFeeSet {
301+
old_fee: U256::ZERO,
302+
new_fee: expected_new_fee,
303+
};
304+
assert!(pyth_contract.emitted(&expected_event), "TransactionFeeSet event should be emitted");
305+
272306
let result2 = pyth_contract
273307
.sender(alice)
274308
.execute_governance_instruction(bytes.clone());

0 commit comments

Comments
 (0)