Skip to content

Commit

Permalink
feat: wrap-up test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Oct 30, 2023
1 parent b926ea5 commit b27609a
Show file tree
Hide file tree
Showing 3 changed files with 727 additions and 35 deletions.
9 changes: 6 additions & 3 deletions contracts/pyth-governance-v1.clar
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@
(asserts!
(is-eq
(contract-of storage-contract)
(get pyth-storage-contract expected-plan)) ERR_UNAUTHORIZED_ACCESS)
(get pyth-storage-contract expected-plan))
ERR_UNAUTHORIZED_ACCESS)
(ok true)))

(define-private (expect-active-decoder-contract
Expand All @@ -299,7 +300,8 @@
(asserts!
(is-eq
(contract-of decoder-contract)
(get pyth-decoder-contract expected-plan)) ERR_UNAUTHORIZED_ACCESS)
(get pyth-decoder-contract expected-plan))
ERR_UNAUTHORIZED_ACCESS)
(ok true)))

(define-private (expect-active-wormhole-contract
Expand All @@ -314,7 +316,8 @@
(asserts!
(is-eq
(contract-of wormhole-contract)
(get wormhole-core-contract expected-plan)) ERR_UNAUTHORIZED_ACCESS)
(get wormhole-core-contract expected-plan))
ERR_UNAUTHORIZED_ACCESS)
(ok true)))

(define-private (parse-and-verify-ptgm (ptgm-bytes (buff 8192)) (sequence uint))
Expand Down
37 changes: 37 additions & 0 deletions unit-tests/pyth/pnau.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,41 @@ describe("pyth-pnau-decoder-v1::decode-and-verify-price-feeds failures", () => {
);
expect(res.result).toBeErr(Cl.uint(2005));
});

it("should fail if PNAU include Merkle root mismatches", () => {
let actualPricesUpdates = pyth.buildPriceUpdateBatch([
[pyth.BtcPriceIdentifier, { price: 100n, publishTime: 10000003n }],
]);
let actualPricesUpdatesVaaPayload =
pyth.buildAuwvVaaPayload(actualPricesUpdates);
actualPricesUpdatesVaaPayload.merkleRootHash = new Uint8Array(
Buffer.alloc(32),
);
let payload = pyth.serializeAuwvVaaPayloadToBuffer(
actualPricesUpdatesVaaPayload,
);
let vaaBody = wormhole.buildValidVaaBodySpecs({
payload,
emitter: pyth.DefaultPricesDataSources[0],
});
let vaaHeader = wormhole.buildValidVaaHeader(guardianSet, vaaBody, {
version: 1,
guardianSetId: 1,
});
let vaa = wormhole.serializeVaaToBuffer(vaaHeader, vaaBody);
let pnauHeader = pyth.buildPnauHeader();
let pnau = pyth.serializePnauToBuffer(pnauHeader, {
vaa,
pricesUpdates: actualPricesUpdates,
pricesUpdatesToSubmit,
});

let res = simnet.callPublicFn(
pythOracleContractName,
"verify-and-update-price-feeds",
[Cl.buffer(pnau), executionPlan],
sender,
);
expect(res.result).toBeErr(Cl.uint(2008));
});
});
Loading

0 comments on commit b27609a

Please sign in to comment.