diff --git a/.github/workflows/test-contract.yaml b/.github/workflows/test-contract.yaml index 72c0d78..a4b0b28 100644 --- a/.github/workflows/test-contract.yaml +++ b/.github/workflows/test-contract.yaml @@ -1,4 +1,7 @@ -name: Test contract +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Test get-price contract on: push: @@ -21,5 +24,12 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: npm i -f - - run: npm run test + - run: npm ci + - run: npm run test:reports + + - name: Upload coverage data to codecov + if: ${{ matrix.node-version == '22.x' }} + uses: codecov/codecov-action@v4 + with: + files: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 76c2842..c9ead91 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ **/settings/Testnet.toml .cache/** history.txt +.DS_Store logs *.log diff --git a/Clarinet.toml b/Clarinet.toml index afc67c9..e60703a 100644 --- a/Clarinet.toml +++ b/Clarinet.toml @@ -20,5 +20,5 @@ epoch = 3.1 [repl.remote_data] enabled = true -api_url = "https://api.hiro.so" +api_url = 'https://api.hiro.so' initial_height = 522000 diff --git a/package-lock.json b/package-lock.json index b9b1b24..0b78fc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { - "name": "pyth-client-tests", - "version": "1.0.0", + "name": "@hirosystems/clarinet-pyth-example", + "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "pyth-client-tests", - "version": "1.0.0", - "license": "ISC", + "name": "@hirosystems/clarinet-pyth-example", + "version": "0.1.0", + "license": "Apache-2.0", "dependencies": { - "@hirosystems/clarinet-sdk": "^2.13.0-beta15", + "@hirosystems/clarinet-sdk": "^2.13.0-beta18", "@stacks/transactions": "^6.12.0", "chokidar-cli": "^3.0.0", "typescript": "^5.3.3", @@ -390,12 +390,12 @@ } }, "node_modules/@hirosystems/clarinet-sdk": { - "version": "2.13.11", - "resolved": "https://registry.npmjs.org/@hirosystems/clarinet-sdk/-/clarinet-sdk-2.13.11.tgz", - "integrity": "sha512-n+w3YHssZTm1MRiuKpMqiMj8m2RmxnWvkiactXvtBbpzna+6L//nk6ky62MvP6PHySkLNFdYONVP2TYmWKyNsQ==", + "version": "2.13.0-beta18", + "resolved": "https://registry.npmjs.org/@hirosystems/clarinet-sdk/-/clarinet-sdk-2.13.0-beta18.tgz", + "integrity": "sha512-Ml+kHInWfVvVWIfI8vUKQbnUGWdLtijAOglgBD+sdBM9ku6mY8gsSQSQlZ2wIRdqJBItfSWtpwill3WLFIqE5Q==", "license": "GPL-3.0", "dependencies": { - "@hirosystems/clarinet-sdk-wasm": "2.13.0-beta11", + "@hirosystems/clarinet-sdk-wasm": "2.13.0-beta18", "@stacks/transactions": "^6.13.0", "kolorist": "^1.8.0", "prompts": "^2.4.2", @@ -410,9 +410,9 @@ } }, "node_modules/@hirosystems/clarinet-sdk-wasm": { - "version": "2.13.0-beta11", - "resolved": "https://registry.npmjs.org/@hirosystems/clarinet-sdk-wasm/-/clarinet-sdk-wasm-2.13.0-beta11.tgz", - "integrity": "sha512-Mz8jsCb42oRp+tZCVet3AXtB41xs/ivX+DdrTA0nP4NgNpfgtXmg6/MAd3KDiTEAxXvEWXklk67RAPlGiR/ogQ==", + "version": "2.13.0-beta18", + "resolved": "https://registry.npmjs.org/@hirosystems/clarinet-sdk-wasm/-/clarinet-sdk-wasm-2.13.0-beta18.tgz", + "integrity": "sha512-tAfMWX6wycvG5J93WZlb2b5Zt+y2pHuvJGEhBsz6TYmFZSaZ1ZwiFYbTyu3PkvpL+t/YmHKOa1gehtKXShBIpA==", "license": "GPL-3.0", "dependencies": { "sync-request": "6.1.0" @@ -2053,9 +2053,9 @@ } }, "node_modules/object-inspect": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz", - "integrity": "sha512-kDCGIbxkDSXE3euJZZXzc6to7fCrKHNI/hSRQnRuQ+BWjFNzZwiFF8fj/6o2t2G9/jTj8PSIYTfCLelLZEeRpA==", + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", "license": "MIT", "engines": { "node": ">= 0.4" diff --git a/package.json b/package.json index b684df3..1f34175 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "type": "module", "private": true, "scripts": { - "test": "vitest run", + "test": "vitest run -- --costs", "test:report": "vitest run -- --coverage --costs", "test:watch": "chokidar \"tests/**/*.ts\" \"contracts/**/*.clar\" -c \"npm run test:report\"" }, @@ -15,7 +15,7 @@ "node": ">=22.12.0" }, "dependencies": { - "@hirosystems/clarinet-sdk": "^2.13.0-beta15", + "@hirosystems/clarinet-sdk": "^2.13.0-beta18", "@stacks/transactions": "^6.12.0", "chokidar-cli": "^3.0.0", "typescript": "^5.3.3", diff --git a/tests/get-price.test.ts b/tests/get-price.test.ts index 11630dd..3a0ce5d 100644 --- a/tests/get-price.test.ts +++ b/tests/get-price.test.ts @@ -87,3 +87,38 @@ describe("example tests", () => { expect(result).toBeOk(Cl.uint(100738000)); }); }); + +describe("mint-sbtc demo", () => { + it("can get tx costs", () => { + const blockHeight = 1000; + const hash = simnet.callPublicFn( + "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-deposit", + "get-burn-header", + [Cl.uint(blockHeight)], + address1, + ); + // @ts-ignore + const burnHash = hash.result.value.buffer; + + const { result, costs: _costs } = simnet.callPublicFn( + "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-deposit", + "complete-deposit-wrapper", + [ + Cl.bufferFromHex( + "3ae3dfeedc6eb99fb5e2c5d0c90697a66de969c3f4d974ebe2ef104fcea7f13b", + ), + Cl.uint(1), + Cl.uint(100000000), // 1 BTC + Cl.principal(address1), + Cl.buffer(burnHash), + Cl.uint(blockHeight), + Cl.bufferFromHex( + "52500d11cabf1049ebb139a82b439d08bd3a8e867a41fb3f368dfa125e043989", + ), + ], + "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4", + ); + + expect(result).toBeOk(Cl.bool(true)); + }); +}); diff --git a/vitest.config.js b/vitest.config.js index aa37443..fd592ec 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -21,11 +21,15 @@ import { - vitest run -- --coverage --costs # collect coverage and cost reports */ +const args = getClarinetVitestsArgv(); + export default defineConfig({ test: { - environment: "clarinet", // use vitest-environment-clarinet + // use vitest-environment-clarinet + environment: "clarinet", pool: "forks", poolOptions: { + // run in a single thread if coverage is enabled forks: { singleFork: true }, }, setupFiles: [ @@ -34,8 +38,7 @@ export default defineConfig({ ], environmentOptions: { clarinet: { - ...getClarinetVitestsArgv(), - // add or override options + ...args, }, }, },