From aaacce758c9171f855dbb2ebb90365e69887a90f Mon Sep 17 00:00:00 2001 From: Pavel Strakhov Date: Fri, 12 Jul 2024 16:58:01 +0100 Subject: [PATCH] feat(target_chains/starknet): specify guardian set index in wormhole constructor (#1764) --- .../starknet/contracts/deploy/deploy.sh | 45 ++++++++-------- .../starknet/contracts/src/wormhole.cairo | 4 +- .../starknet/contracts/tests/pyth.cairo | 51 +++++++++++++++---- .../starknet/contracts/tests/wormhole.cairo | 43 ++++++++++++---- 4 files changed, 101 insertions(+), 42 deletions(-) diff --git a/target_chains/starknet/contracts/deploy/deploy.sh b/target_chains/starknet/contracts/deploy/deploy.sh index 813334c8fc..1f8f975dc0 100755 --- a/target_chains/starknet/contracts/deploy/deploy.sh +++ b/target_chains/starknet/contracts/deploy/deploy.sh @@ -53,33 +53,36 @@ if [ -z ${PYTH_WORMHOLE_ADDRESS+x} ]; then # deploying wormhole with mainnet guardians - # guardian set #0 + # guardian set #4 PYTH_WORMHOLE_ADDRESS=$(starkli deploy --not-unique --salt 0 --watch "${wormhole_hash}" \ - 1 `# num_guardians` \ - 0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5 \ + 4 `# guardian_set_index` \ + 19 `# num_guardians` \ + 0x5893B5A76c3f739645648885bDCcC06cd70a3Cd3 \ + 0xfF6CB952589BDE862c25Ef4392132fb9D4A42157 \ + 0x114De8460193bdf3A2fCf81f86a09765F4762fD1 \ + 0x107A0086b32d7A0977926A205131d8731D39cbEB \ + 0x8C82B2fd82FaeD2711d59AF0F2499D16e726f6b2 \ + 0x11b39756C042441BE6D8650b69b54EbE715E2343 \ + 0x54Ce5B4D348fb74B958e8966e2ec3dBd4958a7cd \ + 0x15e7cAF07C4e3DC8e7C469f92C8Cd88FB8005a20 \ + 0x74a3bf913953D695260D88BC1aA25A4eeE363ef0 \ + 0x000aC0076727b35FBea2dAc28fEE5cCB0fEA768e \ + 0xAF45Ced136b9D9e24903464AE889F5C8a723FC14 \ + 0xf93124b7c738843CBB89E864c862c38cddCccF95 \ + 0xD2CC37A4dc036a8D232b48f62cDD4731412f4890 \ + 0xDA798F6896A3331F64b48c12D1D57Fd9cbe70811 \ + 0x71AA1BE1D36CaFE3867910F99C09e347899C19C3 \ + 0x8192b6E7387CCd768277c17DAb1b7a5027c0b3Cf \ + 0x178e21ad2E77AE06711549CFBB1f9c7a9d8096e8 \ + 0x5E1487F35515d02A92753504a8D75471b9f49EdB \ + 0x6FbEBc898F403E4773E95feB15E80C9A99c8348d \ "${chain_id}" \ 1 `# governance_chain_id` \ 4 0 `# governance_contract` \ ) - # guardian set #1: https://raw.githubusercontent.com/wormhole-foundation/wormhole-networks/master/mainnetv2/guardianset/v1.prototxt - starkli invoke --watch "${PYTH_WORMHOLE_ADDRESS}" submit_new_guardian_set \ - 16 18 1766847064779994277746302277072294871108550301449637470263976489521154979 374953657095152923031303770743522269007103499920836805761143506434463979495 373725794026553362537846905304981854320892126869150736450761801254169477120 4835703278458516786446336 1131377253 3533694129556775410652111826415980944262631656421498398215501759245151417 145493015216602589471695207668173527044214450021182755196032581352392984224 267497573836069714380350521200881787609530659298168186016481773490244091266 443348533394886521835330696538264729103669807313401311199245411889706258110 200303433165499832354845293203843028338419687800279845786613090211434473108 37282816539161742972709083946551920068062204748477644719930149699874385462 111200938271608595261384934914291476246753101189480743698823215749338358345 5785682963869019134199015821749288033381872318410562688180948003975909269 372447340016996751453958019806457886428852701283870538393820846119845147788 33251468085387571623103303511315696691298281336333243761063342581452341650 323161992096034641767541451811925056802673576212351940217752194462561980347 55852237138651071644815135002358067220635692701051811455610533875912981641 190413173566657072516608762222993749133 - - # guardian set #2: https://raw.githubusercontent.com/wormhole-foundation/wormhole-networks/master/mainnetv2/guardianset/v2.prototxt - starkli invoke --watch "${PYTH_WORMHOLE_ADDRESS}" submit_new_guardian_set \ - 2 44 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 - - # guardian set #3: https://raw.githubusercontent.com/wormhole-foundation/wormhole-networks/master/mainnetv2/guardianset/v3.prototxt - starkli invoke --watch "${PYTH_WORMHOLE_ADDRESS}" submit_new_guardian_set \ - 2 44 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 - - # guardian set #4 - starkli invoke --watch "${PYTH_WORMHOLE_ADDRESS}" submit_new_guardian_set \ - 2 44 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 - starkli call "${PYTH_WORMHOLE_ADDRESS}" parse_and_verify_vm \ - 22 31 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 \ + 22 31 1766847066444781320994483841501749070683184988175346608350833289606460334 212947826323005836459324855622644222616018636992885372105331942586552907468 81660979013353137202642548915832448550451466019996482702323407067724296209 95741624021272728945013270250501993581942556170497732530874878801908144306 165662966900701670449626245581208493004355854955829824194179550634929852833 231912243281085290502810326487185927508155143635177563530631143752065571856 133730969669302854135794272412794164777529338092917842377346428324893829718 97343519857054363566972377057665192056385575884831516477409350758778510013 342746596549774708451947636608846531729658415956055005599080197161394229544 204948333737363743462797621387740902958435788255332697090876514925204619872 125787105691919345394003488771492742490859967707652521322286557930363979017 289200441361010062493817560570776272352820259703146050518813030756504119411 36195295116764854597152684464284437789913478631575450098838448744525463562 130697462617163042959679149176086940549838452585515384044528481294282239773 139674875825513167776845831735936913825147169161587975770748518358126310163 286436305036613647658881186849841354733955967089763556118750317745412087118 5671512721815753211739698846518575453028006970790831305727447899144867646 180304609612262763148200461959875457419015520474026908793738699141169185653 136946758109572962207110548190873778291130450786827595307800254515421619327 17170199244368630212159858748270977608822555594170776804998295695629059235 114140636989602096102794655124749460421508327132088332268734394379961251785 64189131401465205213890974671328939393264177584900517481608375067694905706 28957877657506210079383392143467334592067254866216421163714019229559325481 380789826843014410401773923893528872620094041727761136528833781507143759200 344750914201194299660412358835877469155882340746976208490274423530736037757 368626793571455386480158022104523417706403593747958116469345778842065816527 44398516609262992569922245814359474479109794484528484046528251267154070475 130858275066136325098757860094387148405443006714509562306749555136599024623 43192785595291340058788190601908070333310658291317702311902081 52685537088250779930155363782858917659425217657512936523711408953498337280 14615187937441566980859118820051424312305759711346586 \ 1>&2 fi echo "PYTH_WORMHOLE_ADDRESS=${PYTH_WORMHOLE_ADDRESS}" @@ -112,7 +115,7 @@ pyth_address=$(starkli deploy --not-unique --salt 0 --watch "${pyth_hash}" \ starkli invoke --watch "${fee_token_address1}" approve "${pyth_address}" 1000 0 starkli invoke --watch "${pyth_address}" update_price_feeds \ - 11 41 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 + 11 41 141887862745809943100717722154781668656425228150258363002663887732857548075 399793171101922163607717906910020156439802651815166374105600343045575931912 205983572864866548810075966151139050810706099666354694408986588005072300221 151451952208610765038741735376830560508647207417250420083288609153397964481 86500771940909656434129966404881206990783089169853273096126376095161148476 226128071698991949569342896653857259217290864736270016974365368327197190188 377698250859392108521341636250067678937984182266455992791761951028534274645 359481881021010868573625646624159016709204941239347558851817240293252854322 269752247307988210724584131415546296182395279893478036136383326770680756016 1795390197095010264738527441013169771569683827600670029637766897428840143 234116006474879126519208934707397575502368608154160721412947025189419787194 189800847222104556167598630039931285094024694085247523307780296439180585091 286206863474379560841614954761399331434812535348350225390274576176798886031 380778504466325787198909189418135115031120011427014465236265515817642556890 128785010970678423864351132498736713626005612397319240493515416417380099413 395419216432871057204438489759682910781574046646010114747283889104834443397 184981610545658962928833309057692452941395349433458372962283948260273947156 110573687320157468197346423602708230855113764048934963897254568602798981891 359831064918860887692030922920274851680298668214543004760245859301314852951 430048018037020109398934292236837834709370591653776097569938580165539734124 265079002668517523371293797450754079826401787503533883360533359118093613709 118956066417175616647948432812222980193178970842860785889932661265944570805 289275771653255859826082430219295399339085718287922176066620100061685069367 236281080443323007784750945204995275799519083197981738780888611083509567478 251042542087561162756580709366349731114715604419679060279244203132266921212 98235342442817522140724982668491795525073680697047819016960109902179866805 88342865348230190810084665689239940103607621061956069700600977485132311440 362045407519743532711403801060857872682086780812134177115599591240431143367 16066483776176414842828409371714210177224680637354816226962534075790344474 247660009137502548346315865368477795392972486141407802997108167405894850048 3530678887550352072827758533436734366288448089041832078266099519 272101358674132653417860014541384836605087997364704101839695292681479883518 394112423559676785086059691419737479771752814065338155011845462169193807974 151755140354137577506498286435010205890750984061355535849635897370673003944 210196797635098012510106281616028853575843684847951745405842531072933610917 65848881303037889845233189630325925691014776183743685310081069912626992101 110542381473451658848567609117180625628841970992142907142739541724557861958 157546342890129829983246193527213822449181723932011157069167729323808635205 165998047372192053828934221954381957675361960853286466716634704795532379661 28583007876111384456149499846085318299326698960792831530075402396150538907 126290914008245563820443505 >&2 echo Pyth contract has been successfully deployed at "${pyth_address}" diff --git a/target_chains/starknet/contracts/src/wormhole.cairo b/target_chains/starknet/contracts/src/wormhole.cairo index 293b5347bc..2335f443b1 100644 --- a/target_chains/starknet/contracts/src/wormhole.cairo +++ b/target_chains/starknet/contracts/src/wormhole.cairo @@ -84,6 +84,7 @@ mod wormhole { #[constructor] fn constructor( ref self: ContractState, + initial_guardian_set_index: u32, initial_guardians: Array, chain_id: u16, governance_chain_id: u16, @@ -92,8 +93,7 @@ mod wormhole { self.chain_id.write(chain_id); self.governance_chain_id.write(governance_chain_id); self.governance_contract.write(governance_contract); - let set_index = 0; - self.store_guardian_set(set_index, @initial_guardians); + self.store_guardian_set(initial_guardian_set_index, @initial_guardians); } #[abi(embed_v0)] diff --git a/target_chains/starknet/contracts/tests/pyth.cairo b/target_chains/starknet/contracts/tests/pyth.cairo index 824aedc4ca..b25641125f 100644 --- a/target_chains/starknet/contracts/tests/pyth.cairo +++ b/target_chains/starknet/contracts/tests/pyth.cairo @@ -987,6 +987,7 @@ fn test_rejects_set_wormhole_with_incompatible_guardians() { .unwrap(); super::wormhole::deploy_declared_at( @wormhole_class, + 0, array_try_into(array![0x301]), super::wormhole::CHAIN_ID, super::wormhole::GOVERNANCE_CHAIN_ID, @@ -1093,6 +1094,41 @@ fn test_upgrade_rejects_wrong_magic() { pyth.execute_governance_instruction(data::pyth_upgrade_wrong_magic()); } +#[test] +#[should_panic(expected: ('invalid guardian set index',))] +fn update_price_feeds_with_set3_rejects_on_guardian_set4() { + let wormhole = super::wormhole::deploy_with_mainnet_guardian_set4(); + let ctx = deploy_with_wormhole(wormhole); + let pyth = ctx.pyth; + ctx.approve_fee(1000); + start_prank(CheatTarget::One(pyth.contract_address), ctx.user.try_into().unwrap()); + pyth.update_price_feeds(data::good_update1()); + stop_prank(CheatTarget::One(pyth.contract_address)); +} + +#[test] +fn update_price_feeds_works_with_guardian_set4() { + let wormhole = super::wormhole::deploy_with_mainnet_guardian_set4(); + let ctx = deploy_with_wormhole(wormhole); + let pyth = ctx.pyth; + ctx.approve_fee(1000); + start_prank(CheatTarget::One(pyth.contract_address), ctx.user.try_into().unwrap()); + pyth.update_price_feeds(data::unique_update1()); + stop_prank(CheatTarget::One(pyth.contract_address)); +} + +#[test] +fn update_price_feeds_works_with_guardian_sets_3_4() { + let wormhole = super::wormhole::deploy_with_mainnet_guardian_sets_3_4(); + let ctx = deploy_with_wormhole(wormhole); + let pyth = ctx.pyth; + ctx.approve_fee(2000); + start_prank(CheatTarget::One(pyth.contract_address), ctx.user.try_into().unwrap()); + pyth.update_price_feeds(data::good_update1()); + pyth.update_price_feeds(data::unique_update1()); + stop_prank(CheatTarget::One(pyth.contract_address)); +} + #[derive(Drop, Copy)] struct Context { user: ContractAddress, @@ -1118,20 +1154,15 @@ impl ContextImpl of ContextTrait { } fn deploy_test() -> Context { - let user = 'user'.try_into().unwrap(); - let wormhole = super::wormhole::deploy_with_test_guardian(); - let fee_class = declare("ERC20"); - let fee_contract = deploy_fee_contract(fee_class, fee_address1(), user); - let fee_contract2 = deploy_fee_contract(fee_class, fee_address2(), user); - let pyth = deploy_pyth_default( - wormhole.contract_address, fee_contract.contract_address, fee_contract2.contract_address - ); - Context { user, wormhole, fee_contract, fee_contract2, pyth } + deploy_with_wormhole(super::wormhole::deploy_with_test_guardian()) } fn deploy_mainnet() -> Context { + deploy_with_wormhole(super::wormhole::deploy_with_mainnet_guardians()) +} + +fn deploy_with_wormhole(wormhole: IWormholeDispatcher) -> Context { let user = 'user'.try_into().unwrap(); - let wormhole = super::wormhole::deploy_with_mainnet_guardians(); let fee_class = declare("ERC20"); let fee_contract = deploy_fee_contract(fee_class, fee_address1(), user); let fee_contract2 = deploy_fee_contract(fee_class, fee_address2(), user); diff --git a/target_chains/starknet/contracts/tests/wormhole.cairo b/target_chains/starknet/contracts/tests/wormhole.cairo index 0adbed594b..25abac4726 100644 --- a/target_chains/starknet/contracts/tests/wormhole.cairo +++ b/target_chains/starknet/contracts/tests/wormhole.cairo @@ -99,7 +99,7 @@ fn test_submit_guardian_set_rejects_invalid_emitter() { #[test] #[should_panic(expected: ('invalid guardian set index',))] fn test_submit_guardian_set_rejects_wrong_index_in_signer() { - let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT); + let dispatcher = deploy_with_mainnet_guardian_set0(); dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade1()); dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade3()); @@ -107,7 +107,7 @@ fn test_submit_guardian_set_rejects_wrong_index_in_signer() { #[test] fn test_submit_guardian_set_emits_events() { - let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT); + let dispatcher = deploy_with_mainnet_guardian_set0(); let mut spy = spy_events(SpyOn::One(dispatcher.contract_address)); @@ -152,7 +152,7 @@ fn test_submit_guardian_set_emits_events() { #[test] fn test_get_guardian_set_works() { - let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT); + let dispatcher = deploy_with_mainnet_guardian_set0(); let set0 = dispatcher.get_guardian_set(0); assert!(set0.keys == guardian_set0()); @@ -194,7 +194,7 @@ fn test_get_guardian_set_works() { #[test] #[should_panic(expected: ('invalid index',))] fn test_get_guardian_set_rejects_invalid_index() { - let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT); + let dispatcher = deploy_with_mainnet_guardian_set0(); dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade1()); dispatcher.get_guardian_set(2); } @@ -210,7 +210,7 @@ fn test_submit_guardian_set_rejects_wrong_index_in_payload() { #[test] #[should_panic(expected: ('no guardians specified',))] fn test_deploy_rejects_empty() { - deploy(array![], CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT); + deploy(0, array![], CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT); } #[test] @@ -225,7 +225,7 @@ fn test_submit_guardian_set_rejects_empty() { #[fuzzer(runs: 100, seed: 0)] #[should_panic] 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 dispatcher = deploy_with_mainnet_guardian_set0(); let vm = corrupted_vm(data::mainnet_guardian_set_upgrade1(), pos, random1, random2); dispatcher.submit_new_guardian_set(vm); @@ -234,7 +234,7 @@ fn test_submit_guardian_set_rejects_corrupted(pos: usize, random1: usize, random #[test] #[should_panic(expected: ('wrong governance chain',))] 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); + let dispatcher = deploy_with_mainnet_guardian_set0(); dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade1()); dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade2()); @@ -247,6 +247,7 @@ fn test_submit_guardian_set_rejects_non_governance(pos: usize, random1: usize, r // If address is not specified, the default address derivation is used. pub fn deploy_declared_at( class: @ContractClass, + guardian_set_index: u32, guardians: Array, chain_id: u16, governance_chain_id: u16, @@ -254,6 +255,7 @@ pub fn deploy_declared_at( address: Option, ) -> IWormholeDispatcher { let mut args = array![]; + guardian_set_index.serialize(ref args); (guardians, chain_id, governance_chain_id, governance_contract).serialize(ref args); let result = match address { Option::Some(address) => class.deploy_at(@args, address), @@ -268,6 +270,7 @@ pub fn deploy_declared_at( // Declares and deploys the contract. fn deploy( + guardian_set_index: u32, guardians: Array, chain_id: u16, governance_chain_id: u16, @@ -275,13 +278,19 @@ fn deploy( ) -> IWormholeDispatcher { let class = declare("wormhole"); deploy_declared_at( - @class, guardians, chain_id, governance_chain_id, governance_contract, Option::None + @class, + guardian_set_index, + guardians, + chain_id, + governance_chain_id, + governance_contract, + Option::None ) } // Declares and deploys the contract and initializes it with mainnet guardian set upgrades. pub fn deploy_with_mainnet_guardians() -> IWormholeDispatcher { - let dispatcher = deploy(guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT); + let dispatcher = deploy_with_mainnet_guardian_set0(); dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade1()); dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade2()); @@ -291,9 +300,24 @@ pub fn deploy_with_mainnet_guardians() -> IWormholeDispatcher { dispatcher } +pub fn deploy_with_mainnet_guardian_sets_3_4() -> IWormholeDispatcher { + let dispatcher = deploy(3, guardian_set3(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT); + dispatcher.submit_new_guardian_set(data::mainnet_guardian_set_upgrade4()); + dispatcher +} + +pub fn deploy_with_mainnet_guardian_set4() -> IWormholeDispatcher { + deploy(4, guardian_set4(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT) +} + +pub fn deploy_with_mainnet_guardian_set0() -> IWormholeDispatcher { + deploy(0, guardian_set0(), CHAIN_ID, GOVERNANCE_CHAIN_ID, GOVERNANCE_CONTRACT) +} + // 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( + 0, array_try_into(array![data::TEST_GUARDIAN_ADDRESS1]), CHAIN_ID, GOVERNANCE_CHAIN_ID, @@ -308,6 +332,7 @@ pub fn deploy_declared_with_test_guardian_at( ) -> IWormholeDispatcher { deploy_declared_at( class, + 0, array_try_into(array![data::TEST_GUARDIAN_ADDRESS1]), CHAIN_ID, GOVERNANCE_CHAIN_ID,