test: update contract test suite

This commit is contained in:
Ludovic Galabru
2020-12-03 14:51:17 -05:00
parent b92368b9cc
commit d50789d716
24 changed files with 6944 additions and 1030 deletions

9
bns-test/babel.config.js Normal file
View File

@@ -0,0 +1,9 @@
// babel.config.js
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};

16
bns-test/jest.config.js Normal file
View File

@@ -0,0 +1,16 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
coverageDirectory: './coverage/',
collectCoverage: true,
globals: {
'ts-jest': {
diagnostics: {
ignoreCodes: ['TS151001'],
},
},
},
moduleFileExtensions: ['js', 'ts', 'd.ts'],
// setupFiles: ['./tests/global-setup.ts'],
// setupFilesAfterEnv: ['./tests/setup.ts'],
};

73
bns-test/package.json Normal file
View File

@@ -0,0 +1,73 @@
{
"name": "@blockstack/core-contracts",
"version": "1.0.0-alpha.0",
"description": "Core contracts",
"license": "MIT",
"main": "lib/index.js",
"repository": "blockstack/blockstack-core",
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "npm run clean && npm run compile",
"clean": "shx rm -rf ./lib tsconfig.build.tsbuildinfo",
"compile": "tsc --build tsconfig.build.json",
"prepublishOnly": "npm run build",
"lint": "tslint -p tsconfig.json 'src/**/*.ts' 'test/**/*.ts'",
"lint-fix": "tslint --fix -p tsconfig.json 'src/**/*.ts' 'test/**/*.ts'",
"test": "jest",
"test:watch": "jest --watch --coverage=false --runInBand"
},
"engines": {
"node": ">=10"
},
"files": [
"/src",
"/test",
"/lib",
"/contracts"
],
"dependencies": {
"@blockstack/clarity": "^0.3.0",
"@blockstack/clarity-native-bin": "^0.3.0",
"@types/ripemd160": "^2.0.0",
"@types/sha.js": "^2.4.0",
"ripemd160": "^2.0.2",
"sha.js": "^2.4.11"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"@types/chai": "^4.1.7",
"@types/fs-extra": "^9.0.4",
"@types/jest": "^25.2.1",
"@types/node": "^10",
"babel-jest": "^26.6.3",
"chai": "^4.2.0",
"fs-extra": "^9.0.1",
"jest": "^25.2.6",
"jest-circus": "^25.2.6",
"nyc": "^14.1.1",
"shx": "^0.3.2",
"source-map-support": "^0.5.12",
"ts-jest": "^25.3.0",
"ts-node": "^8.2.0",
"tslint": "^5.17.0",
"typescript": "^4.0.5"
},
"nyc": {
"all": true,
"cache": false,
"extension": [
".ts"
],
"include": [
"src"
],
"reporter": [
"text",
"lcov"
]
}
}

View File

@@ -1,4 +1,5 @@
import { Client, Provider, Receipt, Result } from "@blockstack/clarity";
import { Client, Provider, Receipt, Result, NativeClarityBinProvider, Transaction } from "@blockstack/clarity";
import { ExecutionError } from "@blockstack/clarity/lib/providers/clarityBin";
import ripemd160 from 'ripemd160';
import shajs from 'sha.js';
@@ -11,8 +12,31 @@ export interface PriceFunction {
}
export class BNSClient extends Client {
constructor(provider: Provider) {
super("S1G2081040G2081040G2081040G208105NK8PE5.bns", "bns", provider);
constructor(provider: NativeClarityBinProvider) {
super("S1G2081040G2081040G2081040G208105NK8PE5.bns", "../../src/chainstate/stacks/boot/bns", provider);
}
submitTransaction = async (tx: Transaction): Promise<Receipt> => {
if (!tx.method || !tx.sender) {
throw 'Invalid TX';
}
try {
const res = await this.provider.execute(
this.name,
tx.method.name,
tx.sender,
...tx.method.args
);
return res;
} catch (error) {
if (error instanceof ExecutionError) {
return {
success: false,
error: error.commandOutput,
}
}
throw error;
}
}
// (namespace-preorder (hashed-namespace (buff 20))
@@ -148,7 +172,7 @@ export class BNSClient extends Client {
async nameTransfer(namespace: string,
name: string,
newOwner: string,
zonefileContent: string,
zonefileContent: string|null,
params: { sender: string }): Promise<Receipt> {
const args = [`"${namespace}"`, `"${name}"`, `'${newOwner}`];
args.push(zonefileContent === null ? "none" : `(some\ "${zonefileContent}")`);
@@ -209,4 +233,14 @@ export class BNSClient extends Client {
const res = await this.submitTransaction(tx);
return res;
}
async mineBlocks(blocks: number) {
for (let index = 0; index < blocks; index++) {
const query = this.createQuery({
atChaintip: false,
method: { name: "compute-namespace-price?", args: ['0x0000'] }
});
const res = await this.submitQuery(query);
}
}
}

View File

@@ -0,0 +1,173 @@
import { Provider, ProviderRegistry, NativeClarityBinProvider } from "@blockstack/clarity";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { expect } from "chai";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAME_IMPORT", () => {
let bns: BNSClient;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR",
"SPMQEKN07D1VHAB8XQV835E3PTY3QWZRZ5H0DM36"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const dave = addresses[3];
const cases = [{
namespace: "blockstack",
version: 1,
salt: "0000",
value: 96,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
base: 4,
coeff: 250,
noVoyelDiscount: 4,
nonAlphaDiscount: 4,
},
renewalRule: 10,
nameImporter: bob,
zonefile: "0000",
}, {
namespace: "id",
version: 1,
salt: "0000",
value: 9600,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
base: 4,
coeff: 250,
noVoyelDiscount: 20,
nonAlphaDiscount: 20,
},
renewalRule: 52595,
nameImporter: alice,
zonefile: "1111",
}];
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Given a launched namespace 'blockstack', owned by Alice, where Bob is nameImporter", () => {
beforeEach(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('Returned: u12');
receipt = await bns.namespaceReveal(
cases[0].namespace,
cases[0].version,
cases[0].salt,
cases[0].priceFunction,
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('Returned: true');
await bns.mineBlocks(1);
});
it("Charlie trying to import 'alpha.blockstack' should fail", async () => {
var receipt = await bns.nameImport(cases[0].namespace, "alpha", cases[0].zonefile, { sender: charlie })
expect(receipt.success).eq(false);
expect(receipt.error).include('Aborted: 1011');
// });
// it("Bob trying to import 'alpha.blockstack' should succeed", async () => {
receipt = await bns.nameImport(cases[0].namespace, "alpha", cases[0].zonefile, { sender: bob })
expect(receipt.success).eq(true);
expect(receipt.result).include('Returned: true');
// });
// it("Resolving an imported name should fail if the namespace is not ready", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"alpha", { sender: cases[0].nameOwner });
expect(receipt.result).include('0x30303030');
console.log(receipt);
expect(receipt.success).eq(true);
// });
// it("Bob trying to import 'beta.blockstack' should fail after the launch of the domain", async () => {
receipt = await bns.namespaceReady(cases[0].namespace, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).include('true');
await bns.mineBlocks(1);
receipt = await bns.nameImport(cases[0].namespace, "beta", cases[0].zonefile, { sender: bob })
expect(receipt.success).eq(false);
expect(receipt.error).include('1014');
// });
// it("Resolving an imported name should succeed if the namespace is ready", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"alpha", { sender: bob });
expect(receipt.result).include('0x30303030');
expect(receipt.success).eq(true);
// });
// it("Charlie trying to register 'alpha.blockstack' should fail", async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"alpha",
cases[0].salt,
160000, { sender: charlie });
expect(receipt.success).eq(true);
expect(receipt.result).include('u22');
receipt = await bns.nameRegister(
cases[0].namespace,
"alpha",
cases[0].salt,
cases[0].zonefile, { sender: charlie });
expect(receipt.error).include('2004');
expect(receipt.success).eq(false);
// });
// it("Charlie trying to renew 'alpha.blockstack' should fail", async () => {
receipt = await bns.nameRenewal(cases[0].namespace, "alpha", 160000, charlie, cases[0].zonefile, { sender: charlie })
expect(receipt.success).eq(false);
expect(receipt.error).include('2006');
// });
// it("Bob trying to renew 'alpha.blockstack' should succeed", async () => {
receipt = await bns.nameRenewal(cases[0].namespace, "alpha", 160000, charlie, "6666", { sender: bob })
expect(receipt.success).eq(true);
expect(receipt.result).include('true');
// });
// it("Resolving an imported name should fail after expiration", async () => {
await bns.mineBlocks(100);
receipt = await bns.getNameZonefile(
cases[0].namespace,
"alpha", { sender: cases[0].nameOwner });
expect(receipt.error).include('2008');
expect(receipt.success).eq(false);
});
});
});

