Skip to content

Commit 2441d0a

Browse files
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: [email protected] <[email protected]>
1 parent 946f6e5 commit 2441d0a

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

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

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -182,38 +182,49 @@ mod test {
182182
);
183183
}
184184

185-
// This test is commented out because it requires an already deployed new Wormhole contract.
186-
// This function demonstrates the usage of this instruction, however.
187-
/*
188-
#[motsu::test]
189-
fn test_set_wormhole_address(
190-
pyth_contract: Contract<PythReceiver>,
191-
wormhole_contract: Contract<WormholeContract>,
192-
alice: Address,
193-
) {
194-
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
195-
196-
let hex_str = "010000000001001daf08e5e3799cbc6096a90c2361e43220325418f377620a7a73d6bece18322679f6ada9725d9081743805efb8bccecd51098f1d76f34cba8b835fae643bbd9c000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010600027e5f4552091a69125d5dfcb7b8c2659029395bdf";
197-
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
198-
199-
let result = pyth_contract
200-
.sender(alice)
201-
.execute_governance_instruction(bytes.clone());
202-
if result.is_err() {
203-
println!(
204-
"SetWormholeAddress Error: {:?}",
205-
result.as_ref().unwrap_err()
206-
);
207-
}
208-
assert!(result.is_ok());
209-
210-
let result2 = pyth_contract
211-
.sender(alice)
212-
.execute_governance_instruction(bytes.clone());
213-
assert!(result2.is_err(), "Second execution should fail due to sequence number check");
185+
#[motsu::test]
186+
fn test_set_wormhole_address(
187+
pyth_contract: Contract<PythReceiver>,
188+
wormhole_contract: Contract<WormholeContract>,
189+
wormhole_contract_2: Contract<WormholeContract>,
190+
alice: Address,
191+
) {
192+
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
193+
194+
let guardians = vec![address!("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf")];
195+
let governance_contract =
196+
Address::from_slice(&GOVERNANCE_CONTRACT.to_be_bytes::<32>()[12..32]);
197+
wormhole_contract_2
198+
.sender(alice)
199+
.initialize(
200+
guardians,
201+
0,
202+
CHAIN_ID,
203+
GOVERNANCE_CHAIN_ID,
204+
governance_contract,
205+
)
206+
.unwrap();
207+
208+
let hex_str = format!("010000000001001daf08e5e3799cbc6096a90c2361e43220325418f377620a7a73d6bece18322679f6ada9725d9081743805efb8bccecd51098f1d76f34cba8b835fae643bbd9c000000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d01060002{:040x}", wormhole_contract_2.address());
209+
let bytes = Vec::from_hex(&hex_str).expect("Invalid hex string");
214210

211+
let result = pyth_contract
212+
.sender(alice)
213+
.execute_governance_instruction(bytes.clone());
214+
if result.is_err() {
215+
println!(
216+
"SetWormholeAddress Error: {:?}",
217+
result.as_ref().unwrap_err()
218+
);
215219
}
216-
*/
220+
assert!(result.is_ok());
221+
222+
let result2 = pyth_contract
223+
.sender(alice)
224+
.execute_governance_instruction(bytes.clone());
225+
assert!(result2.is_err(), "Second execution should fail due to sequence number check");
226+
227+
}
217228
#[motsu::test]
218229
fn test_authorize_governance_data_source_transfer(
219230
pyth_contract: Contract<PythReceiver>,

0 commit comments

Comments
 (0)