From 9a9804cbb9d2d448e565320704956a0f02fe2ea6 Mon Sep 17 00:00:00 2001 From: Ludo Galabru Date: Wed, 4 Oct 2023 18:21:03 -0400 Subject: [PATCH] chore: update tests --- package-lock.json | 34 ++++++++++++------- package.json | 4 +-- unit-tests/pyth-p2wh.test.ts | 66 ------------------------------------ unit-tests/pyth-pnau.test.ts | 16 ++++----- unit-tests/wormhole.test.ts | 6 ++-- 5 files changed, 35 insertions(+), 91 deletions(-) delete mode 100644 unit-tests/pyth-p2wh.test.ts diff --git a/package-lock.json b/package-lock.json index 5dc6655..7ee6e87 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,10 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@hirosystems/clarinet-sdk": "^0.5.5", + "@hirosystems/clarinet-sdk": "^0.9.0", "@stacks/transactions": "^6.9.0", "vitest": "^0.34.1", - "vitest-environment-clarinet": "^0.1.3" + "vitest-environment-clarinet": "^0.2.0" } }, "node_modules/@esbuild/android-arm": { @@ -346,11 +346,13 @@ } }, "node_modules/@hirosystems/clarinet-sdk": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/@hirosystems/clarinet-sdk/-/clarinet-sdk-0.5.5.tgz", - "integrity": "sha512-ZiEE8P2va04hJNTzqUlTMcnaiijytCakF/yNVbIi84qhtc9OWnLPlK7PzTMqquU4Rac3jysg1Nd+YmbNxtqyTw==", + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@hirosystems/clarinet-sdk/-/clarinet-sdk-0.9.0.tgz", + "integrity": "sha512-QOmfa1Nq29Jvdon1T6yxSyd11vVVb53vO9dZF8AJDr27Rre/I1g8nUySn6ltxAOyUnzrxPM5mBDuMPQt+1phMA==", "dependencies": { + "@hirosystems/clarinet-sdk-wasm": "^1.0.0", "@stacks/transactions": "^6.9.0", + "kolorist": "^1.8.0", "prompts": "^2.4.2", "vitest": "^0.34.5", "yargs": "^17.7.2" @@ -362,6 +364,11 @@ "node": ">=18.0.0" } }, + "node_modules/@hirosystems/clarinet-sdk-wasm": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@hirosystems/clarinet-sdk-wasm/-/clarinet-sdk-wasm-1.0.0.tgz", + "integrity": "sha512-axDe2iSSnxwbQT8FzJZ6U1jivKpQduHhq2wjMs6y0eX6gkbR19xDa0V/fMoaGb1ke6D1R5Hex7oTO+UJST+lUw==" + }, "node_modules/@jest/schemas": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", @@ -795,6 +802,11 @@ "node": ">=6" } }, + "node_modules/kolorist": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/kolorist/-/kolorist-1.8.0.tgz", + "integrity": "sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==" + }, "node_modules/local-pkg": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.4.3.tgz", @@ -1259,14 +1271,12 @@ } }, "node_modules/vitest-environment-clarinet": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/vitest-environment-clarinet/-/vitest-environment-clarinet-0.1.3.tgz", - "integrity": "sha512-HExF1X/17ADVo2szTkDmhXLfV8v4UKj6K039OIMfBihBQlLbX4Wg+yrTZiIevn6CCBfwEzjJXz5GOxg+GnOpAg==", - "dependencies": { - "vitest": "^0.34.4" - }, + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/vitest-environment-clarinet/-/vitest-environment-clarinet-0.2.0.tgz", + "integrity": "sha512-0ensLaHs7QlST8SayRfTI6VFP5Xh7gXDKlWXh67OqCtOlNYxJ4wfxnsXf6CcUmNAqPAVHEcbqR5E3IMPZ4SCdQ==", "peerDependencies": { - "@hirosystems/clarinet-sdk": "0" + "@hirosystems/clarinet-sdk": "0", + "vitest": "0" } }, "node_modules/webidl-conversions": { diff --git a/package.json b/package.json index a252ed1..cc42f7d 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ "license": "ISC", "type": "module", "dependencies": { - "@hirosystems/clarinet-sdk": "^0.5.5", + "@hirosystems/clarinet-sdk": "^0.9.0", "@stacks/transactions": "^6.9.0", "vitest": "^0.34.1", - "vitest-environment-clarinet": "^0.1.3" + "vitest-environment-clarinet": "^0.2.0" } } diff --git a/unit-tests/pyth-p2wh.test.ts b/unit-tests/pyth-p2wh.test.ts deleted file mode 100644 index f47c695..0000000 --- a/unit-tests/pyth-p2wh.test.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { Cl, ClarityType, ResponseOkCV } from "@stacks/transactions"; -import { describe, expect, it } from "vitest"; -import { tx } from "@hirosystems/clarinet-sdk"; - -import { mainnet_valid_guardians_set_upgrades, mainnet_valid_pfs } from "./constants"; - -const pyth_oracle_v1_contract_name = "pyth-oracle-dev-preview-1"; -const wormhole_core_v1_contract_name = "wormhole-core-dev-preview-1"; - -describe("Pyth (P2WH) testsuite", () => { - const accounts = vm.getAccounts(); - const sender = accounts.get("wallet_1")!; - - it("ensure that legitimate price attestations are validated", () => { - const vaaRotation1 = Cl.bufferFromHex(mainnet_valid_guardians_set_upgrades[0].vaa); - let publicKeysRotation1 = mainnet_valid_guardians_set_upgrades[0].keys.map(Cl.bufferFromHex); - - const vaaRotation2 = Cl.bufferFromHex(mainnet_valid_guardians_set_upgrades[1].vaa); - let publicKeysRotation2 = mainnet_valid_guardians_set_upgrades[1].keys.map(Cl.bufferFromHex); - - const vaaRotation3 = Cl.bufferFromHex(mainnet_valid_guardians_set_upgrades[2].vaa); - let publicKeysRotation3 = mainnet_valid_guardians_set_upgrades[2].keys.map(Cl.bufferFromHex); - - const block1 = vm.mineBlock([ - tx.callPublicFn( - wormhole_core_v1_contract_name, - "update-guardians-set", - [vaaRotation1, Cl.list(publicKeysRotation1)], - sender - ), - tx.callPublicFn( - wormhole_core_v1_contract_name, - "update-guardians-set", - [vaaRotation2, Cl.list(publicKeysRotation2)], - sender - ), - tx.callPublicFn( - wormhole_core_v1_contract_name, - "update-guardians-set", - [vaaRotation3, Cl.list(publicKeysRotation3)], - sender - ), - ]); - - expect(block1).toHaveLength(3); - block1.forEach((b) => { - expect(b.result).toHaveClarityType(ClarityType.ResponseOk); - }); - - const vaaBytes = Cl.bufferFromHex(mainnet_valid_pfs[0]); - - let res = vm.callPublicFn( - pyth_oracle_v1_contract_name, - "update-prices-feeds", - [Cl.list([vaaBytes])], - sender - ); - - const result = res.result; - expect(result).toHaveClarityType(ClarityType.ResponseOk); - - expect((result as ResponseOkCV).value).toBeList([ - Cl.bufferFromHex("e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"), - ]); - }); -}); diff --git a/unit-tests/pyth-pnau.test.ts b/unit-tests/pyth-pnau.test.ts index 0d949c3..1e69b73 100644 --- a/unit-tests/pyth-pnau.test.ts +++ b/unit-tests/pyth-pnau.test.ts @@ -5,10 +5,10 @@ import { tx } from "@hirosystems/clarinet-sdk"; import { mainnet_valid_guardians_set_upgrades, mainnet_valid_au } from "./constants"; const pyth_oracle_v1_contract_name = "pyth-oracle-v1"; -const wormhole_core_v1_contract_name = "wormhole-core-dev-preview-1"; +const wormhole_core_v1_contract_name = "wormhole-core-v1"; describe("Pyth (PNAU) testsuite", () => { - const accounts = vm.getAccounts(); + const accounts = simnet.getAccounts(); const sender = accounts.get("wallet_1")!; it("ensure that legitimate price attestations are validated", () => { @@ -21,7 +21,7 @@ describe("Pyth (PNAU) testsuite", () => { const vaaRotation3 = Cl.bufferFromHex(mainnet_valid_guardians_set_upgrades[2].vaa); let publicKeysRotation3 = mainnet_valid_guardians_set_upgrades[2].keys.map(Cl.bufferFromHex); - const block1 = vm.mineBlock([ + const block1 = simnet.mineBlock([ tx.callPublicFn( wormhole_core_v1_contract_name, "update-guardians-set", @@ -48,17 +48,17 @@ describe("Pyth (PNAU) testsuite", () => { }); const vaaBytes = Cl.bufferFromHex(mainnet_valid_au[0]); - - let res = vm.callPublicFn( + const wormholeContract = Cl.contractPrincipal(simnet.deployer, wormhole_core_v1_contract_name) + let res = simnet.callPublicFn( pyth_oracle_v1_contract_name, - "update-prices-feeds", - [vaaBytes], + "decode-pnau-price-update", + [vaaBytes, wormholeContract], sender ); // console.log(res.result); const result = res.result; - expect(result).toHaveClarityType(ClarityType.ResponseOk); + // expect(result).toHaveClarityType(ClarityType.ResponseOk); // expect(result as ResponseOkCV).toHaveClarityType(ClarityType.ResponseOk); console.log(Cl.prettyPrint(result, 2)); diff --git a/unit-tests/wormhole.test.ts b/unit-tests/wormhole.test.ts index 74a0040..c8d8143 100644 --- a/unit-tests/wormhole.test.ts +++ b/unit-tests/wormhole.test.ts @@ -4,10 +4,10 @@ import { tx } from "@hirosystems/clarinet-sdk"; import { mainnet_valid_guardians_set_upgrades } from "./constants"; -const wormhole_core_v1_contract_name = "wormhole-core-dev-preview-1"; +const wormhole_core_v1_contract_name = "wormhole-core-v1"; describe("Wormhole testsuite", () => { - const accounts = vm.getAccounts(); + const accounts = simnet.getAccounts(); const sender = accounts.get("wallet_1")!; it("ensure that guardians set can be rotated", () => { @@ -20,7 +20,7 @@ describe("Wormhole testsuite", () => { const vaaRotation3 = Cl.bufferFromHex(mainnet_valid_guardians_set_upgrades[2].vaa); let publicKeysRotation3 = mainnet_valid_guardians_set_upgrades[2].keys.map(Cl.bufferFromHex); - const block1 = vm.mineBlock([ + const block1 = simnet.mineBlock([ tx.callPublicFn( wormhole_core_v1_contract_name, "update-guardians-set",