Skip to content

Commit d89e32e

Browse files
committed
fix: use correct annotation object
1 parent 22678a9 commit d89e32e

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

example/tests/my-contract_test.clar

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
)
99

10+
;; @caller 'ST000000000000000000002AMW42H
1011
(define-public (test-a-times-b2)
1112
(begin
1213
(asserts! (is-eq (ok u108) (contract-call? .my-contract a-times-b u9 u12))

src/clarunit-generator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ export function generateUnitTests(simnet: Simnet) {
5656
delete functionAnnotations.prepare;
5757

5858
// handle caller address for this test
59-
const callerAddress = functionAnnotations.caller
60-
? annotations.caller[0] === "'"
61-
? `${(annotations.caller as string).substring(1)}`
62-
: accounts.get(annotations.caller)!
59+
const callerAddress = functionAnnotations.caller && typeof functionAnnotations.caller === "string"
60+
? functionAnnotations.caller[0] === "'"
61+
? `${(functionAnnotations.caller as string).substring(1)}`
62+
: accounts.get(functionAnnotations.caller)!
6363
: accounts.get("deployer")!;
6464

6565
if (functionAnnotations.prepare) {

tests/clarity-parser-flow.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ describe("verify clarity parser for flow tests", () => {
5353
functionName: "allow-contract-caller",
5454
},
5555
});
56+
expect(callInfos["test-simple-flow"][3]).toEqual({
57+
callAnnotations: { caller: "'ST000000000000000000002AMW42H" },
58+
callInfo: {
59+
args: [],
60+
contractName: "",
61+
functionName: "my-test-function",
62+
},
63+
});
5664
});
5765

5866
it("should parse flow test with bad annotations", () => {

tests/clarity-parser.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ describe("verify clarity parser", () => {
4646
"mine-before": "20",
4747
name: "all annotation test 2",
4848
});
49+
50+
expect(result["test-all-annotations-3"]).toEqual({
51+
caller: "'ST000000000000000000002AMW42H",
52+
});
4953
});
5054

5155
it("should parse with bad annotations", () => {

tests/contracts/parser-tests/all-annotations.clar

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
;; @mine-before 20
1111
;; @caller wallet_2
1212
(define-public (test-all-annotations-2)
13+
(ok true))
14+
15+
;; @caller 'ST000000000000000000002AMW42H
16+
(define-public (test-all-annotations-3)
1317
(ok true))

tests/contracts/parser-tests/simple-flow.clar

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
(try! (my-test-function2))
88
;; @caller wallet_1
99
(unwrap! (contract-call? 'ST000000000000000000002AMW42H.pox-4 allow-contract-caller .pox4-self-service-multi none) (err "allow-contract-caller failed"))
10+
;; @caller 'ST000000000000000000002AMW42H
11+
(try! (my-test-function))
1012
(ok true)))
1113

1214
(define-public (my-test-function)

0 commit comments

Comments
 (0)