Преглед на файлове

hore(target_chains/starknet): automate test data generation (#1587)

Pavel Strakhov преди 1 година
родител
ревизия
74f02c46ff

+ 7 - 4
.github/workflows/ci-starknet-tools.yml

@@ -21,9 +21,12 @@ jobs:
         run: cargo fmt --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml -- --check
       - name: Run clippy
         run: cargo clippy --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --all-targets -- --deny warnings
-      - name: Run wormhole_mainnet_upgrades binary
-        run: cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin wormhole_mainnet_upgrades
       - name: Run generate_keypair binary
         run: cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin generate_keypair
-      - name: Run generate_wormhole_vaas binary
-        run: cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin generate_wormhole_vaas
+      - name: Check test data
+        run: |
+          cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin generate_test_data > /tmp/data.cairo
+          if ! diff ./target_chains/starknet/contracts/tests/data.cairo /tmp/data.cairo; then
+            >&2 echo "Re-run generate_test_data to update data.cairo"
+            exit 1
+          fi

+ 3 - 5
target_chains/starknet/contracts/README.md

@@ -13,14 +13,12 @@ The `.tool-versions` file in this directory specifies the tool versions used by
 
 Run `snforge test` in this directory to run the contract unit tests and integration tests.
 
-Some tests contain input data that was generated with `test_vaas` tool.
-To run it, use the following commands from the repository root (requires Rust installation):
+The `tests/data.cairo` file contains input data that was generated with `test_vaas` tool.
+To regenerate it, run the following commands from the repository root (requires Rust installation):
 
 ```
 cd target_chains/starknet/tools/test_vaas
-cargo run --bin re_sign_price_updates
-cargo run --bin generate_wormhole_vaas
-cargo run --bin wormhole_mainnet_upgrades
+cargo run --bin generate_test_data > ../../contracts/tests/data.cairo
 ```
 
 ## Formatting

+ 450 - 0
target_chains/starknet/contracts/tests/data.cairo

@@ -0,0 +1,450 @@
+// Generated with generate_test_data.rs, do not edit
+
+use pyth::byte_array::{ByteArray, ByteArrayImpl};
+use pyth::util::array_try_into;
+
+// A random update pulled from Hermes.
+pub fn good_update1() -> ByteArray {
+    let bytes = array![
+        141887862745809943100717722154781668316147089807066324001213790862261653767,
+        451230040559159019530944948086670994623010697390864133264612902902585665886,
+        355897384610106978643111834734000274494997301794613218547634257521495150151,
+        140511063638834349363702006999356227863549404051701803148734324248522745879,
+        435849190784772134907557391544163070978531038970298390345939133663347953446,
+        416390591179833928094641114955594939466104495718036761707729297119441316151,
+        360454929416220920336539568461651500076647166763464050800345920693176904002,
+        316054999864337699543932294956493808847640383114707243342262764542081441331,
+        325277902980160684959962429721294603784343718796390808940252812862355246813,
+        43683235854839458868457367619068018785880460427473556950900276498953667,
+        448289429405712011882317781416869052550573589492688760675666957663813001522,
+        118081463902430977133121147164253483958565039026724621562859841189218059803,
+        194064310618695309465615383754562031677972810736048112738513050109934134235,
+        133901765334590923121691219814784557892214901646312752962904032795881821509,
+        404227501001709279944936006741063968912686453006275462577777397594240621266,
+        81649001731335394114026683805238949464016657447685509824621946636993704965,
+        32402065226491532148674904435794801976788068837745943243341272676331333141,
+        431262841416902409381606630149292665102873776020834630861578112749151562174,
+        6164523115980545628843981978797257048781800754033825701059814297149591186,
+        408761574582108996678203805090470134287794603493622537384530614829262728153,
+        185368533577943244707350150853170361880334596276529206938783888784867529821,
+        173578821500714074579643724957224629379984215847383417303110192934676518530,
+        90209855380378362490166376523380463998928070428866100240907090599465187835,
+        97758466908511588082569287391708453107999243934457382895073183209581711489,
+        132725011490528489913736834798247512772139171145730373610858422315799224432,
+        117123868005849140967825260063167768530251411611975150066586827543934313288,
+        408149062252618928234854115279677715692278734600386004492580987016428761675,
+        164529520317122600276020522906605877985809506451193373524142111430138855019,
+        444793051809958482843529748761971363435331354795896511243191618771787268378,
+        247660009137502548346315865368477795392972486141407800140910365553760622080,
+        3281582060272565111592312037403686940429019548922889497694300188,
+        93649805131515836129946966966350066506512123780266587069413066350925286142,
+        394112423559676785086098106350541172262729583743734966358666094809121292390,
+        35403101004688876764673991514113473446030702766599795822870037077688984558,
+        99366103604611980443183454746643823071419076016677225828619807954313149423,
+        10381657217606191031071521950784155484751645280452344547752823767622424055,
+        391045354044274401116419632681482293741435113770205621235865697077178955228,
+        311250087759201408758984550959714865999349469611700431708031036894849650573,
+        59953730895385399344628932835545900304309851622811198425230584225200786697,
+        226866843267230707879834616967256711063296411939069440476882347301771901839,
+        95752383404870925303422787,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 11)
+}
+
+// A wormhole VAA from a random update pulled from Hermes.
+pub fn good_vm1() -> ByteArray {
+    let bytes = array![
+        1766847066033410293701000231337210964058791470455465385734308943533652138,
+        250126301534699068413432844632573953364878937343368310395142095034982913232,
+        374780571002258088211231890250917843593951765403462661483498298003400611238,
+        23190137343211334092589308306056431640588154666326612124726174150537328574,
+        238750269065878649216923353030193912502813798896051725498208457553032584635,
+        29844190303057534696518006438077948796328243878877072296680853158289181326,
+        106329507856770018708432343978518079724691760719405501795955774399597471533,
+        50779865592261858016477142415230454208001695486195806892438697217059319645,
+        448669871976126446102256476358498380455807705600424321390063431836375575318,
+        115682669871397824853706713833773246708114483862317474710603223566297521279,
+        301634766618012930739391408723909107532790832406455099966028276947414082504,
+        104473166230846104217366042152018649207811514257244625711402436055500423094,
+        64445621634231668761998815864645440965239569561546522651415024970517905416,
+        192317190225976528694195501079591384434869624408066864018183189813956862386,
+        289982656017597431343118552054719821766658675456661448685110903889153449006,
+        218840601196095059731241556733624112758673153548932709011933806481899680620,
+        430933799927481265070475198137531816946660368757134588278434352703899277070,
+        69322998883710289192076494057541346430050879299268159627180404869988632073,
+        23862615839737051269352321086490452186237833007444069999578906611768140646,
+        444634264607471510688862284107804392707600799506487897206707262445172121289,
+        438038196736233160320436150616293672539386464061037100698335568417587662951,
+        4682255185797880874381673193118803274635247527626050223938224759013169366,
+        337620725992972686809095065321563509600769533202700218393281926304544120094,
+        106657917096532484607371891267699639824731774168349872862335217581425289654,
+        71240348385993236445536577509595968468284689483611375124653855125285401592,
+        347603391821038175842934311068097986460257977131947418186118379296987051086,
+        414263571545410645948841360836383289766662078574048514890988877286444618669,
+        250301638008739107522011802538487063969565433276260914336890309092111026583,
+        43192785595291340058788190601908070333310658291317702311902081,
+        52685537088250779930155363779405986390839624071318818148325576008719597568,
+        14615204155786886573933667335033405822686404253588533,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 22)
+}
+
+// An actual mainnet wormhole governance VAA from https://github.com/pyth-network/pyth-crosschain/blob/main/contract_manager/src/contracts/wormhole.ts#L32-L37
+pub fn mainnet_guardian_set_upgrade1() -> ByteArray {
+    let bytes = array![
+        1766847064779994277746302277072294871108550301449637470263976489521154979,
+        374953657095152923031303770743522269007103499920836805761143506434463979495,
+        373725794026553362537846905304981854320892126869150736450761801254169477120,
+        4835703278458516786446336,
+        1131377253,
+        3533694129556775410652111826415980944262631656421498398215501759245151417,
+        145493015216602589471695207668173527044214450021182755196032581352392984224,
+        267497573836069714380350521200881787609530659298168186016481773490244091266,
+        443348533394886521835330696538264729103669807313401311199245411889706258110,
+        200303433165499832354845293203843028338419687800279845786613090211434473108,
+        37282816539161742972709083946551920068062204748477644719930149699874385462,
+        111200938271608595261384934914291476246753101189480743698823215749338358345,
+        5785682963869019134199015821749288033381872318410562688180948003975909269,
+        372447340016996751453958019806457886428852701283870538393820846119845147788,
+        33251468085387571623103303511315696691298281336333243761063342581452341650,
+        323161992096034641767541451811925056802673576212351940217752194462561980347,
+        55852237138651071644815135002358067220635692701051811455610533875912981641,
+        190413173566657072516608762222993749133,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 16)
+}
+
+// An actual mainnet wormhole governance VAA from https://github.com/pyth-network/pyth-crosschain/blob/main/contract_manager/src/contracts/wormhole.ts#L32-L37
+pub fn mainnet_guardian_set_upgrade2() -> ByteArray {
+    let bytes = array![
+        1766847065210651126944505525521222069599854288126726949998063840465138797,
+        39054013088470866893599813322035661048501117089555726788687392536164861911,
+        186918267413056900890218521593203545230034250983266377769400670103688217224,
+        54214750922097681971590495378823998039261772575502204791108963815396679538,
+        248994008232667872698758486001506749115615219491023036208140426934463230397,
+        224235483823871042187452194579994340291351644933258737665365374081962645784,
+        129444929990547403397151941456764812818993218972657847255833740800106200260,
+        318548597134783137700627869311159664823693239605331630210202210299165477657,
+        308852933010951129895011963941866000261904600807292935694851016610643657184,
+        57272874228621364335170723193404742446392708606247574725663969156507973216,
+        268057363923565984687253533797066429881117576606682526627284795527707196557,
+        421894189151847402000239734668088381785344768284464330085711322870200424121,
+        387584417395337067059819722404321580961380603778956902593594676080614899975,
+        443523131755342451570503958659975367050637907361274652611595274647186073286,
+        375107813087591446268414166006799680982485924290770541964399283524664437852,
+        269085314426821465871247165234113878276592898426373369094610290261431112145,
+        394348694527460459816454348661249546781513091938003106009521096332701847735,
+        125670844183465056159554034633959680574572737212268749779705635378223489518,
+        35053869475614771227400345921974210525173525784259894123687028214330135561,
+        57544237843860512274491447149877290860624174166427313971286819807773907946,
+        110681468147560408039747352809294082929396639199393789980441736520638055418,
+        45709869872872997180086402576677640909777820941436708911954532772405320395,
+        339910511168418517917975736269171135752028257685502872671902330279073260362,
+        76482764517489607955778008190826845581092838692650194719207882266659669490,
+        443663869577220861680293443959666949893574779475752540587040489501289361777,
+        231057874919577223790659840464529054850239319545221055959374917590157019925,
+        309066533217885002074480704480667619809952056265738927105682076502747220549,
+        212379788814604791028007106821871908074818251907335322546331543385945316762,
+        165408661499085325620077702639227003047567884011538988728381864749733773312,
+        29852013947978990147012099107546124222651092940097518043136,
+        5874446556610227706402640854088357165514903,
+        314635470832203526600706472223155382046271943513513368538979543914002758100,
+        289993023590817330918274026889451152915026890048318491140264484864242055689,
+        211265316833000774821515110003986084297271807500310630074520699505436206838,
+        314620948986744608212517578488307826224331071350776523303159889004405167502,
+        242768143829057016675085776170635413106817756232919004913342240722183648628,
+        289318220340670045883106021427202666948428587921558828582664470923483208386,
+        254304247593881109676724582609273741670949040469906895867342151706444640548,
+        324707984060675446628128892371664948354047882542253609514703956739624414429,
+        125786084546320950738753348592393927755418642173185609412108154831520915923,
+        192033422676298173731756291271054199566981168481817292625435767748408605264,
+        70237018464728620254434305961956673950089621204502627373468857093940647376,
+        75218391584551901010047495874303520775865073092730040058902770251005073864,
+        13453,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 2)
+}
+
+// An actual mainnet wormhole governance VAA from https://github.com/pyth-network/pyth-crosschain/blob/main/contract_manager/src/contracts/wormhole.ts#L32-L37
+pub fn mainnet_guardian_set_upgrade3() -> ByteArray {
+    let bytes = array![
+        1766847065622031860560134801367788401015571316785630090767859240961980367,
+        408239335069601434456324970231880063141100099721451058487412176729277688481,
+        239499689753305520381601038928513796227317320911002802551444547638809838552,
+        377515301744513788082523380503265415136454305699441419871183462725292421897,
+        293792427782284265052215516935690252661713253004854348809536189867737815900,
+        307592266914902727916633292174670243188255704510048236277225897328900269063,
+        127373290139474278928992577974696343462455769904046193125018730285162391253,
+        391788800785481654990215164673817619378887263909639120513493454202816019863,
+        410413307118599096084169722886408584518140871169074821252461819158667354254,
+        18837648490111595970198935552266546643395427923804444528866768515056419823,
+        29964034682984173558839379357821569529808274426015494950430380078317881569,
+        86017868501532670528023530422115758730056738654625156800662778409971102579,
+        316587967137295297243489759859408971025377360462781809717927347025414193161,
+        412080542369789462767669836400697110505430973769191785499739175360336337147,
+        342817079347905714229318925597762381802367663565411998187223317628701911440,
+        323381353160339090772037140072061985169258958022395380273676898316834639836,
+        199931590715070935127318740956564588449721873695471932311700469202637695100,
+        53310522180389647586576928116330850824055549848985438538201222342553700451,
+        387322343922164253479438966163491855981414317104760621828688810466847848718,
+        81609701542274539489711635515209037026645626576756528749469616228397567798,
+        182108205861564989333892774796475580877981373947799860454217397980367659628,
+        21549663410658134468902761710868642321546772465973442277960059676129502668,
+        189434039785735939400321781125039794740638779195156759980704929066694157130,
+        52255833533187953003213955242027099690232530588872309460610106220279805641,
+        197105018621162723372171195601447549272902142615124680111298974553437412361,
+        243585516151555343004264928593678764289083751554802049062044286334698216184,
+        98577806073901898829375415748245478967425496216912736575886605480181121443,
+        92916551389967933235240931764170084503123511470557201449603712010638670912,
+        279247190794260779926452059689914005511524938154821508635388069101252378624,
+        27765181507524306000048567556593270127801507143251178553344,
+        5874446556610227706402640926145951203442839,
+        314635470832203526600706472223155382046271943513513368538979543914002758100,
+        289993023590817330918274026889451152915026890048318491140264484864242055689,
+        211265316833000774821515110003986084297271807500310630074520699505436206838,
+        314620948986744608212517578488307826224331071350776523303159889004405167502,
+        242768143829057016675085658054156069029173843566452718977789980910319968372,
+        289318220340670045883106021427202666948428587921558828582664470923483208386,
+        254304247593881109676724582609273741670949040469906895867342151706444640548,
+        324707984060675446628128892371664948354047882542253609514703956739624414429,
+        125786084546320950738753348592393927755418642173185609412108154831520915923,
+        192033422676298173731756291271054199566981168481817292625435767748408605264,
+        70237018464728620254434305961956673950089621204502627373468857093940647376,
+        75218391584551901010047495874303520775865073092730040058902770251005073864,
+        13453,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 2)
+}
+
+// An actual mainnet wormhole governance VAA from https://github.com/pyth-network/pyth-crosschain/blob/main/contract_manager/src/contracts/wormhole.ts#L32-L37
+pub fn mainnet_guardian_set_upgrade4() -> ByteArray {
+    let bytes = array![
+        1766847066033426987337757245669159273063358729535478806850006662056807068,
+        191023158244075433218055661747029015323596061316379687901032561397223546211,
+        30156550775609732785124128084945604136341937408029517653427049258063209215,
+        301841618969457377999846355946508544313297803407604349411042057045510372286,
+        399879387152070823070522891203531321261797829310211644637928969034931151834,
+        1184971666775858810527395126763859219514013163556756790208661779020321698,
+        427827873217506136303198988655697899138087317492051993053159867826892618987,
+        55439109913191967501571602277685262841453050617358377329061538069328212552,
+        34944602254693785869427132065664922748183924456022812505745784482260734500,
+        50091615215549712387991200985741575718080363004681463525186508796585379155,
+        265247833149227842278059484961926330281584344437952973839486092319885300192,
+        421631446041795295328070636491346018953171276542115189082171457479754499396,
+        59057903625576869235407103565877017330396402246452653660114888284545941770,
+        315797852826246435174946736461540321579373154656484006452063031513301027405,
+        9521420622979958910372839981791309896262328383324674284772682980734269170,
+        272964069264268937653695089515793248726920319914036642027008415285406913245,
+        194708434228888226032102758315234166672190899487218971410889219134701358728,
+        117864954129109327302856065706421701676973859697066630532570005860486924893,
+        323457021720552374478769194145226061243431674370101604382965685057422991463,
+        327482733702858147057975319784026874245182397914737119038454598086198587150,
+        159726033816658034104416471293601013976445904149240898589368461412472508473,
+        165970343982649234398221341351816767302457220504375238905210573566962780340,
+        66269488760319836583658182431744051236825244016843316092957806563966254500,
+        360882001282595740056823749884962228392082962172369522212117195988772429063,
+        202692667772209236945884489592750537635169234501360011152939202347962132650,
+        407257364829649465305126488148712878739144584682351279109461295389594525334,
+        270499607712829989691415988895838806019492861138165540862008308077962735002,
+        388443296961168536186587069708212659389994895697827691755155284015603161464,
+        45068266527940236008536134081672474027695203549460934893262212861351952384,
+        31319268777966350508118557206583844424308993254125039779840,
+        5874446556610227706402640998203302487747647,
+        204224545225244051821590480758420624947979343122083461045877549162059250132,
+        289993023590817330918274026889451152915026890048318491140264484864242055689,
+        211265316833000774821515110003986084297271807500310630074520699505436206838,
+        314620948986744608212517578488307826224331071350776523303159889004405167502,
+        242768143829057016675085658054156069029173843566452718977789980910319968372,
+        289318220340670045883106021427202666948428587921558828582664470923483208386,
+        254304247593881109676724582609273741670949040469906895867342151706444640548,
+        324707984060675446628128892371664948354047882542253609514703956739624414429,
+        125786084546320950738753348592393927755418642173185609412108154831520915923,
+        192033422676298173731756291271054199566981168481817292625435767748408605264,
+        70237018464728620254434305961956673950089621204502627373468857093940647376,
+        75218391584551901010047495874303520775865073092730040058902770251005073864,
+        13453,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 2)
+}
+
+pub const TEST_GUARDIAN_ADDRESS1: felt252 = 0x686b9ea8e3237110eaaba1f1b7467559a3273819;
+pub const TEST_GUARDIAN_ADDRESS2: felt252 = 0x363598f080a817e633fc2d8f2b92e6e637f8b449;
+
+// An invalid wormhole guardian set upgrade instruction containing no new guardians.
+pub fn empty_set_upgrade() -> ByteArray {
+    let bytes = array![
+        1766847064779992178996580835909277664613661950847933439396875833330622292,
+        364268459763994160238907315760635322263304542127720162879870384990884673431,
+        419730305090247124548471445441531015782496798516552461724622762829422788608,
+        4835703278458516699153920,
+        1131377253,
+        210141960835432704,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 8)
+}
+
+// A wormhole guardian set upgrade instruction with emitter not expected by the test.
+pub fn wrong_emitter_upgrade() -> ByteArray {
+    let bytes = array![
+        1766847064779994286935846877901139612104608837038764127758248269325228906,
+        418887508807350452965708560347030276949211978189626151402664101079839557558,
+        197343809067707990824443354127489340211392396345777701010771497603219587072,
+        6044629098073145873860096,
+        1131377253,
+        307122819832911374634462256129025725147663742791077927773782095897,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 28)
+}
+
+// A wormhole guardian set upgrade instruction with set index = 3 not expected by the test.
+pub fn wrong_index_upgrade() -> ByteArray {
+    let bytes = array![
+        1766847064779996028795173168119917022867471281757617479529431178557452389,
+        193283302630366040376283958080462867566389017166937293916301423178932756308,
+        242372832420793675848312873608890898918531405734576271399238077831505248256,
+        4835703278458516699153920,
+        1131377253,
+        210624583337115497886730203944140689990237281548333499058561169433,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 28)
+}
+
+// A wormhole governance guardian set upgrade instruction signed by test guardian #1 containing test guardian #2 as the new guardian set.
+pub fn upgrade_to_test2() -> ByteArray {
+    let bytes = array![
+        1766847064779995287375101177319600239435018729139341591012343354326614060,
+        152103705464783935682610402914146418697934830197930803919710856925871578605,
+        421150899970781847000318380764303006646986333759174982038890844802036793344,
+        4835703278458516699153920,
+        1131377253,
+        210624583337114749311237613435643962969294824395451022190048752713,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 28)
+}
+
+// A Pyth governance instruction to set fee signed by the test guardian #1.
+pub fn pyth_set_fee() -> ByteArray {
+    let bytes = array![
+        1766847064779993955862540543984267022910717161432209540262366788014689913,
+        322968519187498395396360816568387642032723484530650782503164941848016432477,
+        407975527128964115747680681091773270935844489133353741223501742992990928896,
+        49565958604199796163020368,
+        8072278384728444780182694421117884443886221966887092226,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 23)
+}
+
+// A Pyth governance instruction to set data sources signed by the test guardian #1.
+pub fn pyth_set_data_sources() -> ByteArray {
+    let bytes = array![
+        1766847064779993795984967344618836356750759980724568847727566676204733945,
+        319252252405206634291073190903653114488682078063415369176250618646860635118,
+        427774687951454487776318063357824898404188691225649546174530713404617785344,
+        49565958604199796163020368,
+        148907253454411774545738931219166892876160512393929267898119961543514185585,
+        223938022913800988696085410923418445187967252047785407181969631814277398528,
+        301,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 14)
+}
+
+// A Pyth governance instruction to set wormhole address signed by the test guardian #1.
+pub fn pyth_set_wormhole() -> ByteArray {
+    let bytes = array![
+        1766847064779993746734475762358060494055703996306832791834621971457521573,
+        304597972750688370688620483915336485865968448355388067310514768529150663948,
+        37753701654018547624593082738443625808734511977366199414609989499994767360,
+        49565958604199796163020368,
+        148907253456057279176930315687485033494639386197985334929728922792833758561,
+        3789456330195130818,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 8)
+}
+
+// An update pulled from Hermes and re-signed by the test guardian #1.
+pub fn test_price_update1() -> ByteArray {
+    let bytes = array![
+        141887862745809943100421399774809552050876420277163116849842965275903806689,
+        210740906737592158039211995620336526131859667363627655742687286503264782608,
+        437230063624699337579360546580839669896712252828825008570863758867641146081,
+        3498691308882995183871222184377409432186747119716981166996399082193594993,
+        1390200166945919815453709407753165121175395927094647129599868236,
+        222819573728193325268644030206737371345667885599602384508424089704440116301,
+        341318259000017461738706238280879290398059773267212529438772847337449455616,
+        1275126645346645395843037504005879519843596923369759718556759844520336145,
+        363528783578153760894082184744116718493621815898909809604883433584616420886,
+        301537311768214106147206781423041990995720118715322906821301413003463484347,
+        83150006264761451992768264969047148434524798781124754530141755679159432208,
+        96387772316726941183358990094337324283641753573556594738287498821253761827,
+        395908154570808692326126405856049827157095768069251211022053821585519235652,
+        87135893730137265929093180553063146337041045646221968026289709394440932141,
+        245333243912241114598596888050489286502591033459250287888834,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 25)
+}
+
+// An update pulled from Hermes and re-signed by the test guardian #1.
+pub fn test_price_update2() -> ByteArray {
+    let bytes = array![
+        141887862745809943100421399774809552050874823427618844548942380383465221086,
+        106893583704677921907497845070624642590618427233243792006390965895909696183,
+        126617671723931969110123875642449115250793288301361049879364132884271078113,
+        3498691308882995183871222184377409432186747119716981166996399082193594993,
+        1390200461185063661704370212555794334034815850290352693418762308,
+        419598057710749587537080281518289024699150505326900462079484531390510117965,
+        341318259000017461738706238280879290398059773267212529438780607147892801536,
+        1437437604754599821041091415535991441313586347841485651963630208563420739,
+        305222830440467078008666830004555943609735125691441831219591213494068931362,
+        358396406696718360717615797531477055540194104082154743994717297650279402646,
+        429270385827211102844129651648706540139690432947840438198166022904666187018,
+        343946166212648899477337159288779715507980257611242783073384876024451565860,
+        67853010773876862913176476530730880916439012004585961528150130218675908823,
+        370855179649505412564259994413632062925303311800103998016489412083011059699,
+        1182295126766215829784496273374889928477877265080355104888778,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 25)
+}
+
+// An update pulled from Hermes and re-signed by the test guardian #1 with another emitter address.
+pub fn test_update2_alt_emitter() -> ByteArray {
+    let bytes = array![
+        141887862745809943100421399774809552050876183715022494587482285730295850458,
+        359963320496358929787450247990998878269668655936959553372924597144593948268,
+        168294065609209340478050191639515428002729901421915929480902120205187023616,
+        301,
+        1390200461185063661704370212555794334034815850290352693418762308,
+        419598057710749587537080281518289024699150505326900462079484531390510117965,
+        341318259000017461738706238280879290398059773267212529438780607147892801536,
+        1437437604754599821041091415535991441313586347841485651963630208563420739,
+        305222830440467078008666830004555943609735125691441831219591213494068931362,
+        358396406696718360717615797531477055540194104082154743994717297650279402646,
+        429270385827211102844129651648706540139690432947840438198166022904666187018,
+        343946166212648899477337159288779715507980257611242783073384876024451565860,
+        67853010773876862913176476530730880916439012004585961528150130218675908823,
+        370855179649505412564259994413632062925303311800103998016489412083011059699,
+        1182295126766215829784496273374889928477877265080355104888778,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 25)
+}
+
+// An update pulled from Hermes and re-signed by the test guardian #2.
+pub fn test_update2_set2() -> ByteArray {
+    let bytes = array![
+        141887862745809943100421399774809552391157901121219476151849805356757998433,
+        22927445661989480418689320204846867835510434886542566099417398893061382455,
+        299474373929736638290349370983054029794228129896969116108467835428084390625,
+        3498691308882995183871222184377409432186747119716981166996399082193594993,
+        1390200461185063661704370212555794334034815850290352693418762308,
+        419598057710749587537080281518289024699150505326900462079484531390510117965,
+        341318259000017461738706238280879290398059773267212529438780607147892801536,
+        1437437604754599821041091415535991441313586347841485651963630208563420739,
+        305222830440467078008666830004555943609735125691441831219591213494068931362,
+        358396406696718360717615797531477055540194104082154743994717297650279402646,
+        429270385827211102844129651648706540139690432947840438198166022904666187018,
+        343946166212648899477337159288779715507980257611242783073384876024451565860,
+        67853010773876862913176476530730880916439012004585961528150130218675908823,
+        370855179649505412564259994413632062925303311800103998016489412083011059699,
+        1182295126766215829784496273374889928477877265080355104888778,
+    ];
+    ByteArrayImpl::new(array_try_into(bytes), 25)
+}

+ 20 - 223
target_chains/starknet/contracts/tests/pyth.cairo

@@ -12,6 +12,7 @@ use pyth::wormhole::IWormholeDispatcherTrait;
 use core::starknet::ContractAddress;
 use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
 use super::wormhole::corrupted_vm;
+use super::data;
 
 fn decode_event(event: @Event) -> PythEvent {
     let key0 = *event.keys.at(0);
@@ -56,7 +57,7 @@ fn update_price_feeds_works() {
     let mut spy = spy_events(SpyOn::One(pyth.contract_address));
 
     start_prank(CheatTarget::One(pyth.contract_address), user.try_into().unwrap());
-    pyth.update_price_feeds(good_update1());
+    pyth.update_price_feeds(data::good_update1());
     stop_prank(CheatTarget::One(pyth.contract_address));
 
     spy.fetch_events();
@@ -103,7 +104,7 @@ fn test_governance_set_fee_works() {
 
     let mut balance = fee_contract.balanceOf(user);
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update1_test());
+    pyth.update_price_feeds(data::test_price_update1());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let new_balance = fee_contract.balanceOf(user);
     assert!(balance - new_balance == 1000);
@@ -113,10 +114,10 @@ fn test_governance_set_fee_works() {
         .unwrap_with_felt252();
     assert!(last_price.price == 6281060000000);
 
-    pyth.execute_governance_instruction(governance_set_fee());
+    pyth.execute_governance_instruction(data::pyth_set_fee());
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update2_test());
+    pyth.update_price_feeds(data::test_price_update2());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let new_balance = fee_contract.balanceOf(user);
     assert!(balance - new_balance == 4200);
@@ -136,7 +137,7 @@ fn test_rejects_corrupted_governance_instruction(pos: usize, random1: usize, ran
     let fee_contract = deploy_fee_contract(user);
     let pyth = deploy_default(owner, wormhole.contract_address, fee_contract.contract_address);
 
-    let input = corrupted_vm(governance_set_fee(), pos, random1, random2);
+    let input = corrupted_vm(data::pyth_set_fee(), pos, random1, random2);
     pyth.execute_governance_instruction(input);
 }
 
@@ -153,17 +154,17 @@ fn test_governance_set_data_sources_works() {
     stop_prank(CheatTarget::One(fee_contract.contract_address));
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update1_test());
+    pyth.update_price_feeds(data::test_price_update1());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let last_price = pyth
         .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
         .unwrap_with_felt252();
     assert!(last_price.price == 6281060000000);
 
-    pyth.execute_governance_instruction(governance_set_data_sources());
+    pyth.execute_governance_instruction(data::pyth_set_data_sources());
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update2_test_alt_emitter());
+    pyth.update_price_feeds(data::test_update2_alt_emitter());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let last_price = pyth
         .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
@@ -185,17 +186,17 @@ fn test_rejects_update_after_data_source_changed() {
     stop_prank(CheatTarget::One(fee_contract.contract_address));
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update1_test());
+    pyth.update_price_feeds(data::test_price_update1());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let last_price = pyth
         .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
         .unwrap_with_felt252();
     assert!(last_price.price == 6281060000000);
 
-    pyth.execute_governance_instruction(governance_set_data_sources());
+    pyth.execute_governance_instruction(data::pyth_set_data_sources());
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update2_test());
+    pyth.update_price_feeds(data::test_price_update2());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let last_price = pyth
         .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
@@ -222,7 +223,7 @@ fn test_governance_set_wormhole_works() {
     stop_prank(CheatTarget::One(fee_contract.contract_address));
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update1_test());
+    pyth.update_price_feeds(data::test_price_update1());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let last_price = pyth
         .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
@@ -236,11 +237,11 @@ fn test_governance_set_wormhole_works() {
     let wormhole2 = super::wormhole::deploy_declared_with_test_guardian_at(
         @wormhole_class, wormhole2_address
     );
-    wormhole2.submit_new_guardian_set(super::wormhole::upgrade_test_guardian_1_to_2());
+    wormhole2.submit_new_guardian_set(data::upgrade_to_test2());
 
     let mut spy = spy_events(SpyOn::One(pyth.contract_address));
 
-    pyth.execute_governance_instruction(governance_set_wormhole());
+    pyth.execute_governance_instruction(data::pyth_set_wormhole());
 
     spy.fetch_events();
     assert!(spy.events.len() == 1);
@@ -253,7 +254,7 @@ fn test_governance_set_wormhole_works() {
     assert!(event == PythEvent::WormholeAddressSet(expected));
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update2_test2_guardian());
+    pyth.update_price_feeds(data::test_update2_set2());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let last_price = pyth
         .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
@@ -275,7 +276,7 @@ fn test_rejects_price_update_without_setting_wormhole() {
     stop_prank(CheatTarget::One(fee_contract.contract_address));
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update1_test());
+    pyth.update_price_feeds(data::test_price_update1());
     stop_prank(CheatTarget::One(pyth.contract_address));
     let last_price = pyth
         .get_price_unsafe(0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43)
@@ -283,7 +284,7 @@ fn test_rejects_price_update_without_setting_wormhole() {
     assert!(last_price.price == 6281060000000);
 
     start_prank(CheatTarget::One(pyth.contract_address), user);
-    pyth.update_price_feeds(price_update2_test2_guardian());
+    pyth.update_price_feeds(data::test_update2_set2());
 }
 
 // This test doesn't pass because of an snforge bug.
@@ -304,7 +305,7 @@ fn test_rejects_set_wormhole_without_deploying() {
     let user = 'user'.try_into().unwrap();
     let fee_contract = deploy_fee_contract(user);
     let pyth = deploy_default(owner, wormhole.contract_address, fee_contract.contract_address);
-    pyth.execute_governance_instruction(governance_set_wormhole());
+    pyth.execute_governance_instruction(data::pyth_set_wormhole());
 }
 
 #[test]
@@ -334,7 +335,7 @@ fn test_rejects_set_wormhole_with_incompatible_guardians() {
         super::wormhole::GOVERNANCE_CONTRACT,
         Option::Some(wormhole2_address),
     );
-    pyth.execute_governance_instruction(governance_set_wormhole());
+    pyth.execute_governance_instruction(data::pyth_set_wormhole());
 }
 
 fn deploy_default(
@@ -397,207 +398,3 @@ fn deploy_fee_contract(recipient: ContractAddress) -> IERC20CamelDispatcher {
     };
     IERC20CamelDispatcher { contract_address }
 }
-
-// A random update pulled from Hermes.
-fn good_update1() -> ByteArray {
-    let bytes = array![
-        141887862745809943100717722154781668316147089807066324001213790862261653767,
-        451230040559159019530944948086670994623010697390864133264612902902585665886,
-        355897384610106978643111834734000274494997301794613218547634257521495150151,
-        140511063638834349363702006999356227863549404051701803148734324248522745879,
-        435849190784772134907557391544163070978531038970298390345939133663347953446,
-        416390591179833928094641114955594939466104495718036761707729297119441316151,
-        360454929416220920336539568461651500076647166763464050800345920693176904002,
-        316054999864337699543932294956493808847640383114707243342262764542081441331,
-        325277902980160684959962429721294603784343718796390808940252812862355246813,
-        43683235854839458868457367619068018785880460427473556950900276498953667,
-        448289429405712011882317781416869052550573589492688760675666957663813001522,
-        118081463902430977133121147164253483958565039026724621562859841189218059803,
-        194064310618695309465615383754562031677972810736048112738513050109934134235,
-        133901765334590923121691219814784557892214901646312752962904032795881821509,
-        404227501001709279944936006741063968912686453006275462577777397594240621266,
-        81649001731335394114026683805238949464016657447685509824621946636993704965,
-        32402065226491532148674904435794801976788068837745943243341272676331333141,
-        431262841416902409381606630149292665102873776020834630861578112749151562174,
-        6164523115980545628843981978797257048781800754033825701059814297149591186,
-        408761574582108996678203805090470134287794603493622537384530614829262728153,
-        185368533577943244707350150853170361880334596276529206938783888784867529821,
-        173578821500714074579643724957224629379984215847383417303110192934676518530,
-        90209855380378362490166376523380463998928070428866100240907090599465187835,
-        97758466908511588082569287391708453107999243934457382895073183209581711489,
-        132725011490528489913736834798247512772139171145730373610858422315799224432,
-        117123868005849140967825260063167768530251411611975150066586827543934313288,
-        408149062252618928234854115279677715692278734600386004492580987016428761675,
-        164529520317122600276020522906605877985809506451193373524142111430138855019,
-        444793051809958482843529748761971363435331354795896511243191618771787268378,
-        247660009137502548346315865368477795392972486141407800140910365553760622080,
-        3281582060272565111592312037403686940429019548922889497694300188,
-        93649805131515836129946966966350066506512123780266587069413066350925286142,
-        394112423559676785086098106350541172262729583743734966358666094809121292390,
-        35403101004688876764673991514113473446030702766599795822870037077688984558,
-        99366103604611980443183454746643823071419076016677225828619807954313149423,
-        10381657217606191031071521950784155484751645280452344547752823767622424055,
-        391045354044274401116419632681482293741435113770205621235865697077178955228,
-        311250087759201408758984550959714865999349469611700431708031036894849650573,
-        59953730895385399344628932835545900304309851622811198425230584225200786697,
-        226866843267230707879834616967256711063296411939069440476882347301771901839,
-        95752383404870925303422787,
-    ];
-    ByteArrayImpl::new(array_try_into(bytes), 11)
-}
-
-// Generated with `../../tools/test_vaas/src/bin/generate_wormhole_vaas.rs`
-fn governance_set_fee() -> ByteArray {
-    ByteArrayImpl::new(
-        array_try_into(
-            array![
-                1766847064779993955862540543984267022910717161432209540262366788014689913,
-                322968519187498395396360816568387642032723484530650782503164941848016432477,
-                407975527128964115747680681091773270935844489133353741223501742992990928896,
-                49565958604199796163020368,
-                8072278384728444780182694421117884443886221966887092226,
-            ]
-        ),
-        23
-    )
-}
-
-// Generated with `../../tools/test_vaas/src/bin/generate_wormhole_vaas.rs`
-fn governance_set_data_sources() -> ByteArray {
-    ByteArrayImpl::new(
-        array_try_into(
-            array![
-                1766847064779993795984967344618836356750759980724568847727566676204733945,
-                319252252405206634291073190903653114488682078063415369176250618646860635118,
-                427774687951454487776318063357824898404188691225649546174530713404617785344,
-                49565958604199796163020368,
-                148907253454411774545738931219166892876160512393929267898119961543514185585,
-                223938022913800988696085410923418445187967252047785407181969631814277398528,
-                301,
-            ]
-        ),
-        14
-    )
-}
-
-// Generated with `../../tools/test_vaas/src/bin/generate_wormhole_vaas.rs`
-fn governance_set_wormhole() -> ByteArray {
-    ByteArrayImpl::new(
-        array_try_into(
-            array![
-                1766847064779993746734475762358060494055703996306832791834621971457521573,
-                304597972750688370688620483915336485865968448355388067310514768529150663948,
-                37753701654018547624593082738443625808734511977366199414609989499994767360,
-                49565958604199796163020368,
-                148907253456057279176930315687485033494639386197985334929728922792833758561,
-                3789456330195130818,
-            ]
-        ),
-        8
-    )
-}
-
-// Generated with `../../tools/test_vaas/src/bin/re_sign_price_updates.rs`
-fn price_update1_test() -> ByteArray {
-    ByteArrayImpl::new(
-        array_try_into(
-            array![
-                141887862745809943100421399774809552050876420277163116849842965275903806689,
-                210740906737592158039211995620336526131859667363627655742687286503264782608,
-                437230063624699337579360546580839669896712252828825008570863758867641146081,
-                3498691308882995183871222184377409432186747119716981166996399082193594993,
-                1390200166945919815453709407753165121175395927094647129599868236,
-                222819573728193325268644030206737371345667885599602384508424089704440116301,
-                341318259000017461738706238280879290398059773267212529438772847337449455616,
-                1275126645346645395843037504005879519843596923369759718556759844520336145,
-                363528783578153760894082184744116718493621815898909809604883433584616420886,
-                301537311768214106147206781423041990995720118715322906821301413003463484347,
-                83150006264761451992768264969047148434524798781124754530141755679159432208,
-                96387772316726941183358990094337324283641753573556594738287498821253761827,
-                395908154570808692326126405856049827157095768069251211022053821585519235652,
-                87135893730137265929093180553063146337041045646221968026289709394440932141,
-                245333243912241114598596888050489286502591033459250287888834,
-            ]
-        ),
-        25
-    )
-}
-
-// Generated with `../../tools/test_vaas/src/bin/re_sign_price_updates.rs`
-fn price_update2_test() -> ByteArray {
-    ByteArrayImpl::new(
-        array_try_into(
-            array![
-                141887862745809943100421399774809552050874823427618844548942380383465221086,
-                106893583704677921907497845070624642590618427233243792006390965895909696183,
-                126617671723931969110123875642449115250793288301361049879364132884271078113,
-                3498691308882995183871222184377409432186747119716981166996399082193594993,
-                1390200461185063661704370212555794334034815850290352693418762308,
-                419598057710749587537080281518289024699150505326900462079484531390510117965,
-                341318259000017461738706238280879290398059773267212529438780607147892801536,
-                1437437604754599821041091415535991441313586347841485651963630208563420739,
-                305222830440467078008666830004555943609735125691441831219591213494068931362,
-                358396406696718360717615797531477055540194104082154743994717297650279402646,
-                429270385827211102844129651648706540139690432947840438198166022904666187018,
-                343946166212648899477337159288779715507980257611242783073384876024451565860,
-                67853010773876862913176476530730880916439012004585961528150130218675908823,
-                370855179649505412564259994413632062925303311800103998016489412083011059699,
-                1182295126766215829784496273374889928477877265080355104888778,
-            ]
-        ),
-        25
-    )
-}
-
-// Generated with `../../tools/test_vaas/src/bin/re_sign_price_updates.rs`
-// (same as `price_update2_test()` but with a different emitter)
-fn price_update2_test_alt_emitter() -> ByteArray {
-    ByteArrayImpl::new(
-        array_try_into(
-            array![
-                141887862745809943100421399774809552050876183715022494587482285730295850458,
-                359963320496358929787450247990998878269668655936959553372924597144593948268,
-                168294065609209340478050191639515428002729901421915929480902120205187023616,
-                301,
-                1390200461185063661704370212555794334034815850290352693418762308,
-                419598057710749587537080281518289024699150505326900462079484531390510117965,
-                341318259000017461738706238280879290398059773267212529438780607147892801536,
-                1437437604754599821041091415535991441313586347841485651963630208563420739,
-                305222830440467078008666830004555943609735125691441831219591213494068931362,
-                358396406696718360717615797531477055540194104082154743994717297650279402646,
-                429270385827211102844129651648706540139690432947840438198166022904666187018,
-                343946166212648899477337159288779715507980257611242783073384876024451565860,
-                67853010773876862913176476530730880916439012004585961528150130218675908823,
-                370855179649505412564259994413632062925303311800103998016489412083011059699,
-                1182295126766215829784496273374889928477877265080355104888778,
-            ]
-        ),
-        25
-    )
-}
-
-// Generated with `../../tools/test_vaas/src/bin/re_sign_price_updates.rs`
-fn price_update2_test2_guardian() -> ByteArray {
-    ByteArrayImpl::new(
-        array_try_into(
-            array![
-                141887862745809943100421399774809552391157901121219476151849805356757998433,
-                22927445661989480418689320204846867835510434886542566099417398893061382455,
-                299474373929736638290349370983054029794228129896969116108467835428084390625,
-                3498691308882995183871222184377409432186747119716981166996399082193594993,
-                1390200461185063661704370212555794334034815850290352693418762308,
-                419598057710749587537080281518289024699150505326900462079484531390510117965,
-                341318259000017461738706238280879290398059773267212529438780607147892801536,
-                1437437604754599821041091415535991441313586347841485651963630208563420739,
-                305222830440467078008666830004555943609735125691441831219591213494068931362,
-                358396406696718360717615797531477055540194104082154743994717297650279402646,
-                429270385827211102844129651648706540139690432947840438198166022904666187018,
-                343946166212648899477337159288779715507980257611242783073384876024451565860,
-                67853010773876862913176476530730880916439012004585961528150130218675908823,
-                370855179649505412564259994413632062925303311800103998016489412083011059699,
-                1182295126766215829784496273374889928477877265080355104888778,
-            ]
-        ),
-        25
-    )
-}

+ 20 - 296
target_chains/starknet/contracts/tests/wormhole.cairo

@@ -5,13 +5,14 @@ use pyth::byte_array::{ByteArray, ByteArrayImpl};
 use pyth::util::{UnwrapWithFelt252, array_try_into};
 use core::starknet::{ContractAddress, EthAddress};
 use core::panic_with_felt252;
+use super::data;
 
 #[test]
 fn test_parse_and_verify_vm_works() {
     let dispatcher = deploy_with_mainnet_guardians();
     assert!(dispatcher.chain_id() == CHAIN_ID);
 
-    let vm = dispatcher.parse_and_verify_vm(good_vm1());
+    let vm = dispatcher.parse_and_verify_vm(data::good_vm1());
     assert!(vm.version == 1);
     assert!(vm.guardian_set_index == 3);
     assert!(vm.signatures.len() == 13);
@@ -40,7 +41,7 @@ fn test_parse_and_verify_vm_works() {
 fn test_parse_and_verify_vm_rejects_corrupted_vm(pos: usize, random1: usize, random2: usize) {
     let dispatcher = deploy_with_mainnet_guardians();
 
-    let input = corrupted_vm(good_vm1(), pos, random1, random2);
+    let input = corrupted_vm(data::good_vm1(), pos, random1, random2);
     let vm = dispatcher.parse_and_verify_vm(input);
     println!("no error, output: {:?}", vm);
 }
@@ -50,22 +51,7 @@ fn test_parse_and_verify_vm_rejects_corrupted_vm(pos: usize, random1: usize, ran
 fn test_submit_guardian_set_rejects_invalid_emitter() {
     let dispatcher = deploy_with_test_guardian();
 
-    dispatcher
-        .submit_new_guardian_set(
-            ByteArrayImpl::new(
-                array_try_into(
-                    array![
-                        1766847064779994286935846877901139612104608837038764127758248269325228906,
-                        418887508807350452965708560347030276949211978189626151402664101079839557558,
-                        197343809067707990824443354127489340211392396345777701010771497603219587072,
-                        6044629098073145873860096,
-                        1131377253,
-                        307122819832911374634462256129025725147663742791077927773782095897,
-                    ]
-                ),
-                28
-            )
-        );
+    dispatcher.submit_new_guardian_set(data::wrong_emitter_upgrade());
 }
 
 #[test]
@@ -73,8 +59,8 @@ fn test_submit_guardian_set_rejects_invalid_emitter() {
 fn test_submit_guardian_set_rejects_wrong_index_in_signer() {
     let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT);
 
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm1());
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm3());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade1());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade3());
 }
 
 #[test]
