wdb: Add timeCache to the interactive rescan callback.

test: fix NodeContext usage and update tests.
This commit is contained in:
Nodari Chkuaselidze 2024-08-29 15:36:25 +04:00
parent de79842af1
commit 6aeceed719
No known key found for this signature in database
GPG key ID: B018A7BB437D1F05
9 changed files with 25 additions and 11 deletions

View file

@ -61,9 +61,7 @@ class TXDB {
this.db = wdb.db;
this.logger = wdb.logger;
this.nowFn = wdb.options.nowFn || util.now;
this.maxTXs = wdb.options.maxHistoryTXs || 100;
this.nowFn = util.now;
this.wid = wid || 0;
this.bucket = null;

View file

@ -203,9 +203,13 @@ class WalletDB extends EventEmitter {
this.client.hook('block rescan interactive', async (entry, txs) => {
try {
return await this.rescanBlockInteractive(entry, txs);
this.timeCache.start();
const result = await this.rescanBlockInteractive(entry, txs);
this.timeCache.commit();
return result;
} catch (e) {
this.emit('error', e);
this.timeCache.drop();
return {
type: scanActions.ABORT
};

View file

@ -439,6 +439,8 @@ describe('Node HTTP', function() {
wallet: true
});
nodeCtx.init();
const {nclient} = nodeCtx;
before(async () => {
@ -532,6 +534,8 @@ describe('Node HTTP', function() {
wallet: true
});
nodeCtx.init();
const {nclient, network} = nodeCtx;
const genesisBlock = Block.decode(network.genesisBlock);
let minedHashes;
@ -705,7 +709,7 @@ async function mineBlocks(nodeCtx, count, address) {
count
);
const hashes = await nodeCtx.mineBlocks(count, address);
const blocks = await nodeCtx.mineBlocks(count, address);
await blockEvents;
return hashes;
return blocks.map(block => block.hash().toString('hex'));
}

View file

@ -372,10 +372,15 @@ class NodeContext {
if (!tip)
tip = this.chain.tip;
const blocks = [];
for (let i = 0; i < count; i++) {
const block = await this.miner.mineBlock(tip, address);
tip = await this.chain.add(block);
blocks.push(block);
}
return blocks;
}
}

View file

@ -25,7 +25,8 @@ exports.generateInitialBlocks = async (options) => {
await nodeCtx.nclient.execute('setmocktime', [blocktime]);
const blocks = await nodeCtx.mineBlocks(1, coinbase);
const block = await nodeCtx.nclient.execute('getblock', [blocks[0]]);
const firstHash = blocks[0].hash().toString('hex');
const block = await nodeCtx.nclient.execute('getblock', [firstHash]);
assert(block.time <= blocktime + 1);
assert(block.time >= blocktime);

View file

@ -1189,8 +1189,6 @@ describe('Wallet HTTP', function() {
if (key.startsWith(wid1 + '42'))
dumpSlice[key] = dump[key];
});
console.log(dumpSlice);
});
it('should get auction info', async () => {

View file

@ -65,7 +65,8 @@ describe('WalletDB Pagination', function() {
const mtx = await dummyTX(wallet);
const wids = await wdb.addTX(mtx.toTX());
assert.strictEqual(wids.size, 1);
assert(wids);
assert.strictEqual(wids.wids.size, 1);
const txCount = await wallet.txdb.getCountForTX(mtx.hash());
assert.strictEqual(txCount.index, initUCount.index);

View file

@ -53,6 +53,8 @@ describe('Wallet RPC Methods', function() {
wallet: true
});
nodeCtx.init();
wclient = nodeCtx.wclient;
nclient = nodeCtx.nclient;
wdb = nodeCtx.wdb;

View file

@ -2061,14 +2061,15 @@ describe('Wallet', function() {
});
it('should pass nowFn to the txdb', async () => {
const nowFn = () => 1;
const NOW = 1;
const nowFn = () => NOW;
const wallet = new Wallet({
options: {
nowFn
}
});
assert.strictEqual(wallet.txdb.nowFn(), nowFn());
assert.strictEqual(wallet.txdb.nowFn(), NOW);
});
it('should cleanup', async () => {