Skip to content

Commit

Permalink
feat: tests for namespace pricing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Jun 14, 2023
1 parent 5b519d1 commit 190c350
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 17 deletions.
5 changes: 2 additions & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
1 change: 1 addition & 0 deletions packages/client/tests/api-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BnsApiClient } from '../src';
import { expect, test } from 'vitest';

const api = new BnsApiClient();

Expand Down
1 change: 1 addition & 0 deletions packages/client/tests/contracts.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
36 changes: 36 additions & 0 deletions packages/client/tests/pricing.test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});
1 change: 1 addition & 0 deletions packages/client/tests/wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -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 = '';
Expand Down
1 change: 1 addition & 0 deletions packages/client/tests/zonefile.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './clarigen';
export * from './utils';
export * from './types';
export * from './namespaces';
export * from './namespace-helpers';
58 changes: 44 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 190c350

Please sign in to comment.