diff --git a/packages/client/package.json b/packages/client/package.json index 9cf70ae..b15a93b 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -20,7 +20,7 @@ "build": "tsup", "generate:openapi": "pnpm -r build:openapi && pnpm openapi -i ./tmp/openapi.yaml -c axios -o src/generated --name BNS --useUnionTypes", "generate:zwj-regex": "pnpm tsx scripts/serialize-emoji.ts", - "test": "vitest" + "test": "vitest run" }, "dependencies": { "@adraffy/punycode": "^1.2.0", @@ -33,17 +33,16 @@ "micro-stacks": "^1.1.4" }, "devDependencies": { - "@types/jest": "^29.2.4", "@types/regenerate": "^1.4.1", "@unicode/unicode-15.0.0": "^1.3.1", "emoji-regex": "^10.2.1", - "jest": "^29.3.1", "openapi-typescript-codegen": "^0.23.0", "regenerate": "^1.4.2", "ts-jest": "^29.0.3", "tsup": "^6.7.0", "tsx": "^3.12.3", "typescript": "4.9.5", + "vitest": "^0.31.0", "zod": "3.20.6" } } diff --git a/packages/client/tests/api-client.test.ts b/packages/client/tests/api-client.test.ts index 8745c30..d8a2dae 100644 --- a/packages/client/tests/api-client.test.ts +++ b/packages/client/tests/api-client.test.ts @@ -1,4 +1,5 @@ import { BnsApiClient } from '../src'; +import { expect, test } from 'vitest'; const api = new BnsApiClient(); diff --git a/packages/client/tests/contracts.test.ts b/packages/client/tests/contracts.test.ts index ed3a558..a39cd49 100644 --- a/packages/client/tests/contracts.test.ts +++ b/packages/client/tests/contracts.test.ts @@ -1,5 +1,6 @@ import { asciiToBytes } from 'micro-stacks/common'; import { BnsContractsClient, hashFqn, randomSalt } from '../src'; +import { expect, test } from 'vitest'; const client = new BnsContractsClient('devnet'); const core = client.bnsCore; diff --git a/packages/client/tests/pricing.test.ts b/packages/client/tests/pricing.test.ts new file mode 100644 index 0000000..5e45d2f --- /dev/null +++ b/packages/client/tests/pricing.test.ts @@ -0,0 +1,36 @@ +import { test, expect } from 'vitest'; +import { BnsContractsClient } from '../src'; +import { ALL_NAMESPACES, computeNamePrice } from '@bns-x/core'; + +const validAsciiCharsStr = 'abcdefghijklmnopqrstuvwxyz0123456789-_'; +export const validAsciiChars = validAsciiCharsStr.split(''); + +const maxAsciiSize = 48; +export function randomName({ + length, + allowInvalid, +}: { + length?: number; + allowInvalid?: boolean; +} = {}) { + const len = length || Math.floor(Math.random() * maxAsciiSize + 1); + let name = ''; + for (let i = 0; i < len; i++) { + const charIndex = Math.floor(Math.random() * validAsciiChars.length); + const char = validAsciiChars[charIndex]; + name += char; + } + return name; +} + +const client = new BnsContractsClient('mainnet'); + +test('stx pricing is correct', async () => { + const numTests = 10; + for (let i = 0; i < numTests; i++) { + const name = randomName(); + const price = computeNamePrice(name, 'stx'); + const realPrice = await client.computeNamePrice(name, 'stx'); + expect(realPrice).toEqual(price); + } +}); diff --git a/packages/client/tests/wrapper.test.ts b/packages/client/tests/wrapper.test.ts index afcfe24..d25e588 100644 --- a/packages/client/tests/wrapper.test.ts +++ b/packages/client/tests/wrapper.test.ts @@ -1,4 +1,5 @@ import { BnsContractsClient } from '../src/index'; +import { expect, test } from 'vitest'; test('works for different environments', () => { process.env.NEXT_PUBLIC_NETWORK_KEY = ''; diff --git a/packages/client/tests/zonefile.test.ts b/packages/client/tests/zonefile.test.ts index 297b7cd..591005d 100644 --- a/packages/client/tests/zonefile.test.ts +++ b/packages/client/tests/zonefile.test.ts @@ -1,4 +1,5 @@ import { ZoneFile } from '../src/zonefile'; +import { expect, test, describe } from 'vitest'; const _zonefileRaw = '$ORIGIN hank.btc.\n$TTL 3600\n_http._tcp\tIN\tURI\t10\t1\t"https://gaia.blockstack.org/hub/13WcjxWGz3JkZYhoPeCHw2ukcK1f1zH6M1/profile.json"\n\n_btc._addr\tIN\tTXT\t"bc1qqx4xnlcqkavs2d0e8wnxnj95yv87z7209dfp4e"\n\n'; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 33ca7b2..7e42846 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -2,3 +2,4 @@ export * from './clarigen'; export * from './utils'; export * from './types'; export * from './namespaces'; +export * from './namespace-helpers'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 871777f..5026f99 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -237,13 +237,11 @@ importers: '@bns-x/punycode': workspace:* '@clarigen/core': 1.0.14 '@fungible-systems/zone-file': ^2.0.0 - '@types/jest': ^29.2.4 '@types/regenerate': ^1.4.1 '@unicode/unicode-15.0.0': ^1.3.1 axios: ^1.3.4 emoji-regex: ^10.2.1 form-data: ^4.0.0 - jest: ^29.3.1 micro-stacks: ^1.1.4 openapi-typescript-codegen: ^0.23.0 regenerate: ^1.4.2 @@ -251,6 +249,7 @@ importers: tsup: ^6.7.0 tsx: ^3.12.3 typescript: 4.9.5 + vitest: ^0.31.0 zod: 3.20.6 dependencies: '@adraffy/punycode': 1.2.0 @@ -262,17 +261,16 @@ importers: form-data: 4.0.0 micro-stacks: 1.1.4 devDependencies: - '@types/jest': 29.2.4 '@types/regenerate': 1.4.1 '@unicode/unicode-15.0.0': 1.3.1 emoji-regex: 10.2.1 - jest: 29.3.1 openapi-typescript-codegen: 0.23.0 regenerate: 1.4.2 - ts-jest: 29.0.3_hfbqr3rujuziiw7lzul6vua4r4 + ts-jest: 29.0.3_typescript@4.9.5 tsup: 6.7.0_typescript@4.9.5 tsx: 3.12.3 typescript: 4.9.5 + vitest: 0.31.0 zod: 3.20.6 packages/core: @@ -558,8 +556,8 @@ packages: - supports-color dev: true - /@artilleryio/int-core/2.0.6: - resolution: {integrity: sha512-ShcvHIcsArTzot+/cGvSTgdl7KgRMUxSfnPkDxY9OJpRAt0l6iEtf40qvF96hf9Is/PntD+reDOsC0GD1n2qKA==} + /@artilleryio/int-core/2.0.7: + resolution: {integrity: sha512-AVOW9gdkgzWzkfFYi0SnAddVqkBhuDjM28FEFHReA/g7EF5113jdlh+7sO8W4Vql5tpS26x8pNnkEa60gHMAsA==} dependencies: '@artilleryio/int-commons': 2.0.0 '@artilleryio/sketches-js': 1.0.4 @@ -6314,8 +6312,8 @@ packages: - supports-color dev: true - /artillery-plugin-ensure/1.1.2: - resolution: {integrity: sha512-7qScjfOeAmgRd/D2Rn2EzFdqCP5ZfHYt0x4k9NrJTuCae/xdQcWrod1k0nfn07bkVHjhapP6kmVO+uM98tHpVw==} + /artillery-plugin-ensure/1.1.3: + resolution: {integrity: sha512-wQ64fP/pnIRXadUbi/4FS0t9QBXPx5tEfitEeaEGmv0P8ax4ZJQ59dj4xwVlfhbgH2f7zGt0l+/942Cu194RyA==} dependencies: debug: 4.3.4 filtrex: 2.2.3 @@ -6342,8 +6340,8 @@ packages: - supports-color dev: true - /artillery-plugin-publish-metrics/2.3.0: - resolution: {integrity: sha512-cTyurhOhVopbH8FoWc8C6MWQm6V2NuGKwaBZn3loVhjbikKXgA1VCIPdaHM7+fuUx+6I9zOV0Ei03nWIVHhf0w==} + /artillery-plugin-publish-metrics/2.4.0: + resolution: {integrity: sha512-1mvOXdfCza356oUvWPJublMtOkExCwBB3KDIxvFEeo0GSZBL05Kk96GAE9gJNjt48q95dXuNvTvOiKIWbIKaaw==} dependencies: '@aws-sdk/client-cloudwatch': 3.13.0 async: 2.6.4 @@ -6370,17 +6368,17 @@ packages: hasBin: true dependencies: '@artilleryio/int-commons': 2.0.0 - '@artilleryio/int-core': 2.0.6 + '@artilleryio/int-core': 2.0.7 '@aws-sdk/credential-providers': 3.264.0 '@oclif/command': 1.8.22 '@oclif/config': 1.18.8 '@oclif/plugin-help': 3.3.1 '@oclif/plugin-not-found': 2.3.18 archiver: 5.3.1 - artillery-plugin-ensure: 1.1.2 + artillery-plugin-ensure: 1.1.3 artillery-plugin-expect: 2.2.1 artillery-plugin-metrics-by-endpoint: 1.0.2 - artillery-plugin-publish-metrics: 2.3.0 + artillery-plugin-publish-metrics: 2.4.0 async: 2.6.4 aws-sdk: 2.1356.0 chalk: 2.4.2 @@ -14120,6 +14118,38 @@ packages: yargs-parser: 21.1.1 dev: true + /ts-jest/29.0.3_typescript@4.9.5: + resolution: {integrity: sha512-Ibygvmuyq1qp/z3yTh9QTwVVAbFdDy/+4BtIQR2sp6baF2SJU/8CKK/hhnGIDY2L90Az2jIqTwZPnN2p+BweiQ==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true + peerDependencies: + '@babel/core': '>=7.0.0-beta.0 <8' + '@jest/types': ^29.0.0 + babel-jest: ^29.0.0 + esbuild: '*' + jest: ^29.0.0 + typescript: '>=4.3' + peerDependenciesMeta: + '@babel/core': + optional: true + '@jest/types': + optional: true + babel-jest: + optional: true + esbuild: + optional: true + dependencies: + bs-logger: 0.2.6 + fast-json-stable-stringify: 2.1.0 + jest-util: 29.3.1 + json5: 2.2.3 + lodash.memoize: 4.1.2 + make-error: 1.3.6 + semver: 7.3.8 + typescript: 4.9.5 + yargs-parser: 21.1.1 + dev: true + /tsconfig-paths/3.14.1: resolution: {integrity: sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==} dependencies: