diff --git a/target_chains/starknet/contracts/tests/data.cairo b/target_chains/starknet/contracts/tests/data.cairo index 5c4e0cbfec..0e8a735e85 100644 --- a/target_chains/starknet/contracts/tests/data.cairo +++ b/target_chains/starknet/contracts/tests/data.cairo @@ -89,6 +89,54 @@ pub fn good_vm1() -> ByteBuffer { ByteBufferImpl::new(bytes, 22) } +// A random update pulled from Hermes. +pub fn good_update2() -> ByteBuffer { + let bytes = array![ + 141887862745809943100717722154781668656427509438421147322308927102724604288, + 195033686964122459031146728084966594727160973586244819321236510906147812136, + 407284115079266273703820558425166316148631567216546256235525584097593977317, + 183129361303443069966099786368613810060875697145922990811223748156446589691, + 211770679289991149680353390875789870975985702604862549317442965649242842854, + 41298198921888098388050109123025093584676988661378162916458822634098826126, + 359572746139636176627880323656946781436397582111029599185414977621837758948, + 43447892561644560665969604494602790081648904091321555611985917062718198323, + 316437306873153282515085292041850009011090069549805063905017828400895631621, + 1808632073924798965594749672351412209316017296820761025927133223030729934, + 87584277168619570562471109095348481799030125672881500169442972604855612229, + 145163433499348629410116614496529397795347778158622069564370141889397312663, + 25684035278413112962744577918057971807941515684998747248789566171837872999, + 423647305080460104318143794931391156124390714431230676173138853704501590277, + 444039338990033458186993461729004007742007577708240647605304483226650067090, + 184316502645626096366264329829812897824286251050516888372699966791394695797, + 358217074190908261457486811927517167368883562819513731015463459672884467276, + 276891297522985882981807711468559725764477062687613644610588250767972958976, + 294684739650331758060103423875803012643846741112777525170937278228428495145, + 273403044175742158946841597110899681113013103975839063186643512346821053777, + 181430008875487814186280787211458694926090715860589986798941427087388139743, + 202405815764322437351169692760143906797339071462594057357500300785122471946, + 362249706137881332854178699625533098640027521804984398645286411405577517456, + 108891577618151682868702186452892931741988086496887553343303288245933117528, + 51562020660219963117721568171928218510906779368200541632225568639965493074, + 36265113879998172456877387291105778015251280095406084920317350894161859029, + 42404838404896016009364484621891740482977244067428049062865199561561964596, + 400309084726075656675334746913008755786417370187268409789718880162525027002, + 184412225736261670476401152034394104500596028960049886422037988283378123034, + 247660009137502548346315865368477795392972486141407805670155831411939431936, + 3764185968709947175972435540804261264573483247991819761982749429, + 330407311811859831895879432914238169233473332723627561500741563663520257152, + 239008904555038498567552611749225600269238829894042362148974101308190490726, + 263519001180037246614618451198674495650237768794904664051741501021771359435, + 319621157572663509773811053656997796281807849782154038103099710071724420867, + 371142574919487516620430124473731862752334035949677427525084182769927172891, + 34529864768413294700260963626605680759186129379574488717138450227756192027, + 300724598947183219344707986045989093146797544729497805400362056327810428775, + 73559819098186314680566751133619385490187392057353932547381513965006148534, + 387716298707040429040766458724262682246736227927618559740105419790525108736, + 51421972426116570708669697807982264105083926945707485622590596040392442183, + ]; + ByteBufferImpl::new(bytes, 31) +} + // A first update for a certain timestamp pulled from Hermes. pub fn unique_update1() -> ByteBuffer { let bytes = array![ diff --git a/target_chains/starknet/contracts/tests/pyth.cairo b/target_chains/starknet/contracts/tests/pyth.cairo index b25641125f..a488deed71 100644 --- a/target_chains/starknet/contracts/tests/pyth.cairo +++ b/target_chains/starknet/contracts/tests/pyth.cairo @@ -227,6 +227,18 @@ fn update_price_feeds_works() { ); } +#[test] +fn update_price_feeds_works2() { + let ctx = deploy_mainnet(); + let pyth = ctx.pyth; + let fee = pyth.get_update_fee(data::good_update2(), ctx.fee_contract.contract_address); + assert!(fee == 1000); + ctx.approve_fee(fee); + start_prank(CheatTarget::One(pyth.contract_address), ctx.user.try_into().unwrap()); + pyth.update_price_feeds(data::good_update2()); + stop_prank(CheatTarget::One(pyth.contract_address)); +} + #[test] fn test_accepts_secondary_fee() { let ctx = deploy_mainnet(); diff --git a/target_chains/starknet/sdk/js/src/index.ts b/target_chains/starknet/sdk/js/src/index.ts index 23401b3304..31bebcdfbb 100644 --- a/target_chains/starknet/sdk/js/src/index.ts +++ b/target_chains/starknet/sdk/js/src/index.ts @@ -55,6 +55,6 @@ export class ByteBuffer { } pos += 31; } - return new ByteBuffer(0, data); + return new ByteBuffer(data.length == 0 ? 0 : 31, data); } } diff --git a/target_chains/starknet/tools/test_vaas/Cargo.lock b/target_chains/starknet/tools/test_vaas/Cargo.lock index aa6f237647..82c6c58051 100644 --- a/target_chains/starknet/tools/test_vaas/Cargo.lock +++ b/target_chains/starknet/tools/test_vaas/Cargo.lock @@ -53,6 +53,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bit-set" version = "0.5.3" @@ -352,7 +358,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" dependencies = [ "arrayref", - "base64", + "base64 0.13.1", "digest", "hmac-drbg", "libsecp256k1-core", @@ -723,6 +729,7 @@ name = "test_vaas" version = "0.1.0" dependencies = [ "alloy-primitives", + "base64 0.22.1", "byteorder", "hex", "libsecp256k1", diff --git a/target_chains/starknet/tools/test_vaas/Cargo.toml b/target_chains/starknet/tools/test_vaas/Cargo.toml index 548ccdfc5b..296c3205e8 100644 --- a/target_chains/starknet/tools/test_vaas/Cargo.toml +++ b/target_chains/starknet/tools/test_vaas/Cargo.toml @@ -11,3 +11,4 @@ libsecp256k1 = "0.7.1" wormhole-vaas = "0.1.1" rand = "0.8.5" alloy-primitives = "0.2.0" +base64 = "0.22.1" diff --git a/target_chains/starknet/tools/test_vaas/src/bin/generate_test_data.rs b/target_chains/starknet/tools/test_vaas/src/bin/generate_test_data.rs index df0e9af371..ca39ed3f18 100644 --- a/target_chains/starknet/tools/test_vaas/src/bin/generate_test_data.rs +++ b/target_chains/starknet/tools/test_vaas/src/bin/generate_test_data.rs @@ -1,5 +1,6 @@ use std::{path::Path, process::Command, str}; +use base64::Engine; use libsecp256k1::SecretKey; use primitive_types::U256; use test_vaas::{ @@ -28,6 +29,16 @@ fn main() { "A wormhole VAA from a random update pulled from Hermes.", ); + let good_update2 = "UE5BVQEAAAADuAEAAAAEDQDLz4c8SRI+cJCVggwBgG5imYNF7CVDXwIo8VSuInpr8wcGYrnQ7USTpGS2Myjmg79ygcrxSg0CJY479bBJq1U/AQJH8/3yjavneunlZ6XFiH6b6zXznxg8h58ER43u+zHKHWbdvEUlArHC+3fbow/DgLM/7iFhx8NikpyWUt2qjPXKAQNDUuzF5uYXX7tVpAHRFl0IGN0Epth2VekSeU0+Ya/WfmTNbpuOy4LOan9wLdhivC2YkZic2hElqUqrh6YjrSPmAARB5BiXM+c6xlsTWocV0pcyCkYMVrksteM2hp7ESc7ckjOzGOAMsya77VChmW2/qB3hjekN/WV2fIDxD1KlMCEFAQYN5GKWXt58nCV9VKcAZCZk+TmOE3wLdsoJaJmszjGSKWVRam/IwyhZEMVOnH1/YzOl+IHTNqPB8lgp80VSKNsBAAqjQlEvDDt1OvTI8BAh7+FW9KwCGtEBdMyXDolh0Ph87zacGOILfyB+jtd3ter3xj7oE/q5Cs+7Z+/Gn+WzOFSoAAtYPBvsaeiF5sxLw82QkqbG+R+keQX7UT55KYoTVvSDjDfYMyVr+6DzUSv76Y/CyuKyPsCSaFHHDYh2eWl/e+61AQw0NOsLAWg0pbVFDoI4n/aadcq+Yb+q6gTSYtMxWizeVnXfi4+B3jEUD2SV78y7VkyctwUJ10Ga9Y2MbmjowJTtAQ2maU+hd4MogeBzqQMApskgfP3Gv7NPcJfTTeFA6zGVyCmH0qRfZszWVLgZKZq9mofeIs8opHUrp8Gf6McDr1W/AQ7oMcnVX0/gzVFmr40MZBhSE1uXhO/1IHynjOo0lAsQXjTM3A2Aq2Dfco7A97nUmtooolI4Z6+OIIq5+Nm7o//MAA/Q1CbwCs0GrGGDinQMQn3VNznIBI7h5B/++rE0+hlbYnzFeZA9oWUYN0AHA/D6pAt7d2VNXPYH/9dN1fgmX6SJARBYHS7dpEmSEPoQ/HQHjnR5mBPvVgNMx7drSy1wYJx3UhSGe9WnvEcDvIJyT0+okbFniJ3SL8Z5dSK47v2LkdUYABLf0loUVJfQ2RQb+YcHaLbVeDuHT+dl5JXZkYA04pEhMUJx5uvL7fEVeks3MQkm97Z+POTit0pDDDUaumhfpZ6gAWaVJX8AAAAAABrhAfrtrFhR4yubI7X5QRqMK6xKrj7U3XuBHdGnLqSqcQAAAAAEG+8TAUFVV1YAAAAAAAkmdWwAACcQf1sptd9IP87qReQ8HcWm+I269bsBAFUA/2FJGpMREt3xvYFHzRtkE3X3n1glEm1mVICHRjT9Cs4AAABNwXiP1gAAAAATsrS1////+AAAAABmlSV/AAAAAGaVJX4AAABN7OHo8AAAAAAQXwluCzFky7TmL6K1mtY5qtwy7vT4n5Et4wchMvACEHARY1ylrwPSDys3e9Vr0HwUt7PDyaR+Zn3JVNOdcOgnaYarq7MbE4sP3ikPgrsIFL2dCVIc1WBSVhZUv8UspKXUjo7RG6o0P1IekpQWEiYUckAQlPd8pq49IknFmd1Oiqoyr2cpoiVVnNeF0pU//z4DM4fgsO5V6O5AxwApVoXbNtO223CMzIIIqUk1zJQFnptq6i8o1FzAs5+9QgEoLPuSAB0akvbK88cgq66559qOGRcCHJ716YbIZHAwkT5wAUc="; + let good_update2 = base64::prelude::BASE64_STANDARD + .decode(good_update2) + .unwrap(); + print_as_cairo_fn( + &good_update2, + "good_update2", + "A random update pulled from Hermes.", + ); + let unique_update1 = "504e41550100000003b801000000040d005b559fa0622f058b45c1555ead2be24660e47d8d831ff3ae788631df2992a1934d3b16658fcd380e065ab1f8087495235aa6e8d2d376cc2e37ee0e680776a5db00010c2a51f4c1237d1ee8bd55b801206ca80706b01136301634fba9bf4063fc8bb924713c3b1459223ec130f52bf4068250c918b25dc30cf52b4f1cdc3b9b5bbc8b000252a99f4e643c7ffbe458092aa7f891a18341f731258c5e078a7a8ab09d73ebae2a613c682cd5c506c07d86b7fb5c104bb0655a3375a95665ea571494eabaa37101036a55cb75a40a9bb12ef22a5637182fd369d2df5fde60c2916ceff7a48344a4f23298aca2f2e24ac45b9abdc1fcd9d72abfb0680a789ebf1aa893d530a0f2f730010422b93f207001d12873ff2433623bdd2a4ae13d608faf17526967d3becf8481454fd95513ee42604731670fa402d39400c806e1abf3f5c08dfe46a3ba6b6c68b3000682528509a3ae808f0c0f15d51ba0d1bf2f5d1f580299a86883a1fcc2956c22327d2873147c5e1cdbe80bf5db38806a3885e882bee4d9e88fd78353b54a023c58000a49f8de527aed1b00d6a2570604084dfa08efa4fdda48e3c58c4f7ca851af1d4f0d9d15c820a1091db313dacdf6e1475cadec6555dfcca1e59d13cd223313a21e010b51fe1a2ca196264a0a60621646cf4eb88568b22546a7f38a8d9d4e0335c019455c5371dfb519ce559fc68cd06c8002143e951e02d8d612a64f3e660c7dab722e010c48c6714ad81751f5f384110303cba83bfdf7478f8a83754d825593310eacc51d5c9daa5baa7b520139f8f857f36607893343ff67a47f09b7ce16221294e87355000d9aeffbd732081d226c960786abd13de3d584a34099ef871435a3c4a0eede7751482684c5d72f7a8d4353a5bb6ef2dad237c924546b35c39b6edbdfc9aebe046b000e513b486bb5a3b96ab6f0c0382cb96a1063bb6111fd7edab5fa9e628233ae013225b7b63785baf85e6411a67a8329d784f7adaf19bc5ec754f9f08f2836530193000ff68e15c56975cf2dd7f560c31f421d35c6c6e4678ae50b33b579ddd2d24abcfc3799675d319572efaf7dd0a2a7b3428d377cf62bf5e279d875aaf867e418b5320012fec4c69ce1cbcf1920f082464586935d20ba586809d270b529e1ab90cce91286251ab5564bcb4a102b2ffbd8349a9715c3a1c6f10c0edab4e189c70917e30122016655e3ef00000000001ae101faedac5851e32b9b23b5f9411a8c2bac4aae3ed4dd7b811dd1a72ea4aa7100000000038b07160141555756000000000008952599000027101e0d33a78138b9851ffe9cfca4292ccf08673f9a01005500e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b4300000623d837b3ff00000001bd545ac7fffffff8000000006655e3ef000000006655e3ee00000632e33606200000000173bf35780a95bda876f7988be2c629ca0f6609677fc3d1ba1efc25dbfb05753be57a1e6243c5a52544e6c1653ef7a177cbb33b6f0bc1b9d147d4acdaad63d7a8ef2f745293e53e9094d00f0c68e8d885487287880bc3f959cb50a44cd00bc65bfd2531e446592b06a4028acc92ee4a59b6a1335949e9383e0613218628c47a5b5d1bb9455df399c87c8adeaa3e6664b0b861c3449311786160f8e56d6c60f263e1c60d102d6aafaa4aa61e74590ec3fe697cb9d9ff4714e12b59675b69013c2c229b6877242aa94fd300c58771"; let unique_update1 = hex::decode(unique_update1).unwrap(); print_as_cairo_fn( diff --git a/target_chains/starknet/tools/test_vaas/src/lib.rs b/target_chains/starknet/tools/test_vaas/src/lib.rs index 81e57cd3f7..76d6f870e9 100644 --- a/target_chains/starknet/tools/test_vaas/src/lib.rs +++ b/target_chains/starknet/tools/test_vaas/src/lib.rs @@ -40,7 +40,7 @@ fn to_cairo_byte_array_data(data: &[u8]) -> CairoByteBufferData { pos += 31; } CairoByteBufferData { - num_last_bytes: 0, + num_last_bytes: if r.is_empty() { 0 } else { 31 }, data: r, } }