Skip to content

Commit

Permalink
chore: add e2e ptgm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Dec 11, 2023
1 parent 3b6808c commit ed9b8ff
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
8 changes: 8 additions & 0 deletions unit-tests/pyth/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ export const p2whTestnetVaas = [
export const pnauMainnetVaas = [
"504e41550100000003b801000000030d002c9e33a703a8c86012c117474849ae41118270cf56e2db61c7af28f64ce322391d33cb738930dc3ffcfe5ae35dbd99c4e08a8ac4b390c858d94dc1f0b91e24d00101901948561c54c17b7a21a9885d3f60a85b410e18209b02ebe098b0dd422b02667565e3b5011203303a6445cf629d20cec3d4771f0b391ab03bfd54364ac049f70002a030ed0060f1ba123ddf5473bef4c1c8f4aec8737b47f11023f94d5339b72c4c3aa325515956ea702537a3950d74f86134396de437bfc97a5365fc090dbb382c0103f1f64ba806fe8ba7b7db3846d85fccbe7d803865e7b757301f4a5de6ebde40f923ee925a7df78871d39299d70fd117635263b91fe53f792bfff450d210431316000439e31501d7b661a1b075a9302b57a6fc500c1e760de7e949e30994055b061b280cefcab3eb3b5c780f56cd555e88ee3c674b798ddeb8713bd27a361b8b8f1c730008db908c61e4158d1a7a7d53b2ec14027a4a2b2f3207edf0db2fbb0f431f3cdc020ee9fc9f38e812d094dcf5dd18f3a8d1d1ee94e840f504b00e08d0fbd607ed6d0109cf5c52aed9f4a42691c3c33bc366fde4a3ad23aacdd46c14669ad321106cf8d257b9379fc45cbe91a26ee87f4800951c5ca89ff0069e4a47299f988b368c6b74000b1241dea623dd874e13135682d760ee48ac1888149bddcfac54ff3787f4b89629063d89e084350ff1168999365918f9bdf469323b817a25491e56341a0da5c498000d538baecc668df092ce3cfeebfa5968447584916cb503ce50e7f77443bbd2a3441bb1d962a7f3401bfcf30f444a3301ab72dcb87cc04b681bdada93d45001f53d010e2fd97eeac94ceb3fd87a6e4ab3b785c64db221d522e58230a6d9eb10cba3b53a086ba6989e4285ab0816a26ff64c1a3a05175d0ffa61f4f744f928d6c5b3f92600107f999fa2f5cd826520cdf36f2e3434f4619eca4c2fb944bdec79d84903f76aaa02727844ec451378ab165910140c866ebdc65aea2cc6717da4747d4ed8a7338700115ce8f97f4a39ccdf5a61c9425d8a306a35b598db9d0f936bece6f2d92e79f9b1306d4c4789fb73ba5bd29bf0d306f2e8079aae818bc70aa9db111b745f1f4ab900126933d7f1317e3e45d98687e66ae033d871e1026e92f1ad168ec197a92ad653571837b78ee8e2263f2aca1dfa112fc78de63de9e2231f62ab79db2d956704146c0165131de200000000001ae101faedac5851e32b9b23b5f9411a8c2bac4aae3ed4dd7b811dd1a72ea4aa710000000000df92280141555756000000000005e1b46c00002710dbdd79b598d499596393b24358343774fd54e63c01005500ec7a775f46379b5e943c3526b1c8d54cd49749176b0b98e02dde68d1bd335c170000000002bf687c00000000000091effffffff80000000065131de10000000065131de00000000002c073dc0000000000008d5f09014cff5b7c5413efc667d2bca5549edadde5324814fed82e330d4110d610f5d0325deddb5541eacccd70da0a613768335768226657b201a456613163b0b4a21cf17276c2be6d02280ff05d08a6d4cf481c00c544f4adff1c86c6845a21871b75b4cffdc9314a2b46bddcb2bd44861fa48d4cc429a0783cb122a3eda67b7a13ad6298995c3bddd6cfa1ba547ddd38f0da18fcb0f7ead4d1de56db6c0442b94883a78f40b3541982a58d2d400dbfb761cce7bf780c",
];

export const ptgmTestnetVaas = [
"01000000030d0022d33714c7bca17f783710d1bda8b139beb78b940ea8bff1e12dccb05ec4d2a53dfff899ef41eee54b4c4539dd47a7510d2ab3984e1c27d987634789492ecd4c000271d46e78487d2d73a530a94056022cb92efc1bda8e3b688f14adbcd05ffc49b85924413e753aa3909b77ed8e7e18491399e5898d865c633303e2d8fbfba7de290106e60b51958831b91996a4a263acb59d172ce2ebbd9bb02719b9b4b2a4cab15a006156f182f764d0539971c403e74602d4417a3ea52007c03fc01f5eae9a4f57ce000719082a4f9bb48a787a05c1fd907b890aeea111f2d2a273b4892b9e51194450e230089e18ae76505aa59c93df5c46690ebfd1aed901486357f89ed9a10161106d00085706f3c17926d4fedda678e5c26b6530fb89f3f66bd618ec4863e6d155072ff871f101a29ac2e73dabbae8c119903198635429fc38b02acacacfedd1c214bd0f0109ea0b0f5e6d8c1c5295b0d679e6e66a603980efe8ed8c789b8abff0b87d62581975cddc7a964364313163c14f0763908739146be9c16ed539e48248a2137ce4a4000b4f6a21bd5e6117dd545645e9da6669e164b69afd1120b5be86cf713301d17d064e8a851833ec329ee178310010028819d5fb675937a8c5a99bcfc3365b74c8ca010dc34180b01424277bec5e972ae867d20a3ff53a6792f622fdfb15a8117473fd71782a86d076c6bde1ba5b4d306dc16e765992e56d80e44fa9362b7e08929b73f4010e039159c6ba738f177d2d9201bc015db04aed4307166915b4e64c272c34984edd3baa3dc8c0c4d6f2916771efbf4372ab53c500e9e5b884dadfc6148a264482cc000f7b6706a24044091c02375ee6106cb2e1d1afbc724ef441759afaf32af4b566666c0cd6e65e732b823aeaf465f6b6c1c93046bc68cb755a2bd9503556a3b58d2c01106662dfa46d1b28ff59794759a884f004d811caa58efd96fdb0039e6938c823980c8dd06892a0e2ba39d1354cc5442d2d819b3e8ce4cf31bf3f4b072b3946a5e80111cc8eb84417132ffdd414bcfd513ae090315317e7ee20c212cb17e9f7c4438764534600bfabc6f8d6b9ea5a43e935e820c78c40cafb973cea0a2922b3a7c7c5c701124d78e295aa1600e8314c4d28ff42d16d289749b5ebf1e52fcf6b3110fe6cd883468f6c38c54d90fad6ee3cb13ef349d992ad68d95e8ab9bb4f47b17fbcd120c000657379540000000000015635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e000000000000006c015054474d0303c37700000000000000020000000000000000"
]

export const ptgmMainnetVaas = [
"01000000030d004ca0e99cdda91001f74bfbf67d25eb09d704b1058066730e738c55efb37b8ac1463df88c173937503e3ebe7ab7503ad2514e12ee74fbd949eba06bf0917c60b00101f2a027549fdc4afa9ea3213b55c5104f60481d22c050122045c7ecf31b8e75c81ace3fac0aa8de80555250a4a0dd7c8d31775fca1907692a057afa419669925501025203c80d232573663a63eeb2864d797ccd4da3115685d45521982ccfe34a946f58d9591e9a2427e190fce9c09d784657cd4ac440fa7cbce773d7345339fa3b3b01040d49206142b72e4719106e8ffa2bf9a32ff6821119f83d1ec2d1ba668140e08b2a77508fbfc22084c68b39831df05684b8235585d644c6c83f7bda00e48874ce00067e8b240c40aa0b5a0101b44cd194997071adc4ebac327c7062bbe558dc6793cb6331f5539330181afe4d76000baec8981523cb3cfdc07500ff32b63c33de249f0107014002d183ab80458b56f1dedf77ebd7438bd43d7bbab0a2fdb02016d996c8160d7febf32785665e804bb4652dafd8c57faf4eb4905d1baa46975af56a8f24b900080565b49f72081fd044f9a7570d7b01f85215bd0db569c093e9f798407626568c62075c6a97c3357657ba4ee47312d319ec8593faf773000f3d0a2d95fc700b840009747ca03fd62e841b055fb5698403ed33c685079b0599be36921f51f69273fc45623351b13f037b81614d0afb3f30bf7ae64f8d2634872d88aa9428c090d46d68000b05643f72907d62fa51d113b835ce4c81fa1161af47b5f15656bb913ab442b2292f9a11b79e634b2ccd3b9d8b3238404701e128f154d9426edc69ad27b9caf6f9010f9b00cbe072e0e3504dc1fbeeef8d4aad3fc2867f3fabbc490fb39cb9e83159b86c4bc2bda774860cc14e97ec1caec3aec2aa6489b7274ef8fc92c19db3a07bf90110314070bbc23ff03d2ea9086559c404960f78ea95ffb3f677e6d640d7a430f56f4177bedaa76f97b4ddb3f2ae8301480250a2749f27e1a216712b23fd289baf820011582b65550cae7cb5f35b6f06013e71f8c1b8e6e4d5dc25bb49e7f6d153b3657e55b14d844538d542f3192b219ccd7ec11b3c8f77f5ac2f1281ee65b2f21ca99c0012af8e67c81ce9d0eec2c004de4a3b230ebf10b337552cbc3eaa6334495d97bb664837e7b33f5301cb7111fabf6ebe809858ea0b9f1063a3dd7c3037a20c523116006573b50d0000000000015635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e000000000000006d015054474d0303ea8600000000000000020000000000000000"
]
65 changes: 63 additions & 2 deletions unit-tests/pyth/ptgm.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,80 @@
import { Cl } from "@stacks/transactions";
import { Cl, ClarityType } from "@stacks/transactions";
import { beforeEach, describe, expect, it } from "vitest";
import { wormhole } from "../wormhole/helpers";
import { pyth } from "./helpers";
import { hexToBytes } from "@noble/hashes/utils";
import { ParsedTransactionResult } from "@hirosystems/clarinet-sdk";
import { ptgmTestnetVaas } from "./fixtures";

const pythOracleContractName = "pyth-oracle-v1";
const pythStorageContractName = "pyth-store-v1";
const pythDecoderPnauContractName = "pyth-pnau-decoder-v1";
const pythGovernanceContractName = "pyth-governance-v1";
const wormholeCoreContractName = "wormhole-core-v1";
const initialFeeRecipient = "ST3CRXBDXQ2N5P7E25Q39MEX1HSMRDSEAP1JST19D";

describe("pyth-governance-v1::update-fee-value mainnet VAAs", () => {
const accounts = simnet.getAccounts();
const sender = accounts.get("wallet_1")!;

let block: ParsedTransactionResult[] | undefined = undefined;

// Before starting the test suite, we have to setup the guardian set.
beforeEach(async () => {
block = wormhole.applyMainnetGuardianSetUpdates(
sender,
wormholeCoreContractName,
);
});

it("should succeed handling the 3 guardians rotations", () => {
expect(block!).toHaveLength(3);
block!.forEach((b: ParsedTransactionResult) => {
expect(b.result).toHaveClarityType(ClarityType.ResponseOk);
});
});

it("should succeed handling PNAU mainnet payloads", () => {
const pnauBytes = Cl.bufferFromHex(ptgmTestnetVaas[0]);

const wormholeContract = Cl.contractPrincipal(
simnet.deployer,
wormholeCoreContractName,
);

let res = simnet.callPublicFn(
pythGovernanceContractName,
"update-fee-value",
[pnauBytes, wormholeContract],
sender,
).result;

expect(res).toBeOk(Cl.tuple({
exponent: Cl.uint(0),
mantissa: Cl.uint(2),
}));

let read = simnet.callReadOnlyFn(
pythGovernanceContractName,
`get-fee-info`,
[],
sender,
);

expect(Cl.ok(read.result)).toBeOk(
Cl.tuple({
address: Cl.standardPrincipal(initialFeeRecipient),
exponent: Cl.uint(0),
mantissa: Cl.uint(2),
}),
);
});
});


describe("pyth-governance-v1::update-fee-value", () => {
const accounts = simnet.getAccounts();
const sender = accounts.get("wallet_1")!;
const initialFeeRecipient = "ST3CRXBDXQ2N5P7E25Q39MEX1HSMRDSEAP1JST19D";
const guardianSet = wormhole.generateGuardianSetKeychain(19);
let updateFeeValue = {
mantissa: 2n,
Expand Down

0 comments on commit ed9b8ff

Please sign in to comment.