Skip to content

Commit

Permalink
Merge pull request #2187 from blockstack/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
lgalabru authored Dec 16, 2020
2 parents c1b74ec + d491d91 commit fe81b98
Show file tree
Hide file tree
Showing 90 changed files with 5,990 additions and 2,465 deletions.
80 changes: 57 additions & 23 deletions bns-test/src/bns-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class BNSClient extends Client {
const tx = this.createTransaction({
method: {
name: "namespace-reveal",
args: [`"${namespace}"`, `"${salt}"`, ...priceFuncAsArgs, `u${renewalRule}`, `'${nameImporter}`]
args: [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(salt)}`, ...priceFuncAsArgs, `u${renewalRule}`, `'${nameImporter}`]
}
});
await tx.sign(params.sender);
Expand All @@ -109,18 +109,18 @@ export class BNSClient extends Client {

// (name-import (namespace (buff 20))
// (name (buff 16))
// (zonefile-content (buff 40960)))
// (zonefile-hash (buff 20)))
async nameImport(namespace: string,
name: string,
beneficiary: string,
zonefileContent: string,
zonefileHash: string,
params: {
sender: string
}): Promise<Receipt> {
const tx = this.createTransaction({
method: {
name: "name-import",
args: [`"${namespace}"`, `"${name}"`, `'${beneficiary}`, `"${zonefileContent}"`]
args: [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`, `'${beneficiary}`, `0x${this.toHexString(zonefileHash)}`]
}
});
await tx.sign(params.sender);
Expand All @@ -135,7 +135,7 @@ export class BNSClient extends Client {
const tx = this.createTransaction({
method: {
name: "namespace-ready",
args: [`"${namespace}"`]
args: [`0x${this.toHexString(namespace)}`]
}
});
await tx.sign(params.sender);
Expand Down Expand Up @@ -170,18 +170,18 @@ export class BNSClient extends Client {
// (name-register (namespace (buff 20))
// (name (buff 16))
// (salt (buff 20))
// (zonefile-content (buff 40960)))
// (zonefile-hash (buff 20)))
async nameRegister(namespace: string,
name: string,
salt: string,
zonefileContent: string,
zonefileHash: string,
params: {
sender: string
}): Promise<Receipt> {
const tx = this.createTransaction({
method: {
name: "name-register",
args: [`"${namespace}"`, `"${name}"`, `"${salt}"`, `"${zonefileContent}"`]
args: [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`, `0x${this.toHexString(salt)}`, `0x${this.toHexString(zonefileHash)}`]
}
});
await tx.sign(params.sender);
Expand All @@ -191,17 +191,17 @@ export class BNSClient extends Client {

// (name-update (namespace (buff 20))
// (name (buff 16))
// (zonefile-content (buff 40960)))
// (zonefile-hash (buff 20)))
async nameUpdate(namespace: string,
name: string,
zonefileContent: string,
zonefileHash: string,
params: {
sender: string
}): Promise<Receipt> {
const tx = this.createTransaction({
method: {
name: "name-update",
args: [`"${namespace}"`, `"${name}"`, `"${zonefileContent}"`]
args: [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`, `0x${this.toHexString(zonefileHash)}`]
}
});
await tx.sign(params.sender);
Expand All @@ -212,16 +212,16 @@ export class BNSClient extends Client {
// (name-transfer (namespace (buff 20))
// (name (buff 16))
// (new-owner principal)
// (zonefile-content (optional (buff 40960))))
// (zonefile-hash (optional (buff 20))))
async nameTransfer(namespace: string,
name: string,
newOwner: string,
zonefileContent: string | null,
zonefileHash: string | null,
params: {
sender: string
}): Promise<Receipt> {
const args = [`"${namespace}"`, `"${name}"`, `'${newOwner}`];
args.push(zonefileContent === null ? "none" : `(some\ "${zonefileContent}")`);
const args = [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`, `'${newOwner}`];
args.push(zonefileHash === null ? "none" : `(some\ 0x${this.toHexString(zonefileHash)})`);

const tx = this.createTransaction({
method: {
Expand All @@ -244,7 +244,7 @@ export class BNSClient extends Client {
const tx = this.createTransaction({
method: {
name: "name-revoke",
args: [`"${namespace}"`, `"${name}"`]
args: [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`]
}
});
await tx.sign(params.sender);
Expand All @@ -256,18 +256,18 @@ export class BNSClient extends Client {
// (name (buff 16))
// (stx-to-burn uint)
// (new-owner (optional principal))
// (zonefile-content (optional (buff 40960))))
// (zonefile-hash (optional (buff 20))))
async nameRenewal(namespace: string,
name: string,
STX: number,
newOwner: null | string,
zonefileContent: null | string,
zonefileHash: null | string,
params: {
sender: string
}): Promise<Receipt> {
const args = [`"${namespace}"`, `"${name}"`, `u${STX}`];
const args = [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`, `u${STX}`];
args.push(newOwner === null ? "none" : `(some\ '${newOwner})`);
args.push(zonefileContent === null ? "none" : `(some\ "${zonefileContent}")`);
args.push(zonefileHash === null ? "none" : `(some\ 0x${this.toHexString(zonefileHash)})`);

const tx = this.createTransaction({
method: {
Expand All @@ -290,7 +290,7 @@ export class BNSClient extends Client {
const tx = this.createTransaction({
method: {
name: "name-resolve",
args: [`"${namespace}"`, `"${name}"`]
args: [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`]
}
});
await tx.sign(params.sender);
Expand All @@ -302,7 +302,7 @@ export class BNSClient extends Client {
// (name (buff 16))
async canNameBeRegistered(namespace: string,
name: string): Promise<Receipt> {
const args = [`"${namespace}"`, `"${name}"`];
const args = [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`];
const query = this.createQuery({
atChaintip: false,
method: {
Expand All @@ -314,16 +314,50 @@ export class BNSClient extends Client {
return res;
}

// (get-name-price (namespace (buff 20))
// (name (buff 16))
async getNamePrice(namespace: string,
name: string): Promise<Receipt> {
const args = [`0x${this.toHexString(namespace)}`, `0x${this.toHexString(name)}`];
const query = this.createQuery({
atChaintip: false,
method: {
name: "get-name-price",
args: args
}
});
const res = await this.submitQuery(query);
return res;
}

// (get-namespace-price (namespace (buff 20))
async getNamespacePrice(namespace: string): Promise<Receipt> {
const args = [`0x${this.toHexString(namespace)}`];
const query = this.createQuery({
atChaintip: false,
method: {
name: "get-namespace-price",
args: args
}
});
const res = await this.submitQuery(query);
return res;
}

async mineBlocks(blocks: number) {
for (let index = 0; index < blocks; index++) {
const query = this.createQuery({
atChaintip: false,
method: {
name: "compute-namespace-price?",
name: "get-namespace-price",
args: ['0x0000']
}
});
const res = await this.submitQuery(query);
}
}

toHexString(input: String): String {
return Buffer.from(input).toString('hex');
}
}
10 changes: 8 additions & 2 deletions bns-test/test/name_import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ describe("BNS Test Suite - NAME_IMPORT", () => {
expect(receipt.success).eq(true);
expect(receipt.result).include('Returned: true');

// Bob trying to import 'dave.blockstack' should succeed
receipt = await bns.nameImport(cases[0].namespace, "delta", dave, "4444", {
sender: bob
})
Expand Down Expand Up @@ -180,6 +181,12 @@ describe("BNS Test Suite - NAME_IMPORT", () => {
expect(receipt.result).include('true');
await bns.mineBlocks(1);

receipt = await bns.nameImport(cases[0].namespace, "beta", bob, cases[0].zonefile, {
sender: bob
})
expect(receipt.success).eq(false);
expect(receipt.error).include('Aborted: 1014');

// Now that the namespace is ready, Dave should be able to update his name
receipt = await bns.nameUpdate(
cases[0].namespace,
Expand Down Expand Up @@ -224,7 +231,7 @@ describe("BNS Test Suite - NAME_IMPORT", () => {
sender: charlie
});
expect(receipt.success).eq(true);
expect(receipt.result).include('u28');
expect(receipt.result).include('u29');

receipt = await bns.nameRegister(
cases[0].namespace,
Expand All @@ -236,7 +243,6 @@ describe("BNS Test Suite - NAME_IMPORT", () => {
expect(receipt.error).include('2004');
expect(receipt.success).eq(false);


// Charlie trying to renew 'alpha.blockstack' should fail
receipt = await bns.nameRenewal(cases[0].namespace, "alpha", 160000, charlie, cases[0].zonefile, {
sender: charlie
Expand Down
Loading

0 comments on commit fe81b98

Please sign in to comment.