Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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
8 changes: 4 additions & 4 deletions src/clarunit-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ 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)!
const callerAddress = functionAnnotations.caller && typeof functionAnnotations.caller === "string"
? functionAnnotations.caller[0] === "'"
? `${(functionAnnotations.caller as string).substring(1)}`
: accounts.get(functionAnnotations.caller)!
: accounts.get("deployer")!;

if (functionAnnotations.prepare) {
Expand Down
8 changes: 8 additions & 0 deletions tests/clarity-parser-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ describe("verify clarity parser for flow tests", () => {
functionName: "allow-contract-caller",
},
});
expect(callInfos["test-simple-flow"][3]).toEqual({
callAnnotations: { caller: "'ST000000000000000000002AMW42H" },
callInfo: {
args: [],
contractName: "",
functionName: "my-test-function",
},
});
});

it("should parse flow test with bad annotations", () => {
Expand Down
4 changes: 4 additions & 0 deletions tests/clarity-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ describe("verify clarity parser", () => {
"mine-before": "20",
name: "all annotation test 2",
});

expect(result["test-all-annotations-3"]).toEqual({
caller: "'ST000000000000000000002AMW42H",
});
});

it("should parse with bad annotations", () => {
Expand Down
4 changes: 4 additions & 0 deletions tests/contracts/parser-tests/all-annotations.clar
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
;; @mine-before 20
;; @caller wallet_2
(define-public (test-all-annotations-2)
(ok true))

;; @caller 'ST000000000000000000002AMW42H
(define-public (test-all-annotations-3)
(ok true))
2 changes: 2 additions & 0 deletions tests/contracts/parser-tests/simple-flow.clar
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
(try! (my-test-function2))
;; @caller wallet_1
(unwrap! (contract-call? 'ST000000000000000000002AMW42H.pox-4 allow-contract-caller .pox4-self-service-multi none) (err "allow-contract-caller failed"))
;; @caller 'ST000000000000000000002AMW42H
(try! (my-test-function))
(ok true)))

(define-public (my-test-function)
Expand Down