Skip to content

Commit

Permalink
feat: update @hirosystems/clarinet-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Sep 4, 2024
1 parent b5fca43 commit c0c0386
Show file tree
Hide file tree
Showing 25 changed files with 1,130 additions and 212 deletions.
12 changes: 12 additions & 0 deletions .changeset/little-foxes-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'demo-project': minor
'clarigen-docs': minor
'@clarigen/test': minor
'@clarigen/cli': minor
'@clarigen/boot': minor
'@clarigen/core': minor
'@clarigen/node': minor
'@clarigen/web': minor
---

Updates `@hirosystems/clarinet-sdk` to work with Clarity version 3
4 changes: 4 additions & 0 deletions demo-project/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ contract_id = "SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin"

[contracts.tester]
path = "contracts/tester.clar"
clarity_version = 3
epoch = 3.0

[contracts.counter]
path = "contracts/counter.clar"
clarity_version = 3
epoch = 3.0

[repl.analysis]
passes = []
Expand Down
9 changes: 6 additions & 3 deletions demo-project/deployments/default.simnet-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ plan:
emulated-sender: SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR
path: ".requirements/requirements/SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin.clar"
clarity-version: 1
epoch: "2.1"
- id: 1
transactions:
- emulated-contract-publish:
contract-name: counter
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/counter.clar
clarity-version: 1
clarity-version: 3
- emulated-contract-publish:
contract-name: tester
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/tester.clar
clarity-version: 1
epoch: "2.1"
clarity-version: 3
epoch: "3.0"
8 changes: 4 additions & 4 deletions demo-project/esm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ export const contracts = {
},
non_fungible_tokens: [],
fungible_tokens: [],
epoch: 'Epoch21',
clarity_version: 'Clarity1',
epoch: 'Epoch30',
clarity_version: 'Clarity3',
contractName: 'counter',
},
ftTrait: {
Expand Down Expand Up @@ -603,8 +603,8 @@ export const contracts = {
},
],
fungible_tokens: [{ name: 'ft' }],
epoch: 'Epoch21',
clarity_version: 'Clarity1',
epoch: 'Epoch30',
clarity_version: 'Clarity3',
contractName: 'tester',
},
} as const;
Expand Down
10 changes: 6 additions & 4 deletions demo-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"import": "./dist/index.mjs",
"type": "module",
"dependencies": {
"@clarigen/boot": "workspace:*",
"@clarigen/core": "workspace:*",
"@clarigen/test": "workspace:*",
"@hirosystems/clarinet-sdk": "2.6.0",
"@hirosystems/clarinet-sdk-wasm": "2.6.0",
"@hirosystems/clarinet-sdk": "2.8.0",
"@hirosystems/clarinet-sdk-wasm": "2.8.0",
"@stacks/transactions": "^6.13.1",
"vitest-environment-clarinet": "^1.1.0"
},
"devDependencies": {
"@types/node": "20.10.4",
"vitest": "1.0.4",
"vitest-environment-clarinet": "^1.1.0"
"vite": "^5.1.4",
"vitest": "1.3.1",
"vitest-environment-clarinet": "2.0.0"
}
}
4 changes: 2 additions & 2 deletions docs-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"dependencies": {
"@clarigen/cli": "workspace:*",
"@clarigen/core": "workspace:*",
"@hirosystems/clarinet-sdk": "^2.5.0",
"@hirosystems/clarinet-sdk-wasm": "2.6.0",
"@hirosystems/clarinet-sdk": "2.8.0",
"@hirosystems/clarinet-sdk-wasm": "2.8.0",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.5",
Expand Down
10 changes: 6 additions & 4 deletions packages/clarigen-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
"prettier": "@stacks/prettier-config",
"name": "@clarigen/test",
"author": "Hank Stoever",
"type": "module",
"devDependencies": {
"@types/node": "20.10.4",
"vitest": "1.0.4",
"vitest-environment-clarinet": "^1.1.0",
"vite": "^5.1.4",
"vitest": "1.3.1",
"vitest-environment-clarinet": "2.0.0",
"typescript": "5.4.5"
},
"dependencies": {
"@clarigen/core": "workspace:*",
"@hirosystems/clarinet-sdk": "2.6.0",
"@hirosystems/clarinet-sdk-wasm": "2.6.0",
"@hirosystems/clarinet-sdk": "2.8.0",
"@hirosystems/clarinet-sdk-wasm": "2.8.0",
"@stacks/transactions": "6.13.0"
},
"publishConfig": {
Expand Down
6 changes: 5 additions & 1 deletion packages/clarigen-test/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { vitestSetupFilePath, getClarinetVitestsArgv } from '@hirosystems/clarin
export default defineConfig({
test: {
environment: 'clarinet', // use vitest-environment-clarinet
singleThread: true,
pool: "forks",
poolOptions: {
threads: { singleThread: true },
forks: { singleFork: true },
},
setupFiles: [
vitestSetupFilePath,
// custom setup files can be added here
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"dependencies": {
"@antfu/ni": "^0.21.12",
"@clarigen/core": "workspace:*",
"@hirosystems/clarinet-sdk": "2.6.0",
"@hirosystems/clarinet-sdk-wasm": "2.6.0",
"@hirosystems/clarinet-sdk": "2.8.0",
"@hirosystems/clarinet-sdk-wasm": "2.8.0",
"@iarna/toml": "^2.2.5",
"@stacks/transactions": "6.13.1",
"chokidar": "^3.6.0",
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/clarinet-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
MAINNET_BURN_ADDRESS,
TESTNET_BURN_ADDRESS,
getContractName,
hexToCvValue,
} from '@clarigen/core';
import { ClarityType, ClarityValue } from '@stacks/transactions';

Expand All @@ -18,14 +19,15 @@ export async function getSession(config: Config): Promise<SessionWithVariables>
const accounts = simnet.getAccounts();

const allAccounts = [...accounts.entries()].map(([name, address]) => {
const result = simnet.runSnippet(`(stx-get-balance '${address})`) as ClarityValue;
if (result.type !== ClarityType.UInt) {
throw new Error(`Unexpected result type for \`(stx-get-balance \``);
const result = simnet.runSnippet(`(stx-get-balance '${address})`) as string;
const resultCV = hexToCvValue<bigint>(result);
if (typeof resultCV !== 'bigint') {
throw new Error(`Unexpected result type for \`(stx-get-balance \`, got ${resultCV}`);
}
return {
name,
address,
balance: result.value.toString(),
balance: resultCV.toString(),
};
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/generated/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is automatically generated from the
// version in `package.json`

export const version = '2.0.4';
export const version = '2.0.5';
13 changes: 13 additions & 0 deletions packages/cli/test/dependencies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DefaultCommand } from '../src/commands/default-command';
import { getSession } from '../src/clarinet-sdk';
import { test, describe, expect } from 'vitest';
import { Config } from '../src/config';

test('getting a session with a project that has testnet requirements', async () => {
const config = await Config.load('./test/dependencies');
// console.log('config', config);
const session = await getSession(config);
const testContract = session.contracts.find(c => c.contract_id.endsWith('.TB-test-3'));
expect(testContract).toBeDefined();
// console.log('session', session);
});
4 changes: 4 additions & 0 deletions packages/cli/test/dependencies/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

tests/** linguist-vendored
vitest.config.js linguist-vendored
* text=lf
13 changes: 13 additions & 0 deletions packages/cli/test/dependencies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

**/settings/Mainnet.toml
**/settings/Testnet.toml
.cache/**
history.txt

logs
*.log
npm-debug.log*
coverage
*.info
costs-reports.json
node_modules
4 changes: 4 additions & 0 deletions packages/cli/test/dependencies/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

{
"files.eol": "\n"
}
19 changes: 19 additions & 0 deletions packages/cli/test/dependencies/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

{
"version": "2.0.0",
"tasks": [
{
"label": "check contracts",
"group": "test",
"type": "shell",
"command": "clarinet check"
},
{
"type": "npm",
"script": "test",
"group": "test",
"problemMatcher": [],
"label": "npm test"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

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

# Set where you'd like ESM types output.
# Comment or remove section to skip ESM types
Expand All @@ -9,20 +9,17 @@ clarinet = "../../demo-project/Clarinet.toml"
# output = "esm/index.ts"
# output = "test/generated/clarigen-types.ts"
outputs = [
"test/generated/clarigen-types.ts",
"../core/test/generated/clarigen-types.ts",
"../../demo-project/esm/index.ts",
"../clarigen-test/test/generated/clarigen-types.ts",
"src/clarigen-types.ts"
]

# `esm.after` - script to run after ESM types are generated.
# examples:
after = "pnpm prettier --loglevel error -w ../*/test/generated/clarigen-types.ts ../../demo-project/esm/index.ts"
# after = "pnpm prettier --loglevel error -w ../*/test/generated/clarigen-types.ts ../../demo-project/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 = "../../demo-project/docs"
after = "pnpm prettier --loglevel error -w ../../demo-project/docs"
output = "./docs"
# after = "pnpm prettier --loglevel error -w ../../demo-project/docs"
31 changes: 31 additions & 0 deletions packages/cli/test/dependencies/Clarinet.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[project]
name = 'dependency-test'
description = 'dependency-test'
authors = []
telemetry = true
cache_dir = './.cache'

# [[project.requirements]]
# contract_id = 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2'

# [[project.requirements]]
# contract_id = 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1'

# [[project.requirements]]
# contract_id = 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-pnau-decoder-v1'

[[project.requirements]]
contract_id = 'ST3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3PXDYJG.TB-test-3'

[repl]
clarity_wasm_mode = false
show_timings = false

[repl.analysis]
# passes = ['check_checker']

[repl.analysis.check_checker]
strict = false
trusted_sender = false
trusted_caller = false
callee_filter = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
id: 0
name: "Simulated deployment, used as a default for `clarinet console`, `clarinet test` and `clarinet check`"
network: simnet
genesis:
wallets:
- name: deployer
address: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
balance: "100000000000000"
- name: faucet
address: STNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2CMMMAZ6
balance: "100000000000000"
- name: wallet_1
address: ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5
balance: "100000000000000"
- name: wallet_2
address: ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG
balance: "100000000000000"
- name: wallet_3
address: ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC
balance: "100000000000000"
- name: wallet_4
address: ST2NEB84ASENDXKYGJPQW86YXQCEFEX2ZQPG87ND
balance: "100000000000000"
- name: wallet_5
address: ST2REHHS5J3CERCRBEPMGH7921Q6PYKAADT7JP2VB
balance: "100000000000000"
- name: wallet_6
address: ST3AM1A56AK2C1XAFJ4115ZSV26EB49BVQ10MGCS0
balance: "100000000000000"
- name: wallet_7
address: ST3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXEP8YGKJ
balance: "100000000000000"
- name: wallet_8
address: ST3NBRSFKX28FQ2ZJ1MAKX58HKHSDGNV5N7R21XCP
balance: "100000000000000"
contracts:
- costs
- pox
- pox-2
- pox-3
- pox-4
- lockup
- costs-2
- costs-3
- cost-voting
- bns
plan:
batches:
- id: 0
transactions:
- emulated-contract-publish:
contract-name: commission-trait
emulated-sender: ST3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3PXDYJG
path: "./.cache/requirements/ST3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3PXDYJG.commission-trait.clar"
clarity-version: 1
- emulated-contract-publish:
contract-name: sip-09
emulated-sender: ST3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3PXDYJG
path: "./.cache/requirements/ST3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3PXDYJG.sip-09.clar"
clarity-version: 1
- emulated-contract-publish:
contract-name: TB-test-3
emulated-sender: ST3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3PXDYJG
path: "./.cache/requirements/ST3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3PXDYJG.TB-test-3.clar"
clarity-version: 1
epoch: "2.1"
Loading

0 comments on commit c0c0386

Please sign in to comment.