Skip to content

Commit 2aae277

Browse files
committed
figured out test_set_data_source errors
1 parent 9927f8a commit 2aae277

File tree

5 files changed

+63
-40
lines changed

5 files changed

+63
-40
lines changed

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,30 @@ impl core::fmt::Debug for PythReceiverError {
4343
PythReceiverError::InvalidMerklePath => write!(f, "InvalidMerklePath"),
4444
PythReceiverError::InvalidUnknownSource => write!(f, "InvalidUnknownSource"),
4545
PythReceiverError::NewPriceUnavailable => write!(f, "NewPriceUnavailable"),
46-
PythReceiverError::InvalidAccumulatorMessageType => write!(f, "InvalidAccumulatorMessageType"),
46+
PythReceiverError::InvalidAccumulatorMessageType => {
47+
write!(f, "InvalidAccumulatorMessageType")
48+
}
4749
PythReceiverError::InsufficientFee => write!(f, "InsufficientFee"),
4850
PythReceiverError::InvalidEmitterAddress => write!(f, "InvalidEmitterAddress"),
4951
PythReceiverError::TooManyUpdates => write!(f, "TooManyUpdates"),
50-
PythReceiverError::PriceFeedNotFoundWithinRange => write!(f, "PriceFeedNotFoundWithinRange"),
52+
PythReceiverError::PriceFeedNotFoundWithinRange => {
53+
write!(f, "PriceFeedNotFoundWithinRange")
54+
}
5155
PythReceiverError::NoFreshUpdate => write!(f, "NoFreshUpdate"),
5256
PythReceiverError::PriceFeedNotFound => write!(f, "PriceFeedNotFound"),
5357
PythReceiverError::InvalidGovernanceMessage => write!(f, "InvalidGovernanceMessage"),
5458
PythReceiverError::InvalidGovernanceTarget => write!(f, "InvalidGovernanceTarget"),
5559
PythReceiverError::InvalidGovernanceAction => write!(f, "InvalidGovernanceAction"),
56-
PythReceiverError::InvalidGovernanceDataSource => write!(f, "InvalidGovernanceDataSource"),
60+
PythReceiverError::InvalidGovernanceDataSource => {
61+
write!(f, "InvalidGovernanceDataSource")
62+
}
5763
PythReceiverError::OldGovernanceMessage => write!(f, "OldGovernanceMessage"),
58-
PythReceiverError::GovernanceMessageAlreadyExecuted => write!(f, "GovernanceMessageAlreadyExecuted"),
59-
PythReceiverError::InvalidWormholeAddressToSet => write!(f, "InvalidWormholeAddressToSet"),
64+
PythReceiverError::GovernanceMessageAlreadyExecuted => {
65+
write!(f, "GovernanceMessageAlreadyExecuted")
66+
}
67+
PythReceiverError::InvalidWormholeAddressToSet => {
68+
write!(f, "InvalidWormholeAddressToSet")
69+
}
6070
}
6171
}
6272
}
@@ -70,25 +80,37 @@ impl core::fmt::Display for PythReceiverError {
7080
PythReceiverError::InvalidVaa => write!(f, "Invalid VAA"),
7181
PythReceiverError::InvalidWormholeMessage => write!(f, "Invalid Wormhole message"),
7282
PythReceiverError::InvalidMerkleProof => write!(f, "Invalid Merkle proof"),
73-
PythReceiverError::InvalidAccumulatorMessage => write!(f, "Invalid accumulator message"),
83+
PythReceiverError::InvalidAccumulatorMessage => {
84+
write!(f, "Invalid accumulator message")
85+
}
7486
PythReceiverError::InvalidMerkleRoot => write!(f, "Invalid Merkle root"),
7587
PythReceiverError::InvalidMerklePath => write!(f, "Invalid Merkle path"),
7688
PythReceiverError::InvalidUnknownSource => write!(f, "Invalid unknown source"),
7789
PythReceiverError::NewPriceUnavailable => write!(f, "New price unavailable"),
78-
PythReceiverError::InvalidAccumulatorMessageType => write!(f, "Invalid accumulator message type"),
90+
PythReceiverError::InvalidAccumulatorMessageType => {
91+
write!(f, "Invalid accumulator message type")
92+
}
7993
PythReceiverError::InsufficientFee => write!(f, "Insufficient fee"),
8094
PythReceiverError::InvalidEmitterAddress => write!(f, "Invalid emitter address"),
8195
PythReceiverError::TooManyUpdates => write!(f, "Too many updates"),
82-
PythReceiverError::PriceFeedNotFoundWithinRange => write!(f, "Price feed not found within range"),
96+
PythReceiverError::PriceFeedNotFoundWithinRange => {
97+
write!(f, "Price feed not found within range")
98+
}
8399
PythReceiverError::NoFreshUpdate => write!(f, "No fresh update"),
84100
PythReceiverError::PriceFeedNotFound => write!(f, "Price feed not found"),
85101
PythReceiverError::InvalidGovernanceMessage => write!(f, "Invalid governance message"),
86102
PythReceiverError::InvalidGovernanceTarget => write!(f, "Invalid governance target"),
87103
PythReceiverError::InvalidGovernanceAction => write!(f, "Invalid governance action"),
88-
PythReceiverError::InvalidGovernanceDataSource => write!(f, "Invalid governance data source"),
104+
PythReceiverError::InvalidGovernanceDataSource => {
105+
write!(f, "Invalid governance data source")
106+
}
89107
PythReceiverError::OldGovernanceMessage => write!(f, "Old governance message"),
90-
PythReceiverError::GovernanceMessageAlreadyExecuted => write!(f, "Governance message already executed"),
91-
PythReceiverError::InvalidWormholeAddressToSet => write!(f, "Invalid Wormhole address to set"),
108+
PythReceiverError::GovernanceMessageAlreadyExecuted => {
109+
write!(f, "Governance message already executed")
110+
}
111+
PythReceiverError::InvalidWormholeAddressToSet => {
112+
write!(f, "Invalid Wormhole address to set")
113+
}
92114
}
93115
}
94116
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,13 @@ impl PythReceiver {
543543
let instruction = governance_structs::parse_instruction(vm.body.payload.to_vec())
544544
.map_err(|_| PythReceiverError::InvalidGovernanceMessage)?;
545545

546-
if instruction.target_chain_id != 0
547-
&& instruction.target_chain_id != self.vm().chain_id() as u16
548-
{
546+
let chain_id_config = Call::new();
547+
548+
let wormhole_id = wormhole
549+
.chain_id(chain_id_config)
550+
.map_err(|_| PythReceiverError::InvalidWormholeMessage)?;
551+
552+
if instruction.target_chain_id != 0 && instruction.target_chain_id != wormhole_id {
549553
return Err(PythReceiverError::InvalidGovernanceTarget);
550554
}
551555

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ mod test {
44
use crate::test_data::*;
55
use crate::PythReceiver;
66
use alloy_primitives::{address, Address, U256};
7+
use hex::FromHex;
78
use mock_instant::global::MockClock;
89
use motsu::prelude::*;
910
use pythnet_sdk::wire::v1::{AccumulatorUpdateData, Proof};
1011
use std::time::Duration;
11-
use hex::FromHex;
1212
use wormhole_contract::WormholeContract;
13-
use wormhole_vaas::{Vaa, Readable, Writeable};
13+
use wormhole_vaas::{Readable, Vaa, Writeable};
1414

1515
const PYTHNET_CHAIN_ID: u16 = 26;
1616
const PYTHNET_EMITTER_ADDRESS: [u8; 32] = [
@@ -19,27 +19,31 @@ mod test {
1919
0xaa, 0x71,
2020
];
2121

22-
const CHAIN_ID: u16 = 60051;
22+
const CHAIN_ID: u16 = 2;
2323
const GOVERNANCE_CONTRACT: U256 = U256::from_limbs([4, 0, 0, 0]);
2424

2525
const SINGLE_UPDATE_FEE_IN_WEI: U256 = U256::from_limbs([100, 0, 0, 0]);
2626
const TRANSACTION_FEE_IN_WEI: U256 = U256::from_limbs([32, 0, 0, 0]);
27-
27+
2828
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
29+
0xbe, 0xFA, 0x42, 0x9d, 0x57, 0xcD, 0x18, 0xb7, 0xF8, 0xA4, 0xd9, 0x1A, 0x2d, 0xa9, 0xAB,
30+
0x4A, 0xF0, 0x5d, 0x0F, 0xBe,
3031
]);
3132
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+
0x4b, 0xa0, 0xC2, 0xdb, 0x9A, 0x26, 0x20, 0x8b, 0x3b, 0xB1, 0xa5, 0x0B, 0x01, 0xb1, 0x69,
34+
0x41, 0xc1, 0x0D, 0x76, 0xdb,
3335
]);
3436
const GOVERNANCE_CHAIN_ID: u16 = 1;
3537
const GOVERNANCE_EMITTER: [u8; 32] = [
36-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11
38+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40+
0x00, 0x11,
3841
];
3942
const TEST_PYTH2_WORMHOLE_CHAIN_ID: u16 = 1;
4043
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
44+
0x71, 0xf8, 0xdc, 0xb8, 0x63, 0xd1, 0x76, 0xe2, 0xc4, 0x20, 0xad, 0x66, 0x10, 0xcf, 0x68,
45+
0x73, 0x59, 0x61, 0x2b, 0x6f, 0xb3, 0x92, 0xe0, 0x64, 0x2b, 0x0c, 0xa6, 0xb1, 0xf1, 0x86,
46+
0xaa, 0x3b,
4347
];
4448
const TARGET_CHAIN_ID: u16 = 2;
4549

@@ -48,18 +52,17 @@ mod test {
4852
pyth_contract: &Contract<PythReceiver>,
4953
wormhole_contract: &Contract<WormholeContract>,
5054
alice: &Address,
55+
guardian_set_index: u32,
5156
) {
52-
let guardians = vec![
53-
address!("0x6579c588be2026d866231cccc364881cc1219c56")
54-
];
55-
57+
let guardians = vec![address!("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf")];
58+
5659
let governance_contract =
5760
Address::from_slice(&GOVERNANCE_CONTRACT.to_be_bytes::<32>()[12..32]);
5861
wormhole_contract
5962
.sender(*alice)
6063
.initialize(
6164
guardians,
62-
4,
65+
guardian_set_index,
6366
CHAIN_ID,
6467
GOVERNANCE_CHAIN_ID,
6568
governance_contract,
@@ -93,19 +96,14 @@ mod test {
9396
wormhole_contract: Contract<WormholeContract>,
9497
alice: Address,
9598
) {
96-
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice);
99+
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
97100

98101
let hex_str = "0100000000010069825ef00344cf745b6e72a41d4f869d4e90de517849360c72bf94efc97681671d826e484747b21a80c8f1e7816021df9f55e458a6e7a717cb2bd2a1e85fd57100499602d200000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010200020100010000000000000000000000000000000000000000000000000000000000001111";
99102
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
100103

101-
println!("Executing set_data_sources with bytes: {:?}", bytes);
102-
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);
106-
}
107-
104+
let result = pyth_contract
105+
.sender(alice)
106+
.execute_governance_instruction(bytes.clone());
108107
assert!(result.is_ok());
109108
}
110-
111109
}

target_chains/stylus/contracts/wormhole/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ mod tests {
547547
use motsu::prelude::Contract;
548548
use core::str::FromStr;
549549
use k256::ecdsa::SigningKey;
550-
use motsu::prelude::DefaultStorage;
551550
use stylus_sdk::alloy_primitives::keccak256;
552551

553552
#[cfg(test)]

target_chains/stylus/contracts/wormhole/tests/integration_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,4 @@ fn test_duplicate_verification(wormhole_contract: Contract<WormholeContract>, al
419419
let result = wormhole_contract.sender(alice).parse_and_verify_vm(test_vaa);
420420
println!("result: {:?}", result);
421421
assert!(result.is_err());
422-
}
422+
}

0 commit comments

Comments
 (0)