Skip to content

Commit ab0b2a3

Browse files
committed
cleaned up test_data file usage
1 parent 0f9de33 commit ab0b2a3

File tree

3 files changed

+79
-77
lines changed

3 files changed

+79
-77
lines changed

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

Lines changed: 11 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#[cfg(test)]
22
mod test {
3-
use crate::error::PythReceiverError;
4-
use crate::test_data;
3+
use crate::{error::PythReceiverError};
4+
use crate::test_data::{self, good_update2_results, multiple_updates_results};
5+
use crate::test_data::good_update1_results;
56
use crate::PythReceiver;
6-
use alloy_primitives::{address, Address, I32, I64, U256, U64};
7+
use alloy_primitives::{Address, U256};
78
use motsu::prelude::*;
89
use pythnet_sdk::wire::v1::{AccumulatorUpdateData, Proof};
910
use wormhole_contract::WormholeContract;
@@ -12,13 +13,7 @@ mod test {
1213
0xdb, 0x33, 0x0f, 0x7a, 0xc6, 0x6b, 0x72, 0xdc, 0x65, 0x8a, 0xfe, 0xdf, 0x0f, 0x4a, 0x41,
1314
0x5b, 0x43,
1415
];
15-
const TEST_PUBLISH_TIME: u64 = 1751563000;
16-
const TEST_PRICE: i64 = 10967241867779;
17-
const TEST_CONF: u64 = 4971244966;
18-
const TEST_EXPO: i32 = -8;
19-
const TEST_EMA_PRICE: i64 = 10942391100000;
20-
const TEST_EMA_CONF: u64 = 4398561400;
21-
16+
2217
const PYTHNET_CHAIN_ID: u16 = 26;
2318
const PYTHNET_EMITTER_ADDRESS: [u8; 32] = [
2419
0xe1, 0x01, 0xfa, 0xed, 0xac, 0x58, 0x51, 0xe3, 0x2b, 0x9b, 0x23, 0xb5, 0xf9, 0x41, 0x1a,
@@ -32,31 +27,6 @@ mod test {
3227

3328
const SINGLE_UPDATE_FEE_IN_WEI: U256 = U256::from_limbs([100, 0, 0, 0]);
3429

35-
#[cfg(test)]
36-
fn current_guardians() -> Vec<Address> {
37-
vec![
38-
address!("0x5893B5A76c3f739645648885bDCcC06cd70a3Cd3"), // Rockaway
39-
address!("0xfF6CB952589BDE862c25Ef4392132fb9D4A42157"), // Staked
40-
address!("0x114De8460193bdf3A2fCf81f86a09765F4762fD1"), // Figment
41-
address!("0x107A0086b32d7A0977926A205131d8731D39cbEB"), // ChainodeTech
42-
address!("0x8C82B2fd82FaeD2711d59AF0F2499D16e726f6b2"), // Inotel
43-
address!("0x11b39756C042441BE6D8650b69b54EbE715E2343"), // HashKey Cloud
44-
address!("0x54Ce5B4D348fb74B958e8966e2ec3dBd4958a7cd"), // ChainLayer
45-
address!("0x15e7cAF07C4e3DC8e7C469f92C8Cd88FB8005a20"), // xLabs
46-
address!("0x74a3bf913953D695260D88BC1aA25A4eeE363ef0"), // Forbole
47-
address!("0x000aC0076727b35FBea2dAc28fEE5cCB0fEA768e"), // Staking Fund
48-
address!("0xAF45Ced136b9D9e24903464AE889F5C8a723FC14"), // Moonlet Wallet
49-
address!("0xf93124b7c738843CBB89E864c862c38cddCccF95"), // P2P Validator
50-
address!("0xD2CC37A4dc036a8D232b48f62cDD4731412f4890"), // 01node
51-
address!("0xDA798F6896A3331F64b48c12D1D57Fd9cbe70811"), // MCF
52-
address!("0x71AA1BE1D36CaFE3867910F99C09e347899C19C3"), // Everstake
53-
address!("0x8192b6E7387CCd768277c17DAb1b7a5027c0b3Cf"), // Chorus One
54-
address!("0x178e21ad2E77AE06711549CFBB1f9c7a9d8096e8"), // Syncnode
55-
address!("0x5E1487F35515d02A92753504a8D75471b9f49EdB"), // Triton
56-
address!("0x6FbEBc898F403E4773E95feB15E80C9A99c8348d"), // Staking Facilities
57-
]
58-
}
59-
6030
#[cfg(test)]
6131
fn mock_get_update_fee(update_data: Vec<u8>) -> Result<U256, PythReceiverError> {
6232
let update_data_array: &[u8] = &update_data;
@@ -77,7 +47,7 @@ mod test {
7747
wormhole_contract: &Contract<WormholeContract>,
7848
alice: &Address,
7949
) {
80-
let guardians = current_guardians();
50+
let guardians = test_data::current_guardians();
8151
let governance_contract =
8252
Address::from_slice(&GOVERNANCE_CONTRACT.to_be_bytes::<32>()[12..32]);
8353
wormhole_contract
@@ -137,14 +107,7 @@ mod test {
137107
assert!(price_result.is_ok());
138108
assert_eq!(
139109
price_result.unwrap(),
140-
(
141-
U64::from(TEST_PUBLISH_TIME),
142-
I32::from_le_bytes(TEST_EXPO.to_le_bytes()),
143-
I64::from_le_bytes(TEST_PRICE.to_le_bytes()),
144-
U64::from(TEST_CONF),
145-
I64::from_le_bytes(TEST_EMA_PRICE.to_le_bytes()),
146-
U64::from(TEST_EMA_CONF)
147-
)
110+
good_update1_results()
148111
);
149112
}
150113

@@ -198,14 +161,7 @@ mod test {
198161
assert!(price_result.is_ok());
199162
assert_eq!(
200163
price_result.unwrap(),
201-
(
202-
U64::from(1751573860u64),
203-
I32::from_le_bytes((-8i32).to_le_bytes()),
204-
I64::from_le_bytes(10985663592646i64.to_le_bytes()),
205-
U64::from(4569386330u64),
206-
I64::from_le_bytes(10977795800000i64.to_le_bytes()),
207-
U64::from(3919318300u64)
208-
)
164+
good_update2_results()
209165
);
210166
}
211167

@@ -273,14 +229,7 @@ mod test {
273229
assert!(price_result.is_ok());
274230
assert_eq!(
275231
price_result.unwrap(),
276-
(
277-
U64::from(1751573860u64),
278-
I32::from_le_bytes((-8i32).to_le_bytes()),
279-
I64::from_le_bytes(10985663592646i64.to_le_bytes()),
280-
U64::from(4569386330u64),
281-
I64::from_le_bytes(10977795800000i64.to_le_bytes()),
282-
U64::from(3919318300u64)
283-
)
232+
good_update2_results()
284233
);
285234
}
286235

@@ -345,28 +294,14 @@ mod test {
345294
assert!(first_price_result.is_ok());
346295
assert_eq!(
347296
first_price_result.unwrap(),
348-
(
349-
U64::from(1751573123u64),
350-
I32::from_le_bytes((-8i32).to_le_bytes()),
351-
I64::from_le_bytes(10990356724259i64.to_le_bytes()),
352-
U64::from(3891724259u64),
353-
I64::from_le_bytes(10974970400000i64.to_le_bytes()),
354-
U64::from(3918344000u64)
355-
)
297+
multiple_updates_results()[0]
356298
);
357299

358300
let second_price_result = pyth_contract.sender(alice).get_price_unsafe(second_id);
359301
assert!(second_price_result.is_ok());
360302
assert_eq!(
361303
second_price_result.unwrap(),
362-
(
363-
U64::from(1751573123u64),
364-
I32::from_le_bytes((-8i32).to_le_bytes()),
365-
I64::from_le_bytes(258906787480i64.to_le_bytes()),
366-
U64::from(158498649u64),
367-
I64::from_le_bytes(258597182000i64.to_le_bytes()),
368-
U64::from(131285914u64)
369-
)
304+
multiple_updates_results()[1]
370305
);
371306
}
372307
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use alloc::{vec::Vec};
2-
use serde::Serialize;
32
use stylus_sdk::alloy_primitives::{keccak256, FixedBytes, B256, I32, I64, U16, U256, U64};
43
use stylus_sdk::{
54
prelude::*,

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
11
use hex::FromHex;
2+
use alloy_primitives::{I32, I64, U64, address, Address};
23

34
pub fn good_update1() -> Vec<u8> {
45
let hex_str = "504e41550100000003b801000000040d0216f3809b6396fdb0708bc94515ddb96a3bc8fb1993916e74f522ab4c34a268836a0bb38786303b55cc40ecb50d18c92bf9fd61688a143f3d24a73a3f468e4ab0000365be4f3a330fe96bab246922d9fa4816a865dec40d7c522e37f7e3605673b8f52eb30a4dad7aee3e1ac4b21337b8831c6147ef6e359e843b307872e83b5c7fe80004b6f12766eb395d04bdb146b1b69a4b9a8831a9c9ea20ee841d55efe72c629aef17038b925584493af7882981260b09587d73b6463415f4e1f8fb0a2a2c959c8301065c18a776cf558e43494bf31dd26ac0e3aed07a01ca0063abcfca3736b892368e4bf8b957f2d2e83ff9eb3fa8f667ef97a5f48c286103f70fda4a72e077719a0200085896c930febfb864a8c292bde679092e386e53389cb2d26bd12ceed64d22c0cd27676dc5c46d3e3c5949abbce89d4cc5ec378cfbf9ab1b0c24cfeb3371df4864000a1c67e67adea9f8a71eee76765f1fe4c7d9539d21b62d0336513692897cc6acbe1c827599a1f8c73b7478e8d788443b4cfd4e373344ab1ac9f771c9c494124863000b7e08e1cc1291340e6ec7d1b04c6a9c63f74077a074ee68edf4f95cf24c9743620f8abc8213884c8e4848fb76ec319d365e0cdc746a6e534a4cb828e51719be79010c61a2fedeedf34e4c80624d80cb93e24bafe9f6d23339173004d84e61c2395bfb5f552e87b901beb192ba6f4fc905eae30317c52b8614071e08a265592f24e8de000de38d08612edc5ebc863ea5a96325cb991750a94ff0e50f86bc322cce81db7cd17cb4ed3703f7477eb111a9d881e1345f5b79d618814f31b46034196563ee6a18000e5b11510d585a2decaba0be9e71386865b6069061478f7254d7852d55116569eb426c385267e40264d16db08e0f1a9e2c44b7d1c926d3c3ba662b212572386483010fa1ad0278402104b146b6f4d1cf85ac4df961d24eea0c7948b700f9973596cad130abfff25feef37125ba38507f34308d967455651e7014e40264a0c6510d3af001101f2e4e70868d6c327c92229537f1ffa33e488da3140ccc086f8210b437b162190742bd01ad1cb495a93f20045b4bb47e1562fdd82a8a1548d87d788a492b17190111847f5095df3edefc58be0956aee19876e850516e132506fd67504afee3c8cf240f07fb607b3c8282a2e56dcad23959e6759bdf8ad345ba8150448da56ff34fcc016866baf800000000001ae101faedac5851e32b9b23b5f9411a8c2bac4aae3ed4dd7b811dd1a72ea4aa71000000000880cea9014155575600000000000d8e5c8d0000271085e6ab1bb044f57c4cd6c1d32aa0a82a5032198301005500e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43000009f9828e420300000001284f2da6fffffff8000000006866baf8000000006866baf8000009f3b955a26000000001062cb8780c1283a49180b4986f0dec3c746d3daeb597887747b8f66a09876e1253a1ebb8a6bc4a5793daaa343db6057b82ec29715d7e1db0ffd6db523f7b80b03e3866ef5f5c80728801b92f5acecc28d8517e5615335d89c553f94b4370f3a20be0bc23e0fd401c4e5bd8bd32948a26233fc48f116428a490f087030ccfc442753e3074e2b9bbc1c61a009d86aaa200645c627a6b7f2f6597e34c60b14a58ef2583bcbb1d0e21b71a264fad2648ecc545031c7ed598772ffe875bf94a488389a49e6025e1b2a1f07ec598d0d9aa8ef7dd2733c8502c49d1d1323f1ae664e82e8a5e14978d52ab448ba9b1afc78f06c8cd17415a17";
56
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
67
bytes
78
}
89

10+
pub fn good_update1_results() -> (U64, I32, I64, U64, I64, U64) {
11+
(
12+
U64::from(1751563000u64),
13+
I32::from_le_bytes((-8i32).to_le_bytes()),
14+
I64::from_le_bytes(10967241867779i64.to_le_bytes()),
15+
U64::from(4971244966u64),
16+
I64::from_le_bytes(10942391100000i64.to_le_bytes()),
17+
U64::from(4398561400u64)
18+
)
19+
}
20+
21+
pub fn multiple_updates_results() -> [(U64, I32, I64, U64, I64, U64); 2] {
22+
[
23+
(
24+
U64::from(1751573123u64),
25+
I32::from_le_bytes((-8i32).to_le_bytes()),
26+
I64::from_le_bytes(10990356724259i64.to_le_bytes()),
27+
U64::from(3891724259u64),
28+
I64::from_le_bytes(10974970400000i64.to_le_bytes()),
29+
U64::from(3918344000u64)
30+
),
31+
(
32+
U64::from(1751573123u64),
33+
I32::from_le_bytes((-8i32).to_le_bytes()),
34+
I64::from_le_bytes(258906787480i64.to_le_bytes()),
35+
U64::from(158498649u64),
36+
I64::from_le_bytes(258597182000i64.to_le_bytes()),
37+
U64::from(131285914u64)
38+
)
39+
]
40+
}
41+
42+
pub fn good_update2_results() -> (U64, I32, I64, U64, I64, U64) {
43+
(
44+
U64::from(1751573860u64),
45+
I32::from_le_bytes((-8i32).to_le_bytes()),
46+
I64::from_le_bytes(10985663592646i64.to_le_bytes()),
47+
U64::from(4569386330u64),
48+
I64::from_le_bytes(10977795800000i64.to_le_bytes()),
49+
U64::from(3919318300u64)
50+
)
51+
}
52+
953
pub fn good_update2() -> Vec<u8> {
1054
let hex_str = "504e41550100000003b801000000040d0239010392dab908eb9903d480abf8118d887f2a0c5eaeb9062e6eabab86c1b382127604c63358a7266cc5bade7726e159403c2bf317c7b3a4d8b489bfad4e334301031823d70352d3260226cbdddab0cf7d1584c0e1d23d4358ed12f9620e18a0db2154fbb096ac4cb8d5728e2cecf2b1398d7b9b51954f3fb8b4f59990ce017b0260000495e2691d8e6a0537d8ab3f41b5eb655acde7fbeaea0fdbe1f582383680f54c8a3a697c2c0f8b4110422f1b6beb0bfb601c929148b54dbf85fb19c333ccbb833c00066993a56c5980bf17d2790b933861fffb1fd09618921a90db4ab82cc8b148301f1a55d804d14cb39f648fdb0ef8c9ef1e24edc38d30f2aea7151025240a614bca0008a64a366c59bd6c4ce9d24a0e3beef2a33d28546826b1b969af184a257d648aab5672ad8a9eaf14473da40327e12e5c18168892bcebd693c8bed3df8ee50b85db010a36daa7c639c412969283f83749af93aef2464b27b83914b6026b721a59c8a04446a655686725247bd9154c71ca66505719df5867f775863a788d8bffb1bd637c000b237772560d72da81a782e89b138caf8bf1221b929ead77ca7d178b7b7af1c9141d9e77e22c98fe41b819f023695e6feed6f5215a5cdb6436bf52dc3c4c93e309010c89f2f3c64a8c77ccea47448e7871bbd70b59ed5761e5677458dbe6f82796efa2399e9ad9bf846d88d4688f1d19f9e2adeb2299017baf015c36a811d05c539b86000d6ba11d2f9a0edfd3a4bc23024d18dd010a83803faa79d40aec10a4deee40e8dd3c4c5401118b67bd6d879683cae3ea83d4f9afa744c655775615a7ce34237a02000e09a554d70c0f8e57bb79ce41552e38b836ad7b6bd1967e60c880f831341ad412699e4a9f5346713a6db2c7032bb7d1b3cc8e42f49ba17000f9d0916a13f2debf000f1ce88af88b96aaeb0104d4c966303eb9609df1b851a0d6149d05bba82f3fd70820a26d7f9d6fe18a7653fd3e3eda94fd9184726dadd2e8d58d09a8473e919f0800104583407293c41bef15c05ac20fc45fd5f9d00639c5b1f738d1ba42cd290fe5291e05219cefa8568806bfc1de76bcf5f799c90c9c6dd54bd69f9d459e994acb7a00110638c8067b42005ae678a7619e9eaad5fb66f0630547ab252179668e60b738c479ba6ff7e1f3dcffddab15e1bfebf93e0e4cb051535bdda3ecef6620aea32132016866e56400000000001ae101faedac5851e32b9b23b5f9411a8c2bac4aae3ed4dd7b811dd1a72ea4aa710000000008813690014155575600000000000d8ec4750000271098d4f856e398eb41afbd0f2b24ad80e58b1f57b601005500e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43000009fdcc9378c600000001105b4d5afffffff8000000006866e564000000006866e564000009fbf79e7bc000000000e99c0d1c0c02b95abadee324fbb6534576de1507c74c8ddef2b928c314cb3d4978a5ada03db907df05ba0fc051e659facec6479c324c276e5098fde9dcae0b462cd32d9e2e5b617b51ced85d38a8456022f3ab370d3c45a07acb686cfb39976b2f4bb1007a91e599951ed929f714a04dab0e6bd885a0c91a076f3b83ee8f765b70a3edda569876102f2c62cae15024e529a2e5e17c50411aa736c7511278a92f4d9cdda3239057c3a942a1365a58771734a982e41e1d7aa8bae87748f1becd045fcb5e1cb1993e978168147d6be8a2cba24a3cc8a2f78e7313f18c87ec2bb238510ebeb47aab50a449fd2ce3dc6b8c0d08d361c102";
1155
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
@@ -17,3 +61,27 @@ pub fn multiple_updates() -> Vec<u8> {
1761
let bytes = Vec::from_hex(hex_str).expect("Invalid hex string");
1862
bytes
1963
}
64+
65+
pub fn current_guardians() -> Vec<Address> {
66+
vec![
67+
address!("0x5893B5A76c3f739645648885bDCcC06cd70a3Cd3"), // Rockaway
68+
address!("0xfF6CB952589BDE862c25Ef4392132fb9D4A42157"), // Staked
69+
address!("0x114De8460193bdf3A2fCf81f86a09765F4762fD1"), // Figment
70+
address!("0x107A0086b32d7A0977926A205131d8731D39cbEB"), // ChainodeTech
71+
address!("0x8C82B2fd82FaeD2711d59AF0F2499D16e726f6b2"), // Inotel
72+
address!("0x11b39756C042441BE6D8650b69b54EbE715E2343"), // HashKey Cloud
73+
address!("0x54Ce5B4D348fb74B958e8966e2ec3dBd4958a7cd"), // ChainLayer
74+
address!("0x15e7cAF07C4e3DC8e7C469f92C8Cd88FB8005a20"), // xLabs
75+
address!("0x74a3bf913953D695260D88BC1aA25A4eeE363ef0"), // Forbole
76+
address!("0x000aC0076727b35FBea2dAc28fEE5cCB0fEA768e"), // Staking Fund
77+
address!("0xAF45Ced136b9D9e24903464AE889F5C8a723FC14"), // Moonlet Wallet
78+
address!("0xf93124b7c738843CBB89E864c862c38cddCccF95"), // P2P Validator
79+
address!("0xD2CC37A4dc036a8D232b48f62cDD4731412f4890"), // 01node
80+
address!("0xDA798F6896A3331F64b48c12D1D57Fd9cbe70811"), // MCF
81+
address!("0x71AA1BE1D36CaFE3867910F99C09e347899C19C3"), // Everstake
82+
address!("0x8192b6E7387CCd768277c17DAb1b7a5027c0b3Cf"), // Chorus One
83+
address!("0x178e21ad2E77AE06711549CFBB1f9c7a9d8096e8"), // Syncnode
84+
address!("0x5E1487F35515d02A92753504a8D75471b9f49EdB"), // Triton
85+
address!("0x6FbEBc898F403E4773E95feB15E80C9A99c8348d"), // Staking Facilities
86+
]
87+
}

0 commit comments

Comments
 (0)