@@ -82,22 +68,7 @@ fn test_submit_guardian_set_rejects_wrong_index_in_signer() {
 fn test_submit_guardian_set_rejects_wrong_index_in_payload() {
     let dispatcher = deploy_with_test_guardian();
 
-    dispatcher
-        .submit_new_guardian_set(
-            ByteArrayImpl::new(
-                array_try_into(
-                    array![
-                        1766847064779996028795173168119917022867471281757617479529431178557452389,
-                        193283302630366040376283958080462867566389017166937293916301423178932756308,
-                        242372832420793675848312873608890898918531405734576271399238077831505248256,
-                        4835703278458516699153920,
-                        1131377253,
-                        210624583337115497886730203944140689990237281548333499058561169433,
-                    ]
-                ),
-                28
-            )
-        );
+    dispatcher.submit_new_guardian_set(data::wrong_index_upgrade());
 }
 
 #[test]
@@ -111,22 +82,7 @@ fn test_deploy_rejects_empty() {
 fn test_submit_guardian_set_rejects_empty() {
     let dispatcher = deploy_with_test_guardian();
 
-    dispatcher
-        .submit_new_guardian_set(
-            ByteArrayImpl::new(
-                array_try_into(
-                    array![
-                        1766847064779992178996580835909277664613661950847933439396875833330622292,
-                        364268459763994160238907315760635322263304542127720162879870384990884673431,
-                        419730305090247124548471445441531015782496798516552461724622762829422788608,
-                        4835703278458516699153920,
-                        1131377253,
-                        210141960835432704,
-                    ]
-                ),
-                8
-            )
-        );
+    dispatcher.submit_new_guardian_set(data::empty_set_upgrade());
 }
 
 #[test]
@@ -135,7 +91,7 @@ fn test_submit_guardian_set_rejects_empty() {
 fn test_submit_guardian_set_rejects_corrupted(pos: usize, random1: usize, random2: usize) {
     let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT);
 
-    let vm = corrupted_vm(governance_upgrade_vm1(), pos, random1, random2);
+    let vm = corrupted_vm(data::mainnet_guardian_set_upgrade1(), pos, random1, random2);
     dispatcher.submit_new_guardian_set(vm);
 }
 
@@ -144,11 +100,11 @@ fn test_submit_guardian_set_rejects_corrupted(pos: usize, random1: usize, random
 fn test_submit_guardian_set_rejects_non_governance(pos: usize, random1: usize, random2: usize) {
     let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT);
 
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm1());
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm2());
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm3());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade1());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade2());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade3());
 
