block-syncer-js

Fast block sync and retrieval using bloom filters
git clone git://git.defalsify.org/block-sync-js.git
Log | Files | Refs

1_sync.js (754B)


      1 const assert = require('assert');
      2 const moolb = require('moolb');
      3 
      4 const sync = require('../sync');
      5 
      6 describe('sync', () => {
      7 
      8 	it('blocks_tx', () => {
      9 		const filter_blocks = new moolb.Bloom(8192, 3);
     10 		const filter_blocktxs = new moolb.Bloom(8192, 3);
     11 
     12 		let b = new ArrayBuffer(4);
     13 		let w = new DataView(b);
     14 		w.setUint32(0, 42);
     15 
     16 		filter_blocks.add(new Uint8Array(b));
     17 
     18 		b = new ArrayBuffer(8);
     19 		w = new DataView(b);
     20 		w.setUint32(0, 42);
     21 		w.setUint32(4, 13);
     22 		filter_blocktxs.add(new Uint8Array(b));
     23 
     24 		const countGetter = (n) => {
     25 			return new Promise((yay, nay) => {
     26 				yay(100);
     27 			});	
     28 		}
     29 
     30 		sync.by_filter(0, 50, filter_blocks, filter_blocktxs, countGetter, (r, t) => {
     31 			assert.equals(r, 42);
     32 			assert.equals(r, 42);
     33 		});
     34 	});
     35 });