Skip to content

Commit b9cd402

Browse files
committed
added real test data from mock hermes calls
1 parent 870e661 commit b9cd402

File tree

3 files changed

+234
-13
lines changed

3 files changed

+234
-13
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
mod test {
44
use crate::PythReceiver;
55
use crate::error::PythReceiverError;
6+
use crate::test_data;
67
use alloy_primitives::{address, U256, FixedBytes};
78
use stylus_sdk::testing::TestVM;
89
use pythnet_sdk::wire::v1::PYTHNET_ACCUMULATOR_UPDATE_MAGIC;
@@ -53,10 +54,7 @@ mod test {
5354
}
5455

5556
fn create_valid_update_data() -> Vec<u8> {
56-
let mut data = Vec::new();
57-
data.extend_from_slice(PYTHNET_ACCUMULATOR_UPDATE_MAGIC);
58-
data.extend_from_slice(&[0u8; 100]);
59-
data
57+
test_data::good_update1()
6058
}
6159

6260
fn create_invalid_magic_data() -> Vec<u8> {
@@ -252,15 +250,24 @@ mod test {
252250
assert!(initial_result.is_err());
253251
assert!(matches!(initial_result.unwrap_err(), PythReceiverError::PriceUnavailable));
254252

255-
// let update_data = create_valid_update_data();
256-
// let update_result = contract.update_price_feeds(update_data);
257-
258-
// let price_result = contract.get_price_unsafe(TEST_PRICE_ID);
259-
// assert!(price_result.is_ok());
253+
}
260254

261-
// let price_info = price_result.unwrap();
262-
// assert_eq!(price_info.0.to::<u64>(), TEST_PUBLISH_TIME);
263-
// assert_eq!(price_info.2.to::<i64>(), TEST_PRICE);
264-
// assert_eq!(price_info.3.to::<u64>(), TEST_CONF);
255+
#[test]
256+
fn test_realistic_test_data_functions() {
257+
let good_update_data = test_data::good_update1();
258+
assert!(!good_update_data.is_empty());
259+
assert!(good_update_data.len() > 100);
260+
261+
let vaa_data = test_data::good_vm1();
262+
assert!(!vaa_data.is_empty());
263+
assert!(vaa_data.len() > 50);
264+
265+
let price_update_data = test_data::test_price_update1();
266+
assert!(!price_update_data.is_empty());
267+
assert!(price_update_data.len() > 100);
268+
269+
let price_update2_data = test_data::test_price_update2();
270+
assert!(!price_update2_data.is_empty());
271+
assert!(price_update2_data.len() > 100);
265272
}
266273
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ extern crate alloc;
77

88
mod structs;
99
mod error;
10+
#[cfg(test)]
1011
mod integration_tests;
12+
#[cfg(test)]
13+
mod test_data;
1114

1215
use alloc::vec::Vec;
1316
use stylus_sdk::{alloy_primitives::{U16, U32, U256, U64, I32, I64, FixedBytes, Address},
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
use alloy_primitives::U256;
2+
3+
fn from_cairo_byte_array_data(data: &[U256], num_last_bytes: usize) -> Vec<u8> {
4+
let mut result = Vec::new();
5+
6+
if data.is_empty() {
7+
return result;
8+
}
9+
10+
for (i, &item) in data.iter().enumerate() {
11+
let buf = item.to_be_bytes::<32>();
12+
13+
if i == data.len() - 1 {
14+
if num_last_bytes > 0 {
15+
let start_idx = 32 - num_last_bytes;
16+
result.extend_from_slice(&buf[start_idx..]);
17+
}
18+
} else {
19+
result.extend_from_slice(&buf[1..]);
20+
}
21+
}
22+
23+
result
24+
}
25+
26+
pub fn good_update1() -> Vec<u8> {
27+
let bytes = [
28+
U256::from_str_radix("141887862745809943100717722154781668316147089807066324001213790862261653767", 10).unwrap(),
29+
U256::from_str_radix("451230040559159019530944948086670994623010697390864133264612902902585665886", 10).unwrap(),
30+
U256::from_str_radix("355897384610106978643111834734000274494997301794613218547634257521495150151", 10).unwrap(),
31+
U256::from_str_radix("140511063638834349363702006999356227863549404051701803148734324248522745879", 10).unwrap(),
32+
U256::from_str_radix("435849190784772134907557391544163070978531038970298390345939133663347953446", 10).unwrap(),
33+
U256::from_str_radix("416390591179833928094641114955594939466104495718036761707729297119441316151", 10).unwrap(),
34+
U256::from_str_radix("360454929416220920336539568461651500076647166763464050800345920693176904002", 10).unwrap(),
35+
U256::from_str_radix("316054999864337699543932294956493808847640383114707243342262764542081441331", 10).unwrap(),
36+
U256::from_str_radix("325277902980160684959962429721294603784343718796390808940252812862355246813", 10).unwrap(),
37+
U256::from_str_radix("43683235854839458868457367619068018785880460427473556950900276498953667", 10).unwrap(),
38+
U256::from_str_radix("448289429405712011882317781416869052550573589492688760675666957663813001522", 10).unwrap(),
39+
U256::from_str_radix("118081463902430977133121147164253483958565039026724621562859841189218059803", 10).unwrap(),
40+
U256::from_str_radix("194064310618695309465615383754562031677972810736048112738513050109934134235", 10).unwrap(),
41+
U256::from_str_radix("133901765334590923121691219814784557892214901646312752962904032795881821509", 10).unwrap(),
42+
U256::from_str_radix("404227501001709279944936006741063968912686453006275462577777397594240621266", 10).unwrap(),
43+
U256::from_str_radix("81649001731335394114026683805238949464016657447685509824621946636993704965", 10).unwrap(),
44+
U256::from_str_radix("32402065226491532148674904435794801976788068837745943243341272676331333141", 10).unwrap(),
45+
U256::from_str_radix("431262841416902409381606630149292665102873776020834630861578112749151562174", 10).unwrap(),
46+
U256::from_str_radix("6164523115980545628843981978797257048781800754033825701059814297149591186", 10).unwrap(),
47+
U256::from_str_radix("408761574582108996678203805090470134287794603493622537384530614829262728153", 10).unwrap(),
48+
U256::from_str_radix("185368533577943244707350150853170361880334596276529206938783888784867529821", 10).unwrap(),
49+
U256::from_str_radix("173578821500714074579643724957224629379984215847383417303110192934676518530", 10).unwrap(),
50+
U256::from_str_radix("90209855380378362490166376523380463998928070428866100240907090599465187835", 10).unwrap(),
51+
U256::from_str_radix("97758466908511588082569287391708453107999243934457382895073183209581711489", 10).unwrap(),
52+
U256::from_str_radix("132725011490528489913736834798247512772139171145730373610858422315799224432", 10).unwrap(),
53+
U256::from_str_radix("117123868005849140967825260063167768530251411611975150066586827543934313288", 10).unwrap(),
54+
U256::from_str_radix("408149062252618928234854115279677715692278734600386004492580987016428761675", 10).unwrap(),
55+
U256::from_str_radix("164529520317122600276020522906605877985809506451193373524142111430138855019", 10).unwrap(),
56+
U256::from_str_radix("444793051809958482843529748761971363435331354795896511243191618771787268378", 10).unwrap(),
57+
U256::from_str_radix("247660009137502548346315865368477795392972486141407800140910365553760622080", 10).unwrap(),
58+
U256::from_str_radix("3281582060272565111592312037403686940429019548922889497694300188", 10).unwrap(),
59+
U256::from_str_radix("93649805131515836129946966966350066506512123780266587069413066350925286142", 10).unwrap(),
60+
U256::from_str_radix("394112423559676785086098106350541172262729583743734966358666094809121292390", 10).unwrap(),
61+
U256::from_str_radix("35403101004688876764673991514113473446030702766599795822870037077688984558", 10).unwrap(),
62+
U256::from_str_radix("99366103604611980443183454746643823071419076016677225828619807954313149423", 10).unwrap(),
63+
U256::from_str_radix("10381657217606191031071521950784155484751645280452344547752823767622424055", 10).unwrap(),
64+
U256::from_str_radix("391045354044274401116419632681482293741435113770205621235865697077178955228", 10).unwrap(),
65+
U256::from_str_radix("311250087759201408758984550959714865999349469611700431708031036894849650573", 10).unwrap(),
66+
U256::from_str_radix("59953730895385399344628932835545900304309851622811198425230584225200786697", 10).unwrap(),
67+
U256::from_str_radix("226866843267230707879834616967256711063296411939069440476882347301771901839", 10).unwrap(),
68+
U256::from_str_radix("95752383404870925303422787", 10).unwrap(),
69+
];
70+
from_cairo_byte_array_data(&bytes, 11)
71+
}
72+
73+
pub fn good_vm1() -> Vec<u8> {
74+
let bytes = [
75+
U256::from_str_radix("1766847066033410293701000231337210964058791470455465385734308943533652138", 10).unwrap(),
76+
U256::from_str_radix("250126301534699068413432844632573953364878937343368310395142095034982913232", 10).unwrap(),
77+
U256::from_str_radix("374780571002258088211231890250917843593951765403462661483498298003400611238", 10).unwrap(),
78+
U256::from_str_radix("23190137343211334092589308306056431640588154666326612124726174150537328574", 10).unwrap(),
79+
U256::from_str_radix("238750269065878649216923353030193912502813798896051725498208457553032584635", 10).unwrap(),
80+
U256::from_str_radix("29844190303057534696518006438077948796328243878877072296680853158289181326", 10).unwrap(),
81+
U256::from_str_radix("106329507856770018708432343978518079724691760719405501795955774399597471533", 10).unwrap(),
82+
U256::from_str_radix("50779865592261858016477142415230454208001695486195806892438697217059319645", 10).unwrap(),
83+
U256::from_str_radix("448669871976126446102256476358498380455807705600424321390063431836375575318", 10).unwrap(),
84+
U256::from_str_radix("115682669871397824853706713833773246708114483862317474710603223566297521279", 10).unwrap(),
85+
U256::from_str_radix("301634766618012930739391408723909107532790832406455099966028276947414082504", 10).unwrap(),
86+
U256::from_str_radix("104473166230846104217366042152018649207811514257244625711402436055500423094", 10).unwrap(),
87+
U256::from_str_radix("64445621634231668761998815864645440965239569561546522651415024970517905416", 10).unwrap(),
88+
U256::from_str_radix("192317190225976528694195501079591384434869624408066864018183189813956862386", 10).unwrap(),
89+
U256::from_str_radix("289982656017597431343118552054719821766658675456661448685110903889153449006", 10).unwrap(),
90+
U256::from_str_radix("218840601196095059731241556733624112758673153548932709011933806481899680620", 10).unwrap(),
91+
U256::from_str_radix("430933799927481265070475198137531816946660368757134588278434352703899277070", 10).unwrap(),
92+
U256::from_str_radix("69322998883710289192076494057541346430050879299268159627180404869988632073", 10).unwrap(),
93+
U256::from_str_radix("23862615839737051269352321086490452186237833007444069999578906611768140646", 10).unwrap(),
94+
U256::from_str_radix("444634264607471510688862284107804392707600799506487897206707262445172121289", 10).unwrap(),
95+
U256::from_str_radix("438038196736233160320436150616293672539386464061037100698335568417587662951", 10).unwrap(),
96+
U256::from_str_radix("4682255185797880874381673193118803274635247527626050223938224759013169366", 10).unwrap(),
97+
U256::from_str_radix("337620725992972686809095065321563509600769533202700218393281926304544120094", 10).unwrap(),
98+
U256::from_str_radix("106657917096532484607371891267699639824731774168349872862335217581425289654", 10).unwrap(),
99+
U256::from_str_radix("71240348385993236445536577509595968468284689483611375124653855125285401592", 10).unwrap(),
100+
U256::from_str_radix("347603391821038175842934311068097986460257977131947418186118379296987051086", 10).unwrap(),
101+
U256::from_str_radix("414263571545410645948841360836383289766662078574048514890988877286444618669", 10).unwrap(),
102+
U256::from_str_radix("250301638008739107522011802538487063969565433276260914336890309092111026583", 10).unwrap(),
103+
U256::from_str_radix("43192785595291340058788190601908070333310658291317702311902081", 10).unwrap(),
104+
U256::from_str_radix("52685537088250779930155363779405986390839624071318818148325576008719597568", 10).unwrap(),
105+
U256::from_str_radix("14615204155786886573933667335033405822686404253588533", 10).unwrap(),
106+
];
107+
from_cairo_byte_array_data(&bytes, 22)
108+
}
109+
110+
pub fn test_price_update1() -> Vec<u8> {
111+
let bytes = [
112+
U256::from_str_radix("141887862745809943100421399774809552050876420277163116849842965275903806689", 10).unwrap(),
113+
U256::from_str_radix("210740906737592158039211995620336526131859667363627655742687286503264782608", 10).unwrap(),
114+
U256::from_str_radix("437230063624699337579360546580839669896712252828825008570863758867641146081", 10).unwrap(),
115+
U256::from_str_radix("3498691308882995183871222184377409432186747119716981166996399082193594993", 10).unwrap(),
116+
U256::from_str_radix("1390200166945919815453709407753165121175395927094647129599868236", 10).unwrap(),
117+
U256::from_str_radix("222819573728193325268644030206737371345667885599602384508424089704440116301", 10).unwrap(),
118+
U256::from_str_radix("341318259000017461738706238280879290398059773267212529438772847337449455616", 10).unwrap(),
119+
U256::from_str_radix("1275126645346645395843037504005879519843596923369759718556759844520336145", 10).unwrap(),
120+
U256::from_str_radix("363528783578153760894082184744116718493621815898909809604883433584616420886", 10).unwrap(),
121+
U256::from_str_radix("301537311768214106147206781423041990995720118715322906821301413003463484347", 10).unwrap(),
122+
U256::from_str_radix("83150006264761451992768264969047148434524798781124754530141755679159432208", 10).unwrap(),
123+
U256::from_str_radix("96387772316726941183358990094337324283641753573556594738287498821253761827", 10).unwrap(),
124+
U256::from_str_radix("395908154570808692326126405856049827157095768069251211022053821585519235652", 10).unwrap(),
125+
U256::from_str_radix("87135893730137265929093180553063146337041045646221968026289709394440932141", 10).unwrap(),
126+
U256::from_str_radix("245333243912241114598596888050489286502591033459250287888834", 10).unwrap(),
127+
];
128+
from_cairo_byte_array_data(&bytes, 25)
129+
}
130+
131+
pub fn test_price_update2() -> Vec<u8> {
132+
let bytes = [
133+
U256::from_str_radix("141887862745809943100421399774809552050874823427618844548942380383465221086", 10).unwrap(),
134+
U256::from_str_radix("106893583704677921907497845070624642590618427233243792006390965895909696183", 10).unwrap(),
135+
U256::from_str_radix("126617671723931969110123875642449115250793288301361049879364132884271078113", 10).unwrap(),
136+
U256::from_str_radix("3498691308882995183871222184377409432186747119716981166996399082193594993", 10).unwrap(),
137+
U256::from_str_radix("1390200461185063661704370212555794334034815850290352693418762308", 10).unwrap(),
138+
U256::from_str_radix("419598057710749587537080281518289024699150505326900462079484531390510117965", 10).unwrap(),
139+
U256::from_str_radix("341318259000017461738706238280879290398059773267212529438780607147892801536", 10).unwrap(),
140+
U256::from_str_radix("1437437604754599821041091415535991441313586347841485651963630208563420739", 10).unwrap(),
141+
U256::from_str_radix("305222830440467078008666830004555943609735125691441831219591213494068931362", 10).unwrap(),
142+
U256::from_str_radix("358396406696718360717615797531477055540194104082154743994717297650279402646", 10).unwrap(),
143+
U256::from_str_radix("429270385827211102844129651648706540139690432947840438198166022904666187018", 10).unwrap(),
144+
U256::from_str_radix("343946166212648899477337159288779715507980257611242783073384876024451565860", 10).unwrap(),
145+
U256::from_str_radix("67853010773876862913176476530730880916439012004585961528150130218675908823", 10).unwrap(),
146+
U256::from_str_radix("370855179649505412564259994413632062925303311800103998016489412083011059699", 10).unwrap(),
147+
U256::from_str_radix("1182295126766215829784496273374889928477877265080355104888778", 10).unwrap(),
148+
];
149+
from_cairo_byte_array_data(&bytes, 25)
150+
}
151+
152+
pub fn pyth_set_fee() -> Vec<u8> {
153+
let bytes = [
154+
U256::from_str_radix("1766847064779993955862540543984267022910717161432209540262366788014689913", 10).unwrap(),
155+
U256::from_str_radix("322968519187498395396360816568387642032723484530650782503164941848016432477", 10).unwrap(),
156+
U256::from_str_radix("49565958604199796163020368", 10).unwrap(),
157+
U256::from_str_radix("8072278384728444780182694421117884443886221966887092226", 10).unwrap(),
158+
];
159+
from_cairo_byte_array_data(&bytes, 23)
160+
}
161+
162+
pub fn pyth_set_data_sources() -> Vec<u8> {
163+
let bytes = [
164+
U256::from_str_radix("1766847064779993795984967344618836356750759980724568847727566676204733945", 10).unwrap(),
165+
U256::from_str_radix("319252252405206634291073190903653114488682078063415369176250618646860635118", 10).unwrap(),
166+
U256::from_str_radix("223938022913800988696085410923418445187967252047785407181969631814277398528", 10).unwrap(),
167+
U256::from_str_radix("301", 10).unwrap(),
168+
];
169+
from_cairo_byte_array_data(&bytes, 14)
170+
}
171+
172+
pub fn create_realistic_price_update_test() -> Vec<u8> {
173+
test_price_update1()
174+
}
175+
176+
pub fn create_realistic_vaa_test() -> Vec<u8> {
177+
good_vm1()
178+
}
179+
180+
#[cfg(test)]
181+
mod tests {
182+
use super::*;
183+
184+
#[test]
185+
fn test_conversion_logic() {
186+
let test_data = [U256::from(0x010203u32)];
187+
let result = from_cairo_byte_array_data(&test_data, 3);
188+
assert_eq!(result, vec![0x01, 0x02, 0x03]);
189+
}
190+
191+
#[test]
192+
fn test_good_update1_not_empty() {
193+
let data = good_update1();
194+
assert!(!data.is_empty());
195+
assert!(data.len() > 100);
196+
}
197+
198+
#[test]
199+
fn test_test_price_update1_not_empty() {
200+
let data = test_price_update1();
201+
assert!(!data.is_empty());
202+
assert!(data.len() > 100);
203+
}
204+
205+
#[test]
206+
fn test_good_vm1_not_empty() {
207+
let data = good_vm1();
208+
assert!(!data.is_empty());
209+
assert!(data.len() > 50);
210+
}
211+
}

0 commit comments

Comments
 (0)