2_ondemand.js (861B)
1 const assert = require('assert'); 2 const Web3 = require('web3'); 3 const moolb = require('moolb'); 4 5 const driver = require('../driver'); 6 const sync = require('../sync'); 7 8 describe('ondemand', () => { 9 10 it('driver', () => { 11 const w3 = new Web3('http://localhost:8545'); 12 13 const callback = (r) => { 14 assert.equal(r.blockNumber, 2); 15 assert.equal(r.transactionIndex, 0); 16 } 17 18 const filter_blocks = new moolb.Bloom(8192, 3); 19 const filter_blocktxs = new moolb.Bloom(8192, 3); 20 21 let b = new ArrayBuffer(4); 22 let w = new DataView(b); 23 w.setUint32(0, 2); 24 25 filter_blocks.add(new Uint8Array(b)); 26 27 b = new ArrayBuffer(8); 28 w = new DataView(b); 29 w.setUint32(0, 2); 30 w.setUint32(4, 0); 31 filter_blocktxs.add(new Uint8Array(b)); 32 33 const drv = new driver.Driver(w3, 0, [filter_blocks, filter_blocktxs], sync.by_filter, callback); 34 35 drv.start(); 36 }); 37 38 }); 39