-
Notifications
You must be signed in to change notification settings - Fork 677
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
Add unit tests in Clarity #4100
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3757a97
feat: add unit tests in clarity
friedger 6f3f983
chore: add log file for flow tests
friedger 7abb389
chore: push package-lock.json
friedger f77f32e
chore: add comments
friedger c5f9e4a
chore: improve code readability
friedger 748a330
chore: add more tests
friedger c85906d
Merge branch 'next' into feat/clarinet-flow-tests
friedger 3e9b3af
feat(tests): Add clarity-parser-string-to-cv.prop.test.ts property-ba…
moodmosaic 3420904
feat(tests): Add clarity-parser.prop.test.ts property-based tests
moodmosaic 1755973
Merge branch 'next' into feat/clarinet-flow-tests
friedger 35d51ea
Merge branch 'next' into feat/clarinet-flow-tests
friedger fedc750
Merge branch 'next' into feat/clarinet-flow-tests
friedger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,6 @@ npm-debug.log* | |
coverage | ||
*.info | ||
costs-reports.json | ||
node_modules | ||
node_modules | ||
*.log.txt | ||
history.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
contrib/core-contract-tests/contracts/bns-tests/bns_flow_test.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(define-constant ERR_NAMESPACE_NOT_FOUND 1005) | ||
|
||
;; @name: test delegation to wallet_2, stacking and revoking | ||
(define-public (test-name-registration) | ||
(begin | ||
;; @caller wallet_1 | ||
(unwrap! (contract-call? .bns name-preorder 0x0123456789abcdef01230123456789abcdef0123 u1000000) (err "name-preorder by wallet 1 should succeed")) | ||
;; @caller wallet_2 | ||
(unwrap! (contract-call? .bns name-preorder 0x30123456789abcdef01230123456789abcdef012 u1000000) (err "name-preorder by wallet 2 should succeed")) | ||
|
||
;; @mine-blocks-before 100 | ||
;; @caller wallet_1 | ||
(try! (register)) | ||
(ok true))) | ||
|
||
(define-public (register) | ||
(let ((result (contract-call? .bns name-register 0x123456 0x123456 0x123456 0x))) | ||
(asserts! (is-eq result (err ERR_NAMESPACE_NOT_FOUND)) (err "name-register should fail")) | ||
(ok true))) |
10 changes: 10 additions & 0 deletions
10
contrib/core-contract-tests/contracts/bns-tests/bns_test.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(define-constant ERR_NAMESPACE_NOT_FOUND 1005) | ||
|
||
;; @name: test preorder and publish with invalid names | ||
;; @caller: wallet_1 | ||
(define-public (test-name-registration) | ||
(begin | ||
(unwrap! (contract-call? .bns name-preorder 0x0123456789abcdef01230123456789abcdef0123 u1000000) (err "preorder should succeeed")) | ||
(let ((result (contract-call? .bns name-register 0x123456 0x123456 0x123456 0x))) | ||
(asserts! (is-eq result (err ERR_NAMESPACE_NOT_FOUND)) (err "registration should fail")) | ||
(ok true)))) |
13 changes: 13 additions & 0 deletions
13
contrib/core-contract-tests/contracts/parser-tests/all-annotations.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
;; @name all annotation test | ||
;; @description all annotation test | ||
;; @mine-before 10 | ||
;; @caller wallet_1 | ||
(define-public (test-all-annotations-1) | ||
(ok true)) | ||
|
||
;; @name all annotation test 2 | ||
;; @description all annotation test 2 | ||
;; @mine-before 20 | ||
;; @caller wallet_2 | ||
(define-public (test-all-annotations-2) | ||
(ok true)) |
5 changes: 5 additions & 0 deletions
5
contrib/core-contract-tests/contracts/parser-tests/bad-annotations.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
;; @namexx bad annotation test | ||
;; @mine-after 10 | ||
;; @callerxx wallet_1 | ||
(define-public (test-bad-annotations) | ||
(ok false)) |
12 changes: 12 additions & 0 deletions
12
contrib/core-contract-tests/contracts/parser-tests/bad-flow.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
;;@name bad annotation flow test | ||
(define-public (test-bad-flow) | ||
(begin | ||
;; @caller wallet_1 | ||
(try! (my-test-function)) | ||
(unwrap! (contract-call? invalid-syntax)) | ||
(unwrap! (contract-call? .bns)) | ||
(ok true))) | ||
|
||
|
||
(define-private (my-test-function) | ||
(ok true)) |
2 changes: 2 additions & 0 deletions
2
contrib/core-contract-tests/contracts/parser-tests/no-annotations.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(define-public (test-no-annotations) | ||
(ok true)) |
4 changes: 4 additions & 0 deletions
4
contrib/core-contract-tests/contracts/parser-tests/simple-annotations.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
;; @name simple annotation test | ||
(define-public (test-simple-annotations) | ||
;; @mine-before is ignored here | ||
(ok true)) |
11 changes: 11 additions & 0 deletions
11
contrib/core-contract-tests/contracts/parser-tests/simple-flow.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
;;@name simple flow test | ||
(define-public (test-simple-flow) | ||
(begin | ||
;; @caller wallet_1 | ||
(try! (my-test-function)) | ||
;; @caller wallet_2 | ||
(unwrap! (contract-call? .bns name-resolve 0x 0x)) | ||
(ok true))) | ||
|
||
(define-public (my-test-function) | ||
(ok true)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future PR I think it's doable (and a bit challenging too) to enable tests with parameters, to run those tests also as fuzz tests:
The tricky part might be the extra work around regexes, though the heavily lifting part around fast-check shouldn't be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can specify parameter testing / fuzzing with annotations. The regexes originally came from a concept implementation to enable us to write Clarity tests in Clarity. After that, they were good enough so we just left it. If we want to make it more robust we will need to switch to a LISP interpreter, should not be too hard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can sort this part out, I can integrate this with fast-check and we'll have it generate/fuzz everything for us. What's very nice about this is the shrinking part; if there's a bug/edge-case detected, fast-check will give us the minimum counterexample and a seed to reproduce the failure (if the bug/edge-case is detected when running on CI).