-    dispatcher.submit_new_guardian_set(good_vm1());
+    dispatcher.submit_new_guardian_set(data::good_vm1());
 }
 
 // Deploys a previously declared wormhole contract class at the specified address.
@@ -194,20 +150,18 @@ fn deploy(
 pub fn deploy_with_mainnet_guardians() -> IWormholeDispatcher {
     let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT);
 
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm1());
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm2());
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm3());
-    dispatcher.submit_new_guardian_set(governance_upgrade_vm4());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade1());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade2());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade3());
+    dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade4());
 
     dispatcher
 }
 
-const TEST_GUARDIAN_ADDRESS: felt252 = 0x686b9ea8e3237110eaaba1f1b7467559a3273819;
-
 // Declares and deploys the contract with the test guardian address that's used to sign VAAs generated in `test_vaas`.
 pub fn deploy_with_test_guardian() -> IWormholeDispatcher {
     deploy(
-        array_try_into(array![TEST_GUARDIAN_ADDRESS]),
+        array_try_into(array![data::TEST_GUARDIAN_ADDRESS1]),
         CHAIN_ID,
         GOVERNANCE_CHAIN_ID,
         GOVERNANCE_CONTRACT,
@@ -221,7 +175,7 @@ pub fn deploy_declared_with_test_guardian_at(
 ) -> IWormholeDispatcher {
     deploy_declared_at(
         class,
-        array_try_into(array![TEST_GUARDIAN_ADDRESS]),
+        array_try_into(array![data::TEST_GUARDIAN_ADDRESS1]),
         CHAIN_ID,
         GOVERNANCE_CHAIN_ID,
         GOVERNANCE_CONTRACT,
@@ -292,241 +246,11 @@ fn corrupted_byte(value: u8, random: usize) -> u8 {
     (v % 256).try_into().unwrap()
 }
 
+// Initial mainnet guardian set.
 fn guardian_set0() -> Array<EthAddress> {
     array_try_into(array![0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5])
 }
 
-// A random VAA pulled from Hermes.
-fn good_vm1() -> ByteArray {
-    let bytes = array![
-        1766847066033410293701000231337210964058791470455465385734308943533652138,
-        250126301534699068413432844632573953364878937343368310395142095034982913232,
-        374780571002258088211231890250917843593951765403462661483498298003400611238,
-        23190137343211334092589308306056431640588154666326612124726174150537328574,
-        238750269065878649216923353030193912502813798896051725498208457553032584635,
-        29844190303057534696518006438077948796328243878877072296680853158289181326,
-        106329507856770018708432343978518079724691760719405501795955774399597471533,
-        50779865592261858016477142415230454208001695486195806892438697217059319645,
-        448669871976126446102256476358498380455807705600424321390063431836375575318,
-        115682669871397824853706713833773246708114483862317474710603223566297521279,
-        301634766618012930739391408723909107532790832406455099966028276947414082504,
-        104473166230846104217366042152018649207811514257244625711402436055500423094,
-        64445621634231668761998815864645440965239569561546522651415024970517905416,
-        192317190225976528694195501079591384434869624408066864018183189813956862386,
-        289982656017597431343118552054719821766658675456661448685110903889153449006,
-        218840601196095059731241556733624112758673153548932709011933806481899680620,
-        430933799927481265070475198137531816946660368757134588278434352703899277070,
-        69322998883710289192076494057541346430050879299268159627180404869988632073,
-        23862615839737051269352321086490452186237833007444069999578906611768140646,
-        444634264607471510688862284107804392707600799506487897206707262445172121289,
-        438038196736233160320436150616293672539386464061037100698335568417587662951,
-        4682255185797880874381673193118803274635247527626050223938224759013169366,
-        337620725992972686809095065321563509600769533202700218393281926304544120094,
-        106657917096532484607371891267699639824731774168349872862335217581425289654,
-        71240348385993236445536577509595968468284689483611375124653855125285401592,
-        347603391821038175842934311068097986460257977131947418186118379296987051086,
-        414263571545410645948841360836383289766662078574048514890988877286444618669,
-        250301638008739107522011802538487063969565433276260914336890309092111026583,
-        43192785595291340058788190601908070333310658291317702311902081,
-        52685537088250779930155363779405986390839624071318818148325576008719597568,
-        14615204155786886573933667335033405822686404253588533,
-    ];
-    ByteArrayImpl::new(array_try_into(bytes), 22)
-}
-
 pub const CHAIN_ID: u16 = 60051;
 pub const GOVERNANCE_CHAIN_ID: u16 = 1;
 pub const GOVERNANCE_CONTRACT: u256 = 4;
-
-// Generated with `../../tools/test_vaas/src/bin/generate_wormhole_vaas.rs`
-pub fn upgrade_test_guardian_1_to_2() -> ByteArray {
-    ByteArrayImpl::new(
-        array_try_into(
-            array![
-                1766847064779995287375101177319600239435018729139341591012343354326614060,
-                152103705464783935682610402914146418697934830197930803919710856925871578605,
-                421150899970781847000318380764303006646986333759174982038890844802036793344,
-                4835703278458516699153920,
-                1131377253,
-                210624583337114749311237613435643962969294824395451022190048752713,
-            ]
-        ),
-        28
-    )
-}
-
-// Below are actual guardian set upgrade VAAS from
-// https://github.com/pyth-network/pyth-crosschain/blob/main/contract_manager/src/contracts/wormhole.ts#L32-L37
-fn governance_upgrade_vm1() -> ByteArray {
-    let bytes = array![
-        1766847064779994277746302277072294871108550301449637470263976489521154979,
-        374953657095152923031303770743522269007103499920836805761143506434463979495,
-        373725794026553362537846905304981854320892126869150736450761801254169477120,
-        4835703278458516786446336,
-        1131377253,
-        3533694129556775410652111826415980944262631656421498398215501759245151417,
-        145493015216602589471695207668173527044214450021182755196032581352392984224,
-        267497573836069714380350521200881787609530659298168186016481773490244091266,
-        443348533394886521835330696538264729103669807313401311199245411889706258110,
-        200303433165499832354845293203843028338419687800279845786613090211434473108,
-        37282816539161742972709083946551920068062204748477644719930149699874385462,
-        111200938271608595261384934914291476246753101189480743698823215749338358345,
-        5785682963869019134199015821749288033381872318410562688180948003975909269,
-        372447340016996751453958019806457886428852701283870538393820846119845147788,
-        33251468085387571623103303511315696691298281336333243761063342581452341650,
-        323161992096034641767541451811925056802673576212351940217752194462561980347,
-        55852237138651071644815135002358067220635692701051811455610533875912981641,
-        190413173566657072516608762222993749133,
-    ];
-    ByteArrayImpl::new(array_try_into(bytes), 16)
-}
-
-fn governance_upgrade_vm2() -> ByteArray {
-    let bytes = array![
-        1766847065210651126944505525521222069599854288126726949998063840465138797,
-        39054013088470866893599813322035661048501117089555726788687392536164861911,
-        186918267413056900890218521593203545230034250983266377769400670103688217224,
-        54214750922097681971590495378823998039261772575502204791108963815396679538,
-        248994008232667872698758486001506749115615219491023036208140426934463230397,
-        224235483823871042187452194579994340291351644933258737665365374081962645784,
-        129444929990547403397151941456764812818993218972657847255833740800106200260,
-        318548597134783137700627869311159664823693239605331630210202210299165477657,
-        308852933010951129895011963941866000261904600807292935694851016610643657184,
-        57272874228621364335170723193404742446392708606247574725663969156507973216,
-        268057363923565984687253533797066429881117576606682526627284795527707196557,
-        421894189151847402000239734668088381785344768284464330085711322870200424121,
-        387584417395337067059819722404321580961380603778956902593594676080614899975,
-        443523131755342451570503958659975367050637907361274652611595274647186073286,
-        375107813087591446268414166006799680982485924290770541964399283524664437852,
-        269085314426821465871247165234113878276592898426373369094610290261431112145,
-        394348694527460459816454348661249546781513091938003106009521096332701847735,
-        125670844183465056159554034633959680574572737212268749779705635378223489518,
-        35053869475614771227400345921974210525173525784259894123687028214330135561,
-        57544237843860512274491447149877290860624174166427313971286819807773907946,
-        110681468147560408039747352809294082929396639199393789980441736520638055418,
-        45709869872872997180086402576677640909777820941436708911954532772405320395,
-        339910511168418517917975736269171135752028257685502872671902330279073260362,
-        76482764517489607955778008190826845581092838692650194719207882266659669490,
-        443663869577220861680293443959666949893574779475752540587040489501289361777,
-        231057874919577223790659840464529054850239319545221055959374917590157019925,
-        309066533217885002074480704480667619809952056265738927105682076502747220549,
-        212379788814604791028007106821871908074818251907335322546331543385945316762,
-        165408661499085325620077702639227003047567884011538988728381864749733773312,
-        29852013947978990147012099107546124222651092940097518043136,
-        5874446556610227706402640854088357165514903,
-        314635470832203526600706472223155382046271943513513368538979543914002758100,
-        289993023590817330918274026889451152915026890048318491140264484864242055689,
-        211265316833000774821515110003986084297271807500310630074520699505436206838,
-        314620948986744608212517578488307826224331071350776523303159889004405167502,
-        242768143829057016675085776170635413106817756232919004913342240722183648628,
-        289318220340670045883106021427202666948428587921558828582664470923483208386,
-        254304247593881109676724582609273741670949040469906895867342151706444640548,
-        324707984060675446628128892371664948354047882542253609514703956739624414429,
-        125786084546320950738753348592393927755418642173185609412108154831520915923,
-        192033422676298173731756291271054199566981168481817292625435767748408605264,
-        70237018464728620254434305961956673950089621204502627373468857093940647376,
-        75218391584551901010047495874303520775865073092730040058902770251005073864,
-        13453,
-    ];
-    ByteArrayImpl::new(array_try_into(bytes), 2)
-}
-
-fn governance_upgrade_vm3() -> ByteArray {
-    let bytes = array![
-        1766847065622031860560134801367788401015571316785630090767859240961980367,
-        408239335069601434456324970231880063141100099721451058487412176729277688481,
-        239499689753305520381601038928513796227317320911002802551444547638809838552,
-        377515301744513788082523380503265415136454305699441419871183462725292421897,
-        293792427782284265052215516935690252661713253004854348809536189867737815900,
-        307592266914902727916633292174670243188255704510048236277225897328900269063,
-        127373290139474278928992577974696343462455769904046193125018730285162391253,
-        391788800785481654990215164673817619378887263909639120513493454202816019863,
-        410413307118599096084169722886408584518140871169074821252461819158667354254,
-        18837648490111595970198935552266546643395427923804444528866768515056419823,
-        29964034682984173558839379357821569529808274426015494950430380078317881569,
-        86017868501532670528023530422115758730056738654625156800662778409971102579,
-        316587967137295297243489759859408971025377360462781809717927347025414193161,
-        412080542369789462767669836400697110505430973769191785499739175360336337147,
-        342817079347905714229318925597762381802367663565411998187223317628701911440,
-        323381353160339090772037140072061985169258958022395380273676898316834639836,
-        199931590715070935127318740956564588449721873695471932311700469202637695100,
-        53310522180389647586576928116330850824055549848985438538201222342553700451,
-        387322343922164253479438966163491855981414317104760621828688810466847848718,
-        81609701542274539489711635515209037026645626576756528749469616228397567798,
-        182108205861564989333892774796475580877981373947799860454217397980367659628,
-        21549663410658134468902761710868642321546772465973442277960059676129502668,
-        189434039785735939400321781125039794740638779195156759980704929066694157130,
-        52255833533187953003213955242027099690232530588872309460610106220279805641,
-        197105018621162723372171195601447549272902142615124680111298974553437412361,
-        243585516151555343004264928593678764289083751554802049062044286334698216184,
-        98577806073901898829375415748245478967425496216912736575886605480181121443,
-        92916551389967933235240931764170084503123511470557201449603712010638670912,
-        279247190794260779926452059689914005511524938154821508635388069101252378624,
-        27765181507524306000048567556593270127801507143251178553344,
-        5874446556610227706402640926145951203442839,
-        314635470832203526600706472223155382046271943513513368538979543914002758100,
-        289993023590817330918274026889451152915026890048318491140264484864242055689,
-        211265316833000774821515110003986084297271807500310630074520699505436206838,
-        314620948986744608212517578488307826224331071350776523303159889004405167502,
-        242768143829057016675085658054156069029173843566452718977789980910319968372,
-        289318220340670045883106021427202666948428587921558828582664470923483208386,
-        254304247593881109676724582609273741670949040469906895867342151706444640548,
-        324707984060675446628128892371664948354047882542253609514703956739624414429,
-        125786084546320950738753348592393927755418642173185609412108154831520915923,
-        192033422676298173731756291271054199566981168481817292625435767748408605264,
-        70237018464728620254434305961956673950089621204502627373468857093940647376,
-        75218391584551901010047495874303520775865073092730040058902770251005073864,
-        13453,
-    ];
-    ByteArrayImpl::new(array_try_into(bytes), 2)
-}
-
-fn governance_upgrade_vm4() -> ByteArray {
-    let bytes = array![
-        1766847066033426987337757245669159273063358729535478806850006662056807068,
-        191023158244075433218055661747029015323596061316379687901032561397223546211,
-        30156550775609732785124128084945604136341937408029517653427049258063209215,
-        301841618969457377999846355946508544313297803407604349411042057045510372286,
-        399879387152070823070522891203531321261797829310211644637928969034931151834,
-        1184971666775858810527395126763859219514013163556756790208661779020321698,
-        427827873217506136303198988655697899138087317492051993053159867826892618987,
-        55439109913191967501571602277685262841453050617358377329061538069328212552,
-        34944602254693785869427132065664922748183924456022812505745784482260734500,
-        50091615215549712387991200985741575718080363004681463525186508796585379155,
-        265247833149227842278059484961926330281584344437952973839486092319885300192,
-        421631446041795295328070636491346018953171276542115189082171457479754499396,
-        59057903625576869235407103565877017330396402246452653660114888284545941770,
-        315797852826246435174946736461540321579373154656484006452063031513301027405,
-        9521420622979958910372839981791309896262328383324674284772682980734269170,
-        272964069264268937653695089515793248726920319914036642027008415285406913245,
-        194708434228888226032102758315234166672190899487218971410889219134701358728,
-        117864954129109327302856065706421701676973859697066630532570005860486924893,
-        323457021720552374478769194145226061243431674370101604382965685057422991463,
-        327482733702858147057975319784026874245182397914737119038454598086198587150,
-        159726033816658034104416471293601013976445904149240898589368461412472508473,
-        165970343982649234398221341351816767302457220504375238905210573566962780340,
-        66269488760319836583658182431744051236825244016843316092957806563966254500,
-        360882001282595740056823749884962228392082962172369522212117195988772429063,
-        202692667772209236945884489592750537635169234501360011152939202347962132650,
-        407257364829649465305126488148712878739144584682351279109461295389594525334,
-        270499607712829989691415988895838806019492861138165540862008308077962735002,
-        388443296961168536186587069708212659389994895697827691755155284015603161464,
-        45068266527940236008536134081672474027695203549460934893262212861351952384,
-        31319268777966350508118557206583844424308993254125039779840,
-        5874446556610227706402640998203302487747647,
-        204224545225244051821590480758420624947979343122083461045877549162059250132,
-        289993023590817330918274026889451152915026890048318491140264484864242055689,
-        211265316833000774821515110003986084297271807500310630074520699505436206838,
-        314620948986744608212517578488307826224331071350776523303159889004405167502,
-        242768143829057016675085658054156069029173843566452718977789980910319968372,
-        289318220340670045883106021427202666948428587921558828582664470923483208386,
-        254304247593881109676724582609273741670949040469906895867342151706444640548,
-        324707984060675446628128892371664948354047882542253609514703956739624414429,
-        125786084546320950738753348592393927755418642173185609412108154831520915923,
-        192033422676298173731756291271054199566981168481817292625435767748408605264,
-        70237018464728620254434305961956673950089621204502627373468857093940647376,
-        75218391584551901010047495874303520775865073092730040058902770251005073864,
-        13453,
-    ];
-    ByteArrayImpl::new(array_try_into(bytes), 2)
-}

Файловите разлики са ограничени, защото са твърде много
+ 13 - 0
target_chains/starknet/tools/test_vaas/src/bin/generate_test_data.rs


+ 0 - 177
target_chains/starknet/tools/test_vaas/src/bin/generate_wormhole_vaas.rs

@@ -1,177 +0,0 @@
-use libsecp256k1::SecretKey;
-use test_vaas::{
-    print_as_array_and_last, serialize_vaa, u256_to_be, EthAddress, GuardianSet, GuardianSetUpgrade,
-};
-use wormhole_vaas::{PayloadKind, VaaBody};
-
-fn main() {
-    let secret1 = "047f10198517025e9bf2f6d09ebb650826b35397f01ca2a64a38348cae653f86";
-    let address1 = EthAddress(hex::decode("686b9ea8e3237110eaaba1f1b7467559a3273819").unwrap());
-
-    // secret2 = "a95d32e5e2b9464b3f49a0f7ef2ede3ff17585836b253b96c832a86d2b5614cb"
-    let address2 = EthAddress(hex::decode("363598f080a817e633fc2d8f2b92e6e637f8b449").unwrap());
-
-    let guardians = GuardianSet {
-        set_index: 0,
-        secrets: vec![SecretKey::parse_slice(&hex::decode(secret1).unwrap()).unwrap()],
-    };
-
-    let empty_set_upgrade = serialize_vaa(
-        guardians.sign_vaa(
-            &[0],
-            VaaBody {
-                timestamp: 1,
-                nonce: 2,
-                emitter_chain: 1,
-                emitter_address: u256_to_be(4.into()).into(),
-                sequence: 5.try_into().unwrap(),
-                consistency_level: 6,
-                payload: PayloadKind::Binary(
-                    GuardianSetUpgrade {
-                        chain_id: 60051,
-                        set_index: 1,
-                        guardians: Vec::new(),
-                    }
-                    .serialize(),
-                ),
-            },
-        ),
-    );
-    println!("empty upgrade");
-    print_as_array_and_last(&empty_set_upgrade);
-    println!();
-
-    let wrong_emitter_upgrade = serialize_vaa(
-        guardians.sign_vaa(
-            &[0],
-            VaaBody {
-                timestamp: 1,
-                nonce: 2,
-                emitter_chain: 1,
-                emitter_address: u256_to_be(5.into()).into(),
-                sequence: 5.try_into().unwrap(),
-                consistency_level: 6,
-                payload: PayloadKind::Binary(
-                    GuardianSetUpgrade {
-                        chain_id: 60051,
-                        set_index: 1,
-                        guardians: vec![address1.clone()],
-                    }
-                    .serialize(),
-                ),
-            },
-        ),
-    );
-    println!("wrong_emitter_upgrade");
-    print_as_array_and_last(&wrong_emitter_upgrade);
-    println!();
-
-    let wrong_index_upgrade = serialize_vaa(
-        guardians.sign_vaa(
-            &[0],
-            VaaBody {
-                timestamp: 1,
-                nonce: 2,
-                emitter_chain: 1,
-                emitter_address: u256_to_be(4.into()).into(),
-                sequence: 5.try_into().unwrap(),
-                consistency_level: 6,
-                payload: PayloadKind::Binary(
-                    GuardianSetUpgrade {
-                        chain_id: 0,
-                        set_index: 3,
-                        guardians: vec![address1.clone()],
-                    }
-                    .serialize(),
-                ),
-            },
-        ),
-    );
-    println!("wrong_index_upgrade");
-    print_as_array_and_last(&wrong_index_upgrade);
-    println!();
-
-    let upgrade_to_test2 = serialize_vaa(
-        guardians.sign_vaa(
-            &[0],
-            VaaBody {
-                timestamp: 1,
-                nonce: 2,
-                emitter_chain: 1,
-                emitter_address: u256_to_be(4.into()).into(),
-                sequence: 5.try_into().unwrap(),
-                consistency_level: 6,
-                payload: PayloadKind::Binary(
-                    GuardianSetUpgrade {
-                        chain_id: 0,
-                        set_index: 1,
-                        guardians: vec![address2],
-                    }
-                    .serialize(),
-                ),
-            },
-        ),
-    );
-    println!("upgrade_to_test2");
-    print_as_array_and_last(&upgrade_to_test2);
-    println!();
-
-    let pyth_set_fee = serialize_vaa(guardians.sign_vaa(
-        &[0],
-        VaaBody {
-            timestamp: 1,
-            nonce: 2,
-            emitter_chain: 1,
-            emitter_address: u256_to_be(41.into()).into(),
-            sequence: 1.try_into().unwrap(),
-            consistency_level: 6,
-            payload: PayloadKind::Binary(vec![
-                80, 84, 71, 77, 1, 3, 234, 147, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 2,
-            ]),
-        },
-    ));
-    println!("pyth_set_fee");
-    print_as_array_and_last(&pyth_set_fee);
-    println!();
-
-    let pyth_set_data_sources = serialize_vaa(guardians.sign_vaa(
-        &[0],
-        VaaBody {
-            timestamp: 1,
-            nonce: 2,
-            emitter_chain: 1,
-            emitter_address: u256_to_be(41.into()).into(),
-            sequence: 1.try_into().unwrap(),
-            consistency_level: 6,
-            payload: PayloadKind::Binary(vec![
-                80, 84, 71, 77, 1, 2, 234, 147, 2, 0, 1, 107, 177, 69, 9, 166, 18, 240, 31, 187,
-                196, 207, 254, 235, 212, 187, 251, 73, 42, 134, 223, 113, 126, 190, 146, 235, 109,
-                244, 50, 163, 240, 10, 37, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 45,
-            ]),
-        },
-    ));
-    println!("pyth_set_data_sources");
-    print_as_array_and_last(&pyth_set_data_sources);
-    println!();
-
-    let pyth_set_wormhole = serialize_vaa(guardians.sign_vaa(
-        &[0],
-        VaaBody {
-            timestamp: 1,
-            nonce: 2,
-            emitter_chain: 1,
-            emitter_address: u256_to_be(41.into()).into(),
-            sequence: 1.try_into().unwrap(),
-            consistency_level: 6,
-            payload: PayloadKind::Binary(vec![
-                80, 84, 71, 77, 1, 6, 234, 147, 5, 3, 63, 6, 213, 196, 123, 204, 231, 150, 14, 167,
-                3, 176, 74, 11, 246, 75, 243, 63, 111, 46, 181, 97, 52, 150, 218, 116, 117, 34,
-                217, 194,
-            ]),
-        },
-    ));
-    println!("pyth_set_wormhole");
-    print_as_array_and_last(&pyth_set_wormhole);
-    println!();
-}

Файловите разлики са ограничени, защото са твърде много
+ 0 - 23
target_chains/starknet/tools/test_vaas/src/bin/re_sign_price_updates.rs


Файловите разлики са ограничени, защото са твърде много
+ 0 - 4
target_chains/starknet/tools/test_vaas/src/bin/wormhole_mainnet_upgrades.rs


+ 40 - 11
target_chains/starknet/tools/test_vaas/src/lib.rs

@@ -1,4 +1,7 @@
-use std::io::{Cursor, Seek, SeekFrom};
+use std::{
+    fmt::Display,
+    io::{Cursor, Seek, SeekFrom},
+};
 
 use alloy_primitives::FixedBytes;
 use byteorder::{ReadBytesExt, WriteBytesExt, BE};
@@ -53,14 +56,21 @@ pub fn print_as_cli_input(data: &[u8]) {
 }
 
 /// Print data in the format suitable for embedding in tests.
-pub fn print_as_array_and_last(data: &[u8]) {
+pub fn print_as_cairo_fn(data: &[u8], name: impl Display, comment: impl Display) {
+    println!();
+    println!("// {comment}");
     let data = to_cairo_byte_array_data(data);
-    println!("let bytes = array![");
+    println!("pub fn {name}() -> ByteArray {{");
+    println!("    let bytes = array![");
     for item in data.data {
-        println!("    {item},");
+        println!("        {item},");
     }
-    println!("];");
-    println!("let last = {};", data.num_last_bytes);
+    println!("    ];");
+    println!(
+        "    ByteArrayImpl::new(array_try_into(bytes), {})",
+        data.num_last_bytes
+    );
+    println!("}}");
 }
 
 pub struct GuardianSet {
@@ -144,11 +154,13 @@ pub struct DataSource {
     pub emitter_address: FixedBytes<32>,
 }
 
-pub fn re_sign_price_update(
-    update: &[u8],
-    guardian_set: &GuardianSet,
-    new_emitter: Option<DataSource>,
-) -> Vec<u8> {
+pub struct VaaIndexes {
+    pub pos_before_vaa_size: usize,
+    pub pos_before_vaa: usize,
+    pub pos_after_vaa: usize,
+}
+
+pub fn locate_vaa_in_price_update(update: &[u8]) -> VaaIndexes {
     let mut reader = Cursor::new(update);
     reader.seek(SeekFrom::Current(6)).unwrap();
     let trailing_header_len = reader.read_u8().unwrap();
@@ -161,6 +173,23 @@ pub fn re_sign_price_update(
     let wh_proof_size: usize = reader.read_u16::<BE>().unwrap().into();
     let pos_before_vaa: usize = reader.position().try_into().unwrap();
     let pos_after_vaa = pos_before_vaa + wh_proof_size;
+    VaaIndexes {
+        pos_before_vaa_size,
+        pos_before_vaa,
+        pos_after_vaa,
+    }
+}
+
+pub fn re_sign_price_update(
+    update: &[u8],
+    guardian_set: &GuardianSet,
+    new_emitter: Option<DataSource>,
+) -> Vec<u8> {
+    let VaaIndexes {
+        pos_before_vaa_size,
+        pos_before_vaa,
+        pos_after_vaa,
+    } = locate_vaa_in_price_update(update);
 
     let mut vaa = Vaa::read(&mut Cursor::new(&update[pos_before_vaa..pos_after_vaa])).unwrap();
     if let Some(new_emitter) = new_emitter {

Някои файлове не бяха показани, защото твърде много файлове са промени