Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ coverage
costs-reports.json
node_modules
*.log.txt
history.txt
history.txt
.cache
38 changes: 37 additions & 1 deletion Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,35 @@ description = ''
authors = []
telemetry = false
cache_dir = './.cache'
requirements = []
requirements = [
{ contract_id = "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccd001-direct-execute"},
{ contract_id = "SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH.ccip024-miamicoin-signal-vote"}
]

[contracts.annotations_test]
path = "tests/contracts/generator-tests/annotations_test.clar"
clarity_version = 3
epoch = "3.1"

[contracts.annotations_flow_test]
path = "tests/contracts/generator-tests/annotations_flow_test.clar"
clarity_version = 3
epoch = "3.1"

[contracts.contract_call_flow_test]
path = "tests/contracts/generator-tests/contract-call_flow_test.clar"
clarity_version = 3
epoch = "3.1"

[contracts.list-args_flow_test]
path = "tests/contracts/generator-tests/list-args_flow_test.clar"
clarity_version = 3
epoch = "3.1"

[contracts.some-contract]
path = "tests/contracts/some-contract.clar"
clarity_version = 3
epoch = "3.1"

[repl.analysis]
passes = ['check_checker']
Expand All @@ -14,3 +42,11 @@ strict = false
trusted_sender = false
trusted_caller = false
callee_filter = false


[repl.remote_data]
# Enable mainnet execution simulation
enabled = true
# Specify the Stacks block height to fork from
initial_height = 3491155
use_mainnet_wallets = true
137 changes: 84 additions & 53 deletions deployments/default.simnet-plan.yaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,90 @@
---
id: 0
name: "Simulated deployment, used as a default for `clarinet console`, `clarinet test` and `clarinet check`"
name: Simulated deployment, used as a default for `clarinet console`, `clarinet test` and `clarinet check`
network: simnet
genesis:
wallets:
- name: deployer
address: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: faucet
address: STNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2CMMMAZ6
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: wallet_1
address: ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: wallet_2
address: ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: wallet_3
address: ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: wallet_4
address: ST2NEB84ASENDXKYGJPQW86YXQCEFEX2ZQPG87ND
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: wallet_5
address: ST2REHHS5J3CERCRBEPMGH7921Q6PYKAADT7JP2VB
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: wallet_6
address: ST3AM1A56AK2C1XAFJ4115ZSV26EB49BVQ10MGCS0
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: wallet_7
address: ST3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXEP8YGKJ
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: wallet_8
address: ST3NBRSFKX28FQ2ZJ1MAKX58HKHSDGNV5N7R21XCP
balance: "100000000000000"
sbtc-balance: "1000000000"
- name: deployer
address: SP1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRCBGD7R
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: faucet
address: SPNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2C69MJD9
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: wallet_1
address: SP1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2XG1V316
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: wallet_2
address: SP2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CH94GRJ
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: wallet_3
address: SP2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1J5QKA2F
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: wallet_4
address: SP2NEB84ASENDXKYGJPQW86YXQCEFEX2ZPB1S2EP
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: wallet_5
address: SP2REHHS5J3CERCRBEPMGH7921Q6PYKAADR2V8W5C
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: wallet_6
address: SP3AM1A56AK2C1XAFJ4115ZSV26EB49BVQ3JJEPMJ
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: wallet_7
address: SP3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXFA1W3C2
balance: '100000000000000'
sbtc-balance: '1000000000'
- name: wallet_8
address: SP3NBRSFKX28FQ2ZJ1MAKX58HKHSDGNV5N6R5192Q
balance: '100000000000000'
sbtc-balance: '1000000000'
contracts:
- costs
- pox
- pox-2
- pox-3
- pox-4
- lockup
- costs-2
- costs-3
- cost-voting
- bns
- genesis
- lockup
- bns
- cost-voting
- costs
- pox
- costs-2
- pox-2
- costs-3
- pox-3
- pox-4
- signers
- signers-voting
- costs-4
plan:
batches: []
batches:
- id: 0
transactions:
- transaction-type: emulated-contract-publish
contract-name: annotations_flow_test
emulated-sender: SP1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRCBGD7R
path: tests/contracts/generator-tests/annotations_flow_test.clar
clarity-version: 3
- transaction-type: emulated-contract-publish
contract-name: annotations_test
emulated-sender: SP1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRCBGD7R
path: tests/contracts/generator-tests/annotations_test.clar
clarity-version: 3
- transaction-type: emulated-contract-publish
contract-name: contract_call_flow_test
emulated-sender: SP1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRCBGD7R
path: tests/contracts/generator-tests/contract-call_flow_test.clar
clarity-version: 3
- transaction-type: emulated-contract-publish
contract-name: some-contract
emulated-sender: SP1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRCBGD7R
path: tests/contracts/some-contract.clar
clarity-version: 3
- transaction-type: emulated-contract-publish
contract-name: list-args_flow_test
emulated-sender: SP1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRCBGD7R
path: tests/contracts/generator-tests/list-args_flow_test.clar
clarity-version: 3
epoch: '3.1'
10 changes: 5 additions & 5 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"author": "",
"license": "ISC",
"dependencies": {
"@hirosystems/clarinet-sdk": "3.1.0",
"@stacks/clarinet-sdk": "3.9.1",
"@stacks/clarunit": "^0.1.0",
"@stacks/transactions": "^7.1.0",
"chokidar-cli": "^3.0.0",
"typescript": "^5.8.3",
"vite": "^7.0.0",
"vitest": "^3.2.4",
"vitest-environment-clarinet": "^2.3.0"
"typescript": "^5.9.3",
"vite": "^7.2.2",
"vitest": "^4.0.8",
"vitest-environment-clarinet": "^3.0.1"
}
}
1 change: 1 addition & 0 deletions example/tests/my-contract_test.clar
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
)