View File

@@ -1,19 +1,24 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAME_PREORDER", async () => {
describe("BNS Test Suite - NAME_PREORDER", () => {
let bns: BNSClient;
let provider: Provider;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR"
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR",
"SPMQEKN07D1VHAB8XQV835E3PTY3QWZRZ5H0DM36"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const dave = addresses[3];
const cases = [{
namespace: "blockstack",
@@ -51,64 +56,75 @@ describe("BNS Test Suite - NAME_PREORDER", async () => {
zonefile: "LOREM IPSUM DOLOR SIT AMET",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Pre-ordering the name 'bob.blockstack'", async () => {
test("should fail if the hash of the FQN is mal-formed");
describe("Pre-ordering the name 'bob.blockstack'", () => {
// it("should fail if the hash of the FQN is mal-formed");
test("should fail if Bob's balance is insufficient", async () => {
let receipt = await bns.namePreorder(
it("should fail if Bob's balance is insufficient", async () => {
await mineBlocks(bns, 20);
var receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
20000000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('4001');
});
expect(receipt.error).include('4001');
// });
it("should succeed if Bob's balance is provisioned", async () => {
let receipt = await bns.namePreorder(
// it("should succeed if Bob's balance is provisioned", async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
200, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
});
expect(receipt.result).include('u33');
// });
it("should fail if the same order is being re-submitted by Bob", async () => {
let receipt = await bns.namePreorder(
// it("should fail if the same order is being re-submitted by Bob", async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
200, { sender: cases[0].nameOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('2016');
});
expect(receipt.error).include('2016');
// });
it("should succeed if the same order is being re-submitted by Alice", async () => {
let receipt = await bns.namePreorder(
// it("should succeed if the same order is being re-submitted by Alice", async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
200, { sender: alice });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
});
expect(receipt.result).include('u35');
// });
it("should succeed once claimability TTL expired", async () => {
await provider.mineBlocks(11);
let receipt = await bns.namePreorder(
// it("should succeed once claimability TTL expired", async () => {
await mineBlocks(bns, 10);
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
200, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u41');
expect(receipt.result).include('u46');
});
});
});

View File

@@ -1,19 +1,24 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAME_REGISTER", async () => {
describe("BNS Test Suite - NAME_REGISTER", () => {
let bns: BNSClient;
let provider: Provider;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR"
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR",
"SPMQEKN07D1VHAB8XQV835E3PTY3QWZRZ5H0DM36"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const dave = addresses[3];
const cases = [{
namespace: "blockstack",
@@ -51,34 +56,35 @@ describe("BNS Test Suite - NAME_REGISTER", async () => {
zonefile: "1111",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Revealing the name 'bob.blockstack'", async () => {
it("should fail if the namespace 'blockstack' is not registered");
it("should fail if the namespace 'blockstack' is not launched");
it("should fail if no matching pre-order can be found", async () => {
let receipt = await bns.nameRegister(
await mineBlocks(bns, 20);
var receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('2001');
});
});
expect(receipt.error).include('2001');
describe("Given an unlaunched namespace 'id', owned by Alice", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include('u33');
receipt = await bns.namespaceReveal(
cases[1].namespace,
@@ -88,17 +94,14 @@ describe("BNS Test Suite - NAME_REGISTER", async () => {
cases[1].renewalRule,
cases[1].nameImporter, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
});
expect(receipt.result).include('true');
describe("Pre-ordering and Revealing the name 'baobab.blockstack'", async () => {
it("should fail, since the namespace isn't launched", async () => {
let receipt = await bns.namePreorder(
receipt = await bns.namePreorder(
cases[1].namespace,
"baobab",
cases[1].salt,
100, { sender: bob });
expect(receipt.result).eq('u30');
expect(receipt.result).include('u35');
expect(receipt.success).eq(true);
receipt = await bns.nameRegister(
@@ -106,18 +109,15 @@ describe("BNS Test Suite - NAME_REGISTER", async () => {
"baobab",
cases[1].salt,
cases[1].zonefile, { sender: bob });
expect(receipt.result).eq('1007');
expect(receipt.error).include('1007');
expect(receipt.success).eq(false);
});
});
});
// describe("Given a launched namespace 'blockstack', owned by Alice", () => {
describe("Given a launched namespace 'blockstack', owned by Alice", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
// beforeEach(async () => {
receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include('u37');
receipt = await bns.namespaceReveal(
cases[0].namespace,
@@ -127,217 +127,221 @@ describe("BNS Test Suite - NAME_REGISTER", async () => {
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
receipt = await bns.namespaceReady(cases[0].namespace, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
await provider.mineBlocks(1);
});
await bns.mineBlocks(1);
// });
describe("Revealing the name 'bob.blockstack'", async () => {
it("should fail if no matching pre-order can be found", async () => {
let receipt = await bns.nameRegister(
// describe("Revealing the name 'bob.blockstack'", () => {
// it("should fail if no matching pre-order can be found", async () => {
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('2001');
});
});
expect(receipt.error).include('2001');
// });
// });
describe("Given a pre-order of the name 'bub.blockstack', burning 2559999 STX instead of 2560000 STX, Revealing the name", async () => {
before(async () => {
// describe("Given a pre-order of the name 'bub.blockstack', burning 2559999 STX instead of 2560000 STX, Revealing the name", async () => {
// beforeEach(async () => {
let receipt = await bns.namePreorder(
receipt = await bns.namePreorder(
cases[0].namespace,
"bub",
cases[0].salt,
2559999, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
});
expect(receipt.result).include('u42');
// });
it("should fail", async () => {
let receipt = await bns.nameRegister(
// it("should fail", async () => {
receipt = await bns.nameRegister(
cases[0].namespace,
"bub",
cases[0].salt,
cases[0].zonefile, { sender: bob });
expect(receipt.result).eq('2007');
expect(receipt.error).include('2007');
expect(receipt.success).eq(false);
});
});
// });
// });
describe("Given an existing pre-order of the name 'Bob.blockstack', initiated by Bob at block #21", async () => {
// describe("Given an existing pre-order of the name 'Bob.blockstack', initiated by Bob at block #21", async () => {
before(async () => {
let receipt = await bns.namePreorder(
// beforeEach(async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"Bob",
cases[0].salt,
2560000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
});
expect(receipt.result).include('u44');
// });
it("Bob registering the name 'Bob.blockstack' should fail", async () => {
let receipt = await bns.nameRegister(
// it("Bob registering the name 'Bob.blockstack' should fail", async () => {
receipt = await bns.nameRegister(
cases[0].namespace,
"Bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('2022');
expect(receipt.error).include('2022');
expect(receipt.success).eq(false);
});
});
// });
// });
describe("Given an existing pre-order of the name 'bob.blockstack', initiated by Bob at block #21", async () => {
// describe("Given an existing pre-order of the name 'bob.blockstack', initiated by Bob at block #21", () => {
before(async () => {
let receipt = await bns.namePreorder(
// beforeEach(async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
});
expect(receipt.result).include('u46');
// });
describe("Bob registering the name 'bob.blockstack'", async () => {
// describe("Bob registering the name 'bob.blockstack'", async () => {
it("should succeed", async () => {
let receipt = await bns.nameRegister(
// it("should succeed", async () => {
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x30303030');
expect(receipt.result).include('0x30303030');
expect(receipt.success).eq(true);
});
// });
it("should fail registering twice", async () => {
let receipt = await bns.nameRegister(
// it("should fail registering twice", async () => {
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('2004');
expect(receipt.error).include('2004');
expect(receipt.success).eq(false);
});
// });
});
// });
describe("Charlie registering 'bob.blockstack'", async () => {
// describe("Charlie registering 'bob.blockstack'", () => {
it("should fail", async () => {
// it("should fail", async () => {
let receipt = await bns.namePreorder(
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: charlie });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
expect(receipt.result).include('u50');
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: charlie });
expect(receipt.result).eq('2004');
expect(receipt.error).include('2004');
expect(receipt.success).eq(false);
});
});
// });
// });
// todo(ludo): investigate the case where 'name.namespace' was preordered while being unavailable
// and then became available
describe("Bob registering a second name 'bobby.blockstack'", async () => {
// // todo(ludo): investigate the case where 'name.namespace' was preordered while being unavailable
// // and then became available
// describe("Bob registering a second name 'bobby.blockstack'", () => {
it("should fail if 'bob.blockstack' is not expired", async () => {
await provider.mineBlocks(1);
// it("should fail if 'bob.blockstack' is not expired", async () => {
await bns.mineBlocks(1);
let receipt = await bns.namePreorder(
receipt = await bns.namePreorder(
cases[0].namespace,
"bobby",
cases[0].salt,
160000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u32');
expect(receipt.result).include('u53');
receipt = await bns.nameRegister(
cases[0].namespace,
"bobby",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('3001');
expect(receipt.error).include('3001');
expect(receipt.success).eq(false);
});
// });
it("should succeed once 'bob.blockstack' is expired", async () => {
await provider.mineBlocks(cases[0].renewalRule);
// it("should succeed once 'bob.blockstack' is expired", async () => {
await mineBlocks(bns, cases[0].renewalRule);
let receipt = await bns.namePreorder(
receipt = await bns.namePreorder(
cases[0].namespace,
"bobby",
cases[0].salt,
160000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u42');
expect(receipt.result).include('u65');
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
receipt = await bns.nameRegister(
cases[0].namespace,
"bobby",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bobby", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x30303030');
expect(receipt.result).include('0x30303030');
expect(receipt.success).eq(true);
});
});
// });
// });
describe("Charlie registering 'bob.blockstack'", async () => {
// describe("Charlie registering 'bob.blockstack'", () => {
it("should succeed once 'bob.blockstack' is expired", async () => {
// it("should succeed once 'bob.blockstack' is expired", async () => {
let receipt = await bns.namePreorder(
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: charlie });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u42');
expect(receipt.result).include('u69');
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
"AAAA", { sender: charlie });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x41414141');
expect(receipt.result).include('0x41414141');
expect(receipt.success).eq(true);
});
});
// });
// });
});
// });
});
});

View File

@@ -1,10 +1,13 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAME_RENEWAL", async () => {
describe("BNS Test Suite - NAME_RENEWAL", () => {
let bns: BNSClient;
let provider: Provider;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
@@ -53,18 +56,31 @@ describe("BNS Test Suite - NAME_RENEWAL", async () => {
zonefile: "1111",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Given a launched namespace 'id' not requiring renewing names", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
it("Given a launched namespace 'id' not requiring renewing names", async () => {
let block_height = 2;
let namespace_preorder_ttl = 10;
let name_preorder_ttl = 10;
// beforeEach(async () => {
var receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include(`${block_height+namespace_preorder_ttl}`);
block_height+= 1;
receipt = await bns.namespaceReveal(
cases[1].namespace,
@@ -73,34 +89,35 @@ describe("BNS Test Suite - NAME_RENEWAL", async () => {
cases[1].priceFunction,
cases[1].renewalRule,
cases[1].nameImporter, { sender: cases[1].namespaceOwner });
expect(receipt.result).eq('true');
block_height+= 1;
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
receipt = await bns.namespaceReady(cases[1].namespace, { sender: cases[1].namespaceOwner });
expect(receipt.result).eq('true');
block_height+= 1;
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
await provider.mineBlocks(1);
});
// });
it("Charlie should not be able to renew 'charlie.id'", async () => {
let receipt = await bns.namePreorder(
// it("Charlie should not be able to renew 'charlie.id'", async () => {
receipt = await bns.namePreorder(
cases[1].namespace,
"charlie",
cases[1].salt,
2560000, { sender: charlie });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
expect(receipt.result).include(`${block_height+name_preorder_ttl}`);
block_height+= 1;
receipt = await bns.nameRegister(
cases[1].namespace,
"charlie",
cases[1].salt,
cases[1].zonefile, { sender: charlie });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
await provider.mineBlocks(5);
block_height+= 1;
receipt = await bns.nameRenewal(
cases[1].namespace,
@@ -108,17 +125,20 @@ describe("BNS Test Suite - NAME_RENEWAL", async () => {
2560000,
null,
cases[1].zonefile, { sender: charlie });
expect(receipt.result).eq('2006');
expect(receipt.error).include('2006');
expect(receipt.success).eq(false);
});
});
block_height+= 1;
describe("Given a launched namespace 'blockstack' requiring renewing names after 10 blocks", async () => {
// });
// });
before(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
// describe("Given a launched namespace 'blockstack' requiring renewing names after 10 blocks", () => {
// beforeEach(async () => {
receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u36');
expect(receipt.result).include(`${block_height+namespace_preorder_ttl}`);
block_height+= 1;
receipt = await bns.namespaceReveal(
cases[0].namespace,
@@ -128,71 +148,43 @@ describe("BNS Test Suite - NAME_RENEWAL", async () => {
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
block_height+= 1;
receipt = await bns.namespaceReady(cases[0].namespace, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
block_height+= 1;
await provider.mineBlocks(1);
});
// });
describe("Given a registered name 'bob.blockstack', initiated by Bob at block #21", async () => {
// describe("Given a registered name 'bob.blockstack', initiated by Bob at block #21", () => {
before(async () => {
let receipt = await bns.namePreorder(
// beforeEach(async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u37');
expect(receipt.result).include(`${block_height+name_preorder_ttl}`);
block_height+= 1;
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
block_height+= 1;
// });
describe("When Bob is renewing 'bob.blockstack' at block #29", async () => {
// describe("When Bob is renewing 'bob.blockstack' at block #29", () => {
it("should succeed and set the new expiration date to #41", async () => {
await provider.mineBlocks(8);
let receipt = await bns.nameRenewal(
cases[0].namespace,
"bob",
2560000,
null,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.success).eq(true);
});
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x30303030');
expect(receipt.success).eq(true);
});
});
describe("When Bob is renewing 'bob.blockstack' at block #44 (grace period)", async () => {
it("should succeed and set the new expiration date to #51", async () => {
await provider.mineBlocks(15);
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('2009');
expect(receipt.success).eq(false);
// it("should succeed and set the new expiration date to #41", async () => {
// await mineBlocks(bns, 8);
receipt = await bns.nameRenewal(
cases[0].namespace,
@@ -200,29 +192,36 @@ describe("BNS Test Suite - NAME_RENEWAL", async () => {
2560000,
null,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
block_height+= 1;
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// });
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x30303030');
expect(receipt.result).include('0x30303030');
expect(receipt.success).eq(true);
});
});
block_height+= 1;
describe("When Bob is renewing 'bob.blockstack' at block #56 (expired)", async () => {
// });
// });
it("should fail renewing", async () => {
await provider.mineBlocks(16);
// describe("When Bob is renewing 'bob.blockstack' at block #44 (grace period)", () => {
let receipt = await bns.getNameZonefile(
// it("should succeed and set the new expiration date to #51", async () => {
expect(block_height).eq(15);
await mineBlocks(bns, 10);
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('2008');
expect(receipt.error).include('2009');
expect(receipt.success).eq(false);
block_height+= 1;
receipt = await bns.nameRenewal(
cases[0].namespace,
@@ -230,59 +229,104 @@ describe("BNS Test Suite - NAME_RENEWAL", async () => {
2560000,
null,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('2008');
expect(receipt.success).eq(false);
});
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
block_height+= 1;
it("Dave should succeed re-registering 'bob.blockstack'", async () => {
let receipt = await bns.namePreorder(
// });
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).include('0x30303030');
expect(receipt.success).eq(true);
block_height+= 1;
// });
// });
// describe("When Bob is renewing 'bob.blockstack' at block #56 (expired)", () => {
// it("should fail renewing", async () => {
await mineBlocks(bns, 16);
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.error).include('2008');
expect(receipt.success).eq(false);
block_height+= 1;
receipt = await bns.nameRenewal(
cases[0].namespace,
"bob",
2560000,
null,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.error).include('2008');
expect(receipt.success).eq(false);
block_height+= 1;
// });
// it("Dave should succeed re-registering 'bob.blockstack'", async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: dave });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u76');
expect(receipt.result).include('u56');
block_height+= 1;
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
"4444", { sender: dave });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
block_height+= 1;
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// });
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x34343434');
expect(receipt.result).include('0x34343434');
expect(receipt.success).eq(true);
});
block_height+= 1;
it("Dave should succeed and set the new expiration date to #41", async () => {
await provider.mineBlocks(8);
// });
let receipt = await bns.nameRenewal(
// it("Dave should succeed and set the new expiration date to #41", async () => {
await mineBlocks(bns, 8);
receipt = await bns.nameRenewal(
cases[0].namespace,
"bob",
2560000,
bob,
"1111", { sender: dave });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
block_height+= 1;
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// });
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x31313131');
expect(receipt.result).include('0x31313131');
expect(receipt.success).eq(true);
});
});
});
block_height+= 1;
// });
// });
// });
});
});

View File

@@ -1,19 +1,24 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAME_REVOKE", async () => {
describe("BNS Test Suite - NAME_REVOKE", () => {
let bns: BNSClient;
let provider: Provider;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR"
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR",
"SPMQEKN07D1VHAB8XQV835E3PTY3QWZRZ5H0DM36"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const dave = addresses[3];
const cases = [{
namespace: "blockstack",
@@ -51,18 +56,31 @@ describe("BNS Test Suite - NAME_REVOKE", async () => {
zonefile: "1111",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Given a launched namespace 'blockstack', owned by Alice", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
describe("Given a launched namespace 'blockstack', owned by Alice", () => {
it("Given a registered name 'bob.blockstack', initiated by Bob at block #21", async () => {
let block_height = 2;
let namespace_preorder_ttl = 10;
let name_preorder_ttl = 10;
var receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include(`${block_height+namespace_preorder_ttl}`);
receipt = await bns.namespaceReveal(
cases[0].namespace,
@@ -72,245 +90,245 @@ describe("BNS Test Suite - NAME_REVOKE", async () => {
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
block_height+= 1;
receipt = await bns.nameImport(cases[0].namespace, "alice", cases[0].zonefile, { sender: cases[0].nameImporter })
expect(receipt.success).eq(true);
block_height+= 1;
receipt = await bns.namespaceReady(cases[0].namespace, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
await provider.mineBlocks(1);
});
expect(receipt.result).include('true');
block_height+= 1;
describe("Given a registered name 'bob.blockstack', initiated by Bob at block #21", async () => {
before(async () => {
let receipt = await bns.namePreorder(
// beforeEach(async () => {
var receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
expect(receipt.result).include(`${block_height+namespace_preorder_ttl}`);
block_height+= 1;
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
describe("Charlie revoking 'bob.blockstack' on Bob's behalf", async () => {
// describe("Charlie revoking 'bob.blockstack' on Bob's behalf", () => {
it("should fail", async () => {
// it("should fail", async () => {
let receipt = await bns.nameRevoke(
receipt = await bns.nameRevoke(
cases[0].namespace,
"bob", { sender: charlie });
expect(receipt.result).eq('2006');
expect(receipt.error).include('2006');
expect(receipt.success).eq(false);
});
// });
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x30303030');
expect(receipt.result).include('0x30303030');
expect(receipt.success).eq(true);
});
});
// });
// });
describe("Bob revoking 'bob.blockstack'", async () => {
// describe("Bob revoking 'bob.blockstack'", () => {
it("should succeed", async () => {
// it("should succeed", async () => {
let receipt = await bns.nameRevoke(
receipt = await bns.nameRevoke(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
it("should not be able to resolve", async () => {
let receipt = await bns.getNameZonefile(
// it("should not be able to resolve", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('2014');
expect(receipt.error).include('2014');
expect(receipt.success).eq(false);
});
// });
it("Bob trying to update 'bob.blockstack' should fail", async () => {
let receipt = await bns.nameUpdate(
// it("Bob trying to update 'bob.blockstack' should fail", async () => {
receipt = await bns.nameUpdate(
cases[0].namespace,
"bob",
"4444", { sender: bob });
expect(receipt.result).eq('2014');
expect(receipt.error).include('2014');
expect(receipt.success).eq(false);
});
// });
it("Bob trying to transfer 'bob.blockstack' should fail", async () => {
let receipt = await bns.nameTransfer(
// it("Bob trying to transfer 'bob.blockstack' should fail", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"bob",
charlie,
"4444", { sender: bob });
expect(receipt.result).eq('2014');
expect(receipt.error).include('2014');
expect(receipt.success).eq(false);
});
// });
it("Bob trying to register 'bob.blockstack' should fail", async () => {
let receipt = await bns.namePreorder(
// it("Bob trying to register 'bob.blockstack' should fail", async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
"salt#2",
2560000, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
expect(receipt.result).include('u24');
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
"salt#2",
cases[0].zonefile, { sender: bob });
expect(receipt.result).eq('2004');
expect(receipt.error).include('2004');
expect(receipt.success).eq(false);
});
// });
it("Bob trying to renew 'bob.blockstack' should fail", async () => {
let receipt = await bns.nameRenewal(
return
// it("Bob trying to renew 'bob.blockstack' should fail", async () => {
receipt = await bns.nameRenewal(
cases[0].namespace,
"bob",
2560000,
bob,
"4444", { sender: bob });
expect(receipt.result).eq('2014');
expect(receipt.error).include('2014');
expect(receipt.success).eq(false);
});
// });
it("Alice trying to renew 'alice.blockstack' should succeed", async () => {
await provider.mineBlocks(10);
// it("Alice trying to renew 'alice.blockstack' should succeed", async () => {
mineBlocks(bns, 10);
console.log("2");
let receipt = await bns.nameRenewal(
receipt = await bns.nameRenewal(
cases[0].namespace,
"alice",
2560000,
alice,
"6666", { sender: alice });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
it("Bob trying to register 'bob.blockstack', once expired, should succeed", async () => {
await provider.mineBlocks(10);
// it("Bob trying to register 'bob.blockstack', once expired, should succeed", async () => {
mineBlocks(bns, 10);
let receipt = await bns.namePreorder(
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
"salt#2",
2560000, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u51');
expect(receipt.result).include('u51');
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
"salt#2",
cases[0].zonefile, { sender: bob });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
});
describe("Charlie revoking 'alice.blockstack' on Alice's behalf (imported name)", async () => {
// });
// describe("Charlie revoking 'alice.blockstack' on Alice's behalf (imported name)", () => {
it("should fail", async () => {
let receipt = await bns.nameRevoke(
// it("should fail", async () => {
receipt = await bns.nameRevoke(
cases[0].namespace,
"alice", { sender: charlie });
expect(receipt.result).eq('2006');
expect(receipt.error).include('2006');
expect(receipt.success).eq(false);
});
// });
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"alice", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x36363636');
expect(receipt.result).include('0x36363636');
expect(receipt.success).eq(true);
});
});
// });
// });
describe("Alice revoking 'alice.blockstack' (imported name)", async () => {
// describe("Alice revoking 'alice.blockstack' (imported name)", () => {
it("should succeed", async () => {
let receipt = await bns.nameRevoke(
// it("should succeed", async () => {
receipt = await bns.nameRevoke(
cases[0].namespace,
"alice", { sender: alice });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
it("should stop resolving", async () => {
let receipt = await bns.getNameZonefile(
// it("should stop resolving", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"alice", { sender: alice });
expect(receipt.result).eq('2014');
expect(receipt.error).include('2014');
expect(receipt.success).eq(false);
});
// });
it("Alice trying to update 'alice.blockstack' should fail", async () => {
let receipt = await bns.nameUpdate(
// it("Alice trying to update 'alice.blockstack' should fail", async () => {
receipt = await bns.nameUpdate(
cases[0].namespace,
"alice",
"4444", { sender: alice });
expect(receipt.result).eq('2014');
expect(receipt.error).include('2014');
expect(receipt.success).eq(false);
});
// });
it("Alice trying to transfer 'alice.blockstack' should fail", async () => {
let receipt = await bns.nameTransfer(
// it("Alice trying to transfer 'alice.blockstack' should fail", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"alice",
charlie,
"4444", { sender: alice });
expect(receipt.result).eq('2014');
expect(receipt.error).include('2014');
expect(receipt.success).eq(false);
});
// });
it("Alice trying to renew 'alice.blockstack' should fail", async () => {
let receipt = await bns.nameRenewal(
// it("Alice trying to renew 'alice.blockstack' should fail", async () => {
receipt = await bns.nameRenewal(
cases[0].namespace,
"alice",
2560000,
alice,
"4444", { sender: alice });
expect(receipt.result).eq('2014');
expect(receipt.error).include('2014');
expect(receipt.success).eq(false);
});
// });
it("Alice trying to register 'alice.blockstack' should fail", async () => {
let receipt = await bns.namePreorder(
// it("Alice trying to register 'alice.blockstack' should fail", async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"alice",
"salt#2",
2560000, { sender: alice });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u51');
expect(receipt.result).include('u51');
receipt = await bns.nameRegister(
cases[0].namespace,
"alice",
"salt#2",
cases[0].zonefile, { sender: alice });
expect(receipt.result).eq('2004');
expect(receipt.error).include('2004');
expect(receipt.success).eq(false);
});
});
// });
// });
});
});
});

View File

@@ -1,10 +1,13 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAME_TRANSFER", async () => {
describe("BNS Test Suite - NAME_TRANSFER", () => {
let bns: BNSClient;
let provider: Provider;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
@@ -53,18 +56,31 @@ describe("BNS Test Suite - NAME_TRANSFER", async () => {
zonefile: "1111",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Given a launched namespace 'blockstack', owned by Alice", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
it("Given a launched namespace 'blockstack', owned by Alice", async () => {
let block_height = 2;
let namespace_preorder_ttl = 10;
let name_preorder_ttl = 10;
// beforeEach(async () => {
var receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include(`${block_height+namespace_preorder_ttl}`);
block_height += 1;
receipt = await bns.namespaceReveal(
cases[0].namespace,
@@ -74,36 +90,40 @@ describe("BNS Test Suite - NAME_TRANSFER", async () => {
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
block_height += 1;
receipt = await bns.nameImport(cases[0].namespace, "alice", cases[0].zonefile, { sender: cases[0].nameImporter })
expect(receipt.success).eq(true);
block_height += 1;
receipt = await bns.namespaceReady(cases[0].namespace, { sender: cases[0].nameImporter });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
block_height += 1;
await provider.mineBlocks(1);
});
// });
describe("Given some names 'bob.blockstack' and 'charlie.blockstack' registered at block #21", async () => {
// describe("Given some names 'bob.blockstack' and 'charlie.blockstack' registered at block #21", () => {
before(async () => {
let receipt = await bns.namePreorder(
// beforeEach(async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
expect(receipt.result).include('u16');
block_height += 1;
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
block_height += 1;
receipt = await bns.namePreorder(
cases[0].namespace,
@@ -111,181 +131,182 @@ describe("BNS Test Suite - NAME_TRANSFER", async () => {
cases[0].salt,
2560000, { sender: charlie });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
expect(receipt.result).include('u18');
block_height += 1;
receipt = await bns.nameRegister(
cases[0].namespace,
"charlie",
cases[0].salt,
cases[0].zonefile, { sender: charlie });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
describe("Charlie transfering 'bob.blockstack' on Bob's behalf", async () => {
it("should fail", async () => {
let receipt = await bns.nameTransfer(
// describe("Charlie transfering 'bob.blockstack' on Bob's behalf", () => {
// it("should fail", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"bob",
charlie,
"3333", { sender: charlie });
expect(receipt.result).eq('2006');
expect(receipt.error).include('2006');
expect(receipt.success).eq(false);
});
// });
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x30303030');
expect(receipt.result).include('0x30303030');
expect(receipt.success).eq(true);
});
// });
});
// });
describe("Bob transfering 'bob.blockstack' to Dave", async () => {
// describe("Bob transfering 'bob.blockstack' to Dave", () => {
it("should succeed", async () => {
let receipt = await bns.nameTransfer(
// it("should succeed", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"bob",
dave,
"3333", { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x33333333');
expect(receipt.result).include('0x33333333');
expect(receipt.success).eq(true);
});
});
// });
// });
describe("Charlie transfering 'charlie.blockstack' to Dave", async () => {
// describe("Charlie transfering 'charlie.blockstack' to Dave", () => {
it("should fail since Dave already received 'bob.blockstack'", async () => {
let receipt = await bns.nameTransfer(
// it("should fail since Dave already received 'bob.blockstack'", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"charlie",
dave,
"3333", { sender: charlie });
expect(receipt.result).eq('3001');
expect(receipt.error).include('3001');
expect(receipt.success).eq(false);
});
// });
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"charlie", { sender: charlie });
expect(receipt.result).eq('0x30303030');
expect(receipt.result).include('0x30303030');
expect(receipt.success).eq(true);
});
});
// });
// });
describe("Charlie transfering 'charlie.blockstack' to Bob", async () => {
// describe("Charlie transfering 'charlie.blockstack' to Bob", () => {
it("should succeed", async () => {
let receipt = await bns.nameTransfer(
// it("should succeed", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"charlie",
bob,
"4444", { sender: charlie });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"charlie", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x34343434');
expect(receipt.result).include('0x34343434');
expect(receipt.success).eq(true);
});
});
// });
// });
describe("Bob transfering 'charlie.blockstack' back to Charlie", async () => {
it("should succeed", async () => {
let receipt = await bns.nameTransfer(
// describe("Bob transfering 'charlie.blockstack' back to Charlie", () => {
// it("should succeed", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"charlie",
charlie,
null, { sender: bob });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"charlie", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x00');
expect(receipt.result).include('0x00');
expect(receipt.success).eq(true);
});
// });
it("Bob should not be able to update 'charlie.blockstack'", async () => {
let receipt = await bns.nameUpdate(
// it("Bob should not be able to update 'charlie.blockstack'", async () => {
receipt = await bns.nameUpdate(
cases[0].namespace,
"charlie",
"4444", { sender: bob });
expect(receipt.result).eq('2006');
expect(receipt.error).include('2006');
expect(receipt.success).eq(false);
});
// });
it("Charlie should be able to update 'charlie.blockstack'", async () => {
let receipt = await bns.nameUpdate(
// it("Charlie should be able to update 'charlie.blockstack'", async () => {
receipt = await bns.nameUpdate(
cases[0].namespace,
"charlie",
"2222", { sender: charlie });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
});
// });
// });
describe("Dave transfering 'bob.blockstack' back to Bob", async () => {
it("should succeed", async () => {
let receipt = await bns.nameTransfer(
// describe("Dave transfering 'bob.blockstack' back to Bob", () => {
// it("should succeed", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"bob",
bob,
null, { sender: dave });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
// });
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x00');
expect(receipt.result).include('0x00');
expect(receipt.success).eq(true);
});
// });
it("Bob should be able to update its zonefile", async () => {
let receipt = await bns.nameUpdate(
// it("Bob should be able to update its zonefile", async () => {
receipt = await bns.nameUpdate(
cases[0].namespace,
"bob",
"3333", { sender: bob });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
});
// });
// });
describe("Alice trying to transfer 'alice.blockstack' to Dave", async () => {
it("should fail, since 'alice.blockstack' was imported", async () => {
let receipt = await bns.nameTransfer(
// describe("Alice trying to transfer 'alice.blockstack' to Dave", () => {
// it("should succeed, even if 'alice.blockstack' was imported", async () => {
receipt = await bns.nameTransfer(
cases[0].namespace,
"alice",
dave,
"4444", { sender: cases[0].nameImporter });
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
});
});
});
// });
// });
// });
});
});

View File

@@ -0,0 +1,206 @@
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAME_UPDATE", () => {
let bns: BNSClient;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR",
"SPMQEKN07D1VHAB8XQV835E3PTY3QWZRZ5H0DM36"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const dave = addresses[3];
const cases = [{
namespace: "blockstack",
version: 1,
salt: "0000",
value: 96,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
base: 4,
coeff: 250,
noVoyelDiscount: 4,
nonAlphaDiscount: 4,
},
renewalRule: 4294967295,
nameImporter: alice,
zonefile: "0000",
}, {
namespace: "id",
version: 1,
salt: "0000",
value: 9600,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
base: 4,
coeff: 250,
noVoyelDiscount: 20,
nonAlphaDiscount: 20,
},
renewalRule: 52595,
nameImporter: alice,
zonefile: "1111",
}];
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
it("Given an unlaunched namespace 'blockstack', owned by Alice", async () => {
let block_height = 2;
let namespace_preorder_ttl = 10;
let name_preorder_ttl = 10;
var receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include(`${block_height+namespace_preorder_ttl}`);
block_height += 1;
receipt = await bns.namespaceReveal(
cases[0].namespace,
cases[0].version,
cases[0].salt,
cases[0].priceFunction,
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('true');
// });
// it("should be possible for Alice to import a name", async () => {
receipt = await bns.nameImport(cases[0].namespace, "alice", "4444", { sender: alice });
expect(receipt.success).eq(true);
expect(receipt.result).include('true');
// })
// it("should be possible for Alice to update her domain", async () => {
receipt = await bns.nameUpdate(
cases[0].namespace,
"alice",
"5555", { sender: alice });
expect(receipt.error).include('1007');
expect(receipt.success).eq(false);
// });
// it("should not be possible for Bob to import a name", async () => {
receipt = await bns.nameImport(cases[0].namespace, "bob", "4444", { sender: bob });
expect(receipt.success).eq(false);
expect(receipt.error).include('1011');
// })
// it("should not resolve (namespace not launched yet)", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"alice", { sender: cases[0].nameOwner });
expect(receipt.result).include('0x34343434');
expect(receipt.success).eq(true);
// });
// describe("When Alice is launching the namespace 'blockstack' at block #20", () => {
// beforeEach(async () => {
receipt = await bns.namespaceReady(cases[0].namespace, { sender: alice });
expect(receipt.success).eq(true);
expect(receipt.result).include('true');
// });
// it("Resolving 'alice.blockstack' should succeed", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"alice", { sender: cases[0].nameOwner });
expect(receipt.result).include('0x34343434');
expect(receipt.success).eq(true);
// });
// it("Bob preordering 'bob.blockstack' waiting for the namespace to be launched should fail", async () => {
receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('u20');
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
// });
// describe("Bob updating his zonefile - from 1111 to 2222", () => {
// it("should succeed", async () => {
receipt = await bns.nameUpdate(
cases[0].namespace,
"bob",
"2222", { sender: cases[0].nameOwner });
expect(receipt.result).include('true');
expect(receipt.success).eq(true);
// });
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).include('0x32323232');
expect(receipt.success).eq(true);
// });
// });
// describe("Charlie updating Bob's zonefile - from 2222 to 3333", () => {
// it("should fail", async () => {
receipt = await bns.nameUpdate(
cases[0].namespace,
"bob",
"3333", { sender: charlie });
expect(receipt.error).include('2006');
expect(receipt.success).eq(false);
// });
// it("should resolve as expected", async () => {
receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).include('0x32323232');
expect(receipt.success).eq(true);
// });
// });
// });
});
});

View File

@@ -1,10 +1,13 @@
import { Provider, ProviderRegistry, Receipt } from "@blockstack/clarity";
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAMESPACE_PREORDER", async () => {
describe("BNS Test Suite - NAMESPACE_PREORDER", () => {
let bns: BNSClient;
let provider: Provider;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
@@ -53,13 +56,22 @@ describe("BNS Test Suite - NAMESPACE_PREORDER", async () => {
zonefile: "LOREM IPSUM DOLOR SIT AMET",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Triggering this operation", async () => {
describe("Triggering this operation", () => {
it("should fail if 'hashed-namespace' is blank", async () => {
// Should fail when using the helper
@@ -79,7 +91,7 @@ describe("BNS Test Suite - NAMESPACE_PREORDER", async () => {
await tx.sign(cases[0].namespaceOwner);
const res = await bns.submitTransaction(tx);
expect(res.success).eq(false);
expect(res.result).eq('1015');
expect(res.error).include('1015');
});
it("should fail if 'stx-to-burn' is 0", async () => {
@@ -100,57 +112,56 @@ describe("BNS Test Suite - NAMESPACE_PREORDER", async () => {
await tx.sign(cases[0].namespaceOwner);
const res = await bns.submitTransaction(tx);
expect(res.success).eq(false);
expect(res.result).eq('1012');
expect(res.error).include('1015');
});
it("should fail if Alice can't afford paying the fee", async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, 20000000000, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('4001');
expect(receipt.error).include('4001');
});
it("should succeed when Alice pre-orders 'blockstack', 'stx-to-burn' = 96 (balance ok)", async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include('u12');
});
it("should succeed when Alice pre-orders 'id', 'stx-to-burn' = 9600 (balance ok)", async () => {
let receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include('u12');
});
describe("Given an existing pre-order for 'blockstack' registered by Alice ", () => {
describe("When Bob submits a pre-order with the same salted hashed namespace", async () => {
it("should succeed", async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
});
});
// describe("Given an existing pre-order for 'blockstack' registered by Alice", () => {
// describe("When Bob submits a pre-order with the same salted hashed namespace", () => {
// });
// });
it("should succeed", async () => {
var receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).include('u12');
// });
// });
describe("When Alice submits a pre-order with the same salted hashed namespace", () => {
it("should fail if TTL is still valid", async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1003');
});
it("should succeed if TTL is expired", async () => {
// Let's mine 5 blocks and check
await provider.mineBlocks(5);
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1003');
// describe("When Alice submits a pre-order with the same salted hashed namespace", () => {
// it("should fail if TTL is still valid", async () => {
receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('u13');
// Let's mine 5 blocks and check
await mineBlocks(bns, 5);
receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.error).include('1003');
// Let's mine 6 more blocks and check (TTL = 10 (< 5 + 6))
await mineBlocks(bns, 6);
receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).include('u26'); // 20 blocks simulated initially + 11 blocks simulated + TTL
});
// Let's mine 6 more blocks and check (TTL = 10 (< 5 + 6))
await provider.mineBlocks(6);
receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u41'); // 20 blocks simulated initially + 11 blocks simulated + TTL
});
});
});
});
});

View File

@@ -0,0 +1,136 @@
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAMESPACE_READY", () => {
let bns: BNSClient;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR",
"SPMQEKN07D1VHAB8XQV835E3PTY3QWZRZ5H0DM36"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const dave = addresses[3];
const cases = [{
namespace: "blockstack",
version: 1,
salt: "0000",
value: 96,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
base: 1,
coeff: 2,
noVoyelDiscount: 0,
nonAlphaDiscount: 0,
},
renewalRule: 1,
nameImporter: alice,
zonefile: "LOREM IPSUM DOLOR SIT AMET",
}, {
namespace: "id",
version: 1,
salt: "0000",
value: 9600,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
base: 1,
coeff: 2,
noVoyelDiscount: 0,
nonAlphaDiscount: 0,
},
renewalRule: 1,
nameImporter: alice,
zonefile: "LOREM IPSUM DOLOR SIT AMET",
}];
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
it("Given a revealed pre-order from Alice for the namespace 'blockstack' initiated at block #20", async () => {
// beforeEach(async () => {
var receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('u12');
receipt = await bns.namespaceReveal(
cases[0].namespace,
cases[0].version,
cases[0].salt,
cases[0].priceFunction,
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('true');
// });
// describe("Launching the namespace", () => {
// it("should succeed if the namespace has not already been launched, and revealed less than a year ago (todo: fix TTL)", async () => {
receipt = await bns.namespaceReady(cases[0].namespace, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('true');
// });
// it("should fail if launchability TTL expired", async () => {
receipt = await bns.namespaceReady(cases[0].namespace, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.error).include('1014');
// });
// });
// });
// describe("Given a revealed pre-order from Alice for the namespace 'id' initiated at block #20", () => {
// beforeEach(async () => {
receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('u16');
receipt = await bns.namespaceReveal(
cases[1].namespace,
cases[1].version,
cases[1].salt,
cases[1].priceFunction,
cases[1].renewalRule,
cases[1].nameImporter, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).include('true');
// });
// describe("Launching the namespace", () => {
// it("should fail if launchability TTL expired", async () => {
await mineBlocks(bns, 11);
receipt = await bns.namespaceReady(cases[1].namespace, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.error).include('1010');
// });
// });
});
});

View File

@@ -1,19 +1,24 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { NativeClarityBinProvider } from "@blockstack/clarity";
import { expect } from "chai";
import { getTempFilePath } from "@blockstack/clarity/lib/utils/fsUtil";
import { getDefaultBinaryFilePath } from "@blockstack/clarity-native-bin";
import { BNSClient, PriceFunction } from "../src/bns-client";
import { mineBlocks } from "./utils";
describe("BNS Test Suite - NAMESPACE_REVEAL", async () => {
describe("BNS Test Suite - NAMESPACE_REVEAL", () => {
let bns: BNSClient;
let provider: Provider;
let provider: NativeClarityBinProvider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR"
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR",
"SPMQEKN07D1VHAB8XQV835E3PTY3QWZRZ5H0DM36"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const dave = addresses[3];
const cases = [{
namespace: "blockstack",
@@ -51,12 +56,21 @@ describe("BNS Test Suite - NAMESPACE_REVEAL", async () => {
zonefile: "LOREM IPSUM DOLOR SIT AMET",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
beforeEach(async () => {
const allocations = [
{ principal: alice, amount: 10_000_000_000 },
{ principal: bob, amount: 10_000_000 },
{ principal: charlie, amount: 10_000_000 },
{ principal: dave, amount: 10_000_000 },
]
const binFile = getDefaultBinaryFilePath();
const dbFileName = getTempFilePath();
provider = await NativeClarityBinProvider.create(allocations, dbFileName, binFile);
bns = new BNSClient(provider);
await bns.deployContract();
});
it("Revealing a non-existing pre-order should fail", async () => {
let receipt = await bns.namespaceReveal(
cases[0].namespace,
@@ -66,30 +80,30 @@ describe("BNS Test Suite - NAMESPACE_REVEAL", async () => {
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1001');
expect(receipt.error).include('1001');
});
describe("Given an existing, valid pre-order from Alice for the namespace 'id' initiated at block #31, resubmitting the same pre-order", async () => {
describe("Given an existing, valid pre-order from Alice for the namespace 'id' initiated at block #31, resubmitting the same pre-order", () => {
before(async () => {
beforeEach(async () => {
let receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include('u12');
});
it("should fail", async () => {
let receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1003');
expect(receipt.error).include('1003');
});
});
describe("Given an existing, valid pre-order from Alice for the namespace 'blockstack' initiated at block #20, revealing the namespace", async () => {
describe("Given an existing, valid pre-order from Alice for the namespace 'blockstack' initiated at block #20, revealing the namespace", () => {
before(async () => {
beforeEach(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
expect(receipt.result).include('u12');
});
it("should fail if the sender changed", async () => {
@@ -101,11 +115,11 @@ describe("BNS Test Suite - NAMESPACE_REVEAL", async () => {
cases[0].renewalRule,
cases[0].nameImporter, { sender: bob });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1001');
expect(receipt.error).include('1001');
});
it("should fail if TTL expired", async () => {
await provider.mineBlocks(11);
await mineBlocks(bns, 11);
let receipt = await bns.namespaceReveal(
cases[0].namespace,
cases[0].version,
@@ -114,16 +128,16 @@ describe("BNS Test Suite - NAMESPACE_REVEAL", async () => {
cases[0].renewalRule,
cases[0].nameImporter, { sender: bob });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1001');
expect(receipt.error).include('1001');
});
});
describe("Given an existing, valid pre-order from Alice for the namespace 'blockstack' initiated at block #31, revealing the namespace", async () => {
describe("Given an existing, valid pre-order from Alice for the namespace 'blockstack' initiated at block #31, revealing the namespace", () => {
before(async () => {
beforeEach(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u41');
expect(receipt.result).include('u12');
});
@@ -136,16 +150,16 @@ describe("BNS Test Suite - NAMESPACE_REVEAL", async () => {
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
});
});
describe("Given a pre-order, too cheap, from Bob for the namespace 'id' initiated at block #31, revealing the namespace", async () => {
describe("Given a pre-order, too cheap, from Bob for the namespace 'id' initiated at block #31, revealing the namespace", () => {
before(async () => {
beforeEach(async () => {
let receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, 96, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u41');
expect(receipt.result).include('u12');
});
it("should fail", async () => {
@@ -157,16 +171,16 @@ describe("BNS Test Suite - NAMESPACE_REVEAL", async () => {
cases[1].renewalRule,
cases[1].nameImporter, { sender: bob });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1012');
expect(receipt.error).include('1012');
});
});
describe("Given an existing, valid pre-order from Alice for the namespace 'id' initiated at block #31, revealing the namespace", async () => {
describe("Given an existing, valid pre-order from Alice for the namespace 'id' initiated at block #31, revealing the namespace", () => {
before(async () => {
beforeEach(async () => {
let receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u41');
expect(receipt.result).include('u12');
});
it("should succeed if the price-function, renewal-rule, namespace and salt are valid", async () => {
@@ -178,7 +192,7 @@ describe("BNS Test Suite - NAMESPACE_REVEAL", async () => {
cases[1].renewalRule,
cases[1].nameImporter, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
expect(receipt.result).include('true');
});
});

4
bns-test/test/utils.ts Normal file
View File

@@ -0,0 +1,4 @@
import { BNSClient } from "../src/bns-client";
export const mineBlocks = async (bns: BNSClient, blocks: number) => {
await bns.mineBlocks(blocks);
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"lib": ["es2017", "esnext.bigint"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
"sourceMap": true,
"composite": true,
"declaration": true,
"outDir": "./lib",
"rootDir": "./src"
},
"exclude": [
"node_modules",
"dist"
],
"include": [
"src/**/*"
]
}

23
bns-test/tsconfig.json Normal file
View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"lib": ["es2017", "esnext.bigint"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
"sourceMap": true,
"composite": true,
"declaration": true,
"outDir": "./lib",
"rootDir": "./src"
},
"exclude": [
"node_modules",
"dist"
],
"include": [
"src/**/*",
]
}

3
bns-test/tslint.json Normal file
View File

@@ -0,0 +1,3 @@
{
"extends": ["../clarity-tslint/tslint.json"]
}

5586
bns-test/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +0,0 @@
--require ts-node/register/transpile-only
--require source-map-support/register
--extension ts
--timeout 0
--recursive

View File

@@ -1,158 +0,0 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { expect } from "chai";
import { BNSClient, PriceFunction } from "../src/bns-client";
describe("BNS Test Suite - NAME_IMPORT", async () => {
let bns: BNSClient;
let provider: Provider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const cases = [{
namespace: "blockstack",
version: 1,
salt: "0000",
value: 96,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
base: 4,
coeff: 250,
noVoyelDiscount: 4,
nonAlphaDiscount: 4,
},
renewalRule: 10,
nameImporter: bob,
zonefile: "0000",
}, {
namespace: "id",
version: 1,
salt: "0000",
value: 9600,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
base: 4,
coeff: 250,
noVoyelDiscount: 20,
nonAlphaDiscount: 20,
},
renewalRule: 52595,
nameImporter: alice,
zonefile: "1111",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Given a launched namespace 'blockstack', owned by Alice, where Bob is nameImporter", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
receipt = await bns.namespaceReveal(
cases[0].namespace,
cases[0].version,
cases[0].salt,
cases[0].priceFunction,
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
await provider.mineBlocks(1);
});
it("Charlie trying to import 'alpha.blockstack' should fail", async () => {
let receipt = await bns.nameImport(cases[0].namespace, "alpha", cases[0].zonefile, { sender: charlie })
expect(receipt.success).eq(false);
expect(receipt.result).eq('1011');
});
it("Bob trying to import 'alpha.blockstack' should succeed", async () => {
let receipt = await bns.nameImport(cases[0].namespace, "alpha", cases[0].zonefile, { sender: bob })
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
});
it("Resolving an imported name should fail if the namespace is not ready", async () => {
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"alpha", { sender: cases[0].nameOwner });
expect(receipt.result).eq('1007');
expect(receipt.success).eq(false);
});
it("Bob trying to import 'beta.blockstack' should fail after the launch of the domain", async () => {
let receipt = await bns.namespaceReady(cases[0].namespace, { sender: bob });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
await provider.mineBlocks(1);
receipt = await bns.nameImport(cases[0].namespace, "beta", cases[0].zonefile, { sender: bob })
expect(receipt.success).eq(false);
expect(receipt.result).eq('1014');
});
it("Resolving an imported name should succeed if the namespace is ready", async () => {
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"alpha", { sender: bob });
expect(receipt.result).eq('0x30303030');
expect(receipt.success).eq(true);
});
it("Charlie trying to register 'alpha.blockstack' should fail", async () => {
let receipt = await bns.namePreorder(
cases[0].namespace,
"alpha",
cases[0].salt,
160000, { sender: charlie });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u32');
receipt = await bns.nameRegister(
cases[0].namespace,
"alpha",
cases[0].salt,
cases[0].zonefile, { sender: charlie });
expect(receipt.result).eq('2004');
expect(receipt.success).eq(false);
});
it("Charlie trying to renew 'alpha.blockstack' should fail", async () => {
let receipt = await bns.nameRenewal(cases[0].namespace, "alpha", 160000, charlie, cases[0].zonefile, { sender: charlie })
expect(receipt.success).eq(false);
expect(receipt.result).eq('2006');
});
it("Bob trying to renew 'alpha.blockstack' should succeed", async () => {
let receipt = await bns.nameRenewal(cases[0].namespace, "alpha", 160000, charlie, "6666", { sender: bob })
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
});
it("Resolving an imported name should fail after expiration", async () => {
await provider.mineBlocks(20);
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"alpha", { sender: cases[0].nameOwner });
expect(receipt.result).eq('2008');
expect(receipt.success).eq(false);
});
});
});

View File

@@ -1,215 +0,0 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { expect } from "chai";
import { BNSClient, PriceFunction } from "../src/bns-client";
describe("BNS Test Suite - NAME_UPDATE", async () => {
let bns: BNSClient;
let provider: Provider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const cases = [{
namespace: "blockstack",
version: 1,
salt: "0000",
value: 96,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
base: 4,
coeff: 250,
noVoyelDiscount: 4,
nonAlphaDiscount: 4,
},
renewalRule: 4294967295,
nameImporter: alice,
zonefile: "0000",
}, {
namespace: "id",
version: 1,
salt: "0000",
value: 9600,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
base: 4,
coeff: 250,
noVoyelDiscount: 20,
nonAlphaDiscount: 20,
},
renewalRule: 52595,
nameImporter: alice,
zonefile: "1111",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Given an unlaunched namespace 'blockstack', owned by Alice", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
receipt = await bns.namespaceReveal(
cases[0].namespace,
cases[0].version,
cases[0].salt,
cases[0].priceFunction,
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
});
it("should be possible for Alice to import a name", async () => {
let receipt = await bns.nameImport(cases[0].namespace, "alice", "4444", { sender: alice });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
})
it("should be possible for Alice to update her domain", async () => {
let receipt = await bns.nameUpdate(
cases[0].namespace,
"alice",
"4444", { sender: alice });
expect(receipt.result).eq('true');
expect(receipt.success).eq(true);
});
it("should not be possible for Bob to import a name", async () => {
let receipt = await bns.nameImport(cases[0].namespace, "bob", "4444", { sender: bob });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1011');
})
it("should not resolve (namespace not launched yet)", async () => {
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"alice", { sender: cases[0].nameOwner });
expect(receipt.result).eq('1007');
expect(receipt.success).eq(false);
});
describe("When Alice is launching the namespace 'blockstack' at block #20", async () => {
before(async () => {
let receipt = await bns.namespaceReady(cases[0].namespace, { sender: alice });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
});
it("Resolving 'alice.blockstack' should succeed", async () => {
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"alice", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x34343434');
expect(receipt.success).eq(true);
});
it("Charlie preordering 'charlie.blockstack' without waiting for the namespace to be launched should fail", async () => {
let receipt = await bns.namePreorder(
cases[0].namespace,
"charlie",
cases[0].salt,
2560000, { sender: charlie });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
await provider.mineBlocks(1);
receipt = await bns.nameRegister(
cases[0].namespace,
"charlie",
cases[0].salt,
cases[0].zonefile, { sender: charlie });
expect(receipt.result).eq('2018');
expect(receipt.success).eq(false);
});
it("should not resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"charlie", { sender: cases[0].nameOwner });
expect(receipt.result).eq('2013');
expect(receipt.success).eq(false);
});
it("Bob preordering 'bob.blockstack' waiting for the namespace to be launched should fail", async () => {
let receipt = await bns.namePreorder(
cases[0].namespace,
"bob",
cases[0].salt,
2560000, { sender: cases[0].nameOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u31');
receipt = await bns.nameRegister(
cases[0].namespace,
"bob",
cases[0].salt,
cases[0].zonefile, { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.success).eq(true);
});
describe("Bob updating his zonefile - from 1111 to 2222", async () => {
it("should succeed", async () => {
let receipt = await bns.nameUpdate(
cases[0].namespace,
"bob",
"2222", { sender: cases[0].nameOwner });
expect(receipt.result).eq('true');
expect(receipt.success).eq(true);
});
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x32323232');
expect(receipt.success).eq(true);
});
});
describe("Charlie updating Bob's zonefile - from 2222 to 3333", async () => {
it("should fail", async () => {
let receipt = await bns.nameUpdate(
cases[0].namespace,
"bob",
"3333", { sender: charlie });
expect(receipt.result).eq('2006');
expect(receipt.success).eq(false);
});
it("should resolve as expected", async () => {
let receipt = await bns.getNameZonefile(
cases[0].namespace,
"bob", { sender: cases[0].nameOwner });
expect(receipt.result).eq('0x32323232');
expect(receipt.success).eq(true);
});
});
});
});
});

View File

@@ -1,122 +0,0 @@
import { Provider, ProviderRegistry, Receipt, Query } from "@blockstack/clarity";
import { expect } from "chai";
import { BNSClient, PriceFunction } from "../src/bns-client";
describe("BNS Test Suite - NAMESPACE_READY", async () => {
let bns: BNSClient;
let provider: Provider;
const addresses = [
"SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
"S02J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE",
"SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR"
];
const alice = addresses[0];
const bob = addresses[1];
const charlie = addresses[2];
const cases = [{
namespace: "blockstack",
version: 1,
salt: "0000",
value: 96,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
base: 1,
coeff: 2,
noVoyelDiscount: 0,
nonAlphaDiscount: 0,
},
renewalRule: 1,
nameImporter: alice,
zonefile: "LOREM IPSUM DOLOR SIT AMET",
}, {
namespace: "id",
version: 1,
salt: "0000",
value: 9600,
namespaceOwner: alice,
nameOwner: bob,
priceFunction: {
buckets: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
base: 1,
coeff: 2,
noVoyelDiscount: 0,
nonAlphaDiscount: 0,
},
renewalRule: 1,
nameImporter: alice,
zonefile: "LOREM IPSUM DOLOR SIT AMET",
}];
before(async () => {
provider = await ProviderRegistry.createProvider();
bns = new BNSClient(provider);
await bns.deployContract();
});
describe("Given a revealed pre-order from Alice for the namespace 'blockstack' initiated at block #20", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[0].namespace, cases[0].salt, cases[0].value, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
receipt = await bns.namespaceReveal(
cases[0].namespace,
cases[0].version,
cases[0].salt,
cases[0].priceFunction,
cases[0].renewalRule,
cases[0].nameImporter, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
});
describe("Launching the namespace", async () => {
it("should succeed if the namespace has not already been launched, and revealed less than a year ago (todo: fix TTL)", async () => {
let receipt = await bns.namespaceReady(cases[0].namespace, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
});
it("should fail if launchability TTL expired", async () => {
let receipt = await bns.namespaceReady(cases[0].namespace, { sender: cases[0].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1014');
});
});
});
describe("Given a revealed pre-order from Alice for the namespace 'id' initiated at block #20", async () => {
before(async () => {
let receipt = await bns.namespacePreorder(cases[1].namespace, cases[1].salt, cases[1].value, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('u30');
receipt = await bns.namespaceReveal(
cases[1].namespace,
cases[1].version,
cases[1].salt,
cases[1].priceFunction,
cases[1].renewalRule,
cases[1].nameImporter, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(true);
expect(receipt.result).eq('true');
});
describe("Launching the namespace", async () => {
it("should fail if launchability TTL expired", async () => {
await provider.mineBlocks(11);
let receipt = await bns.namespaceReady(cases[1].namespace, { sender: cases[1].namespaceOwner });
expect(receipt.success).eq(false);
expect(receipt.result).eq('1010');
});
});
});
});