test: clarify node-spv-sync event checks.

This commit is contained in:
Nodari Chkuaselidze 2022-05-13 22:26:59 +04:00
parent 6e94e69d5a
commit 5513832961
No known key found for this signature in database
GPG key ID: B018A7BB437D1F05
2 changed files with 9 additions and 6 deletions

View file

@ -1,7 +1,6 @@
'use strict';
const assert = require('bsert');
const chainCommon = require('../lib/blockchain/common');
const Chain = require('../lib/blockchain/chain');
const BlockStore = require('../lib/blockstore/level');
const WorkerPool = require('../lib/workers/workerpool');
@ -19,9 +18,8 @@ const workers = new WorkerPool({
function addBlock(chain, block, wallet) {
if (chain.options.spv) {
const flags = chainCommon.flags.VERIFY_NONE;
const mblock = MerkleBlock.fromBlock(block, wallet.filter);
return chain.add(mblock, flags);
return chain.add(mblock);
}
return chain.add(block);

View file

@ -85,9 +85,6 @@ describe('SPV Node Sync', function() {
// back up
const coinbaseMaturity = node.network.coinbaseMaturity;
if (process.browser)
this.skip();
before(async () => {
await node.open();
await spvnode.open();
@ -238,6 +235,7 @@ describe('SPV Node Sync', function() {
assert(chain.tip.chainwork.gt(tip1.chainwork));
// Wait for all events.
// And collect event responses for later checks.
const [reorgs, resets, blocks] = await Promise.all([
spvReorgedEvent,
spvResetEvent,
@ -245,6 +243,10 @@ describe('SPV Node Sync', function() {
]);
{
// We only had 1 reorganize event, make sure
// tip, competitor, fork of the reorg match with
// chain reorganize event. Checking SPV is doing
// the exact same reorg.
const [tip, competitor, fork] = reorgs[0].values;
assert.bufferEqual(tip.hash, tipHash);
assert.bufferEqual(competitor.hash, competitorHash);
@ -252,11 +254,14 @@ describe('SPV Node Sync', function() {
}
{
// Make sure SPV reset to the FORK point.
const [resetToEntry] = resets[0].values;
assert.bufferEqual(resetToEntry.hash, forkHash);
}
{
// We receive competitorHash.height - fork.height block events.
// Make sure last block event is the same as full node chain.tip.
const lastBlockHash = blocks.pop().values[0].hash();
assert.bufferEqual(lastBlockHash, node.chain.tip.hash);
}