Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagated hsd PR 499 (https://github.com/handshake-org/hsd/pull/499)… #53

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/primitives/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ class Address extends bio.Struct {
throw new Error('Object is not an address.');

if (Buffer.isBuffer(data)) {
if (data.length !== 20 && data.length !== 32)
throw new Error('Object is not an address.');
return data;
}

Expand Down
1 change: 0 additions & 1 deletion lib/wallet/txdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,6 @@ class TXDB {
ns.applyState(delta);

if (ns.isNull()) {
await this.removeNameMap(b, nameHash);
b.del(layout.A.encode(nameHash));
} else {
b.put(layout.A.encode(nameHash), ns.encode());
Expand Down
10 changes: 5 additions & 5 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1228,9 +1228,6 @@ class Wallet extends EventEmitter {
async _importName(name) {
const nameHash = rules.hashName(name);

if (await this.txdb.hasNameState(nameHash))
throw new Error('Name already exists.');

const b = this.db.batch();
await this.wdb.addNameMap(b, nameHash, this.wid);
await b.write();
Expand Down Expand Up @@ -1715,7 +1712,10 @@ class Wallet extends EventEmitter {
continue;
}

const addr = await this.receiveAddress(acct);
const addr = Address.fromNulldata(Buffer.alloc(2));
try {
await this.importName(name);
} catch (err) { /** swallow the case where an expired name re-opened */ }

const output = new Output();
output.address = addr;
Expand Down Expand Up @@ -1749,7 +1749,7 @@ class Wallet extends EventEmitter {
async _createBatchOpen(names, force, options) {
const acct = options ? options.account || 0 : 0;
const {mtx, errors, isAllError} = await this
.makeBatchOpen(names, force, acct);
.makeBatchOpen(names, force, acct);
if (!isAllError) {
await this.fill(mtx, options);
const finalizedMtx = await this.finalize(mtx, options);
Expand Down
15 changes: 4 additions & 11 deletions test/wallet-importname-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,8 @@ describe('Wallet Import Name', function() {
assert(ns4 === null);
});

it('should not re-import an existing name', async () => {
await assert.rejects(
alice.importName(name),
{message: 'Name already exists.'}
);
it('should ignore re-importing existing name', async () => {
await alice.importName(name);
});

it('should bid on names from Alice\'s wallet', async () => {
Expand Down Expand Up @@ -223,13 +220,9 @@ describe('Wallet Import Name', function() {
assert(!bid.own);
});

it('should not re-import name', async () => {
it('should ignore re-importing name', async () => {
await wclient.execute('selectwallet', ['charlie']);

await assert.rejects(
wclient.execute('importname', [name, 0]),
{message: 'Name already exists.'}
);
await wclient.execute('importname', [name, 0]);
});
});
});
48 changes: 24 additions & 24 deletions test/wallet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 2);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.coin, 1); // OPENs are sent to a null address
assert.strictEqual(bal.confirmed, fund);
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, 0);
Expand All @@ -2030,7 +2030,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 2);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.coin, 1);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, 0);
Expand All @@ -2047,7 +2047,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 3);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, lockup);
Expand All @@ -2065,7 +2065,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 3);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, lockup);
Expand All @@ -2082,7 +2082,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 4);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, value);
Expand All @@ -2100,7 +2100,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 4);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, value);
Expand Down Expand Up @@ -2145,7 +2145,7 @@ describe('Wallet', function() {
assert.strictEqual(bal.tx, 5);
// Wallet coin count doesn't change:
// REVEAL + fee money -> REGISTER + change
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2163,7 +2163,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 5);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2178,7 +2178,7 @@ describe('Wallet', function() {
// Check
const senderBal1 = await wallet.getBalance();
assert.strictEqual(senderBal1.tx, 6);
assert.strictEqual(senderBal1.coin, 4);
assert.strictEqual(senderBal1.coin, 3);
assert.strictEqual(senderBal1.confirmed, fund - (cTXCount * fee));
assert.strictEqual(senderBal1.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(senderBal1.ulocked, secondHighest);
Expand All @@ -2204,7 +2204,7 @@ describe('Wallet', function() {
// Check
const senderBal2 = await wallet.getBalance();
assert.strictEqual(senderBal2.tx, 6);
assert.strictEqual(senderBal2.coin, 4);
assert.strictEqual(senderBal2.coin, 3);
assert.strictEqual(senderBal2.confirmed, fund - (cTXCount * fee));
assert.strictEqual(senderBal2.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(senderBal2.ulocked, secondHighest);
Expand All @@ -2230,7 +2230,7 @@ describe('Wallet', function() {
const senderBal3 = await wallet.getBalance();
assert.strictEqual(senderBal3.tx, 7);
// One less wallet coin because name UTXO belongs to recip now
assert.strictEqual(senderBal3.coin, 3);
assert.strictEqual(senderBal3.coin, 2);
assert.strictEqual(senderBal3.confirmed, fund - (cTXCount * fee));
assert.strictEqual(senderBal3.unconfirmed, fund - secondHighest - (uTXCount * fee));
assert.strictEqual(senderBal3.ulocked, 0);
Expand Down Expand Up @@ -2259,7 +2259,7 @@ describe('Wallet', function() {
// Check
senderBalBefore = await wallet.getBalance();
assert.strictEqual(senderBalBefore.tx, 7);
assert.strictEqual(senderBalBefore.coin, 3);
assert.strictEqual(senderBalBefore.coin, 2);
assert.strictEqual(senderBalBefore.confirmed, fund - secondHighest - (cTXCount * fee));
assert.strictEqual(senderBalBefore.unconfirmed, fund - secondHighest - (uTXCount * fee));
assert.strictEqual(senderBalBefore.ulocked, 0);
Expand Down Expand Up @@ -2292,7 +2292,7 @@ describe('Wallet', function() {
// Check
const senderBal4 = await wallet.getBalance();
assert.strictEqual(senderBal4.tx, 7);
assert.strictEqual(senderBal4.coin, 3);
assert.strictEqual(senderBal4.coin, 2);
assert.strictEqual(senderBal4.confirmed, fund - (cTXCount * fee));
assert.strictEqual(senderBal4.unconfirmed, fund - secondHighest - (uTXCount * fee));
assert.strictEqual(senderBal4.ulocked, 0);
Expand Down Expand Up @@ -2396,7 +2396,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 2);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.coin, 1);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, 0);
Expand All @@ -2412,7 +2412,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 2);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.coin, 1);
assert.strictEqual(bal.confirmed, 10e6 - (1 * fee));
assert.strictEqual(bal.unconfirmed, 10e6 - (1 * fee));
assert.strictEqual(bal.ulocked, 0);
Expand All @@ -2431,7 +2431,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 3);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, lockup);
Expand All @@ -2447,7 +2447,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 3);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, 10e6 - (2 * fee));
assert.strictEqual(bal.unconfirmed, 10e6 - (2 * fee));
assert.strictEqual(bal.ulocked, lockup);
Expand All @@ -2466,7 +2466,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 4);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, value);
Expand Down Expand Up @@ -2508,7 +2508,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 4);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, 10e6 - (3 * fee));
assert.strictEqual(bal.unconfirmed, 10e6 - (3 * fee));
assert.strictEqual(bal.ulocked, value);
Expand All @@ -2529,7 +2529,7 @@ describe('Wallet', function() {
assert.strictEqual(bal.tx, 5);
// Wallet coin count doesn't change:
// REVEAL + fee money -> REGISTER + change
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2546,7 +2546,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 5);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2565,7 +2565,7 @@ describe('Wallet', function() {
// Check
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 6);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2581,7 +2581,7 @@ describe('Wallet', function() {
// Check
let bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 6);
assert.strictEqual(bal.coin, 4);
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.confirmed, fund - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - (uTXCount * fee));
assert.strictEqual(bal.ulocked, secondHighest);
Expand All @@ -2601,7 +2601,7 @@ describe('Wallet', function() {
bal = await wallet.getBalance();
assert.strictEqual(bal.tx, 7);
// Coin count reduced by giving away name UTXO
assert.strictEqual(bal.coin, 3);
assert.strictEqual(bal.coin, 2);
assert.strictEqual(bal.confirmed, fund - secondHighest - (cTXCount * fee));
assert.strictEqual(bal.unconfirmed, fund - secondHighest - (uTXCount * fee));
assert.strictEqual(bal.ulocked, 0);
Expand Down