Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip functions with trait reference parameters from selection #83

Merged
merged 10 commits into from
Jan 9, 2025
Merged
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
node: [22, 20, 18]
node: [23, 22, 20, 18]

steps:
- name: Checkout code
Expand All @@ -40,7 +40,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [22, 20, 18]
node: [23, 22, 20, 18]

steps:
- name: Checkout code
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
deployments
dist
coverage
43 changes: 27 additions & 16 deletions app.tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { red } from "ansicolor";
import { main } from "./app";
import { version } from "./package.json";

Expand All @@ -20,8 +21,12 @@ describe("Command-line arguments handling", () => {
--runs - The runs to use for iterating over the tests. Default: 100.
--help - Show the help message.
`;
const noManifestMessage = `\nNo path to Clarinet project provided. Supply it immediately or face the relentless scrutiny of your contract's vulnerabilities.`;
const noContractNameMessage = `\nNo target contract name provided. Please provide the contract name to be fuzzed.`;
const noManifestMessage = red(
`\nNo path to Clarinet project provided. Supply it immediately or face the relentless scrutiny of your contract's vulnerabilities.`
);
const noContractNameMessage = red(
`\nNo target contract name provided. Please provide the contract name to be fuzzed.`
);

it.each([
["manifest path", ["node", "app.js"]],
Expand Down Expand Up @@ -96,56 +101,60 @@ describe("Command-line arguments handling", () => {
[
["no command-line arguments"],
["node", "app.js"],
[
`\nNo path to Clarinet project provided. Supply it immediately or face the relentless scrutiny of your contract's vulnerabilities.`,
helpMessage,
],
[noManifestMessage, helpMessage],
],
[
["manifest path"],
["node", "app.js", "example"],
[
`\nNo target contract name provided. Please provide the contract name to be fuzzed.`,
helpMessage,
],
[noContractNameMessage, helpMessage],
],
[
["manifest path", "contract name"],
["node", "app.js", "example", "counter"],
[
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`,
red(
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`
),
helpMessage,
],
],
[
["manifest path", "contract name", "seed"],
["node", "app.js", "example", "counter", "--seed=123"],
[
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`,
red(
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`
),
helpMessage,
],
],
[
["manifest path", "contract name", "seed", "path"],
["node", "app.js", "example", "counter", "--seed=123", "--path=84:0"],
[
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`,
red(
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`
),
helpMessage,
],
],
[
["manifest path", "contract name", "runs"],
["node", "app.js", "example", "counter", "--runs=10"],
[
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`,
red(
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`
),
helpMessage,
],
],
[
["manifest path", "contract name", "path"],
["node", "app.js", "example", "counter", "--path=84:0"],
[
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`,
red(
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`
),
helpMessage,
],
],
Expand All @@ -161,7 +170,9 @@ describe("Command-line arguments handling", () => {
"--runs=10",
],
[
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`,
red(
`\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant.`
),
helpMessage,
],
],
Expand Down
18 changes: 13 additions & 5 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { EventEmitter } from "events";
import { checkProperties } from "./property";
import { checkInvariants } from "./invariant";
import {
getContractNameFromContractId,
getFunctionsFromContractInterfaces,
getSimnetDeployerContractsInterfaces,
} from "./shared";
import { issueFirstClassCitizenship } from "./citizen";
import { version } from "./package.json";
import { red } from "ansicolor";

const logger = (log: string, logLevel: "log" | "error" | "info" = "log") => {
console[logLevel](log);
Expand Down Expand Up @@ -42,7 +44,7 @@ const parseOptionalArgument = (argName: string) => {
export async function main() {
const radio = new EventEmitter();
radio.on("logMessage", (log) => logger(log));
radio.on("logFailure", (log) => logger(log, "error"));
radio.on("logFailure", (log) => logger(red(log), "error"));

const args = process.argv;
if (args.includes("--help")) {
Expand All @@ -55,7 +57,9 @@ export async function main() {
if (!manifestDir || manifestDir.startsWith("--")) {
radio.emit(
"logMessage",
"\nNo path to Clarinet project provided. Supply it immediately or face the relentless scrutiny of your contract's vulnerabilities."
red(
"\nNo path to Clarinet project provided. Supply it immediately or face the relentless scrutiny of your contract's vulnerabilities."
)
);
radio.emit("logMessage", helpMessage);
return;
Expand All @@ -66,7 +70,9 @@ export async function main() {
if (!sutContractName || sutContractName.startsWith("--")) {
radio.emit(
"logMessage",
"\nNo target contract name provided. Please provide the contract name to be fuzzed."
red(
"\nNo target contract name provided. Please provide the contract name to be fuzzed."
)
);
radio.emit("logMessage", helpMessage);
return;
Expand All @@ -76,7 +82,9 @@ export async function main() {
if (!type || type.startsWith("--") || !["test", "invariant"].includes(type)) {
radio.emit(
"logMessage",
"\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant."
red(
"\nInvalid type provided. Please provide the type of test to be executed. Possible values: test, invariant."
)
);
radio.emit("logMessage", helpMessage);
return;
Expand Down Expand Up @@ -110,7 +118,7 @@ export async function main() {
const rendezvousList = Array.from(
getSimnetDeployerContractsInterfaces(simnet).keys()
).filter((deployedContract) =>
[sutContractName].includes(deployedContract.split(".")[1])
[sutContractName].includes(getContractNameFromContractId(deployedContract))
);

const rendezvousAllFunctions = getFunctionsFromContractInterfaces(
Expand Down
14 changes: 9 additions & 5 deletions heatstroke.tests.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fc from "fast-check";
import { reporter } from "./heatstroke";
import { getContractNameFromRendezvousId } from "./invariant";
import { EventEmitter } from "events";
import { resolve } from "path";
import { initSimnet } from "@hirosystems/clarinet-sdk";
import { getContractNameFromContractId } from "./shared";

describe("Custom reporter logging", () => {
it("handles cases with missing path on failure for invariant testing type", async () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("Custom reporter logging", () => {
`\nError: Property failed after ${r.numRuns} tests.`,
`Seed : ${r.seed}`,
`\nCounterexample:`,
`- Contract : ${getContractNameFromRendezvousId(
`- Contract : ${getContractNameFromContractId(
rendezvousContractId
)}`,
`- Function : ${r.selectedFunction.name} (${r.selectedFunction.access})`,
Expand Down Expand Up @@ -235,7 +235,7 @@ describe("Custom reporter logging", () => {
`Seed : ${r.seed}`,
`Path : ${r.path}`,
`\nCounterexample:`,
`- Contract : ${getContractNameFromRendezvousId(
`- Contract : ${getContractNameFromContractId(
rendezvousContractId
)}`,
`- Function : ${r.selectedFunction.name} (${r.selectedFunction.access})`,
Expand Down Expand Up @@ -444,7 +444,9 @@ describe("Custom reporter logging", () => {
`\nError: Property failed after ${r.numRuns} tests.`,
`Seed : ${r.seed}`,
`\nCounterexample:`,
`- Test Contract : ${testContractId.split(".")[1]}`,
`- Test Contract : ${getContractNameFromContractId(
testContractId
)}`,
`- Test Function : ${r.selectedTestFunction.name} (${r.selectedTestFunction.access})`,
`- Arguments : ${JSON.stringify(r.functionArgsArb)}`,
`- Caller : ${r.testCaller[0]}`,
Expand Down Expand Up @@ -547,7 +549,9 @@ describe("Custom reporter logging", () => {
`Seed : ${r.seed}`,
`Path : ${r.path}`,
`\nCounterexample:`,
`- Test Contract : ${testContractId.split(".")[1]}`,
`- Test Contract : ${getContractNameFromContractId(
testContractId
)}`,
`- Test Function : ${r.selectedTestFunction.name} (${r.selectedTestFunction.access})`,
`- Arguments : ${JSON.stringify(r.functionArgsArb)}`,
`- Caller : ${r.testCaller[0]}`,
Expand Down
10 changes: 6 additions & 4 deletions heatstroke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* @property runDetails.error - The error thrown during the test.
*/

import { EventEmitter } from "events";
import { getContractNameFromRendezvousId } from "./invariant";
import { green } from "ansicolor";
import { EventEmitter } from "events";
import { getContractNameFromContractId } from "./shared";

export function reporter(
//@ts-ignore
Expand All @@ -51,7 +51,7 @@ export function reporter(
radio.emit("logFailure", `\nCounterexample:`);
radio.emit(
"logFailure",
`- Contract : ${getContractNameFromRendezvousId(
`- Contract : ${getContractNameFromContractId(
r.rendezvousContractId
)}`
);
Expand Down Expand Up @@ -101,7 +101,7 @@ export function reporter(
radio.emit("logFailure", `\nCounterexample:`);
radio.emit(
"logFailure",
`- Test Contract : ${r.testContractId.split(".")[1]}`
`- Test Contract : ${getContractNameFromContractId(r.testContractId)}`
);
radio.emit(
"logFailure",
Expand Down Expand Up @@ -138,9 +138,11 @@ export function reporter(
} else {
radio.emit(
"logMessage",
green(
`\nOK, ${
type === "invariant" ? "invariants" : "properties"
} passed after ${runDetails.numRuns} runs.\n`
)
);
}
}
34 changes: 3 additions & 31 deletions invariant.tests.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { initSimnet } from "@hirosystems/clarinet-sdk";
import { initializeClarityContext, initializeLocalContext } from "./invariant";
import {
getContractNameFromRendezvousId,
initializeClarityContext,
initializeLocalContext,
} from "./invariant";
import {
getContractNameFromContractId,
getFunctionsFromContractInterfaces,
getSimnetDeployerContractsInterfaces,
} from "./shared";
import { join } from "path";
import { issueFirstClassCitizenship } from "./citizen";
import { Cl } from "@stacks/transactions";
import fc from "fast-check";

describe("Simnet contracts operations", () => {
it("correctly initializes the local context for a given functions map", async () => {
Expand Down Expand Up @@ -48,7 +44,7 @@ describe("Simnet contracts operations", () => {
const rendezvousList = Array.from(
getSimnetDeployerContractsInterfaces(simnet).keys()
).filter((deployedContract) =>
["counter"].includes(deployedContract.split(".")[1])
["counter"].includes(getContractNameFromContractId(deployedContract))
);

const rendezvousAllFunctions = getFunctionsFromContractInterfaces(
Expand Down Expand Up @@ -97,27 +93,3 @@ describe("Simnet contracts operations", () => {
expect(actualContext).toEqual(expectedContext);
});
});

describe("Rendezvous contract name", () => {
it("gets contract name from Rendezvous contract name", () => {
const addressCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const contractNameCharset =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
fc.assert(
// Arrange
fc.property(
fc.stringOf(fc.constantFrom(...addressCharset)),
fc.stringOf(fc.constantFrom(...contractNameCharset)),
(address, contractName) => {
const rendezvousId = `${address}.${contractName}_rendezvous`;

// Act
const actual = getContractNameFromRendezvousId(rendezvousId);

// Assert
expect(actual).toBe(contractName);
}
)
);
});
});
Loading
Loading