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

Feat: add @clarigen/test library for writing unit tests with Clarinet SDK. #37

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
9 changes: 9 additions & 0 deletions .changeset/brave-camels-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'demo-project': patch
'@clarigen/test': patch
'@clarigen/core': patch
'@clarigen/node': patch
'@clarigen/web': patch
---

Fixed a bug in `cvToValue` when changing tuples with responses in values
9 changes: 9 additions & 0 deletions .changeset/early-pets-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'demo-project': patch
'@clarigen/test': patch
'@clarigen/core': patch
'@clarigen/node': patch
'@clarigen/web': patch
---

Include missing built files
9 changes: 9 additions & 0 deletions .changeset/four-hotels-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'demo-project': patch
'@clarigen/test': patch
'@clarigen/core': patch
'@clarigen/node': patch
'@clarigen/web': patch
---

Adds raw clarity parsing capabilities to `core` and more helper functions to `test`
9 changes: 9 additions & 0 deletions .changeset/lucky-foxes-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'demo-project': patch
'@clarigen/test': patch
'@clarigen/core': patch
'@clarigen/node': patch
'@clarigen/web': patch
---

Export utils from `test`
9 changes: 9 additions & 0 deletions .changeset/many-donuts-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'demo-project': patch
'@clarigen/test': patch
'@clarigen/core': patch
'@clarigen/node': patch
'@clarigen/web': patch
---

Fixes `toCamelCase` to handle UPPER_CASE format
6 changes: 6 additions & 0 deletions .changeset/metal-vans-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'demo-project': patch
'@clarigen/test': patch
---

Created a new `@clarigen/test` package, which uses `@hirosystems/clarinet-sdk`
20 changes: 20 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"demo-project": "1.0.15",
"@clarigen/test": "1.0.15",
"@clarigen/core": "1.0.15",
"@clarigen/node": "1.0.15",
"@clarigen/web": "1.0.15"
},
"changesets": [
"brave-camels-sniff",
"early-pets-sip",
"four-hotels-invite",
"lucky-foxes-flow",
"many-donuts-carry",
"metal-vans-own",
"tough-forks-wave"
]
}
9 changes: 9 additions & 0 deletions .changeset/tough-forks-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'demo-project': patch
'@clarigen/test': patch
'@clarigen/core': patch
'@clarigen/node': patch
'@clarigen/web': patch
---

Improves types in `test` package
9 changes: 9 additions & 0 deletions .changeset/wise-rabbits-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'demo-project': patch
'@clarigen/test': patch
'@clarigen/core': patch
'@clarigen/node': patch
'@clarigen/web': patch
---

Fix: invalid build of previous release
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
"packages/cli/tmp/tests/deno",
"packages/core/dist/deno",
"demo-project/test-runner.ts"
]
],
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"deprecated": true
}
}
46 changes: 46 additions & 0 deletions demo-project/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
# demo-project

## 1.0.16-alpha.6

### Patch Changes

- [#37](https://github.com/mechanismHQ/clarigen/pull/37) [`f63a739`](https://github.com/mechanismHQ/clarigen/commit/f63a73930d80bddb83f1ec18e886a5c738e3a8ef) Thanks [@hstove](https://github.com/hstove)! - Fixed a bug in `cvToValue` when changing tuples with responses in values

## 1.0.16-alpha.5

### Patch Changes

- [#37](https://github.com/mechanismHQ/clarigen/pull/37) [`ac1ef2f`](https://github.com/mechanismHQ/clarigen/commit/ac1ef2ffa39dcb580693694b6c98d15194f07910) Thanks [@hstove](https://github.com/hstove)! - Fixes `toCamelCase` to handle UPPER_CASE format

## 1.0.16-alpha.4

### Patch Changes

- [`b969418`](https://github.com/mechanismHQ/clarigen/commit/b9694186e7b9a07368d75b46a66dcfdb1f9357d7) Thanks [@hstove](https://github.com/hstove)! - Improves types in `test` package

## 1.0.16-alpha.3

### Patch Changes

- [`911cc06`](https://github.com/mechanismHQ/clarigen/commit/911cc06c8f293d53c29e2cd5e16eff38a7762053) Thanks [@hstove](https://github.com/hstove)! - Include missing built files

## 1.0.16-alpha.2

### Patch Changes

- [`9a863ad`](https://github.com/mechanismHQ/clarigen/commit/9a863adcb5c94582e369181f2a8773078416f4f4) Thanks [@hstove](https://github.com/hstove)! - Export utils from `test`

## 1.0.16-alpha.1

### Patch Changes

- [`1e52fd6`](https://github.com/mechanismHQ/clarigen/commit/1e52fd6b8278feec80961dcdd1f34ddf393a132f) Thanks [@hstove](https://github.com/hstove)! - Adds raw clarity parsing capabilities to `core` and more helper functions to `test`

## 1.0.16-alpha.0

### Patch Changes

- Created a new `@clarigen/test` package, which uses `@hirosystems/clarinet-sdk`

- Updated dependencies []:
- @clarigen/[email protected]
- @clarigen/[email protected]

## 1.0.15

## 1.0.14
Expand Down
26 changes: 26 additions & 0 deletions demo-project/Clarigen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Set to your project's Clarinet config file
clarinet = "./Clarinet.toml"

# Set where you'd like Deno types output.
# Comment or remove section to skip Deno types
# [deno]
# `output` can be a directory or a folder.
# output = "artifacts/clarigen.ts"

# Set where you'd like ESM types output.
# Comment or remove section to skip ESM types
[esm]
# `output` can be a directory or a folder.
output = "esm/index.ts"

# `esm.after` - script to run after ESM types are generated.
# examples:
after = "pnpm prettier -w ./esm/index.ts"
# after = "echo 'yay'"

# Set where you'd like generated contract docs
# Generate docs by running `clarigen docs`
# [docs]
# `output` should be a folder
# output = "docs"
3 changes: 3 additions & 0 deletions demo-project/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ contract_id = "SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin"
[contracts.tester]
path = "contracts/tester.clar"

[contracts.counter]
path = "contracts/counter.clar"

[repl.analysis]
passes = []
check_checker = { trusted_sender = false, trusted_caller = false, callee_filter = false }
Expand Down
43 changes: 43 additions & 0 deletions demo-project/contracts/counter.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
;; The counter contract maintains a single global counter
;; variable. Users can change the counter by calling
;; `increment` and `decrement`.

;; The variable used to hold the global counter.
(define-data-var counter uint u1)

;; Get the current counter
(define-read-only (get-counter)
(var-get counter)
)

;; (define-constant test-buff (buff-to-uint-be 0xdeadbeef))
;; (define-constant buff-const 0xdeadbeef)
;; (define-constant ERR_TEST (err u123))

;; Increment the counter.
;;
;; @returns the new value of the counter
;;
;; @param step; The interval to increase the counter by
(define-public (increment (step uint))
(let (
(new-val (+ step (var-get counter)))
)
;; #[allow(unchecked_data)]
(var-set counter new-val)
(print { object: "counter", action: "incremented", value: new-val })
(ok new-val))
)

;; Decrement the counter
;;
;; @param step; The interval to increase the counter by
(define-public (decrement (step uint))
(let (
(new-val (- (var-get counter) step))
)
;; #[allow(unchecked_data)]
(var-set counter new-val)
(print { object: "counter", action: "decremented", value: new-val })
(ok new-val))
)
Loading
Loading