-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initialize clarinet-sdk with the test-core js lib
- Loading branch information
1 parent
1ff5c13
commit 69d6449
Showing
17 changed files
with
1,994 additions
and
7 deletions.
There are no files selected for viewing
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
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
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,3 @@ | ||
dist/ | ||
pkg/ | ||
node_modules/ |
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,77 @@ | ||
# Clarinet SDK | ||
|
||
## Core testing lib | ||
|
||
This a very early preview. | ||
Expect many breaking changes in the API. | ||
|
||
```js | ||
// @ts-check | ||
|
||
import { main } from "obscurity-sdk"; | ||
import { before, describe, it } from "node:test"; | ||
import assert from "node:assert/strict"; | ||
import { Cl } from "@stacks/transactions"; | ||
|
||
describe("test counter", () => { | ||
const contract = "counter"; | ||
const cost = 1000000n; | ||
let deployer; | ||
let contract_addr; | ||
let sender; | ||
/** @type import("obscurity-sdk").Session */ | ||
let session; | ||
|
||
before(async () => { | ||
session = await main(); | ||
await session.initSession(process.cwd(), "./Clarinet.toml"); | ||
|
||
const accounts = session.getAccounts(); | ||
deployer = accounts.get("deployer"); | ||
contract_addr = `${deployer}.${contract}`; | ||
sender = accounts.get("wallet_1"); | ||
}); | ||
|
||
it("gets counter value", () => { | ||
const res = session.callReadOnlyFn(contract, "get-counter", [], sender); | ||
|
||
assert.deepEqual(res.result, Cl.int(0)); | ||
assert.equal(session.blockHeight, 1); | ||
}); | ||
|
||
it("increments counter value", () => { | ||
const stxBefore = session.getAssetsMap().get("STX"); | ||
|
||
const res = session.callPublicFn(contract, "increment", [], sender); | ||
|
||
assert.equal(res.events.length, 2); | ||
const printEvent = res.events[0]; | ||
assert.equal(printEvent.event, "print_event"); | ||
const stxTransferEvent = res.events[1]; | ||
assert.equal(stxTransferEvent.event, "stx_transfer_event"); | ||
assert.equal(stxTransferEvent.data.amount, cost.toString()); | ||
|
||
assert.deepEqual(res.result, Cl.ok(Cl.bool(true))); | ||
assert.equal(session.blockHeight, 2); | ||
|
||
let counter = session.callReadOnlyFn(contract, "get-counter", [], sender); | ||
assert.deepEqual(counter.result, Cl.int(1)); | ||
|
||
const stxAfter = session.getAssetsMap().get("STX"); | ||
// @ts-ignore | ||
assert.equal(stxAfter?.get(sender), stxBefore?.get(sender) - cost); | ||
// @ts-ignore | ||
assert.equal(stxAfter?.get(contract_addr), cost); | ||
}); | ||
|
||
it("add any value", () => { | ||
const addRes = session.callPublicFn(contract, "add", [Cl.int(10)], sender); | ||
assert.deepEqual(addRes.result, Cl.ok(Cl.bool(true))); | ||
assert.equal(session.blockHeight, 3); | ||
|
||
let res = session.callReadOnlyFn(contract, "get-counter", [], sender); | ||
assert.deepEqual(res.result, Cl.int(11)); | ||
assert.equal(session.blockHeight, 3); | ||
}); | ||
}); | ||
``` |
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,65 @@ | ||
[package] | ||
edition = "2021" | ||
name = "clarinet-sdk" | ||
version = "0.0.1" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
name = "clarinet_sdk" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
serde = { version = "1.0.136", features = ["derive"] } | ||
serde_json = "1.0" | ||
clarinet-files = { path = "../clarinet-files", default-features = false } | ||
clarity-repl = { path = "../clarity-repl", default-features = false, optional = true } | ||
clarinet-deployments = { path = "../clarinet-deployments", default-features = false } | ||
|
||
# WASM | ||
console_error_panic_hook = { version = "0.1", optional = true } | ||
js-sys = { version = "0.3", optional = true } | ||
serde-wasm-bindgen = { version = "0.5", optional = true } | ||
wasm-bindgen = { version = "0.2", optional = true } | ||
wasm-bindgen-futures = { version = "0.4", optional = true } | ||
web-sys = { version = "0.3", features = ["console"], optional = true } | ||
|
||
[features] | ||
default = ["wasm"] | ||
wasm = [ | ||
"wasm-bindgen", | ||
"wasm-bindgen-futures", | ||
"serde-wasm-bindgen", | ||
"js-sys", | ||
"web-sys", | ||
"console_error_panic_hook", | ||
"clarinet-deployments/wasm", | ||
"clarity-repl/wasm", | ||
"clarinet-files/wasm", | ||
] | ||
|
||
[package.metadata.wasm-pack.profile.dev] | ||
wasm-opt = ['-O1'] | ||
|
||
[package.metadata.wasm-pack.profile.dev.wasm-bindgen] | ||
debug-js-glue = true | ||
demangle-name-section = true | ||
dwarf-debug-info = false | ||
|
||
[package.metadata.wasm-pack.profile.profiling] | ||
wasm-opt = ['-O'] | ||
|
||
[package.metadata.wasm-pack.profile.profiling.wasm-bindgen] | ||
debug-js-glue = false | ||
demangle-name-section = true | ||
dwarf-debug-info = false | ||
|
||
[package.metadata.wasm-pack.profile.release] | ||
# -04 aggressively optimizes for speed | ||
wasm-opt = false | ||
# -0z aggressively optimizes for size | ||
# wasm-opt = ['-Oz'] | ||
|
||
[package.metadata.wasm-pack.profile.release.wasm-bindgen] | ||
debug-js-glue = false | ||
demangle-name-section = true | ||
dwarf-debug-info = false |
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 @@ | ||
{ | ||
"folders": [{ "path": "../../" }], | ||
"settings": { | ||
"rust-analyzer.check.overrideCommand": [ | ||
"cargo", | ||
"check", | ||
"--no-default-features", | ||
"--package=clarinet-sdk", | ||
"--features=wasm", | ||
"--message-format=json" | ||
] | ||
} | ||
} |
Oops, something went wrong.