;; @caller 'ST000000000000000000002AMW42H
(define-public (test-a-times-b2)
(begin
(asserts! (is-eq (ok u108) (contract-call? .my-contract a-times-b u9 u12))
Expand Down
2 changes: 1 addition & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"noFallthroughCasesInSwitch": true
},
"include": [
"node_modules/@hirosystems/clarinet-sdk/vitest-helpers/src",
"node_modules/@stacks/clarinet-sdk/vitest-helpers/src",
"tests"
]
}
2 changes: 1 addition & 1 deletion example/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from "vite";
import {
vitestSetupFilePath,
getClarinetVitestsArgv,
} from "@hirosystems/clarinet-sdk/vitest";
} from "@stacks/clarinet-sdk/vitest";

/*
In this file, Vitest is configured so that it works seamlessly with Clarinet and the Simnet.
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
},
"homepage": "https://github.com/stacks-network/clarunit#readme",
"dependencies": {
"@hirosystems/clarinet-sdk": "3.1.0",
"@stacks/common": "^7.0.2",
"@stacks/transactions": "7.1.0",
"@stacks/clarinet-sdk": "3.15.1",
"@stacks/common": "^7.3.1",
"@stacks/transactions": "7.4.0",
"chokidar-cli": "^3.0.0",
"typescript": "5.8.3",
"vite": "6.3.5",
"vitest": "3.2.3",
"vitest-environment-clarinet": "2.3.0"
"typescript": "6.0.2",
"vite": "8.0.3",
"vitest": "4.1.2",
"vitest-environment-clarinet": "3.0.2"
},
"devDependencies": {
"fast-check": "4.1.1"
"fast-check": "4.6.0"
}
}
7 changes: 3 additions & 4 deletions src/clarunit-flow-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParsedTransactionResult, tx } from "@hirosystems/clarinet-sdk";
import { ParsedTransactionResult, tx } from "@stacks/clarinet-sdk";
import * as fs from "fs";
import { describe, it } from "vitest";
import {
Expand All @@ -8,6 +8,7 @@ import {
extractTestAnnotationsAndCalls,
} from "./parser/clarity-parser-flow-tests";
import { expectOk, isValidTestFunction } from "./parser/test-helpers";
import { getCaller } from "./clarunit-utils";
import path from "path";

/**
Expand Down Expand Up @@ -100,9 +101,7 @@ function mineBlocksFromFunctionBody(
const mineBlocksBefore =
parseInt(callAnnotations["mine-blocks-before"] as string) || 0;
// get caller address
const caller = accounts.get(
(callAnnotations["caller"] as string) || "deployer"
)!;
const caller = getCaller(callAnnotations, accounts);

if (mineBlocksBefore >= 1) {
if (blockStarted) {
Expand Down
22 changes: 9 additions & 13 deletions src/clarunit-generator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Simnet, tx } from "@hirosystems/clarinet-sdk";
import { Simnet, tx } from "@stacks/clarinet-sdk";
import { describe, it } from "vitest";
import {
extractTestAnnotations,
} from "./parser/clarity-parser";
import { extractTestAnnotations } from "./parser/clarity-parser";
import { expectOkTrue, isValidTestFunction } from "./parser/test-helpers";
import { FunctionAnnotations } from "./parser/clarity-parser-flow-tests";
import { getCaller } from "./clarunit-utils";

/**
* Returns true if the contract is a test contract
* @param contractName name of the contract
* @returns
* @returns
*/
function isTestContract(contractName: string) {
return (
Expand Down Expand Up @@ -44,10 +43,11 @@ export function generateUnitTests(simnet: Simnet) {
annotations[functionName] || {};

const mineBlocksBefore =
parseInt(annotations["mine-blocks-before"] as string) || 0;
parseInt(functionAnnotations["mine-blocks-before"] as string) || 0;
Comment thread
friedger marked this conversation as resolved.

const testDescription = `${functionCall.name}${functionAnnotations.name ? `: ${functionAnnotations.name}` : ""
}`;
const testDescription = `${functionCall.name}${
functionAnnotations.name ? `: ${functionAnnotations.name}` : ""
}`;
it(testDescription, () => {
// handle prepare function for this test
if (hasDefaultPrepareFunction && !functionAnnotations.prepare)
Expand All @@ -56,11 +56,7 @@ export function generateUnitTests(simnet: Simnet) {
delete functionAnnotations.prepare;

// handle caller address for this test
const callerAddress = functionAnnotations.caller
? annotations.caller[0] === "'"
? `${(annotations.caller as string).substring(1)}`
: accounts.get(annotations.caller)!
: accounts.get("deployer")!;
const callerAddress = getCaller(functionAnnotations, accounts);

if (functionAnnotations.prepare) {
// mine block with prepare function call
Expand Down
7 changes: 7 additions & 0 deletions src/clarunit-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getCaller = (annotations: any, accounts: Map<string, string>) => {
return annotations.caller && typeof annotations.caller === "string"
? annotations.caller[0] === "'"
? `${(annotations.caller as string).substring(1)}`
: accounts.get(annotations.caller)!
: accounts.get("deployer")!;
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateUnitTests } from "./clarunit-generator";
import { generateFlowTests } from "./clarunit-flow-generator";
import { Simnet } from "@hirosystems/clarinet-sdk";
import { Simnet } from "@stacks/clarinet-sdk";

export function clarunit(simnet: Simnet) {
generateUnitTests(simnet);
Expand Down
Loading