瀏覽代碼

fix(target_chains/starknet): fix ByteBuffer conversion for len=31*N case (#1769)

Pavel Strakhov 1 年之前
父節點
當前提交
5e944374a0

+ 48 - 0
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![

+ 12 - 0
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();

+ 1 - 1
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);
   }
 }

+ 8 - 1
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",

+ 1 - 0
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"

File diff suppressed because it is too large
+ 11 - 0
target_chains/starknet/tools/test_vaas/src/bin/generate_test_data.rs


+ 1 - 1
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,
     }
 }

Some files were not shown because too many files changed in this diff