Skip to content

Commit

Permalink
wallet: clean up remove and test
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz authored and chikeichan committed Feb 4, 2021
1 parent 79b3b05 commit 5b77ede
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
20 changes: 10 additions & 10 deletions lib/wallet/walletdb.js
Expand Up @@ -1018,6 +1018,16 @@ class WalletDB extends EventEmitter {
return this.removePathMap(b, hash, wid);
});

const niter = this.db.iterator({
gte: layout.N.min(),
lte: layout.N.max()
});

await niter.each((key) => {
const [hash] = layout.N.decode(key);
return this.removeNameMap(b, hash, wid);
});

const removeRange = (opt) => {
return this.db.iterator(opt).each(key => b.del(key));
};
Expand Down Expand Up @@ -1070,16 +1080,6 @@ class WalletDB extends EventEmitter {
return this.removeOutpointMap(b, hash, index, wid);
});

const niter = this.db.iterator({
gte: layout.N.min(),
lte: layout.N.max()
});

await niter.each((key) => {
const [hash] = layout.N.decode(key);
return this.removeNameMap(b, hash, wid);
});

const uiter = bucket.iterator({
gte: tlayout.p.min(),
lte: tlayout.p.max(),
Expand Down
15 changes: 9 additions & 6 deletions test/wallet-test.js
Expand Up @@ -1510,20 +1510,23 @@ describe('Wallet', function() {
await b.write();

// Should return tx from TX Map
assert(await wdb.getWalletsByTX(mtx));
let wids = await wdb.getWalletsByTX(mtx);
assert(wids.has(wid));

// Should have wid in NameMap
const map = await wdb.getNameMap(hashName('test123'));
let map = await wdb.getNameMap(hashName('test123'));
assert(map.wids.has(wid));

// Remove wallet
await wdb.remove('alice100');

// Should not return wid from NameMap after wid is removed
assert(!await wdb.getNameMap(hashName('test123')));

// Should not return tx from TX Map after wallet is removed
assert(!await wdb.getWalletsByTX(mtx));
wids = await wdb.getWalletsByTX(mtx);
assert.strictEqual(wids, null);

// Should not return wid from NameMap after wid is removed
map = await wdb.getNameMap(hashName('test123'));
assert.strictEqual(map, null);

// Should not return wallet after it is removed
assert(!await wdb.get('alice100'));
Expand Down

0 comments on commit 5b77ede

Please sign in to comment.