Skip to content

Commit 1e6251e

Browse files
committed
tests
1 parent 01fecd0 commit 1e6251e

File tree

2 files changed

+43
-46
lines changed

2 files changed

+43
-46
lines changed

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

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod test {
3131
const GOVERNANCE_EMITTER: [u8; 32] = [
3232
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3333
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34-
0x00, 0x11,
34+
0x11, 0x11,
3535
];
3636
const TEST_PYTH2_WORMHOLE_CHAIN_ID: u16 = 1;
3737
const TEST_PYTH2_WORMHOLE_EMITTER: [u8; 32] = [
@@ -69,7 +69,7 @@ mod test {
6969
let data_source_chain_ids = vec![PYTHNET_CHAIN_ID];
7070
let data_source_emitter_addresses = vec![PYTHNET_EMITTER_ADDRESS];
7171

72-
let governance_chain_id = 1u16;
72+
let governance_chain_id = 2u16;
7373
let governance_initial_sequence = 0u64;
7474

7575
pyth_contract.sender(*alice).initialize(
@@ -92,17 +92,21 @@ mod test {
9292
) {
9393
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
9494

95-
let sources = vec![(1u16, [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])];
95+
let sources = vec![(
96+
1u16,
97+
[
98+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100+
0x00, 0x00, 0x11, 0x11,
101+
],
102+
)];
96103
let bytes = crate::test_utils::create_set_data_sources_vaa(sources);
97104

98105
let result = pyth_contract
99106
.sender(alice)
100107
.execute_governance_instruction(bytes.clone());
101108
if result.is_err() {
102-
println!(
103-
"SetDataSources Error: {:?}",
104-
result.as_ref().unwrap_err()
105-
);
109+
println!("SetDataSources Error: {:?}", result.as_ref().unwrap_err());
106110
}
107111
assert!(result.is_ok());
108112

@@ -143,10 +147,12 @@ mod test {
143147
.sender(alice)
144148
.execute_governance_instruction(bytes.clone());
145149

146-
assert!(result.is_ok(), "SetValidPeriod governance instruction should succeed");
150+
assert!(
151+
result.is_ok(),
152+
"SetValidPeriod governance instruction should succeed"
153+
);
147154
}
148155

149-
150156
#[motsu::test]
151157
fn test_set_fee(
152158
pyth_contract: Contract<PythReceiver>,
@@ -231,8 +237,7 @@ mod test {
231237
alice: Address,
232238
) {
233239
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
234-
235-
let hex_str = "010000000001006fc27ac424b300c23a564bcabe1d7888a898cba92b8aec62468c35025baaf4a87056c50d443fbc172c3caa30d28ec57cefc0bbabf4590ffe98c44dff040d0e02000000000100000000000200000000000000000000000000000000000000000000000000000000000011110000000000000001005054474d0105000200000001";
240+
let hex_str = "010000000001006fc27ac424b300c23a564bcabe1d7888a898cba92b8aec62468c35025baaf4a87056c50d443fbc172c3caa30d28ec57cefc0bbabf4590ffe98c44dff040d0e020000000001000000000002000000000000000000000000000000000000000000000000000000000000111100000000000001015054474d01010002010000000001006fc27ac424b300c23a564bcabe1d7888a898cba92b8aec62468c35025baaf4a87056c50d443fbc172c3caa30d28ec57cefc0bbabf4590ffe98c44dff040d0e02000000000100000000000200000000000000000000000000000000000000000000000000000000000011110000000000000001005054474d0105000200000001";
236241
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
237242

238243
let result = pyth_contract
@@ -341,10 +346,7 @@ mod test {
341346
.sender(alice)
342347
.execute_governance_instruction(bytes.clone());
343348

344-
assert!(
345-
result.is_err(),
346-
"Invalid VAA should revert the transaction"
347-
);
349+
assert!(result.is_err(), "Invalid VAA should revert the transaction");
348350
}
349351

350352
#[motsu::test]
@@ -363,10 +365,7 @@ mod test {
363365
.sender(alice)
364366
.execute_governance_instruction(bytes.clone());
365367

366-
assert!(
367-
result.is_err(),
368-
"Invalid VAA should revert the transaction"
369-
);
368+
assert!(result.is_err(), "Invalid VAA should revert the transaction");
370369
}
371370

372371
#[motsu::test]
@@ -384,10 +383,7 @@ mod test {
384383
.sender(alice)
385384
.execute_governance_instruction(bytes.clone());
386385

387-
assert!(
388-
result.is_err(),
389-
"Invalid VAA should revert the transaction"
390-
);
386+
assert!(result.is_err(), "Invalid VAA should revert the transaction");
391387
}
392388

393389
#[motsu::test]
@@ -406,10 +402,7 @@ mod test {
406402
.sender(alice)
407403
.execute_governance_instruction(bytes.clone());
408404

409-
assert!(
410-
result.is_err(),
411-
"Invalid VAA should revert the transaction"
412-
);
405+
assert!(result.is_err(), "Invalid VAA should revert the transaction");
413406
}
414407

415408
#[motsu::test]
@@ -428,10 +421,7 @@ mod test {
428421
.sender(alice)
429422
.execute_governance_instruction(bytes.clone());
430423

431-
assert!(
432-
result.is_err(),
433-
"Invalid VAA should revert the transaction"
434-
);
424+
assert!(result.is_err(), "Invalid VAA should revert the transaction");
435425
}
436426

437427
#[motsu::test]
@@ -450,10 +440,7 @@ mod test {
450440
.sender(alice)
451441
.execute_governance_instruction(bytes.clone());
452442

453-
assert!(
454-
result.is_err(),
455-
"Invalid VAA should revert the transaction"
456-
);
443+
assert!(result.is_err(), "Invalid VAA should revert the transaction");
457444
}
458445

459446
#[motsu::test]
@@ -471,10 +458,7 @@ mod test {
471458
.sender(alice)
472459
.execute_governance_instruction(bytes.clone());
473460

474-
assert!(
475-
result.is_ok(),
476-
"This is a valid VAA, should go through"
477-
);
461+
assert!(result.is_ok(), "This is a valid VAA, should go through");
478462

479463
let result = pyth_contract
480464
.sender(alice)
@@ -529,5 +513,4 @@ mod test {
529513
"Wrong action expected should lead to bad parsing"
530514
);
531515
}
532-
533516
}

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
use alloc::vec::Vec;
42
use hex::FromHex;
53
use stylus_sdk::alloy_primitives::Address;
@@ -15,8 +13,15 @@ pub fn create_authorize_governance_data_source_transfer_vaa(_claim_vaa: Vec<u8>)
1513
}
1614

1715
pub fn create_set_data_sources_vaa(sources: Vec<(u16, [u8; 32])>) -> Vec<u8> {
18-
let expected_source = (1u16, [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]);
19-
16+
let expected_source = (
17+
1u16,
18+
[
19+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21+
0x00, 0x00, 0x11, 0x11,
22+
],
23+
);
24+
2025
if sources.len() == 1 && sources[0] == expected_source {
2126
let hex_str = "0100000000010069825ef00344cf745b6e72a41d4f869d4e90de517849360c72bf94efc97681671d826e484747b21a80c8f1e7816021df9f55e458a6e7a717cb2bd2a1e85fd57100499602d200000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010200020100010000000000000000000000000000000000000000000000000000000000001111";
2227
Vec::from_hex(hex_str).expect("Invalid hex string")
@@ -35,7 +40,9 @@ pub fn create_set_valid_period_vaa(_valid_time_period_seconds: u64) -> Vec<u8> {
3540
Vec::from_hex(hex_str).expect("Invalid hex string")
3641
}
3742

38-
pub fn create_request_governance_data_source_transfer_vaa(_governance_data_source_index: u32) -> Vec<u8> {
43+
pub fn create_request_governance_data_source_transfer_vaa(
44+
_governance_data_source_index: u32,
45+
) -> Vec<u8> {
3946
let hex_str = "01000000000100b2e15dd5ef41b800ec5ec10f61c6415f706a769f459757f43be78a8fd9f1f6e104e909239fe73b4d8652f7aa1a07825e3230d01a0a7bd6efa0be2e7e72377d71010000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010500020000000000000000";
4047
Vec::from_hex(hex_str).expect("Invalid hex string")
4148
}
@@ -86,7 +93,14 @@ mod tests {
8693

8794
#[test]
8895
fn test_create_set_data_sources_vaa() {
89-
let sources = vec![(1u16, [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])];
96+
let sources = vec![(
97+
1u16,
98+
[
99+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101+
0x00, 0x00, 0x11, 0x11,
102+
],
103+
)];
90104
let vaa = create_set_data_sources_vaa(sources);
91105
assert!(!vaa.is_empty());
92106
let hex_str = hex::encode(&vaa);

0 commit comments

Comments
 (0)