diff --git a/subscription-service/.gitattributes b/subscription-service/.gitattributes new file mode 100644 index 0000000..da6a065 --- /dev/null +++ b/subscription-service/.gitattributes @@ -0,0 +1,3 @@ +tests/** linguist-vendored +vitest.config.js linguist-vendored +* text=lf diff --git a/subscription-service/.gitignore b/subscription-service/.gitignore new file mode 100644 index 0000000..76c2842 --- /dev/null +++ b/subscription-service/.gitignore @@ -0,0 +1,13 @@ + +**/settings/Mainnet.toml +**/settings/Testnet.toml +.cache/** +history.txt + +logs +*.log +npm-debug.log* +coverage +*.info +costs-reports.json +node_modules diff --git a/subscription-service/.vscode/settings.json b/subscription-service/.vscode/settings.json new file mode 100644 index 0000000..3062519 --- /dev/null +++ b/subscription-service/.vscode/settings.json @@ -0,0 +1,4 @@ + +{ + "files.eol": "\n" +} diff --git a/subscription-service/.vscode/tasks.json b/subscription-service/.vscode/tasks.json new file mode 100644 index 0000000..4dec0ff --- /dev/null +++ b/subscription-service/.vscode/tasks.json @@ -0,0 +1,19 @@ + +{ + "version": "2.0.0", + "tasks": [ + { + "label": "check contracts", + "group": "test", + "type": "shell", + "command": "clarinet check" + }, + { + "type": "npm", + "script": "test", + "group": "test", + "problemMatcher": [], + "label": "npm test" + } + ] +} diff --git a/subscription-service/Clarinet.toml b/subscription-service/Clarinet.toml new file mode 100644 index 0000000..3e3d43b --- /dev/null +++ b/subscription-service/Clarinet.toml @@ -0,0 +1,19 @@ +[project] +name = 'subscription-service' +description = '' +authors = [] +telemetry = true +cache_dir = '.\.cache' +requirements = [] +[contracts.plan-manager] +path = 'contracts/plan-manager.clar' +clarity_version = 2 +epoch = 2.5 +[repl.analysis] +passes = ['check_checker'] + +[repl.analysis.check_checker] +strict = false +trusted_sender = false +trusted_caller = false +callee_filter = false diff --git a/subscription-service/README.md b/subscription-service/README.md new file mode 100644 index 0000000..563e9e3 --- /dev/null +++ b/subscription-service/README.md @@ -0,0 +1,82 @@ +# Subscription Service Smart Contract + +## Overview + +This smart contract implements a subscription service on the Stacks blockchain. It allows for the creation and management of subscription plans, user subscriptions, and associated financial transactions. + +## Features + +1. Subscription Plan Management + - Add new subscription plans + - Update existing subscription plans + - Delete subscription plans + +2. User Subscription Management + - Subscribe to a plan + - Cancel a subscription + - Renew a subscription + +3. Financial Operations + - Process payments for subscriptions + - Withdraw funds from the contract + +4. Read-only Functions + - Get subscription plan details + - Get user subscription details + - Check if a user's subscription is active + +## Contract Functions + +### Admin Functions (Contract Owner Only) + +1. `add-subscription-plan`: Add a new subscription plan +2. `update-subscription-plan`: Update an existing subscription plan +3. `delete-subscription-plan`: Delete a subscription plan +4. `withdraw-contract-funds`: Withdraw funds from the contract + +### User Functions + +1. `subscribe-to-plan`: Subscribe to a specific plan +2. `cancel-user-subscription`: Cancel the current subscription +3. `renew-user-subscription`: Renew the current subscription + +### Read-only Functions + +1. `get-subscription-plan`: Get details of a specific subscription plan +2. `get-user-subscription-details`: Get details of a user's subscription +3. `is-subscription-active`: Check if a user's subscription is active + +## Error Codes + +- `ERR-OWNER-ONLY (u100)`: Operation restricted to contract owner +- `ERR-NOT-FOUND (u101)`: Requested item not found +- `ERR-ALREADY-EXISTS (u102)`: Item already exists +- `ERR-INSUFFICIENT-BALANCE (u103)`: Insufficient balance for the operation +- `ERR-EXPIRED (u104)`: Subscription has expired + +## Usage + +1. Deploy the contract to the Stacks blockchain. +2. As the contract owner, add subscription plans using `add-subscription-plan`. +3. Users can subscribe to plans using `subscribe-to-plan`. +4. Users can manage their subscriptions with `cancel-user-subscription` and `renew-user-subscription`. +5. The contract owner can manage plans and withdraw funds as needed. + +## Important Considerations + +- Only the contract owner can add, update, or delete subscription plans and withdraw funds. +- Users must have sufficient STX balance to subscribe to a plan or renew their subscription. +- Subscription durations and prices are measured in blocks and micro-STX, respectively. +- The contract uses the current block height for tracking subscription start and end times. + +## Security + +- The contract includes checks to ensure only authorized operations are performed. +- Balance checks are implemented to prevent insufficient fund issues. +- Proper error handling is in place to manage various scenarios. + +## Future Improvements + +- Implement a grace period for subscription renewals. +- Add functionality for tiered pricing or discounts. +- Implement a referral system or loyalty rewards. \ No newline at end of file diff --git a/subscription-service/Testnet.toml b/subscription-service/Testnet.toml new file mode 100644 index 0000000..b9cfb45 --- /dev/null +++ b/subscription-service/Testnet.toml @@ -0,0 +1,7 @@ +[network] +name = "testnet" +stacks_node_rpc_address = "https://api.testnet.hiro.so" +deployment_fee_rate = 10 + +[accounts.deployer] +mnemonic = "" diff --git a/subscription-service/contracts/plan-manager.clar b/subscription-service/contracts/plan-manager.clar new file mode 100644 index 0000000..5d9f3ec --- /dev/null +++ b/subscription-service/contracts/plan-manager.clar @@ -0,0 +1,160 @@ +;; Subscription Service Contract + +;; Constants +(define-constant CONTRACT-OWNER tx-sender) +(define-constant ERR-OWNER-ONLY (err u100)) +(define-constant ERR-NOT-FOUND (err u101)) +(define-constant ERR-ALREADY-EXISTS (err u102)) +(define-constant ERR-INSUFFICIENT-BALANCE (err u103)) +(define-constant ERR-EXPIRED (err u104)) +(define-constant ERR-INVALID-INPUT (err u105)) + +;; Data maps +(define-map subscription-plans + { plan-id: uint } + { plan-name: (string-ascii 50), subscription-duration: uint, plan-price: uint } +) + +(define-map user-subscriptions + { subscriber: principal } + { subscribed-plan-id: uint, subscription-start-block: uint, subscription-end-block: uint } +) + +;; Variables +(define-data-var next-available-plan-id uint u1) + +;; Read-only functions +(define-read-only (get-subscription-plan (plan-id uint)) + (map-get? subscription-plans { plan-id: plan-id }) +) + +(define-read-only (get-user-subscription-details (subscriber principal)) + (map-get? user-subscriptions { subscriber: subscriber }) +) + +(define-read-only (is-subscription-active (subscriber principal)) + (match (get-user-subscription-details subscriber) + subscription-details (> (get subscription-end-block subscription-details) block-height) + false + ) +) + +;; Private functions +(define-private (transfer-stx-tokens (amount uint) (sender principal) (recipient principal)) + (match (stx-transfer? amount sender recipient) + transfer-success (ok true) + transfer-error (err transfer-error) + ) +) + +(define-private (validate-plan-input (plan-name (string-ascii 50)) (subscription-duration uint) (plan-price uint)) + (and + (> (len plan-name) u0) + (< (len plan-name) u51) + (> subscription-duration u0) + (> plan-price u0) + ) +) + +;; Public functions +(define-public (add-subscription-plan (plan-name (string-ascii 50)) (subscription-duration uint) (plan-price uint)) + (begin + (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-OWNER-ONLY) + (asserts! (validate-plan-input plan-name subscription-duration plan-price) ERR-INVALID-INPUT) + (let ((new-plan-id (var-get next-available-plan-id))) + (asserts! (is-none (get-subscription-plan new-plan-id)) ERR-ALREADY-EXISTS) + (map-set subscription-plans + { plan-id: new-plan-id } + { plan-name: plan-name, subscription-duration: subscription-duration, plan-price: plan-price } + ) + (var-set next-available-plan-id (+ new-plan-id u1)) + (ok new-plan-id) + ) + ) +) + +(define-public (update-subscription-plan (plan-id uint) (plan-name (string-ascii 50)) (subscription-duration uint) (plan-price uint)) + (begin + (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-OWNER-ONLY) + (asserts! (validate-plan-input plan-name subscription-duration plan-price) ERR-INVALID-INPUT) + (asserts! (is-some (get-subscription-plan plan-id)) ERR-NOT-FOUND) + (map-set subscription-plans + { plan-id: plan-id } + { plan-name: plan-name, subscription-duration: subscription-duration, plan-price: plan-price } + ) + (ok true) + ) +) + +(define-public (delete-subscription-plan (plan-id uint)) + (begin + (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-OWNER-ONLY) + (asserts! (is-some (get-subscription-plan plan-id)) ERR-NOT-FOUND) + (map-delete subscription-plans { plan-id: plan-id }) + (ok true) + ) +) + +(define-public (subscribe-to-plan (plan-id uint)) + (let ( + (selected-plan (unwrap! (get-subscription-plan plan-id) ERR-NOT-FOUND)) + (plan-price (get plan-price selected-plan)) + (subscription-duration (get subscription-duration selected-plan)) + (subscription-start-block block-height) + (subscription-end-block (+ block-height subscription-duration)) + ) + (asserts! (>= (stx-get-balance tx-sender) plan-price) ERR-INSUFFICIENT-BALANCE) + (match (transfer-stx-tokens plan-price tx-sender (as-contract tx-sender)) + transfer-success (begin + (map-set user-subscriptions + { subscriber: tx-sender } + { subscribed-plan-id: plan-id, subscription-start-block: subscription-start-block, subscription-end-block: subscription-end-block } + ) + (ok true) + ) + transfer-error (err transfer-error) + ) + ) +) + +(define-public (cancel-user-subscription) + (begin + (asserts! (is-some (get-user-subscription-details tx-sender)) ERR-NOT-FOUND) + (map-delete user-subscriptions { subscriber: tx-sender }) + (ok true) + ) +) + +(define-public (renew-user-subscription) + (let ( + (current-subscription (unwrap! (get-user-subscription-details tx-sender) ERR-NOT-FOUND)) + (subscribed-plan-id (get subscribed-plan-id current-subscription)) + (subscription-plan (unwrap! (get-subscription-plan subscribed-plan-id) ERR-NOT-FOUND)) + (renewal-price (get plan-price subscription-plan)) + (renewal-duration (get subscription-duration subscription-plan)) + (new-subscription-end-block (+ block-height renewal-duration)) + ) + (asserts! (>= (stx-get-balance tx-sender) renewal-price) ERR-INSUFFICIENT-BALANCE) + (match (transfer-stx-tokens renewal-price tx-sender (as-contract tx-sender)) + transfer-success (begin + (map-set user-subscriptions + { subscriber: tx-sender } + { subscribed-plan-id: subscribed-plan-id, subscription-start-block: block-height, subscription-end-block: new-subscription-end-block } + ) + (ok true) + ) + transfer-error (err transfer-error) + ) + ) +) + +(define-public (withdraw-contract-funds (withdrawal-amount uint)) + (begin + (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-OWNER-ONLY) + (asserts! (<= withdrawal-amount (stx-get-balance (as-contract tx-sender))) ERR-INSUFFICIENT-BALANCE) + (match (transfer-stx-tokens withdrawal-amount (as-contract tx-sender) CONTRACT-OWNER) + transfer-success (ok true) + transfer-error (err transfer-error) + ) + ) +) \ No newline at end of file diff --git a/subscription-service/package.json b/subscription-service/package.json new file mode 100644 index 0000000..43a2dc9 --- /dev/null +++ b/subscription-service/package.json @@ -0,0 +1,24 @@ + +{ + "name": "subscription-service-tests", + "version": "1.0.0", + "description": "Run unit tests on this project.", + "type": "module", + "private": true, + "scripts": { + "test": "vitest run", + "test:report": "vitest run -- --coverage --costs", + "test:watch": "chokidar \"tests/**/*.ts\" \"contracts/**/*.clar\" -c \"npm run test:report\"" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@hirosystems/clarinet-sdk": "^2.3.2", + "@stacks/transactions": "^6.12.0", + "chokidar-cli": "^3.0.0", + "typescript": "^5.3.3", + "vite": "^5.1.4", + "vitest": "^1.3.1", + "vitest-environment-clarinet": "^2.0.0" + } +} diff --git a/subscription-service/settings/Devnet.toml b/subscription-service/settings/Devnet.toml new file mode 100644 index 0000000..7d865b9 --- /dev/null +++ b/subscription-service/settings/Devnet.toml @@ -0,0 +1,151 @@ +[network] +name = "devnet" +deployment_fee_rate = 10 + +[accounts.deployer] +mnemonic = "twice kind fence tip hidden tilt action fragile skin nothing glory cousin green tomorrow spring wrist shed math olympic multiply hip blue scout claw" +balance = 100_000_000_000_000 +# secret_key: 753b7cc01a1a2e86221266a154af739463fce51219d97e4f856cd7200c3bd2a601 +# stx_address: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM +# btc_address: mqVnk6NPRdhntvfm4hh9vvjiRkFDUuSYsH + +[accounts.wallet_1] +mnemonic = "sell invite acquire kitten bamboo drastic jelly vivid peace spawn twice guilt pave pen trash pretty park cube fragile unaware remain midnight betray rebuild" +balance = 100_000_000_000_000 +# secret_key: 7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801 +# stx_address: ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5 +# btc_address: mr1iPkD9N3RJZZxXRk7xF9d36gffa6exNC + +[accounts.wallet_2] +mnemonic = "hold excess usual excess ring elephant install account glad dry fragile donkey gaze humble truck breeze nation gasp vacuum limb head keep delay hospital" +balance = 100_000_000_000_000 +# secret_key: 530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101 +# stx_address: ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG +# btc_address: muYdXKmX9bByAueDe6KFfHd5Ff1gdN9ErG + +[accounts.wallet_3] +mnemonic = "cycle puppy glare enroll cost improve round trend wrist mushroom scorpion tower claim oppose clever elephant dinosaur eight problem before frozen dune wagon high" +balance = 100_000_000_000_000 +# secret_key: d655b2523bcd65e34889725c73064feb17ceb796831c0e111ba1a552b0f31b3901 +# stx_address: ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC +# btc_address: mvZtbibDAAA3WLpY7zXXFqRa3T4XSknBX7 + +[accounts.wallet_4] +mnemonic = "board list obtain sugar hour worth raven scout denial thunder horse logic fury scorpion fold genuine phrase wealth news aim below celery when cabin" +balance = 100_000_000_000_000 +# secret_key: f9d7206a47f14d2870c163ebab4bf3e70d18f5d14ce1031f3902fbbc894fe4c701 +# stx_address: ST2NEB84ASENDXKYGJPQW86YXQCEFEX2ZQPG87ND +# btc_address: mg1C76bNTutiCDV3t9nWhZs3Dc8LzUufj8 + +[accounts.wallet_5] +mnemonic = "hurry aunt blame peanut heavy update captain human rice crime juice adult scale device promote vast project quiz unit note reform update climb purchase" +balance = 100_000_000_000_000 +# secret_key: 3eccc5dac8056590432db6a35d52b9896876a3d5cbdea53b72400bc9c2099fe801 +# stx_address: ST2REHHS5J3CERCRBEPMGH7921Q6PYKAADT7JP2VB +# btc_address: mweN5WVqadScHdA81aATSdcVr4B6dNokqx + +[accounts.wallet_6] +mnemonic = "area desk dutch sign gold cricket dawn toward giggle vibrant indoor bench warfare wagon number tiny universe sand talk dilemma pottery bone trap buddy" +balance = 100_000_000_000_000 +# secret_key: 7036b29cb5e235e5fd9b09ae3e8eec4404e44906814d5d01cbca968a60ed4bfb01 +# stx_address: ST3AM1A56AK2C1XAFJ4115ZSV26EB49BVQ10MGCS0 +# btc_address: mzxXgV6e4BZSsz8zVHm3TmqbECt7mbuErt + +[accounts.wallet_7] +mnemonic = "prevent gallery kind limb income control noise together echo rival record wedding sense uncover school version force bleak nuclear include danger skirt enact arrow" +balance = 100_000_000_000_000 +# secret_key: b463f0df6c05d2f156393eee73f8016c5372caa0e9e29a901bb7171d90dc4f1401 +# stx_address: ST3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXEP8YGKJ +# btc_address: n37mwmru2oaVosgfuvzBwgV2ysCQRrLko7 + +[accounts.wallet_8] +mnemonic = "female adjust gallery certain visit token during great side clown fitness like hurt clip knife warm bench start reunion globe detail dream depend fortune" +balance = 100_000_000_000_000 +# secret_key: 6a1a754ba863d7bab14adbbc3f8ebb090af9e871ace621d3e5ab634e1422885e01 +# stx_address: ST3NBRSFKX28FQ2ZJ1MAKX58HKHSDGNV5N7R21XCP +# btc_address: n2v875jbJ4RjBnTjgbfikDfnwsDV5iUByw + +[accounts.faucet] +mnemonic = "shadow private easily thought say logic fault paddle word top book during ignore notable orange flight clock image wealth health outside kitten belt reform" +balance = 100_000_000_000_000 +# secret_key: de433bdfa14ec43aa1098d5be594c8ffb20a31485ff9de2923b2689471c401b801 +# stx_address: STNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2CMMMAZ6 +# btc_address: mjSrB3wS4xab3kYqFktwBzfTdPg367ZJ2d + +[devnet] +disable_stacks_explorer = false +disable_stacks_api = false +# disable_subnet_api = false +# disable_bitcoin_explorer = true +# working_dir = "tmp/devnet" +# stacks_node_events_observers = ["host.docker.internal:8002"] +# miner_mnemonic = "fragile loan twenty basic net assault jazz absorb diet talk art shock innocent float punch travel gadget embrace caught blossom hockey surround initial reduce" +# miner_derivation_path = "m/44'/5757'/0'/0/0" +# faucet_mnemonic = "shadow private easily thought say logic fault paddle word top book during ignore notable orange flight clock image wealth health outside kitten belt reform" +# faucet_derivation_path = "m/44'/5757'/0'/0/0" +# orchestrator_port = 20445 +# bitcoin_node_p2p_port = 18444 +# bitcoin_node_rpc_port = 18443 +# bitcoin_node_username = "devnet" +# bitcoin_node_password = "devnet" +# bitcoin_controller_block_time = 30_000 +# stacks_node_rpc_port = 20443 +# stacks_node_p2p_port = 20444 +# stacks_api_port = 3999 +# stacks_api_events_port = 3700 +# bitcoin_explorer_port = 8001 +# stacks_explorer_port = 8000 +# postgres_port = 5432 +# postgres_username = "postgres" +# postgres_password = "postgres" +# postgres_database = "postgres" +# bitcoin_node_image_url = "quay.io/hirosystems/bitcoind:26.0" +# stacks_node_image_url = "quay.io/hirosystems/stacks-node:devnet-2.5" +# stacks_signer_image_url = "quay.io/hirosystems/stacks-signer:devnet-2.5" +# stacks_api_image_url = "hirosystems/stacks-blockchain-api:master" +# stacks_explorer_image_url = "hirosystems/explorer:latest" +# bitcoin_explorer_image_url = "quay.io/hirosystems/bitcoin-explorer:devnet" +# postgres_image_url = "postgres:alpine" +# enable_subnet_node = true +# subnet_node_image_url = "hirosystems/stacks-subnets:0.8.1" +# subnet_leader_mnemonic = "twice kind fence tip hidden tilt action fragile skin nothing glory cousin green tomorrow spring wrist shed math olympic multiply hip blue scout claw" +# subnet_leader_derivation_path = "m/44'/5757'/0'/0/0" +# subnet_contract_id = "ST173JK7NZBA4BS05ZRATQH1K89YJMTGEH1Z5J52E.subnet-v3-0-1" +# subnet_node_rpc_port = 30443 +# subnet_node_p2p_port = 30444 +# subnet_events_ingestion_port = 30445 +# subnet_node_events_observers = ["host.docker.internal:8002"] +# subnet_api_image_url = "hirosystems/stacks-blockchain-api:master" +# subnet_api_postgres_database = "subnet_api" + +# For testing in epoch 2.1 / using Clarity2 +# epoch_2_0 = 100 +# epoch_2_05 = 100 +# epoch_2_1 = 101 +# epoch_2_2 = 102 +# epoch_2_3 = 103 +# epoch_2_4 = 104 +# epoch_2_5 = 108 + + +# Send some stacking orders +[[devnet.pox_stacking_orders]] +start_at_cycle = 1 +duration = 12 +wallet = "wallet_1" +slots = 2 +btc_address = "mr1iPkD9N3RJZZxXRk7xF9d36gffa6exNC" + +[[devnet.pox_stacking_orders]] +start_at_cycle = 1 +duration = 12 +wallet = "wallet_2" +slots = 1 +btc_address = "muYdXKmX9bByAueDe6KFfHd5Ff1gdN9ErG" + +[[devnet.pox_stacking_orders]] +start_at_cycle = 1 +duration = 12 +wallet = "wallet_3" +slots = 1 +btc_address = "mvZtbibDAAA3WLpY7zXXFqRa3T4XSknBX7" diff --git a/subscription-service/tests/plan-manager.test.ts b/subscription-service/tests/plan-manager.test.ts new file mode 100644 index 0000000..f2d4bb8 --- /dev/null +++ b/subscription-service/tests/plan-manager.test.ts @@ -0,0 +1,21 @@ + +import { describe, expect, it } from "vitest"; + +const accounts = simnet.getAccounts(); +const address1 = accounts.get("wallet_1")!; + +/* + The test below is an example. To learn more, read the testing documentation here: + https://docs.hiro.so/clarinet/feature-guides/test-contract-with-clarinet-sdk +*/ + +describe("example tests", () => { + it("ensures simnet is well initalised", () => { + expect(simnet.blockHeight).toBeDefined(); + }); + + // it("shows an example", () => { + // const { result } = simnet.callReadOnlyFn("counter", "get-counter", [], address1); + // expect(result).toBeUint(0); + // }); +}); diff --git a/subscription-service/tsconfig.json b/subscription-service/tsconfig.json new file mode 100644 index 0000000..1bdaf36 --- /dev/null +++ b/subscription-service/tsconfig.json @@ -0,0 +1,26 @@ + +{ + "compilerOptions": { + "target": "ESNext", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ESNext"], + "skipLibCheck": true, + + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + + "strict": true, + "noImplicitAny": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": [ + "node_modules/@hirosystems/clarinet-sdk/vitest-helpers/src", + "tests" + ] +} diff --git a/subscription-service/vitest.config.js b/subscription-service/vitest.config.js new file mode 100644 index 0000000..c6a8506 --- /dev/null +++ b/subscription-service/vitest.config.js @@ -0,0 +1,42 @@ + +/// + +import { defineConfig } from "vite"; +import { vitestSetupFilePath, getClarinetVitestsArgv } from "@hirosystems/clarinet-sdk/vitest"; + +/* + In this file, Vitest is configured so that it works seamlessly with Clarinet and the Simnet. + + The `vitest-environment-clarinet` will initialise the clarinet-sdk + and make the `simnet` object available globally in the test files. + + `vitestSetupFilePath` points to a file in the `@hirosystems/clarinet-sdk` package that does two things: + - run `before` hooks to initialize the simnet and `after` hooks to collect costs and coverage reports. + - load custom vitest matchers to work with Clarity values (such as `expect(...).toBeUint()`) + + The `getClarinetVitestsArgv()` will parse options passed to the command `vitest run --` + - vitest run -- --manifest ./Clarinet.toml # pass a custom path + - vitest run -- --coverage --costs # collect coverage and cost reports +*/ + +export default defineConfig({ + test: { + environment: "clarinet", // use vitest-environment-clarinet + pool: "forks", + poolOptions: { + threads: { singleThread: true }, + forks: { singleFork: true }, + }, + setupFiles: [ + vitestSetupFilePath, + // custom setup files can be added here + ], + environmentOptions: { + clarinet: { + ...getClarinetVitestsArgv(), + // add or override options + }, + }, + }, +}); +