How to use fromCache method in storybook-root

Best JavaScript code snippet using storybook-root

history.js

Source:history.js Github

copy

Full Screen

1'use strict';2var _ = require('lodash');3var async = require('async');4var chai = require('chai');5var sinon = require('sinon');6var should = chai.should();7var log = require('npmlog');8log.debug = log.verbose;9var Bitcore = require('bitcore-lib');10var Bitcore_ = {11 btc: Bitcore,12 bch: require('bitcore-lib-cash')13};14var Common = require('../../ts_build/lib/common');15var Utils = Common.Utils;16var Constants = Common.Constants;17var Defaults = Common.Defaults;18var Model = require('../../ts_build/lib/model');19var WalletService = require('../../ts_build/lib/server');20var HugeTxs = require('./hugetx');21var TestData = require('../testdata');22var helpers = require('./helpers');23var storage, blockchainExplorer, request;24describe('History', function() {25 before(function(done) {26 helpers.before((res) => {27 done();28 });29 });30 beforeEach(function(done) {31 log.level = 'error';32 helpers.beforeEach(function(res) {33 storage = res.storage;34 blockchainExplorer = res.blockchainExplorer;35 request = res.request;36 done();37 });38 });39 after(function(done) {40 helpers.after(done);41 });42 var BCHEIGHT = 10000;43 describe.skip('#checkWalletData', function() {44 it('should check wallet data', (done) => {45 blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, BCHEIGHT, 'hash');46 helpers.createAndJoinWallet(1, 1, function(s, w) {47 server = s;48 wallet = w;49 helpers.createAddresses(server, wallet, 1, 1, function(main, change) {50 mainAddresses = main;51 changeAddresses = change;52 helpers.stubFeeLevels({53 24: 10000,54 });55 helpers.stubCheckData(blockchainExplorer, server, wallet.coin == 'bch', done);56 });57 });58 });59 });60 describe('#getTxHistory', function() {61 var server, wallet, mainAddresses, changeAddresses;62 beforeEach(function(done) {63 blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, BCHEIGHT, 'hash');64 helpers.createAndJoinWallet(1, 1, function(s, w) {65 server = s;66 wallet = w;67 helpers.createAddresses(server, wallet, 1, 1, function(main, change) {68 mainAddresses = main;69 changeAddresses = change;70 helpers.stubFeeLevels({71 24: 10000,72 });73 helpers.stubCheckData(blockchainExplorer, server, wallet.coin == 'bch', done);74 });75 });76 });77 it('should get tx history from insight, 20 items', function(done) {78 helpers.stubHistory(50, BCHEIGHT);79 server.getTxHistory({limit: 20}, function(err, txs, fromCache) {80 should.not.exist(err);81 fromCache.should.equal(false);82 should.exist(txs);83 txs.length.should.equal(20);84 var i = 0;85 _.each(txs, function(tx) {86 tx.txid.should.equal('txid' + i);87 tx.confirmations.should.equal(i);88 if (i) {89 tx.blockheight.should.equal(BCHEIGHT - i + 1);90 } else {91 // The first one is unconfirmed92 should.not.exist(tx.blockheight);93 }94 i++;95 });96 done();97 });98 });99 it('should filter out DUST amount', function(done) {100 let txs= helpers.createTxsV8(50, BCHEIGHT);101 txs[5].satoshis=100;102 txs[15].satoshis=10;103 txs[25].satoshis=1;104 helpers.stubHistory(null, null, txs);105 server.getTxHistory({limit: 50}, function(err, txs, fromCache) {106 should.not.exist(err);107 fromCache.should.equal(false);108 should.exist(txs);109 txs.length.should.equal(47);110 done();111 });112 });113 it('should handle 2 incoming payments on the same txs, 2 different addr', function(done) {114 let txs= helpers.createTxsV8(3, BCHEIGHT);115 txs[1].address=txs[0].address;116 txs[1].txid=txs[0].txid;117 txs[1].id=txs[0].id;118 txs[1].satoshis = 10000;119 txs[1].address='other address';120 121 helpers.stubHistory(null, null, txs);122 server.getTxHistory({limit: 50}, function(err, txs, fromCache) {123 should.not.exist(err);124 fromCache.should.equal(false);125 should.exist(txs);126 txs.length.should.equal(2);127 // one tx from 2 items128 txs[0].amount.should.equal(40001);129 txs[0].outputs.should.deep.equal([130 {131 "address": "muFJi3ZPfR5nhxyD7dfpx2nYZA8Wmwzgck",132 "amount": 30001,133 },134 {135 "address": "other address",136 "amount": 10000,137 }]);138 txs[0].txid.should.equal('txid0');139 txs[1].amount.should.equal(30001);140 done();141 });142 });143 it('should handle 2 incoming payments on the same txs, 2 different addr, one dust', function(done) {144 let txs= helpers.createTxsV8(3, BCHEIGHT);145 txs[1].address=txs[0].address;146 txs[1].txid=txs[0].txid;147 txs[1].id=txs[0].id;148 txs[1].satoshis = 100;149 txs[1].address='other address';150 151 helpers.stubHistory(null, null, txs);152 server.getTxHistory({limit: 50}, function(err, txs, fromCache) {153 should.not.exist(err);154 fromCache.should.equal(false);155 should.exist(txs);156 txs.length.should.equal(2);157 // one tx from 2 items158 txs[0].amount.should.equal(30001);159 txs[0].outputs.should.deep.equal([160 {161 "address": "muFJi3ZPfR5nhxyD7dfpx2nYZA8Wmwzgck",162 "amount": 30001,163 },164 ]);165 txs[0].txid.should.equal('txid0');166 txs[1].amount.should.equal(30001);167 done();168 });169 });170 it('should handle moves, filtering change addresses (case 1)', function(done) {171 let txs= helpers.createTxsV8(20, 1000);172 helpers.createAddresses(server, wallet, 1, 1, function(main, change) {173 // 2 move tx.174 txs[0].address =change[0].address;175 txs[0].txid =txs[1].txid;176 txs[0].height =txs[1].height;177 txs[1].address =main[0].address;178 txs[0].category=txs[1].category='move';179 helpers.stubHistory(null, null, txs);180 server.getTxHistory({limit: 10}, function(err, txs, fromCache) {181 should.not.exist(err);182 fromCache.should.equal(false);183 should.exist(txs);184 txs.length.should.equal(10);185 // should filter out 1 move186 txs[0].action.should.equal('moved');187 txs[1].action.should.equal('received');188 // should keep the main address189 txs[0].outputs[0].address.should.equal(main[0].address);190 done();191 });192 });193 });194 it('should handle moves, filtering change addresses (case 2)', function(done) {195 let txs= helpers.createTxsV8(20, 1000);196 helpers.createAddresses(server, wallet, 1, 1, function(main, change) {197 // 2 move tx, inverted vouts198 txs[0].address =main[0].address;199 txs[0].txid =txs[1].txid;200 txs[0].height =txs[1].height;201 txs[1].address =change[0].address;202 txs[0].category=txs[1].category='move';203 helpers.stubHistory(null, null, txs);204 server.getTxHistory({limit: 10}, function(err, txs, fromCache) {205 should.not.exist(err);206 fromCache.should.equal(false);207 should.exist(txs);208 txs.length.should.equal(10);209 // should filter out 1 move210 txs[0].action.should.equal('moved');211 txs[1].action.should.equal('received');212 // should keep the main address213 txs[0].outputs[0].address.should.equal(main[0].address);214 done();215 });216 });217 });218 it('should handle moves, filtering change addresses in multisend', function(done) {219 let txs= helpers.createTxsV8(20, 1000);220 helpers.createAddresses(server, wallet, 2, 1, function(main, change) {221 txs[0].txid =txs[1].txid = txs[2].txid =txs[3].txid;222 txs[0].height =txs[1].height = txs[2].height =txs[3].height;223 txs[0].category=txs[1].category= txs[2].category=txs[3].category='move';224 txs[0].address =main[0].address;225 txs[1].address =main[0].address;226 txs[2].address =change[0].address;227 txs[3].address =main[1].address;228 helpers.stubHistory(null, null, txs);229 server.getTxHistory({limit: 10}, function(err, txs, fromCache) {230 should.not.exist(err);231 fromCache.should.equal(false);232 should.exist(txs);233 txs.length.should.equal(10);234 // should filter out 1 move235 txs[0].action.should.equal('moved');236 txs[1].action.should.equal('received');237 // should keep the main address238 _.map(txs[0].outputs,'address').should.include(239 main[0].address,240 main[1].address,241 );242 _.map(txs[0].outputs,'address').should.not.include(243 change[0].address,244 );245 done();246 });247 });248 });249 it('should get tx history from cache', function(done) {250 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;251 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;252 helpers.stubHistory(50, BCHEIGHT); //(0->49)253 // this call is to fill the cache254 server.getTxHistory({limit: 20}, function(err, txs, fromCache) {255 fromCache = !!fromCache;256 should.not.exist(err);257 fromCache.should.equal(false);258 should.exist(txs);259 txs.length.should.equal(20);260 _.first(txs).id.should.equal('id0');261 server.getTxHistory({skip: 20, limit: 10}, function(err, txs, fromCache) {262 // first TX result should be:263 // txid: 19264 // confirmations: 19265 should.not.exist(err);266 fromCache.should.equal(true);267 should.exist(txs);268 txs.length.should.equal(10);269 _.first(txs).id.should.equal('id20');270 var i = 20;271 _.each(txs, function(tx) {272 tx.txid.should.equal('txid' + i);273 tx.confirmations.should.equal(i);274 tx.blockheight.should.equal(BCHEIGHT - i + 1);275 i++;276 });277 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;278 done();279 });280 });281 });282 it('should get tx history from cache and bc mixed', function(done) {283 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;284 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;285 helpers.stubHistory(50, BCHEIGHT); //(0->49)286 // this call is to fill the cache287 server.getTxHistory({limit: 20}, function(err, txs, fromCache) {288 should.not.exist(err);289 fromCache.should.equal(false);290 should.exist(txs);291 txs.length.should.equal(20);292 _.first(txs).id.should.equal('id0');293 server.getTxHistory({skip: 5, limit: 20}, function(err, txs, fromCache) {294 // first TX result should be:295 // txid: 19296 // confirmations: 19297 should.not.exist(err);298 fromCache.should.equal(true);299 should.exist(txs);300 txs.length.should.equal(20);301 _.first(txs).id.should.equal('id5');302 var i = 5;303 _.each(txs, function(tx) {304 tx.txid.should.equal('txid' + i);305 tx.confirmations.should.equal(i);306 tx.blockheight.should.equal(BCHEIGHT - i + 1);307 i++;308 });309 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;310 done();311 });312 });313 });314 it('should get tx history from cache and bc mixed, updating confirmations', function(done) {315 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;316 var _time = Defaults.BLOCKHEIGHT_CACHE_TIME ;317 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;318 // remove bc tip cache.319 Defaults.BLOCKHEIGHT_CACHE_TIME = 0;320 helpers.stubHistory(50, BCHEIGHT); //(0->49)321 // this call is to fill the cache322 server.getTxHistory({limit: 20}, function(err, txs, fromCache) {323 should.not.exist(err);324 fromCache.should.equal(false);325 // change height from 10000 to 10100326 let heightOffset = 100;327 blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, 10000 + heightOffset, 'hash');328 server.getTxHistory({skip: 5, limit: 20}, function(err, txs, fromCache) {329 should.not.exist(err);330 fromCache.should.equal(true);331 var i = 5;332 _.each(txs, function(tx) {333 tx.confirmations.should.equal(i + heightOffset);334 i++;335 });336 Defaults.BLOCKHEIGHT_CACHE_TIME = _time;337 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;338 done();339 });340 });341 });342 describe("Stream cache", () => {343 it('should not stream cache on first call', function(done) {344 this.timeout(10000);345 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;346 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;347 helpers.stubHistory(100, 10000);348 let limit =20;349 let allTxs = [];350 // this call is to fill the cache351 server.getTxHistory({limit: limit}, function(err, txs, fromCache, useStream) {352 should.not.exist(err);353 fromCache.should.equal(false);354 useStream.should.equal(false);355 should.exist(txs);356 txs.length.should.equal(limit);357 _.first(txs).id.should.equal('id0');358 allTxs = allTxs.concat(txs);359 let i=limit;360 let cont = true;361 let x=false;362 async.doWhilst(363 (next) => {364 server.getTxHistory({skip: i, limit: limit}, function(err, txs, fromCache, useStream) {365 should.not.exist(err);366 if (txs && txs.length < 20) {367 cont = false;368 return next();369 }370 fromCache.should.equal(true);371 useStream.should.equal(x);372 x=true;373 should.exist(txs);374 allTxs = allTxs.concat(txs);375 _.first(txs).id.should.equal('id' + i);376 i+=limit;377 next();378 });379 },380 () => {381 return cont;382 },383 (err) => {384 should.not.exist(err);385 let i = 0;386 _.each(allTxs, function(x) {387 x.id.should.equal('id' + i);388 i++;389 });390 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;391 done();392 });393 });394 });395 it('should get tx history from cache and bc mixed', function(done) {396 this.timeout(10000);397 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;398 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;399 helpers.stubHistory(1000, 10000); //(0->49)400 let limit =20;401 let allTxs = [];402 // this call is to fill the cache403 server.getTxHistory({limit: limit}, function(err, txs, fromCache) {404 should.not.exist(err);405 fromCache.should.equal(false);406 should.exist(txs);407 txs.length.should.equal(limit);408 _.first(txs).id.should.equal('id0');409 allTxs = allTxs.concat(txs);410 let i=limit;411 let cont = true;412 async.doWhilst(413 (next) => {414 server.getTxHistory({skip: i, limit: limit}, function(err, txs, fromCache) {415 should.not.exist(err);416 if (txs && txs.length < 20) {417 cont = false;418 return next();419 }420 fromCache.should.equal(true);421 should.exist(txs);422 allTxs = allTxs.concat(txs);423 _.first(txs).id.should.equal('id' + i);424 i+=limit;425 next();426 });427 },428 () => {429 return cont;430 },431 (err) => {432 should.not.exist(err);433 let i = 0;434 _.each(allTxs, function(x) {435 x.id.should.equal('id' + i);436 i++;437 });438 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;439 done();440 });441 });442 });443 it('should download history with prime page size and total txs', function(done) {444 this.timeout(10000);445 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;446 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;447 helpers.stubHistory(997, 10000); //(0->49)448 let limit =17;449 let allTxs = [];450 // this call is to fill the cache451 server.getTxHistory({limit: limit}, function(err, txs, fromCache) {452 should.not.exist(err);453 fromCache.should.equal(false);454 should.exist(txs);455 txs.length.should.equal(limit);456 _.first(txs).id.should.equal('id0');457 allTxs = allTxs.concat(txs);458 let i=limit;459 let cont = true;460 async.doWhilst(461 (next) => {462 server.getTxHistory({skip: i, limit: limit}, function(err, txs, fromCache) {463 should.not.exist(err);464 if (txs && txs.length < limit) {465 cont = false;466 return next();467 }468 fromCache.should.equal(true);469 should.exist(txs);470 allTxs = allTxs.concat(txs);471 _.first(txs).id.should.equal('id' + i);472 i+=limit;473 next();474 });475 },476 () => {477 return cont;478 },479 (err) => {480 should.not.exist(err);481 let i = 0;482 _.each(allTxs, function(x) {483 x.id.should.equal('id' + i);484 i++;485 });486 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;487 done();488 });489 });490 });491 it('should download history with stream cache> page', function(done) {492 this.timeout(10000);493 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;494 Defaults.CONFIRMATIONS_TO_START_CACHING = 100;495 helpers.stubHistory(997, 10000); //(0->49)496 let limit =17;497 let allTxs = [];498 // this call is to fill the cache499 server.getTxHistory({limit: limit}, function(err, txs, fromCache) {500 should.not.exist(err);501 fromCache.should.equal(false);502 should.exist(txs);503 txs.length.should.equal(limit);504 _.first(txs).id.should.equal('id0');505 allTxs = allTxs.concat(txs);506 let i=limit;507 let cont = true;508 async.doWhilst(509 (next) => {510 server.getTxHistory({skip: i, limit: limit}, function(err, txs, fromCache) {511 should.not.exist(err);512 if (txs && txs.length < limit) {513 cont = false;514 return next();515 }516 if (i>100)517 fromCache.should.equal(true);518 should.exist(txs);519 allTxs = allTxs.concat(txs);520 _.first(txs).id.should.equal('id' + i);521 i+=limit;522 next();523 });524 },525 () => {526 return cont;527 },528 (err) => {529 should.not.exist(err);530 let i = 0;531 _.each(allTxs, function(x) {532 x.id.should.equal('id' + i);533 i++;534 });535 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;536 done();537 });538 });539 });540 });541 it('should get tx history from insight, in 2 overlapping pages', function(done) {542 helpers.stubHistory(300, BCHEIGHT);543 server.getTxHistory({limit: 25}, function(err, txs, fromCache) {544 should.not.exist(err);545 fromCache.should.equal(false);546 txs.length.should.equal(25);547 // no cache548 server.getTxHistory({skip:5, limit: 21}, function(err, txs2, fromCache) {549 should.not.exist(err);550 fromCache = !!fromCache;551 fromCache.should.equal(false);552 should.exist(txs2);553 txs2.length.should.equal(21);554 var i = 0;555 _.each(txs, function(tx) {556 tx.txid.should.equal('txid' + i++);557 });558 var i = 5;559 _.each(txs2, function(tx) {560 tx.txid.should.equal('txid' + i++);561 });562 done();563 });564 });565 });566 it('should include raw tx in includeExtendedInfo is passed', function(done) {567 var external = '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7';568 helpers.stubUtxos(server, wallet, [1, 2], function(utxos) {569 var txOpts = {570 outputs: [{571 toAddress: external,572 amount: 0.3e8,573 }],574 feePerKb: 100e2,575 customData: {576 "test": true577 },578 };579 helpers.createAndPublishTx(server, txOpts, TestData.copayers[0].privKey_1H_0, function(tx) {580 should.exist(tx);581 var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);582 server.signTx({583 txProposalId: tx.id,584 signatures: signatures,585 }, function(err, tx) {586 should.not.exist(err);587 helpers.stubBroadcast(tx.txid);588 server.broadcastTx({589 txProposalId: tx.id590 }, function(err, txp) {591 should.not.exist(err);592 var t = (new Date).toISOString();593 var txs = [{594 id: 1,595 txid: txp.txid,596 confirmations: 1,597 blockTime: t,598 size: 226,599 category: 'send',600 address: external,601 satoshis: 0.5e8,602 height: 1000,603 },604 {605 id: 2,606 txid: txp.txid,607 confirmations: 1,608 category: 'send',609 blockTime: t,610 satoshis: 0.3e8,611 address: external,612 height: 1000,613 },614 {615 id: 3,616 txid: txp.txid,617 confirmations: 1,618 blockTime: t,619 satoshis: 5460,620 category: 'fee',621 height: 1000,622 },623 ];624 helpers.stubHistory(null, null,txs);625 helpers.stubCheckData(blockchainExplorer, server, wallet.coin == 'bch', () =>{626 server.getTxHistory({627 includeExtendedInfo: true,628 }, function(err, txs) {629 should.not.exist(err);630 should.exist(txs);631 txs.length.should.equal(1);632 var tx = txs[0];633 tx.raw.should.contain('00000000');634 tx.createdOn.should.equal(txp.createdOn);635 tx.action.should.equal('sent');636 tx.amount.should.equal(0.8e8);637 tx.addressTo.should.equal(external);638 tx.actions.length.should.equal(1);639 tx.actions[0].type.should.equal('accept');640 done();641 });642 });643 });644 });645 });646 });647 });648 it('should get tx history with accepted proposal, multisend', function(done) {649 var external = '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7';650 helpers.stubUtxos(server, wallet, [1, 2], function(utxos) {651 var txOpts = {652 outputs: [{653 toAddress: external,654 amount: 0.5e8,655 message: undefined // no message656 }, {657 toAddress: external,658 amount: 0.3e8,659 message: 'message #2'660 }],661 feePerKb: 100e2,662 message: 'some message',663 customData: {664 "test": true665 },666 };667 helpers.createAndPublishTx(server, txOpts, TestData.copayers[0].privKey_1H_0, function(tx) {668 should.exist(tx);669 var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);670 server.signTx({671 txProposalId: tx.id,672 signatures: signatures,673 }, function(err, tx) {674 should.not.exist(err);675 helpers.stubBroadcast(tx.txid);676 server.broadcastTx({677 txProposalId: tx.id678 }, function(err, txp) {679 should.not.exist(err);680 var t = (new Date).toISOString();681 var txs = [{682 id: 1,683 txid: txp.txid,684 confirmations: 1,685 blockTime: t,686 size: 226,687 category: 'send',688 address: external,689 satoshis: 0.5e8,690 height: 1000,691 },692 {693 id: 2,694 txid: txp.txid,695 confirmations: 1,696 category: 'send',697 blockTime: t,698 satoshis: 0.3e8,699 address: external,700 height: 1000,701 },702 {703 id: 3,704 txid: txp.txid,705 confirmations: 1,706 blockTime: t,707 satoshis: 5460,708 category: 'fee',709 height: 1000,710 },711 ];712 helpers.stubHistory(null, null,txs);713 helpers.stubCheckData(blockchainExplorer, server, wallet.coin == 'bch', () =>{714 server.getTxHistory({}, function(err, txs) {715 should.not.exist(err);716 should.exist(txs);717 txs.length.should.equal(1);718 var tx = txs[0];719 tx.createdOn.should.equal(txp.createdOn);720 tx.action.should.equal('sent');721 tx.amount.should.equal(0.8e8);722 should.not.exist(tx.raw);723 tx.message.should.equal('some message');724 tx.addressTo.should.equal(external);725 tx.actions.length.should.equal(1);726 tx.actions[0].type.should.equal('accept');727 tx.actions[0].copayerName.should.equal('copayer 1');728 tx.outputs[0].address.should.equal(external);729 tx.outputs[0].amount.should.equal(0.5e8);730 should.not.exist(tx.outputs[0].message);731 should.not.exist(tx.outputs[0]['isMine']);732 should.not.exist(tx.outputs[0]['isChange']);733 tx.outputs[1].address.should.equal(external);734 tx.outputs[1].amount.should.equal(0.3e8);735 should.exist(tx.outputs[1].message);736 tx.outputs[1].message.should.equal('message #2');737 should.exist(tx.customData);738 should.exist(tx.customData["test"]);739 done();740 });741 });742 });743 });744 });745 });746 });747 it.skip('should get various paginated tx history', function(done) {748 var testCases = [{749 opts: {},750 expected: [50, 40, 30, 20, 10],751 }, {752 opts: {753 skip: 1,754 limit: 3,755 },756 expected: [40, 30, 20],757 }, {758 opts: {759 skip: 1,760 limit: 2,761 },762 expected: [40, 30],763 }, {764 opts: {765 skip: 2,766 },767 expected: [30, 20, 10],768 }, {769 opts: {770 limit: 4,771 },772 expected: [50, 40, 30, 20],773 }, {774 opts: {775 skip: 0,776 limit: 3,777 },778 expected: [50, 40, 30],779 }, {780 opts: {781 skip: 0,782 limit: 0,783 },784 expected: [],785 }, {786 opts: {787 skip: 4,788 limit: 10,789 },790 expected: [10],791 }, {792 opts: {793 skip: 20,794 limit: 1,795 },796 expected: [],797 }];798 var timestamps = [50, 40, 30, 20, 10];799 var txs = _.map(timestamps, function(ts, idx) {800 return {801 txid: (idx + 1).toString(),802 confirmations: ts / 10,803 fees: 100,804 time: ts,805 inputs: [{806 address: 'external',807 amount: 500,808 }],809 outputs: [{810 address: mainAddresses[0].address,811 amount: 200,812 }],813 };814 });815 helpers.stubHistory(txs);816 async.each(testCases, function(testCase, next) {817 server.getTxHistory(testCase.opts, function(err, txs) {818 should.not.exist(err);819 should.exist(txs);820 _.pluck(txs, 'time').should.deep.equal(testCase.expected);821 next();822 });823 }, done);824 });825 it.skip('should fail gracefully if unable to reach the blockchain', function(done) {826 blockchainExplorer.getTransactions = sinon.stub().callsArgWith(3, 'dummy error');827 server.getTxHistory({}, function(err, txs) {828 should.exist(err);829 err.toString().should.equal('dummy error');830 done();831 });832 });833 it('should handle ETH/w ERC20 history history ', function(done) {834 helpers.stubHistory();835 helpers.stubHistory(null, null, TestData.historyETH);836 server.getTxHistory({}, function(err, txs) {837 should.not.exist(err);838 should.exist(txs)839 txs.length.should.equal(9);840 txs[2].should.deep.equal({841 id: '5ddbf28d4ff191801711a948',842 txid:843 '0xf992febe3257518c00c09ae96cafe988dfe5b625bbf5515b679807f650f58e88',844 confirmations: 0,845 blockheight: 8999242,846 fees: 1100740000000000,847 time: 1574695599,848 size: undefined,849 amount: 0,850 action: 'sent',851 addressTo: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',852 outputs:853 [ { address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',854 amount: 0 } ],855 dust: false,856 lowFees: false,857 });858 done();859 });860 });861 it.skip('should set lowFees atribute for sub-superEconomy level fees on unconfirmed txs', function(done) {862 helpers.stubFeeLevels({863 24: 10000,864 });865 var txs = [{866 txid: '1',867 confirmations: 0,868 fees: 100,869 time: 20,870 inputs: [{871 address: 'external',872 amount: 500,873 }],874 outputs: [{875 address: mainAddresses[0].address,876 amount: 200,877 }],878 size: 500,879 }, {880 txid: '2',881 confirmations: 0,882 fees: 6000,883 time: 20,884 inputs: [{885 address: 'external',886 amount: 500,887 }],888 outputs: [{889 address: mainAddresses[0].address,890 amount: 200,891 }],892 size: 500,893 }, {894 txid: '3',895 confirmations: 6,896 fees: 100,897 time: 20,898 inputs: [{899 address: 'external',900 amount: 500,901 }],902 outputs: [{903 address: mainAddresses[0].address,904 amount: 200,905 }],906 size: 500,907 }];908 helpers.stubHistory(txs, BCHEIGHT);909 server.getTxHistory({}, function(err, txs) {910 should.not.exist(err);911 var tx = txs[0];912 tx.feePerKb.should.equal(200);913 tx.lowFees.should.be.true;914 tx = txs[1];915 tx.feePerKb.should.equal(12000);916 tx.lowFees.should.be.false;917 tx = txs[2];918 tx.feePerKb.should.equal(200);919 should.not.exist(tx.lowFees);920 done();921 });922 });923 it.skip('should get tx history even if fee levels are unavailable', function(done) {924 blockchainExplorer.estimateFee = sinon.stub().yields('dummy error');925 var txs = [{926 txid: '1',927 confirmations: 1,928 fees: 100,929 time: 20,930 inputs: [{931 address: 'external',932 amount: 500,933 }],934 outputs: [{935 address: mainAddresses[0].address,936 amount: 200,937 }],938 size: 500,939 }];940 helpers.stubHistory(txs);941 server.getTxHistory({}, function(err, txs) {942 should.not.exist(err);943 var tx = txs[0];944 tx.feePerKb.should.equal(200);945 should.not.exist(tx.foreignCrafted);946 should.not.exist(tx.lowFees);947 done();948 });949 });950 it.skip('should handle outgoing txs where fee > amount', function(done) {951 var x = _.cloneDeep([HugeTxs[0]]);952 x[0].vin[118].addr = mainAddresses[0].address;953 helpers.stubHistory(x);954 server.getTxHistory({}, function(err, txs) {955 should.not.exist(err);956 should.exist(txs);957 txs.length.should.equal(1);958 var tx = txs[0];959 tx.action.should.equal('sent');960 tx.amount.should.equal(3002982);961 tx.fees.should.equal(10000000);962 tx.outputs[0].address.should.equal('1DVhaBdbp5mx5Y8zR1qR9NBiQtrgL9ZNQs');963 tx.outputs[0].amount.should.equal(500000000);964 tx.foreignCrafted.should.equal(true);965 done();966 });967 });968 it.skip('should handle incoming txs with fee > incoming', function(done) {969 var x = _.cloneDeep([HugeTxs[1]]);970 x[0].vout[43].scriptPubKey.addresses = [mainAddresses[0].address];971 helpers.stubHistory(x);972 server.getTxHistory({}, function(err, txs) {973 should.not.exist(err);974 should.exist(txs);975 txs.length.should.equal(1);976 var tx = txs[0];977 tx.action.should.equal('received');978 tx.amount.should.equal(3002982);979 tx.fees.should.equal(130700);980 done();981 });982 });983 });984 describe.skip('Downloading history', function() {985 var h;986 beforeEach(function(done) {987 blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, 1000, 'hash');988 h = helpers.historyCacheTest(200);989 helpers.stubHistory(h, BCHEIGHT);990 server.storage.clearTxHistoryCache(server.walletId, function() {991 done();992 });993 });994 it('from 0 to 200, two times, in order', function(done) {995 async.eachSeries(_.range(0, 200, 5), function(i, next) {996 server.getTxHistory({997 skip: i,998 limit: 5,999 }, function(err, txs, fromCache) {1000 should.not.exist(err);1001 should.exist(txs);1002 txs.length.should.equal(5);1003 var s = h.slice(i, i + 5);1004 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));1005 fromCache.should.equal(false);1006 next();1007 });1008 }, function() {1009 async.eachSeries(_.range(0, 200, 5), function(i, next) {1010 server.getTxHistory({1011 skip: i,1012 limit: 5,1013 }, function(err, txs, fromCache) {1014 should.not.exist(err);1015 should.exist(txs);1016 txs.length.should.equal(5);1017 var s = h.slice(i, i + 5);1018 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));1019 fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING && i < 200);1020 next();1021 });1022 }, done);1023 });1024 });1025 it('from 0 to 200, two times, random', function(done) {1026 var indexes = _.range(0, 200, 5);1027 async.eachSeries(_.shuffle(indexes), function(i, next) {1028 server.getTxHistory({1029 skip: i,1030 limit: 5,1031 }, function(err, txs, fromCache) {1032 should.not.exist(err);1033 should.exist(txs);1034 txs.length.should.equal(5);1035 var s = h.slice(i, i + 5);1036 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));1037 fromCache.should.equal(false);1038 next();1039 });1040 }, function() {1041 async.eachSeries(_.range(0, 190, 7), function(i, next) {1042 server.getTxHistory({1043 skip: i,1044 limit: 7,1045 }, function(err, txs, fromCache) {1046 should.not.exist(err);1047 should.exist(txs);1048 txs.length.should.equal(7);1049 var s = h.slice(i, i + 7);1050 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));1051 fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING);1052 next();1053 });1054 }, done);1055 });1056 });1057 it('from 0 to 200, two times, random, with resets', function(done) {1058 var indexes = _.range(0, 200, 5);1059 async.eachSeries(_.shuffle(indexes), function(i, next) {1060 server.getTxHistory({1061 skip: i,1062 limit: 5,1063 }, function(err, txs, fromCache) {1064 should.not.exist(err);1065 should.exist(txs);1066 txs.length.should.equal(5);1067 var s = h.slice(i, i + 5);1068 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));1069 fromCache.should.equal(false);1070 next();1071 });1072 }, function() {1073 async.eachSeries(_.range(0, 200, 5), function(i, next) {1074 function resetCache(cb) {1075 if (!(i % 25)) {1076 storage.softResetTxHistoryCache(server.walletId, function() {1077 return cb(true);1078 });1079 } else {1080 return cb(false);1081 }1082 }1083 resetCache(function(reset) {1084 server.getTxHistory({1085 skip: i,1086 limit: 5,1087 }, function(err, txs, fromCache) {1088 should.not.exist(err);1089 should.exist(txs);1090 txs.length.should.equal(5);1091 var s = h.slice(i, i + 5);1092 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));1093 fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING && !reset);1094 next();1095 });1096 });1097 }, done);1098 });1099 });1100 });...

Full Screen

Full Screen

attrack-test-data.es

Source:attrack-test-data.es Github

copy

Full Screen

1module.exports = {2 thirdpartyscript: {3 onBeforeRequest: [4 {5 url: 'http://localhost:60508/thirdpartyscript.html',6 method: 'GET',7 frameId: 66,8 parentFrameId: 66,9 tabId: 66,10 type: 6,11 originUrl: 'http://localhost:60508/thirdpartyscript.html',12 isPrivate: false,13 fromCache: false,14 tabUrl: 'http://localhost:60508/thirdpartyscript.html'15 },16 {17 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',18 method: 'GET',19 frameId: 66,20 parentFrameId: 66,21 tabId: 66,22 type: 2,23 originUrl: 'http://localhost:60508/thirdpartyscript.html',24 isPrivate: false,25 fromCache: false,26 tabUrl: 'http://localhost:60508/thirdpartyscript.html'27 },28 {29 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',30 method: 'GET',31 frameId: 66,32 parentFrameId: 66,33 tabId: 66,34 type: 11,35 originUrl: 'http://localhost:60508/thirdpartyscript.html',36 isPrivate: false,37 fromCache: false,38 tabUrl: 'http://localhost:60508/thirdpartyscript.html'39 }40 ],41 onBeforeSendHeaders: [42 {43 url: 'http://localhost:60508/thirdpartyscript.html',44 method: 'GET',45 frameId: 66,46 parentFrameId: 66,47 tabId: 66,48 type: 6,49 originUrl: 'http://localhost:60508/thirdpartyscript.html',50 isPrivate: false,51 fromCache: false,52 tabUrl: 'http://localhost:60508/thirdpartyscript.html'53 },54 {55 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',56 method: 'GET',57 frameId: 66,58 parentFrameId: 66,59 tabId: 66,60 type: 2,61 originUrl: 'http://localhost:60508/thirdpartyscript.html',62 isPrivate: false,63 fromCache: false,64 tabUrl: 'http://localhost:60508/thirdpartyscript.html'65 },66 {67 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',68 method: 'GET',69 frameId: 66,70 parentFrameId: 66,71 tabId: 66,72 type: 11,73 originUrl: 'http://localhost:60508/thirdpartyscript.html',74 isPrivate: false,75 fromCache: false,76 tabUrl: 'http://localhost:60508/thirdpartyscript.html'77 }78 ],79 onHeadersReceived: [80 {81 url: 'http://localhost:60508/thirdpartyscript.html',82 method: 'GET',83 frameId: 66,84 parentFrameId: 66,85 tabId: 66,86 type: 6,87 originUrl: 'http://localhost:60508/thirdpartyscript.html',88 statusCode: 200,89 isPrivate: false,90 fromCache: true,91 tabUrl: 'http://localhost:60508/thirdpartyscript.html'92 },93 {94 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',95 method: 'GET',96 frameId: 66,97 parentFrameId: 66,98 tabId: 66,99 type: 2,100 originUrl: 'http://localhost:60508/thirdpartyscript.html',101 statusCode: 200,102 isPrivate: false,103 fromCache: false,104 tabUrl: 'http://localhost:60508/thirdpartyscript.html'105 },106 {107 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',108 method: 'GET',109 frameId: 66,110 parentFrameId: 66,111 tabId: 66,112 type: 11,113 originUrl: 'http://localhost:60508/thirdpartyscript.html',114 statusCode: 200,115 isPrivate: false,116 fromCache: false,117 tabUrl: 'http://localhost:60508/thirdpartyscript.html'118 }119 ]120 },121 injectedscript: {122 onBeforeRequest: [123 {124 url: 'http://localhost:60508/injectedscript.html',125 method: 'GET',126 frameId: 69,127 parentFrameId: 69,128 tabId: 69,129 type: 6,130 originUrl: 'http://localhost:60508/injectedscript.html',131 isPrivate: false,132 fromCache: false,133 tabUrl: 'http://localhost:60508/injectedscript.html'134 },135 {136 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',137 method: 'GET',138 frameId: 69,139 parentFrameId: 69,140 tabId: 69,141 type: 11,142 originUrl: 'http://localhost:60508/injectedscript.html',143 isPrivate: false,144 fromCache: false,145 tabUrl: 'http://localhost:60508/injectedscript.html'146 },147 {148 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',149 method: 'GET',150 frameId: 69,151 parentFrameId: 69,152 tabId: 69,153 type: 2,154 originUrl: 'http://localhost:60508/injectedscript.html',155 isPrivate: false,156 fromCache: false,157 tabUrl: 'http://localhost:60508/injectedscript.html'158 }159 ],160 onBeforeSendHeaders: [161 {162 url: 'http://localhost:60508/injectedscript.html',163 method: 'GET',164 frameId: 69,165 parentFrameId: 69,166 tabId: 69,167 type: 6,168 originUrl: 'http://localhost:60508/injectedscript.html',169 isPrivate: false,170 fromCache: false,171 tabUrl: 'http://localhost:60508/injectedscript.html'172 },173 {174 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',175 method: 'GET',176 frameId: 69,177 parentFrameId: 69,178 tabId: 69,179 type: 11,180 originUrl: 'http://localhost:60508/injectedscript.html',181 isPrivate: false,182 fromCache: false,183 tabUrl: 'http://localhost:60508/injectedscript.html'184 },185 {186 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',187 method: 'GET',188 frameId: 69,189 parentFrameId: 69,190 tabId: 69,191 type: 2,192 originUrl: 'http://localhost:60508/injectedscript.html',193 isPrivate: false,194 fromCache: false,195 tabUrl: 'http://localhost:60508/injectedscript.html'196 }197 ],198 onHeadersReceived: [199 {200 url: 'http://localhost:60508/injectedscript.html',201 method: 'GET',202 frameId: 69,203 parentFrameId: 69,204 tabId: 69,205 type: 6,206 originUrl: 'http://localhost:60508/injectedscript.html',207 statusCode: 200,208 isPrivate: false,209 fromCache: true,210 tabUrl: 'http://localhost:60508/injectedscript.html'211 },212 {213 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',214 method: 'GET',215 frameId: 69,216 parentFrameId: 69,217 tabId: 69,218 type: 11,219 originUrl: 'http://localhost:60508/injectedscript.html',220 statusCode: 200,221 isPrivate: false,222 fromCache: false,223 tabUrl: 'http://localhost:60508/injectedscript.html'224 },225 {226 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',227 method: 'GET',228 frameId: 69,229 parentFrameId: 69,230 tabId: 69,231 type: 2,232 originUrl: 'http://localhost:60508/injectedscript.html',233 statusCode: 200,234 isPrivate: false,235 fromCache: false,236 tabUrl: 'http://localhost:60508/injectedscript.html'237 }238 ]239 },240 imgtest: {241 onBeforeRequest: [242 {243 url: 'http://localhost:60508/imgtest.html',244 method: 'GET',245 frameId: 72,246 parentFrameId: 72,247 tabId: 72,248 type: 6,249 originUrl: 'http://localhost:60508/imgtest.html',250 isPrivate: false,251 fromCache: false,252 tabUrl: 'http://localhost:60508/imgtest.html'253 },254 {255 url: 'http://localhost:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',256 method: 'GET',257 frameId: 72,258 parentFrameId: 72,259 tabId: 72,260 type: 3,261 originUrl: 'http://localhost:60508/imgtest.html',262 isPrivate: false,263 fromCache: false,264 tabUrl: 'http://localhost:60508/imgtest.html'265 },266 {267 url: 'http://127.0.0.1:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',268 method: 'GET',269 frameId: 72,270 parentFrameId: 72,271 tabId: 72,272 type: 3,273 originUrl: 'http://localhost:60508/imgtest.html',274 isPrivate: false,275 fromCache: false,276 tabUrl: 'http://localhost:60508/imgtest.html'277 }278 ],279 onBeforeSendHeaders: [280 {281 url: 'http://localhost:60508/imgtest.html',282 method: 'GET',283 frameId: 72,284 parentFrameId: 72,285 tabId: 72,286 type: 6,287 originUrl: 'http://localhost:60508/imgtest.html',288 isPrivate: false,289 fromCache: false,290 tabUrl: 'http://localhost:60508/imgtest.html'291 },292 {293 url: 'http://localhost:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',294 method: 'GET',295 frameId: 72,296 parentFrameId: 72,297 tabId: 72,298 type: 3,299 originUrl: 'http://localhost:60508/imgtest.html',300 isPrivate: false,301 fromCache: false,302 tabUrl: 'http://localhost:60508/imgtest.html'303 },304 {305 url: 'http://127.0.0.1:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',306 method: 'GET',307 frameId: 72,308 parentFrameId: 72,309 tabId: 72,310 type: 3,311 originUrl: 'http://localhost:60508/imgtest.html',312 isPrivate: false,313 fromCache: false,314 tabUrl: 'http://localhost:60508/imgtest.html'315 }316 ],317 onHeadersReceived: [318 {319 url: 'http://localhost:60508/imgtest.html',320 method: 'GET',321 frameId: 72,322 parentFrameId: 72,323 tabId: 72,324 type: 6,325 originUrl: 'http://localhost:60508/imgtest.html',326 statusCode: 200,327 isPrivate: false,328 fromCache: true,329 tabUrl: 'http://localhost:60508/imgtest.html'330 },331 {332 url: 'http://localhost:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',333 method: 'GET',334 frameId: 72,335 parentFrameId: 72,336 tabId: 72,337 type: 3,338 originUrl: 'http://localhost:60508/imgtest.html',339 statusCode: 200,340 isPrivate: false,341 fromCache: false,342 tabUrl: 'http://localhost:60508/imgtest.html'343 },344 {345 url: 'http://127.0.0.1:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',346 method: 'GET',347 frameId: 72,348 parentFrameId: 72,349 tabId: 72,350 type: 3,351 originUrl: 'http://localhost:60508/imgtest.html',352 statusCode: 200,353 isPrivate: false,354 fromCache: false,355 tabUrl: 'http://localhost:60508/imgtest.html'356 }357 ]358 },359 crossdomainxhr: {360 onBeforeRequest: [361 {362 url: 'http://localhost:60508/crossdomainxhr.html',363 method: 'GET',364 frameId: 75,365 parentFrameId: 75,366 tabId: 75,367 type: 6,368 originUrl: 'http://localhost:60508/crossdomainxhr.html',369 isPrivate: false,370 fromCache: false,371 tabUrl: 'http://localhost:60508/crossdomainxhr.html'372 },373 {374 url: 'http://localhost:60508/vendor/jquery.min.js',375 method: 'GET',376 frameId: 75,377 parentFrameId: 75,378 tabId: 75,379 type: 2,380 originUrl: 'http://localhost:60508/crossdomainxhr.html',381 isPrivate: false,382 fromCache: false,383 tabUrl: 'http://localhost:60508/crossdomainxhr.html'384 },385 {386 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',387 method: 'GET',388 frameId: 75,389 parentFrameId: 75,390 tabId: 75,391 type: 11,392 originUrl: 'http://localhost:60508/crossdomainxhr.html',393 isPrivate: false,394 fromCache: false,395 tabUrl: 'http://localhost:60508/crossdomainxhr.html'396 },397 {398 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',399 method: 'GET',400 frameId: 75,401 parentFrameId: 75,402 tabId: 75,403 type: 11,404 originUrl: 'http://localhost:60508/crossdomainxhr.html',405 isPrivate: false,406 fromCache: false,407 tabUrl: 'http://localhost:60508/crossdomainxhr.html'408 }409 ],410 onBeforeSendHeaders: [411 {412 url: 'http://localhost:60508/crossdomainxhr.html',413 method: 'GET',414 frameId: 75,415 parentFrameId: 75,416 tabId: 75,417 type: 6,418 originUrl: 'http://localhost:60508/crossdomainxhr.html',419 isPrivate: false,420 fromCache: false,421 tabUrl: 'http://localhost:60508/crossdomainxhr.html'422 },423 {424 url: 'http://localhost:60508/vendor/jquery.min.js',425 method: 'GET',426 frameId: 75,427 parentFrameId: 75,428 tabId: 75,429 type: 2,430 originUrl: 'http://localhost:60508/crossdomainxhr.html',431 isPrivate: false,432 fromCache: false,433 tabUrl: 'http://localhost:60508/crossdomainxhr.html'434 },435 {436 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',437 method: 'GET',438 frameId: 75,439 parentFrameId: 75,440 tabId: 75,441 type: 11,442 originUrl: 'http://localhost:60508/crossdomainxhr.html',443 isPrivate: false,444 fromCache: false,445 tabUrl: 'http://localhost:60508/crossdomainxhr.html'446 },447 {448 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',449 method: 'GET',450 frameId: 75,451 parentFrameId: 75,452 tabId: 75,453 type: 11,454 originUrl: 'http://localhost:60508/crossdomainxhr.html',455 isPrivate: false,456 fromCache: false,457 tabUrl: 'http://localhost:60508/crossdomainxhr.html'458 }459 ],460 onHeadersReceived: [461 {462 url: 'http://localhost:60508/crossdomainxhr.html',463 method: 'GET',464 frameId: 75,465 parentFrameId: 75,466 tabId: 75,467 type: 6,468 originUrl: 'http://localhost:60508/crossdomainxhr.html',469 statusCode: 200,470 isPrivate: false,471 fromCache: true,472 tabUrl: 'http://localhost:60508/crossdomainxhr.html'473 },474 {475 url: 'http://localhost:60508/vendor/jquery.min.js',476 method: 'GET',477 frameId: 75,478 parentFrameId: 75,479 tabId: 75,480 type: 2,481 originUrl: 'http://localhost:60508/crossdomainxhr.html',482 statusCode: 200,483 isPrivate: false,484 fromCache: true,485 tabUrl: 'http://localhost:60508/crossdomainxhr.html'486 },487 {488 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',489 method: 'GET',490 frameId: 75,491 parentFrameId: 75,492 tabId: 75,493 type: 11,494 originUrl: 'http://localhost:60508/crossdomainxhr.html',495 statusCode: 200,496 isPrivate: false,497 fromCache: false,498 tabUrl: 'http://localhost:60508/crossdomainxhr.html'499 },500 {501 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',502 method: 'GET',503 frameId: 75,504 parentFrameId: 75,505 tabId: 75,506 type: 11,507 originUrl: 'http://localhost:60508/crossdomainxhr.html',508 statusCode: 200,509 isPrivate: false,510 fromCache: false,511 tabUrl: 'http://localhost:60508/crossdomainxhr.html'512 }513 ]514 },515 iframetest: {516 onBeforeRequest: [517 {518 url: 'http://localhost:60508/iframetest.html',519 method: 'GET',520 frameId: 78,521 parentFrameId: 78,522 tabId: 78,523 type: 6,524 originUrl: 'http://localhost:60508/iframetest.html',525 isPrivate: false,526 fromCache: false,527 tabUrl: 'http://localhost:60508/iframetest.html'528 },529 {530 url: 'http://localhost:60508/vendor/jquery.min.js',531 method: 'GET',532 frameId: 78,533 parentFrameId: 78,534 tabId: 78,535 type: 2,536 originUrl: 'http://localhost:60508/iframetest.html',537 isPrivate: false,538 fromCache: false,539 tabUrl: 'http://localhost:60508/iframetest.html'540 },541 {542 url: 'http://127.0.0.1:60508/iframe.html',543 method: 'GET',544 frameId: 81,545 parentFrameId: 78,546 tabId: 78,547 type: 7,548 originUrl: 'http://localhost:60508/iframetest.html',549 isPrivate: false,550 fromCache: false,551 tabUrl: 'http://localhost:60508/iframetest.html'552 },553 {554 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',555 method: 'GET',556 frameId: 78,557 parentFrameId: 78,558 tabId: 78,559 type: 11,560 originUrl: 'http://localhost:60508/iframetest.html',561 isPrivate: false,562 fromCache: false,563 tabUrl: 'http://localhost:60508/iframetest.html'564 },565 {566 url: 'http://127.0.0.1:60508/vendor/jquery.min.js',567 method: 'GET',568 frameId: 81,569 parentFrameId: 78,570 tabId: 78,571 type: 2,572 originUrl: 'http://127.0.0.1:60508/iframe.html',573 isPrivate: false,574 fromCache: false,575 tabUrl: 'http://localhost:60508/iframetest.html'576 },577 {578 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',579 method: 'GET',580 frameId: 81,581 parentFrameId: 78,582 tabId: 78,583 type: 11,584 originUrl: 'http://127.0.0.1:60508/iframe.html',585 isPrivate: false,586 fromCache: false,587 tabUrl: 'http://localhost:60508/iframetest.html'588 }589 ],590 onBeforeSendHeaders: [591 {592 url: 'http://localhost:60508/iframetest.html',593 method: 'GET',594 frameId: 78,595 parentFrameId: 78,596 tabId: 78,597 type: 6,598 originUrl: 'http://localhost:60508/iframetest.html',599 isPrivate: false,600 fromCache: false,601 tabUrl: 'http://localhost:60508/iframetest.html'602 },603 {604 url: 'http://localhost:60508/vendor/jquery.min.js',605 method: 'GET',606 frameId: 78,607 parentFrameId: 78,608 tabId: 78,609 type: 2,610 originUrl: 'http://localhost:60508/iframetest.html',611 isPrivate: false,612 fromCache: false,613 tabUrl: 'http://localhost:60508/iframetest.html'614 },615 {616 url: 'http://127.0.0.1:60508/iframe.html',617 method: 'GET',618 frameId: 81,619 parentFrameId: 78,620 tabId: 78,621 type: 7,622 originUrl: 'http://localhost:60508/iframetest.html',623 isPrivate: false,624 fromCache: false,625 tabUrl: 'http://localhost:60508/iframetest.html'626 },627 {628 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',629 method: 'GET',630 frameId: 78,631 parentFrameId: 78,632 tabId: 78,633 type: 11,634 originUrl: 'http://localhost:60508/iframetest.html',635 isPrivate: false,636 fromCache: false,637 tabUrl: 'http://localhost:60508/iframetest.html'638 },639 {640 url: 'http://127.0.0.1:60508/vendor/jquery.min.js',641 method: 'GET',642 frameId: 81,643 parentFrameId: 78,644 tabId: 78,645 type: 2,646 originUrl: 'http://127.0.0.1:60508/iframe.html',647 isPrivate: false,648 fromCache: false,649 tabUrl: 'http://localhost:60508/iframetest.html'650 },651 {652 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',653 method: 'GET',654 frameId: 81,655 parentFrameId: 78,656 tabId: 78,657 type: 11,658 originUrl: 'http://127.0.0.1:60508/iframe.html',659 isPrivate: false,660 fromCache: false,661 tabUrl: 'http://localhost:60508/iframetest.html'662 }663 ],664 onHeadersReceived: [665 {666 url: 'http://localhost:60508/iframetest.html',667 method: 'GET',668 frameId: 78,669 parentFrameId: 78,670 tabId: 78,671 type: 6,672 originUrl: 'http://localhost:60508/iframetest.html',673 statusCode: 200,674 isPrivate: false,675 fromCache: true,676 tabUrl: 'http://localhost:60508/iframetest.html'677 },678 {679 url: 'http://localhost:60508/vendor/jquery.min.js',680 method: 'GET',681 frameId: 78,682 parentFrameId: 78,683 tabId: 78,684 type: 2,685 originUrl: 'http://localhost:60508/iframetest.html',686 statusCode: 200,687 isPrivate: false,688 fromCache: true,689 tabUrl: 'http://localhost:60508/iframetest.html'690 },691 {692 url: 'http://127.0.0.1:60508/iframe.html',693 method: 'GET',694 frameId: 81,695 parentFrameId: 78,696 tabId: 78,697 type: 7,698 originUrl: 'http://localhost:60508/iframetest.html',699 statusCode: 200,700 isPrivate: false,701 fromCache: true,702 tabUrl: 'http://localhost:60508/iframetest.html'703 },704 {705 url: 'http://127.0.0.1:60508/vendor/jquery.min.js',706 method: 'GET',707 frameId: 81,708 parentFrameId: 78,709 tabId: 78,710 type: 2,711 originUrl: 'http://127.0.0.1:60508/iframe.html',712 statusCode: 200,713 isPrivate: false,714 fromCache: true,715 tabUrl: 'http://localhost:60508/iframetest.html'716 },717 {718 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',719 method: 'GET',720 frameId: 78,721 parentFrameId: 78,722 tabId: 78,723 type: 11,724 originUrl: 'http://localhost:60508/iframetest.html',725 statusCode: 200,726 isPrivate: false,727 fromCache: false,728 tabUrl: 'http://localhost:60508/iframetest.html'729 },730 {731 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',732 method: 'GET',733 frameId: 81,734 parentFrameId: 78,735 tabId: 78,736 type: 11,737 originUrl: 'http://127.0.0.1:60508/iframe.html',738 statusCode: 200,739 isPrivate: false,740 fromCache: false,741 tabUrl: 'http://localhost:60508/iframetest.html'742 }743 ]744 },745 image302test: {746 onBeforeRequest: [747 {748 url: 'http://localhost:60508/image302test.html',749 method: 'GET',750 frameId: 84,751 parentFrameId: 84,752 tabId: 84,753 type: 6,754 originUrl: 'http://localhost:60508/image302test.html',755 isPrivate: false,756 fromCache: false,757 tabUrl: 'http://localhost:60508/image302test.html'758 },759 {760 url: 'http://localhost:60508/tracker302.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',761 method: 'GET',762 frameId: 84,763 parentFrameId: 84,764 tabId: 84,765 type: 3,766 originUrl: 'http://localhost:60508/image302test.html',767 isPrivate: false,768 fromCache: false,769 tabUrl: 'http://localhost:60508/image302test.html'770 },771 {772 url: 'http://localhost:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',773 method: 'GET',774 frameId: 84,775 parentFrameId: 84,776 tabId: 84,777 type: 3,778 originUrl: 'http://localhost:60508/image302test.html',779 isPrivate: false,780 fromCache: false,781 tabUrl: 'http://localhost:60508/image302test.html'782 }783 ],784 onBeforeSendHeaders: [785 {786 url: 'http://localhost:60508/image302test.html',787 method: 'GET',788 frameId: 84,789 parentFrameId: 84,790 tabId: 84,791 type: 6,792 originUrl: 'http://localhost:60508/image302test.html',793 isPrivate: false,794 fromCache: false,795 tabUrl: 'http://localhost:60508/image302test.html'796 },797 {798 url: 'http://localhost:60508/tracker302.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',799 method: 'GET',800 frameId: 84,801 parentFrameId: 84,802 tabId: 84,803 type: 3,804 originUrl: 'http://localhost:60508/image302test.html',805 isPrivate: false,806 fromCache: false,807 tabUrl: 'http://localhost:60508/image302test.html'808 },809 {810 url: 'http://localhost:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',811 method: 'GET',812 frameId: 84,813 parentFrameId: 84,814 tabId: 84,815 type: 3,816 originUrl: 'http://localhost:60508/image302test.html',817 isPrivate: false,818 fromCache: false,819 tabUrl: 'http://localhost:60508/image302test.html'820 },821 {822 url: 'http://127.0.0.1:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',823 method: 'GET',824 frameId: 84,825 parentFrameId: 84,826 tabId: 84,827 type: 3,828 originUrl: 'http://localhost:60508/image302test.html',829 isPrivate: false,830 fromCache: false,831 tabUrl: 'http://localhost:60508/image302test.html'832 }833 ],834 onHeadersReceived: [835 {836 url: 'http://localhost:60508/image302test.html',837 method: 'GET',838 frameId: 84,839 parentFrameId: 84,840 tabId: 84,841 type: 6,842 originUrl: 'http://localhost:60508/image302test.html',843 statusCode: 200,844 isPrivate: false,845 fromCache: false,846 tabUrl: 'http://localhost:60508/image302test.html'847 },848 {849 url: 'http://localhost:60508/tracker302.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',850 method: 'GET',851 frameId: 84,852 parentFrameId: 84,853 tabId: 84,854 type: 3,855 originUrl: 'http://localhost:60508/image302test.html',856 statusCode: 302,857 isPrivate: false,858 fromCache: false,859 tabUrl: 'http://localhost:60508/image302test.html'860 },861 {862 url: 'http://localhost:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',863 method: 'GET',864 frameId: 84,865 parentFrameId: 84,866 tabId: 84,867 type: 3,868 originUrl: 'http://localhost:60508/image302test.html',869 statusCode: 200,870 isPrivate: false,871 fromCache: false,872 tabUrl: 'http://localhost:60508/image302test.html'873 },874 {875 url: 'http://127.0.0.1:60508/test.gif?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',876 method: 'GET',877 frameId: 84,878 parentFrameId: 84,879 tabId: 84,880 type: 3,881 originUrl: 'http://localhost:60508/image302test.html',882 statusCode: 200,883 isPrivate: false,884 fromCache: false,885 tabUrl: 'http://localhost:60508/image302test.html'886 }887 ]888 },889 nestediframetest: {890 onBeforeRequest: [891 {892 url: 'http://localhost:60508/nestediframetest.html',893 method: 'GET',894 frameId: 87,895 parentFrameId: 87,896 tabId: 87,897 type: 6,898 originUrl: 'http://localhost:60508/nestediframetest.html',899 isPrivate: false,900 fromCache: false,901 tabUrl: 'http://localhost:60508/nestediframetest.html'902 },903 {904 url: 'http://localhost:60508/vendor/jquery.min.js',905 method: 'GET',906 frameId: 87,907 parentFrameId: 87,908 tabId: 87,909 type: 2,910 originUrl: 'http://localhost:60508/nestediframetest.html',911 isPrivate: false,912 fromCache: false,913 tabUrl: 'http://localhost:60508/nestediframetest.html'914 },915 {916 url: 'http://cliqztest2.de:60508/proxyiframe.html',917 method: 'GET',918 frameId: 90,919 parentFrameId: 87,920 tabId: 87,921 type: 7,922 originUrl: 'http://localhost:60508/nestediframetest.html',923 isPrivate: false,924 fromCache: false,925 tabUrl: 'http://localhost:60508/nestediframetest.html'926 },927 {928 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',929 method: 'GET',930 frameId: 87,931 parentFrameId: 87,932 tabId: 87,933 type: 11,934 originUrl: 'http://localhost:60508/nestediframetest.html',935 isPrivate: false,936 fromCache: false,937 tabUrl: 'http://localhost:60508/nestediframetest.html'938 },939 {940 url: 'http://cliqztest2.de:60508/vendor/jquery.min.js',941 method: 'GET',942 frameId: 90,943 parentFrameId: 87,944 tabId: 87,945 type: 2,946 originUrl: 'http://cliqztest2.de:60508/proxyiframe.html',947 isPrivate: false,948 fromCache: false,949 tabUrl: 'http://localhost:60508/nestediframetest.html'950 },951 {952 url: 'http://127.0.0.1:60508/iframe2.html',953 method: 'GET',954 frameId: 93,955 parentFrameId: 90,956 tabId: 87,957 type: 7,958 originUrl: 'http://cliqztest2.de:60508/proxyiframe.html',959 isPrivate: false,960 fromCache: false,961 tabUrl: 'http://localhost:60508/nestediframetest.html'962 },963 {964 url: 'http://127.0.0.1:60508/vendor/jquery.min.js',965 method: 'GET',966 frameId: 93,967 parentFrameId: 90,968 tabId: 87,969 type: 2,970 originUrl: 'http://127.0.0.1:60508/iframe2.html',971 isPrivate: false,972 fromCache: false,973 tabUrl: 'http://localhost:60508/nestediframetest.html'974 },975 {976 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',977 method: 'GET',978 frameId: 93,979 parentFrameId: 90,980 tabId: 87,981 type: 11,982 originUrl: 'http://127.0.0.1:60508/iframe2.html',983 isPrivate: false,984 fromCache: false,985 tabUrl: 'http://localhost:60508/nestediframetest.html'986 }987 ],988 onBeforeSendHeaders: [989 {990 url: 'http://localhost:60508/nestediframetest.html',991 method: 'GET',992 frameId: 87,993 parentFrameId: 87,994 tabId: 87,995 type: 6,996 originUrl: 'http://localhost:60508/nestediframetest.html',997 isPrivate: false,998 fromCache: false,999 tabUrl: 'http://localhost:60508/nestediframetest.html'1000 },1001 {1002 url: 'http://localhost:60508/vendor/jquery.min.js',1003 method: 'GET',1004 frameId: 87,1005 parentFrameId: 87,1006 tabId: 87,1007 type: 2,1008 originUrl: 'http://localhost:60508/nestediframetest.html',1009 isPrivate: false,1010 fromCache: false,1011 tabUrl: 'http://localhost:60508/nestediframetest.html'1012 },1013 {1014 url: 'http://cliqztest2.de:60508/proxyiframe.html',1015 method: 'GET',1016 frameId: 90,1017 parentFrameId: 87,1018 tabId: 87,1019 type: 7,1020 originUrl: 'http://localhost:60508/nestediframetest.html',1021 isPrivate: false,1022 fromCache: false,1023 tabUrl: 'http://localhost:60508/nestediframetest.html'1024 },1025 {1026 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',1027 method: 'GET',1028 frameId: 87,1029 parentFrameId: 87,1030 tabId: 87,1031 type: 11,1032 originUrl: 'http://localhost:60508/nestediframetest.html',1033 isPrivate: false,1034 fromCache: false,1035 tabUrl: 'http://localhost:60508/nestediframetest.html'1036 },1037 {1038 url: 'http://cliqztest2.de:60508/vendor/jquery.min.js',1039 method: 'GET',1040 frameId: 90,1041 parentFrameId: 87,1042 tabId: 87,1043 type: 2,1044 originUrl: 'http://cliqztest2.de:60508/proxyiframe.html',1045 isPrivate: false,1046 fromCache: false,1047 tabUrl: 'http://localhost:60508/nestediframetest.html'1048 },1049 {1050 url: 'http://127.0.0.1:60508/iframe2.html',1051 method: 'GET',1052 frameId: 93,1053 parentFrameId: 90,1054 tabId: 87,1055 type: 7,1056 originUrl: 'http://cliqztest2.de:60508/proxyiframe.html',1057 isPrivate: false,1058 fromCache: false,1059 tabUrl: 'http://localhost:60508/nestediframetest.html'1060 },1061 {1062 url: 'http://127.0.0.1:60508/vendor/jquery.min.js',1063 method: 'GET',1064 frameId: 93,1065 parentFrameId: 90,1066 tabId: 87,1067 type: 2,1068 originUrl: 'http://127.0.0.1:60508/iframe2.html',1069 isPrivate: false,1070 fromCache: false,1071 tabUrl: 'http://localhost:60508/nestediframetest.html'1072 },1073 {1074 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',1075 method: 'GET',1076 frameId: 93,1077 parentFrameId: 90,1078 tabId: 87,1079 type: 11,1080 originUrl: 'http://127.0.0.1:60508/iframe2.html',1081 isPrivate: false,1082 fromCache: false,1083 tabUrl: 'http://localhost:60508/nestediframetest.html'1084 }1085 ],1086 onHeadersReceived: [1087 {1088 url: 'http://localhost:60508/nestediframetest.html',1089 method: 'GET',1090 frameId: 87,1091 parentFrameId: 87,1092 tabId: 87,1093 type: 6,1094 originUrl: 'http://localhost:60508/nestediframetest.html',1095 statusCode: 200,1096 isPrivate: false,1097 fromCache: true,1098 tabUrl: 'http://localhost:60508/nestediframetest.html'1099 },1100 {1101 url: 'http://localhost:60508/vendor/jquery.min.js',1102 method: 'GET',1103 frameId: 87,1104 parentFrameId: 87,1105 tabId: 87,1106 type: 2,1107 originUrl: 'http://localhost:60508/nestediframetest.html',1108 statusCode: 200,1109 isPrivate: false,1110 fromCache: true,1111 tabUrl: 'http://localhost:60508/nestediframetest.html'1112 },1113 {1114 url: 'http://cliqztest2.de:60508/proxyiframe.html',1115 method: 'GET',1116 frameId: 90,1117 parentFrameId: 87,1118 tabId: 87,1119 type: 7,1120 originUrl: 'http://localhost:60508/nestediframetest.html',1121 statusCode: 200,1122 isPrivate: false,1123 fromCache: true,1124 tabUrl: 'http://localhost:60508/nestediframetest.html'1125 },1126 {1127 url: 'http://cliqztest2.de:60508/vendor/jquery.min.js',1128 method: 'GET',1129 frameId: 90,1130 parentFrameId: 87,1131 tabId: 87,1132 type: 2,1133 originUrl: 'http://cliqztest2.de:60508/proxyiframe.html',1134 statusCode: 200,1135 isPrivate: false,1136 fromCache: true,1137 tabUrl: 'http://localhost:60508/nestediframetest.html'1138 },1139 {1140 url: 'http://localhost:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',1141 method: 'GET',1142 frameId: 87,1143 parentFrameId: 87,1144 tabId: 87,1145 type: 11,1146 originUrl: 'http://localhost:60508/nestediframetest.html',1147 statusCode: 200,1148 isPrivate: false,1149 fromCache: false,1150 tabUrl: 'http://localhost:60508/nestediframetest.html'1151 },1152 {1153 url: 'http://127.0.0.1:60508/iframe2.html',1154 method: 'GET',1155 frameId: 93,1156 parentFrameId: 90,1157 tabId: 87,1158 type: 7,1159 originUrl: 'http://cliqztest2.de:60508/proxyiframe.html',1160 statusCode: 200,1161 isPrivate: false,1162 fromCache: true,1163 tabUrl: 'http://localhost:60508/nestediframetest.html'1164 },1165 {1166 url: 'http://127.0.0.1:60508/vendor/jquery.min.js',1167 method: 'GET',1168 frameId: 93,1169 parentFrameId: 90,1170 tabId: 87,1171 type: 2,1172 originUrl: 'http://127.0.0.1:60508/iframe2.html',1173 statusCode: 200,1174 isPrivate: false,1175 fromCache: true,1176 tabUrl: 'http://localhost:60508/nestediframetest.html'1177 },1178 {1179 url: 'http://127.0.0.1:60508/test?callback=func&uid=04C2EAD03BAB7F5E-2E85855CF4C75134',1180 method: 'GET',1181 frameId: 93,1182 parentFrameId: 90,1183 tabId: 87,1184 type: 11,1185 originUrl: 'http://127.0.0.1:60508/iframe2.html',1186 statusCode: 200,1187 isPrivate: false,1188 fromCache: false,1189 tabUrl: 'http://localhost:60508/nestediframetest.html'1190 }1191 ]1192 }...

Full Screen

Full Screen

historyV8.js

Source:historyV8.js Github

copy

Full Screen

1'use strict';2var _ = require('lodash');3var async = require('async');4var chai = require('chai');5var sinon = require('sinon');6var should = chai.should();7var log = require('npmlog');8log.debug = log.verbose;9log.level = 'info';10var Bitcore = require('bitcore-lib');11var Bitcore_ = {12 btc: Bitcore,13 bch: require('bitcore-lib-cash')14};15var Common = require('../../lib/common');16var Utils = Common.Utils;17var Constants = Common.Constants;18var Defaults = Common.Defaults;19var Model = require('../../lib/model');20var WalletService = require('../../lib/server');21var HugeTxs = require('./hugetx');22var TestData = require('../testdata');23var helpers = require('./helpers');24var storage, blockchainExplorer, request;25describe('History V8', function() {26 before(function(done) {27 helpers.before(done);28 });29 beforeEach(function(done) {30 helpers.beforeEach(function(res) {31 storage = res.storage;32 blockchainExplorer = res.blockchainExplorer;33 request = res.request;34 done();35 });36 });37 after(function(done) {38 helpers.after(done);39 });40 var BCHEIGHT = 10000;41 describe.skip('#checkWalletData', function() {42 it('should check wallet data', (done) => {43 blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, BCHEIGHT, 'hash');44 helpers.createAndJoinWallet(1, 1, function(s, w) {45 server = s;46 wallet = w;47 helpers.createAddresses(server, wallet, 1, 1, function(main, change) {48 mainAddresses = main;49 changeAddresses = change;50 helpers.stubFeeLevels({51 24: 10000,52 });53 helpers.stubCheckData(blockchainExplorer, server, wallet.coin == 'bch', done);54 });55 });56 });57 });58 59 describe('#getTxHistoryV8', function() {60 var server, wallet, mainAddresses, changeAddresses;61 beforeEach(function(done) {62 blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, BCHEIGHT, 'hash');63 helpers.createAndJoinWallet(1, 1, function(s, w) {64 server = s;65 wallet = w;66 helpers.createAddresses(server, wallet, 1, 1, function(main, change) {67 mainAddresses = main;68 changeAddresses = change;69 helpers.stubFeeLevels({70 24: 10000,71 });72 helpers.stubCheckData(blockchainExplorer, server, wallet.coin == 'bch', done);73 });74 });75 });76 it('should get tx history from insight, 20 items', function(done) {77 helpers.stubHistoryV8(50, BCHEIGHT);78 server.getTxHistory({limit: 20}, function(err, txs, fromCache) {79 should.not.exist(err);80 fromCache.should.equal(false);81 should.exist(txs);82 txs.length.should.equal(20);83 var i = 0;84 _.each(txs, function(tx) {85 tx.txid.should.equal('txid' + i);86 tx.confirmations.should.equal(i);87 if (i) { 88 tx.blockheight.should.equal(BCHEIGHT - i + 1);89 } else {90 // The first one is unconfirmed91 should.not.exist(tx.blockheight);92 }93 i++;94 });95 done();96 });97 });98 it('should handle moves, filtering change addresses (case 1)', function(done) {99 let txs= helpers.createTxsV8(20, 1000);100 helpers.createAddresses(server, wallet, 1, 1, function(main, change) {101 // 2 move tx.102 txs[0].address =change[0].address;103 txs[0].txid =txs[1].txid;104 txs[0].height =txs[1].height;105 txs[1].address =main[0].address;106 txs[0].category=txs[1].category='move';107 108 helpers.stubHistoryV8(null, null, txs);109 server.getTxHistory({limit: 10}, function(err, txs, fromCache) {110 should.not.exist(err);111 fromCache.should.equal(false);112 should.exist(txs);113 txs.length.should.equal(10);114 // should filter out 1 move115 txs[0].action.should.equal('moved');116 txs[1].action.should.equal('received');117 // should keep the main address118 txs[0].outputs[0].address.should.equal(main[0].address);119 done();120 });121 });122 });123 it('should handle moves, filtering change addresses (case 2)', function(done) {124 let txs= helpers.createTxsV8(20, 1000);125 helpers.createAddresses(server, wallet, 1, 1, function(main, change) {126 // 2 move tx, inverted vouts127 txs[0].address =main[0].address;128 txs[0].txid =txs[1].txid;129 txs[0].height =txs[1].height;130 txs[1].address =change[0].address;131 txs[0].category=txs[1].category='move';132 133 helpers.stubHistoryV8(null, null, txs);134 server.getTxHistory({limit: 10}, function(err, txs, fromCache) {135 should.not.exist(err);136 fromCache.should.equal(false);137 should.exist(txs);138 txs.length.should.equal(10);139 // should filter out 1 move140 txs[0].action.should.equal('moved');141 txs[1].action.should.equal('received');142 // should keep the main address143 txs[0].outputs[0].address.should.equal(main[0].address);144 done();145 });146 });147 });148 it('should handle moves, filtering change addresses in multisend', function(done) {149 let txs= helpers.createTxsV8(20, 1000);150 helpers.createAddresses(server, wallet, 2, 1, function(main, change) {151 txs[0].txid =txs[1].txid = txs[2].txid =txs[3].txid;152 txs[0].height =txs[1].height = txs[2].height =txs[3].height;153 txs[0].category=txs[1].category= txs[2].category=txs[3].category='move';154 txs[0].address =main[0].address;155 txs[1].address =main[0].address;156 txs[2].address =change[0].address;157 txs[3].address =main[1].address;158 159 helpers.stubHistoryV8(null, null, txs);160 server.getTxHistory({limit: 10}, function(err, txs, fromCache) {161 should.not.exist(err);162 fromCache.should.equal(false);163 should.exist(txs);164 txs.length.should.equal(10);165 // should filter out 1 move166 txs[0].action.should.equal('moved');167 txs[1].action.should.equal('received');168 // should keep the main address169 _.map(txs[0].outputs,'address').should.include(170 main[0].address,171 main[1].address,172 );173 _.map(txs[0].outputs,'address').should.not.include(174 change[0].address,175 );176 177 done();178 });179 });180 });181 it('should get tx history from cache', function(done) {182 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;183 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;184 helpers.stubHistoryV8(50, BCHEIGHT); //(0->49)185 // this call is to fill the cache186 server.getTxHistory({limit: 20}, function(err, txs, fromCache) {187 fromCache = !!fromCache;188 should.not.exist(err);189 fromCache.should.equal(false);190 should.exist(txs);191 txs.length.should.equal(20);192 _.first(txs).id.should.equal('id0');193 server.getTxHistory({skip: 20, limit: 10}, function(err, txs, fromCache) {194 // first TX result should be:195 // txid: 19 196 // confirmations: 19197 should.not.exist(err);198 fromCache.should.equal(true);199 should.exist(txs);200 txs.length.should.equal(10);201 _.first(txs).id.should.equal('id20');202 var i = 20;203 _.each(txs, function(tx) {204 tx.txid.should.equal('txid' + i);205 tx.confirmations.should.equal(i);206 tx.blockheight.should.equal(BCHEIGHT - i + 1);207 i++;208 });209 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;210 done();211 });212 });213 });214 it('should get tx history from cache and bc mixed', function(done) {215 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;216 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;217 helpers.stubHistoryV8(50, BCHEIGHT); //(0->49)218 // this call is to fill the cache219 server.getTxHistory({limit: 20}, function(err, txs, fromCache) {220 should.not.exist(err);221 fromCache.should.equal(false);222 should.exist(txs);223 txs.length.should.equal(20);224 _.first(txs).id.should.equal('id0');225 server.getTxHistory({skip: 5, limit: 20}, function(err, txs, fromCache) {226 // first TX result should be:227 // txid: 19 228 // confirmations: 19229 should.not.exist(err);230 fromCache.should.equal(true);231 should.exist(txs);232 txs.length.should.equal(20);233 _.first(txs).id.should.equal('id5');234 var i = 5;235 _.each(txs, function(tx) {236 tx.txid.should.equal('txid' + i);237 tx.confirmations.should.equal(i);238 tx.blockheight.should.equal(BCHEIGHT - i + 1);239 i++;240 });241 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;242 done();243 });244 });245 });246 it('should get tx history from cache and bc mixed, updating confirmations', function(done) {247 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;248 var _time = Defaults.BLOCKHEIGHT_CACHE_TIME ;249 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;250 // remove bc tip cache.251 Defaults.BLOCKHEIGHT_CACHE_TIME = 0;252 helpers.stubHistoryV8(50, BCHEIGHT); //(0->49)253 // this call is to fill the cache254 server.getTxHistory({limit: 20}, function(err, txs, fromCache) {255 should.not.exist(err);256 fromCache.should.equal(false);257 // change height from 10000 to 10100258 let heightOffset = 100;259 blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, 10000 + heightOffset, 'hash');260 server.getTxHistory({skip: 5, limit: 20}, function(err, txs, fromCache) {261 should.not.exist(err);262 fromCache.should.equal(true);263 var i = 5;264 _.each(txs, function(tx) {265 tx.confirmations.should.equal(i + heightOffset);266 i++;267 });268 Defaults.BLOCKHEIGHT_CACHE_TIME = _time;269 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;270 done();271 });272 });273 });274 describe("Stream cache", () => {275 it('should not stream cache on first call', function(done) {276 this.timeout(10000);277 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;278 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;279 helpers.stubHistoryV8(100, 10000);280 let limit =20;281 let allTxs = [];282 // this call is to fill the cache283 server.getTxHistory({limit: limit}, function(err, txs, fromCache, useStream) {284 should.not.exist(err);285 fromCache.should.equal(false);286 useStream.should.equal(false);287 should.exist(txs);288 txs.length.should.equal(limit);289 _.first(txs).id.should.equal('id0');290 allTxs = allTxs.concat(txs);291 let i=limit;292 let cont = true;293 let x=false;294 async.doWhilst(295 (next) => {296 server.getTxHistory({skip: i, limit: limit}, function(err, txs, fromCache, useStream) {297 should.not.exist(err);298 if (txs && txs.length < 20) {299 cont = false;300 return next();301 }302 fromCache.should.equal(true);303 useStream.should.equal(x);304 x=true;305 should.exist(txs);306 allTxs = allTxs.concat(txs);307 _.first(txs).id.should.equal('id' + i);308 i+=limit;309 next();310 });311 },312 () => {313 return cont;314 },315 (err) => {316 should.not.exist(err);317 let i = 0;318 _.each(allTxs, function(x) {319 x.id.should.equal('id' + i);320 i++;321 });322 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;323 done();324 });325 });326 });327 it('should get tx history from cache and bc mixed', function(done) {328 this.timeout(10000);329 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;330 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;331 helpers.stubHistoryV8(1000, 10000); //(0->49)332 let limit =20;333 let allTxs = [];334 // this call is to fill the cache335 server.getTxHistory({limit: limit}, function(err, txs, fromCache) {336 should.not.exist(err);337 fromCache.should.equal(false);338 should.exist(txs);339 txs.length.should.equal(limit);340 _.first(txs).id.should.equal('id0');341 allTxs = allTxs.concat(txs);342 let i=limit;343 let cont = true;344 async.doWhilst(345 (next) => {346 server.getTxHistory({skip: i, limit: limit}, function(err, txs, fromCache) {347 should.not.exist(err);348 if (txs && txs.length < 20) {349 cont = false;350 return next();351 }352 fromCache.should.equal(true);353 should.exist(txs);354 allTxs = allTxs.concat(txs);355 _.first(txs).id.should.equal('id' + i);356 i+=limit;357 next();358 });359 },360 () => {361 return cont;362 },363 (err) => {364 should.not.exist(err);365 let i = 0;366 _.each(allTxs, function(x) {367 x.id.should.equal('id' + i);368 i++;369 });370 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;371 done();372 });373 });374 });375 it('should download history with prime page size and total txs', function(done) {376 this.timeout(10000);377 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;378 Defaults.CONFIRMATIONS_TO_START_CACHING = 10;379 helpers.stubHistoryV8(997, 10000); //(0->49)380 let limit =17;381 let allTxs = [];382 // this call is to fill the cache383 server.getTxHistory({limit: limit}, function(err, txs, fromCache) {384 should.not.exist(err);385 fromCache.should.equal(false);386 should.exist(txs);387 txs.length.should.equal(limit);388 _.first(txs).id.should.equal('id0');389 allTxs = allTxs.concat(txs);390 let i=limit;391 let cont = true;392 async.doWhilst(393 (next) => {394 server.getTxHistory({skip: i, limit: limit}, function(err, txs, fromCache) {395 should.not.exist(err);396 if (txs && txs.length < limit) {397 cont = false;398 return next();399 }400 fromCache.should.equal(true);401 should.exist(txs);402 allTxs = allTxs.concat(txs);403 _.first(txs).id.should.equal('id' + i);404 i+=limit;405 next();406 });407 },408 () => {409 return cont;410 },411 (err) => {412 should.not.exist(err);413 let i = 0;414 _.each(allTxs, function(x) {415 x.id.should.equal('id' + i);416 i++;417 });418 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;419 done();420 });421 });422 });423 it('should download history with stream cache> page', function(done) {424 this.timeout(10000);425 var _cache = Defaults.CONFIRMATIONS_TO_START_CACHING;426 Defaults.CONFIRMATIONS_TO_START_CACHING = 100;427 helpers.stubHistoryV8(997, 10000); //(0->49)428 let limit =17;429 let allTxs = [];430 // this call is to fill the cache431 server.getTxHistory({limit: limit}, function(err, txs, fromCache) {432 should.not.exist(err);433 fromCache.should.equal(false);434 should.exist(txs);435 txs.length.should.equal(limit);436 _.first(txs).id.should.equal('id0');437 allTxs = allTxs.concat(txs);438 let i=limit;439 let cont = true;440 async.doWhilst(441 (next) => {442 server.getTxHistory({skip: i, limit: limit}, function(err, txs, fromCache) {443 should.not.exist(err);444 if (txs && txs.length < limit) {445 cont = false;446 return next();447 }448 if (i>100)449 fromCache.should.equal(true);450 should.exist(txs);451 allTxs = allTxs.concat(txs);452 _.first(txs).id.should.equal('id' + i);453 i+=limit;454 next();455 });456 },457 () => {458 return cont;459 },460 (err) => {461 should.not.exist(err);462 let i = 0;463 _.each(allTxs, function(x) {464 x.id.should.equal('id' + i);465 i++;466 });467 Defaults.CONFIRMATIONS_TO_START_CACHING = _cache;468 done();469 });470 });471 });472 });473 it('should get tx history from insight, in 2 overlapping pages', function(done) {474 helpers.stubHistoryV8(300, BCHEIGHT);475 server.getTxHistory({limit: 25}, function(err, txs, fromCache) {476 should.not.exist(err);477 fromCache.should.equal(false);478 txs.length.should.equal(25);479 // no cache480 server.getTxHistory({skip:5, limit: 21}, function(err, txs2, fromCache) {481 should.not.exist(err);482 fromCache = !!fromCache;483 fromCache.should.equal(false);484 should.exist(txs2);485 txs2.length.should.equal(21);486 var i = 0;487 _.each(txs, function(tx) {488 tx.txid.should.equal('txid' + i++);489 });490 var i = 5;491 _.each(txs2, function(tx) {492 tx.txid.should.equal('txid' + i++);493 });494 done();495 });496 });497 });498 it('should get tx history with accepted proposal, multisend', function(done) {499 var external = '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7';500 helpers.stubUtxos(server, wallet, [1, 2], function(utxos) {501 var txOpts = {502 outputs: [{503 toAddress: external,504 amount: 0.5e8,505 message: undefined // no message506 }, {507 toAddress: external,508 amount: 0.3e8,509 message: 'message #2'510 }],511 feePerKb: 100e2,512 message: 'some message',513 customData: {514 "test": true515 },516 };517 helpers.createAndPublishTx(server, txOpts, TestData.copayers[0].privKey_1H_0, function(tx) {518 should.exist(tx);519 var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);520 server.signTx({521 txProposalId: tx.id,522 signatures: signatures,523 }, function(err, tx) {524 should.not.exist(err);525 helpers.stubBroadcast();526 server.broadcastTx({527 txProposalId: tx.id528 }, function(err, txp) {529 should.not.exist(err);530 var t = (new Date).toISOString();531 var txs = [{532 id: 1,533 txid: txp.txid,534 confirmations: 1,535 blockTime: t,536 size: 226,537 category: 'send',538 address: external,539 satoshis: 0.5e8,540 height: 1000,541 },542 {543 id: 2,544 txid: txp.txid,545 confirmations: 1,546 category: 'send',547 blockTime: t,548 satoshis: 0.3e8,549 address: external,550 height: 1000,551 },552 {553 id: 3,554 txid: txp.txid,555 confirmations: 1,556 blockTime: t,557 satoshis: 5460,558 category: 'fee',559 height: 1000,560 },561 ]; 562 563 helpers.stubHistoryV8(null, null,txs);564 helpers.stubCheckData(blockchainExplorer, server, wallet.coin == 'bch', () =>{ 565 server.getTxHistory({}, function(err, txs) {566 should.not.exist(err);567 should.exist(txs);568 txs.length.should.equal(1);569 var tx = txs[0];570 tx.createdOn.should.equal(txp.createdOn);571 tx.action.should.equal('sent');572 tx.amount.should.equal(0.8e8);573 tx.message.should.equal('some message');574 tx.addressTo.should.equal(external);575 tx.actions.length.should.equal(1);576 tx.actions[0].type.should.equal('accept');577 tx.actions[0].copayerName.should.equal('copayer 1');578 tx.outputs[0].address.should.equal(external);579 tx.outputs[0].amount.should.equal(0.5e8);580 should.not.exist(tx.outputs[0].message);581 should.not.exist(tx.outputs[0]['isMine']);582 should.not.exist(tx.outputs[0]['isChange']);583 tx.outputs[1].address.should.equal(external);584 tx.outputs[1].amount.should.equal(0.3e8);585 should.exist(tx.outputs[1].message);586 tx.outputs[1].message.should.equal('message #2');587 should.exist(tx.customData);588 should.exist(tx.customData["test"]);589 done();590 });591 });592 });593 });594 });595 });596 });597 it.skip('should get various paginated tx history', function(done) {598 var testCases = [{599 opts: {},600 expected: [50, 40, 30, 20, 10],601 }, {602 opts: {603 skip: 1,604 limit: 3,605 },606 expected: [40, 30, 20],607 }, {608 opts: {609 skip: 1,610 limit: 2,611 },612 expected: [40, 30],613 }, {614 opts: {615 skip: 2,616 },617 expected: [30, 20, 10],618 }, {619 opts: {620 limit: 4,621 },622 expected: [50, 40, 30, 20],623 }, {624 opts: {625 skip: 0,626 limit: 3,627 },628 expected: [50, 40, 30],629 }, {630 opts: {631 skip: 0,632 limit: 0,633 },634 expected: [],635 }, {636 opts: {637 skip: 4,638 limit: 10,639 },640 expected: [10],641 }, {642 opts: {643 skip: 20,644 limit: 1,645 },646 expected: [],647 }];648 var timestamps = [50, 40, 30, 20, 10];649 var txs = _.map(timestamps, function(ts, idx) {650 return {651 txid: (idx + 1).toString(),652 confirmations: ts / 10,653 fees: 100,654 time: ts,655 inputs: [{656 address: 'external',657 amount: 500,658 }],659 outputs: [{660 address: mainAddresses[0].address,661 amount: 200,662 }],663 };664 });665 helpers.stubHistoryV8(txs);666 async.each(testCases, function(testCase, next) {667 server.getTxHistory(testCase.opts, function(err, txs) {668 should.not.exist(err);669 should.exist(txs);670 _.pluck(txs, 'time').should.deep.equal(testCase.expected);671 next();672 });673 }, done);674 });675 it.skip('should fail gracefully if unable to reach the blockchain', function(done) {676 blockchainExplorer.getTransactions = sinon.stub().callsArgWith(3, 'dummy error');677 server.getTxHistory({}, function(err, txs) {678 should.exist(err);679 err.toString().should.equal('dummy error');680 done();681 });682 });683 it.skip('should handle invalid tx in history ', function(done) {684 var h = _.clone(TestData.history);685 h.push({686 txid: 'xx'687 })688 helpers.stubHistoryV8(h, BCHEIGHT);689 var l = TestData.history.length;690 server.getTxHistory({}, function(err, txs) {691 should.not.exist(err);692 should.exist(txs);693 txs.length.should.equal(l + 1);694 txs[l].action.should.equal('invalid');695 done();696 });697 });698 it.skip('should handle exceeded limit', function(done) {699 server.getTxHistory({700 limit: 1000701 }, function(err, txs) {702 err.code.should.equal('HISTORY_LIMIT_EXCEEDED');703 done();704 });705 });706 it.skip('should set lowFees atribute for sub-superEconomy level fees on unconfirmed txs', function(done) {707 helpers.stubFeeLevels({708 24: 10000,709 });710 var txs = [{711 txid: '1',712 confirmations: 0,713 fees: 100,714 time: 20,715 inputs: [{716 address: 'external',717 amount: 500,718 }],719 outputs: [{720 address: mainAddresses[0].address,721 amount: 200,722 }],723 size: 500,724 }, {725 txid: '2',726 confirmations: 0,727 fees: 6000,728 time: 20,729 inputs: [{730 address: 'external',731 amount: 500,732 }],733 outputs: [{734 address: mainAddresses[0].address,735 amount: 200,736 }],737 size: 500,738 }, {739 txid: '3',740 confirmations: 6,741 fees: 100,742 time: 20,743 inputs: [{744 address: 'external',745 amount: 500,746 }],747 outputs: [{748 address: mainAddresses[0].address,749 amount: 200,750 }],751 size: 500,752 }];753 helpers.stubHistoryV8(txs, BCHEIGHT);754 server.getTxHistory({}, function(err, txs) {755 should.not.exist(err);756 var tx = txs[0];757 tx.feePerKb.should.equal(200);758 tx.lowFees.should.be.true;759 tx = txs[1];760 tx.feePerKb.should.equal(12000);761 tx.lowFees.should.be.false;762 tx = txs[2];763 tx.feePerKb.should.equal(200);764 should.not.exist(tx.lowFees);765 done();766 });767 });768 it.skip('should get tx history even if fee levels are unavailable', function(done) {769 blockchainExplorer.estimateFee = sinon.stub().yields('dummy error');770 var txs = [{771 txid: '1',772 confirmations: 1,773 fees: 100,774 time: 20,775 inputs: [{776 address: 'external',777 amount: 500,778 }],779 outputs: [{780 address: mainAddresses[0].address,781 amount: 200,782 }],783 size: 500,784 }];785 helpers.stubHistoryV8(txs);786 server.getTxHistory({}, function(err, txs) {787 should.not.exist(err);788 var tx = txs[0];789 tx.feePerKb.should.equal(200);790 should.not.exist(tx.foreignCrafted);791 should.not.exist(tx.lowFees);792 done();793 });794 });795 it.skip('should handle outgoing txs where fee > amount', function(done) {796 var x = _.cloneDeep([HugeTxs[0]]);797 x[0].vin[118].addr = mainAddresses[0].address;798 helpers.stubHistoryV8(x);799 server.getTxHistory({}, function(err, txs) {800 should.not.exist(err);801 should.exist(txs);802 txs.length.should.equal(1);803 var tx = txs[0];804 tx.action.should.equal('sent');805 tx.amount.should.equal(3002982);806 tx.fees.should.equal(10000000);807 tx.outputs[0].address.should.equal('1DVhaBdbp5mx5Y8zR1qR9NBiQtrgL9ZNQs');808 tx.outputs[0].amount.should.equal(500000000);809 tx.foreignCrafted.should.equal(true);810 done();811 });812 });813 it.skip('should handle incoming txs with fee > incoming', function(done) {814 var x = _.cloneDeep([HugeTxs[1]]);815 x[0].vout[43].scriptPubKey.addresses = [mainAddresses[0].address];816 helpers.stubHistoryV8(x);817 server.getTxHistory({}, function(err, txs) {818 should.not.exist(err);819 should.exist(txs);820 txs.length.should.equal(1);821 var tx = txs[0];822 tx.action.should.equal('received');823 tx.amount.should.equal(3002982);824 tx.fees.should.equal(130700);825 done();826 });827 });828 });829 describe.skip('Downloading history', function() {830 var h;831 beforeEach(function(done) {832 blockchainExplorer.getBlockchainHeight = sinon.stub().callsArgWith(0, null, 1000, 'hash');833 h = helpers.historyCacheTest(200);834 helpers.stubHistoryV8(h, BCHEIGHT);835 server.storage.clearTxHistoryCache(server.walletId, function() {836 done();837 });838 });839 it('from 0 to 200, two times, in order', function(done) {840 async.eachSeries(_.range(0, 200, 5), function(i, next) {841 server.getTxHistory({842 skip: i,843 limit: 5,844 }, function(err, txs, fromCache) {845 should.not.exist(err);846 should.exist(txs);847 txs.length.should.equal(5);848 var s = h.slice(i, i + 5);849 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));850 fromCache.should.equal(false);851 next();852 });853 }, function() {854 async.eachSeries(_.range(0, 200, 5), function(i, next) {855 server.getTxHistory({856 skip: i,857 limit: 5,858 }, function(err, txs, fromCache) {859 should.not.exist(err);860 should.exist(txs);861 txs.length.should.equal(5);862 var s = h.slice(i, i + 5);863 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));864 fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING && i < 200);865 next();866 });867 }, done);868 });869 });870 it('from 0 to 200, two times, random', function(done) {871 var indexes = _.range(0, 200, 5);872 async.eachSeries(_.shuffle(indexes), function(i, next) {873 server.getTxHistory({874 skip: i,875 limit: 5,876 }, function(err, txs, fromCache) {877 should.not.exist(err);878 should.exist(txs);879 txs.length.should.equal(5);880 var s = h.slice(i, i + 5);881 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));882 fromCache.should.equal(false);883 next();884 });885 }, function() {886 async.eachSeries(_.range(0, 190, 7), function(i, next) {887 server.getTxHistory({888 skip: i,889 limit: 7,890 }, function(err, txs, fromCache) {891 should.not.exist(err);892 should.exist(txs);893 txs.length.should.equal(7);894 var s = h.slice(i, i + 7);895 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));896 fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING);897 next();898 });899 }, done);900 });901 });902 it('from 0 to 200, two times, random, with resets', function(done) {903 var indexes = _.range(0, 200, 5);904 async.eachSeries(_.shuffle(indexes), function(i, next) {905 server.getTxHistory({906 skip: i,907 limit: 5,908 }, function(err, txs, fromCache) {909 should.not.exist(err);910 should.exist(txs);911 txs.length.should.equal(5);912 var s = h.slice(i, i + 5);913 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));914 fromCache.should.equal(false);915 next();916 });917 }, function() {918 async.eachSeries(_.range(0, 200, 5), function(i, next) {919 function resetCache(cb) {920 if (!(i % 25)) {921 storage.softResetTxHistoryCache(server.walletId, function() {922 return cb(true);923 });924 } else {925 return cb(false);926 }927 }928 resetCache(function(reset) {929 server.getTxHistory({930 skip: i,931 limit: 5,932 }, function(err, txs, fromCache) {933 should.not.exist(err);934 should.exist(txs);935 txs.length.should.equal(5);936 var s = h.slice(i, i + 5);937 _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));938 fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING && !reset);939 next();940 });941 });942 }, done);943 });944 });945 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1'use strict';2/*jshint asi: true */3var test = require('tap').test4 , fetchncache = require('../')5 , service = require('./util/service')6 , url = 'http://all.our.resources.com'7 , redis = { port: 6379, host : process.env.REDIS_HOST || '33.33.33.100' }8test('\nall defaults, getting same resource twice ', function (t) {9 var res1= { id: 'res1', data: 'data1' };10 var nock = service(url, {11 '/res1': res1 12 })13 var fnc = fetchncache({ 14 redis: redis15 , service: { url: url }16 }).clearCache();17 t.once('end', function () { 18 fnc.stop();19 nock.cleanAll();20 })21 fnc.fetch('/res1', function (err, res, fromCache) {22 if (err) { t.fail(err); return t.end(); }23 t.deepEqual(JSON.parse(res), res1, 'gets it');24 t.ok(!fromCache, 'not from cache at first');25 fnc.fetch('/res1', function (err, res, fromCache) {26 if (err) { t.fail(err); return t.end(); }27 t.deepEqual(JSON.parse(res), res1, 'gets it');28 t.ok(fromCache, 'from cache the second time');29 t.end();30 })31 })32})33test('\ndefaultExpire 1s, getting same resource three times initially, before and after expire ', function (t) {34 var res1= { id: 'res1', data: 'data1' };35 var nock = service(url, {36 '/res1': res1 37 }, 2)38 var fnc = fetchncache({ 39 redis: redis40 , service: { url: url }41 , expire: 142 })43 .clearCache();44 t.once('end', function () { 45 fnc.stop();46 nock.cleanAll();47 })48 fnc.fetch('/res1', function (err, res, fromCache) {49 if (err) { t.fail(err); return t.end(); }50 t.deepEqual(JSON.parse(res), res1, 'gets it');51 t.ok(!fromCache, 'not from cache at first');52 fnc.fetch('/res1', function (err, res, fromCache) {53 if (err) { t.fail(err); return t.end(); }54 t.deepEqual(JSON.parse(res), res1, 'gets it from cache');55 t.ok(fromCache, 'from cache the second time');56 // wait til default expire kicks in57 setTimeout(fetchAgain, 1500);58 function fetchAgain() {59 fnc.fetch('/res1', function (err, res, fromCache) {60 if (err) { t.fail(err); return t.end(); }61 t.deepEqual(JSON.parse(res), res1, 'gets it from cache first time');62 t.ok(!fromCache, 'not from cache third time');63 t.end();64 })65 }66 })67 })68})69test('\nall defaults getting same resource three times (passing expire) initially, before and after expire ', function (t) {70 var res1= { id: 'res1', data: 'data1' };71 var nock = service(url, {72 '/res1': res1 73 }, 2)74 var fnc = fetchncache({ 75 redis: redis76 , service: { url: url }77 }).clearCache();78 t.once('end', function () { 79 fnc.stop();80 nock.cleanAll();81 })82 fnc.fetch('/res1', { expire: 1 }, function (err, res, fromCache) {83 if (err) { t.fail(err); return t.end(); }84 t.deepEqual(JSON.parse(res), res1, 'gets it');85 t.ok(!fromCache, 'not from cache at first');86 fnc.fetch('/res1', function (err, res, fromCache) {87 if (err) { t.fail(err); return t.end(); }88 t.deepEqual(JSON.parse(res), res1, 'gets it from cache');89 t.ok(fromCache, 'from cache the second time');90 // wait til default expire kicks in91 setTimeout(fetchAgain, 1500);92 function fetchAgain() {93 fnc.fetch('/res1', function (err, res, fromCache) {94 if (err) { t.fail(err); return t.end(); }95 t.deepEqual(JSON.parse(res), res1, 'gets it from cache first time');96 t.ok(!fromCache, 'not from cache third time');97 t.end();98 })99 }100 })101 })102})103test('\nall defaults, getting two different resources twice ', function (t) {104 var res1= { id: 'res1', data: 'data1' };105 var res2= { id: 'res2', data: 'data2' };106 var nock = service(url, {107 '/res1': res1 108 , '/res2': res2 109 })110 var fnc = fetchncache({ 111 redis: redis112 , service: { url: url }113 }).clearCache();114 t.once('end', function () { 115 fnc.stop();116 nock.cleanAll();117 })118 t.plan(8)119 fnc.fetch('/res1', function (err, res, fromCache) {120 if (err) { t.fail(err); return t.end(); }121 t.deepEqual(JSON.parse(res), res1, 'gets res1');122 t.ok(!fromCache, 'not from cache at first');123 fnc.fetch('/res1', function (err, res, fromCache) {124 if (err) { t.fail(err); return t.end(); }125 t.deepEqual(JSON.parse(res), res1, 'gets res1');126 t.ok(fromCache, 'from cache the second time');127 })128 })129 fnc.fetch('/res2', function (err, res, fromCache) {130 if (err) { t.fail(err); return t.end(); }131 t.deepEqual(JSON.parse(res), res2, 'gets res2');132 t.ok(!fromCache, 'not from cache at first');133 fnc.fetch('/res2', function (err, res, fromCache) {134 if (err) { t.fail(err); return t.end(); }135 t.deepEqual(JSON.parse(res), res2, 'gets res2');136 t.ok(fromCache, 'from cache the second time');137 })138 })...

Full Screen

Full Screen

caching2.js

Source:caching2.js Github

copy

Full Screen

1// Кэширование2// Замыкания можно использовать для сохранения состояния и дальнейшей работы с ним.3// Реализуйте функцию cache, которая вернет функцию, возводящую число в степень и возвращающую результат.4// Функция должна запоминать аргументы, которые она уже получала и возвращать результат сразу, не вычисляя его повторно5// Пример:6// const calculate = cache();7// calculate(3, 3); // { value: 27, fromCache: false}8// calculate(2, 10); // { value: 1024, fromCache: false}9// calculate(2, 10); // { value: 1024, fromCache: true}10function cache() {11 let num1;12 let num2;13 let result;14 return (x, y)=>{15 if(x === num1 && y === num2 || x === num2 && y === num1){16 return { value: result, fromCache: true}17 } else {18 return { value: result = Math.pow(num1=x, num2=y), fromCache: false}19 }20 };21}22const calculate = cache();23console.log(calculate(3, 3)); // { value: 27, fromCache: false}24console.log(calculate(2, 10)); // { value: 1024, fromCache: false}25console.log(calculate(2, 10)); // { value: 1024, fromCache: true}26console.log(calculate(-2, -3)); // { value: -0.125, fromCache: false }27console.log(calculate(0, 0)); // { value: 1, fromCache: false }...

Full Screen

Full Screen

product.js

Source:product.js Github

copy

Full Screen

1const { DB2 } = require("../index");2var cache = require("memory-cache");3const Fuse = require("fuse.js");4let fuse = null;5exports.getProductById = async ({ productId }) => {6 try {7 const fromCache = cache.get(`cache/product-${productId}`);8 if (fromCache) {9 return fromCache;10 }11 const db = await DB2;12 const wait = new Promise((res, ej) => {13 // limit 3014 db.query(15 "select * from product where SID=?;",16 [productId],17 (err, data) => {18 if (err) ej(err);19 res(data[0] || { err: "not found" });20 }21 );22 });23 const data = await wait;24 if (!data.err) {25 cache.put(`cache/product-${productId}`, data);26 }27 return data;28 } catch (e) {29 throw e;30 }31};32exports.getAllProducts = async () => {33 try {34 const fromCache = cache.get("all-product");35 if (fromCache) {36 return fromCache;37 }38 const db = await DB2;39 const wait = new Promise((res, ej) => {40 // limit 3041 db.query("select * from product;", (err, data) => {42 if (err) throw err;43 cache.put("all-product", data);44 res(data);45 });46 });47 return await wait;48 } catch (e) {49 throw e;50 }51};52exports.searchProducts = async ({ keyword, category }) => {53 try {54 if (fuse === null) {55 const fromCache = cache.get("all-product");56 let data;57 if (fromCache) {58 data = fromCache;59 } else {60 data = await this.getAllProducts();61 }62 const options = {63 includeScore: true,64 keys: ["des", "feature__MATERIALS", "feature__ORIGIN"],65 };66 fuse = new Fuse(data, options);67 }68 69 const resp= fuse.search(keyword);70 if(category!==null){71 72 return resp.filter(e=>e.item.CATEGORY===category)73 }74 return resp75 } catch (e) {76 throw e77 }...

Full Screen

Full Screen

FsFetch.js

Source:FsFetch.js Github

copy

Full Screen

1const pfs = require('./pfs');2module.exports = class {3 static async dir(path, cache = null) {4 const fromCache = cache && cache.dir(path);5 const entries = typeof fromCache !== 'undefined' ?6 fromCache : await pfs.readDir(path);7 if (!fromCache && cache) {8 cache.dir(path, entries);9 }10 return entries;11 }12 static async stat(path, cache = null) {13 const fromCache = cache && cache.stat(path);14 const stat = typeof fromCache !== 'undefined' ?15 fromCache : await pfs.stat(path);16 if (!fromCache && cache) {17 cache.stat(path, stat);18 }19 return stat;20 }21 static async file(path, cache = null) {22 const fromCache = cache && cache.file(path);23 const content = typeof fromCache !== 'undefined' ?24 fromCache : (await pfs.readFile(path, 'utf8')).toString();25 if (!fromCache && cache) {26 cache.file(path, content);27 }28 return content;29 }30 static async precache(path, cache) {31 if (!cache) return false;32 const stat = await this.stat(path, cache);33 if (stat.isDirectory()) {34 return this.precacheDir(path, cache);35 } else if(stat.isFile()) {36 return this.file(path, cache);37 } else {38 throw `FsFetch.precache: неизвестный тип: '${path}'; умею только файлы и директории`;39 }40 }41 static async precacheDir(path, cache) {42 const entries = await this.dir(path, cache);43 const promises = entries.map(entry =>44 this.precache(`${path}/${entry}`, cache));45 return Promise.all(promises);46 }...

Full Screen

Full Screen

single-promise-cache.js

Source:single-promise-cache.js Github

copy

Full Screen

1import { isEqual } from "lodash";2// Cache only 1 value per request3const cache = new Map();4export const retrieve = ({ request, using }) => {5 const fromCache = cache.get(request);6 return fromCache && isEqual(fromCache.using, using) ? fromCache : undefined;7};8export const store = ({ promise, request, using }) => {9 cache.set(request, { using, promise });10 promise11 .then(result => {12 const fromCache = cache.get(request);13 if (fromCache.promise === promise) {14 cache.set(request, { using, result });15 }16 })17 .catch(error => {18 const fromCache = cache.get(request);19 if (fromCache.promise === promise) {20 cache.set(request, { using, error });21 }22 });23};24export const wrapRequest = request => using => {25 const { result, error, promise: cachedPromise } =26 retrieve({ request, using }) || {};27 if (result) return Promise.resolve(result);28 if (error) return Promise.reject(error);29 if (cachedPromise) return cachedPromise;30 const promise = request(using);31 store({ promise, request, using });32 return promise;33};34export default {35 retrieve,36 store,37 wrapRequest...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fromCache } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs } from '@storybook/addon-knobs';5import { withRoot } from 'storybook-root-decorator';6import { withTests } from '@storybook/addon-jest';7import { withViewport } from '@storybook/addon-viewport';8import { withA11y } from '@storybook/addon-a11y';9import { withPerformance } from 'storybook-addon-performance';10import { withConsole } from '@storybook/addon-console';11import { withTheme } from 'storybook-addon-theme';12import { withContexts } from '@storybook/addon-contexts/react';13import { withThemesProvider } from 'storybook-addon-styled-component-theme';14import { withCssResources } from '@storybook/addon-cssresources';15import { withRedux } from 'addon-redux/withRedux';16import { withReduxDecorator } from 'addon-redux/withReduxDecorator';17import { withI18n } from 'storybook-addon-i18n';18import { withI18nProvider } from 'storybook-addon-i18n/provider';19import { withI18nDecorator } from 'storybook-addon-i18n/decorator';20import { withFormik } from 'storybook-addon-formik';21import { withFormikDecorator } from 'storybook-addon-formik/decorator';22import { withApollo } from 'storybook-addon-apollo-client';23import { withApolloDecorator } from 'storybook-addon-apollo-client/decorator';24import { withApollos } from 'storybook-addon-apollos';25import { withApollosDecorator } from 'storybook-addon-apollos/decorator';26import { withGraphQL } from 'storybook-addon-graphql';27import { withGraphQLDecorator } from 'storybook-addon-graphql/decorator';28import { withRouter } from 'storybook-addon-react-router';29import { withRouterDecorator } from 'storybook-addon-react-router/decorator';30import { withEmotion } from 'storybook-addon-emotion';31import { withEmotionDecorator } from 'storybook-addon-emotion/decorator';32import { withReactRouter } from 'storybook-addon-react-router-6';33import { withReactRouterDecorator } from 'storybook-addon-react-router-6/decorator';34import { withReactIntl } from 'storybook-addon-react-intl';35import { withReactIntlDecorator }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fromCache } from 'storybook-root';2import { fromCache } from 'storybook-root';3import { fromCache } from 'storybook-root';4import { fromCache } from 'storybook-root';5import { fromCache } from 'storybook-root';6import { fromCache } from 'storybook-root';7import { fromCache } from 'storybook-root';8import { fromCache } from 'storybook-root';9import { fromCache } from 'storybook-root';10import { fromCache } from 'storybook-root';11import { fromCache } from 'storybook-root';12import { fromCache } from 'storybook-root';13import { fromCache } from 'storybook-root';14import { fromCache } from 'storybook-root';15import { fromCache } from 'storybook-root';16import { fromCache } from 'storybook-root';17import { fromCache } from 'storybook-root';18import { fromCache } from 'storybook-root';19import { fromCache } from 'storybook-root';20import { fromCache } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1const { fromCache } = require('storybook-root');2const { fromCache } = require('storybook-root');3import { fromCache } from 'storybook-root';4import { fromCache } from 'storybook-root';5const { fromCache } = require('storybook-root');6const { fromCache } = require('storybook-root');7import { fromCache } from 'storybook-root';8import { fromCache } from 'storybook-root';9const { fromCache } = require('storybook-root');10const { fromCache } = require('storybook-root');11import { fromCache } from 'storybook-root';12import { fromCache } from 'storybook-root';13const { fromCache } = require('storybook-root');14const { fromCache } = require('storybook-root');15import { fromCache } from 'storybook-root';16import { fromCache } from 'storybook-root';17const { fromCache } = require('storybook-root');18const { fromCache } = require('storybook-root');19import { fromCache } from 'storybook-root';20import { fromCache } from 'storybook-root';21const { fromCache } = require('storybook-root');22const { fromCache } = require('storybook-root');23import { fromCache } from 'storybook-root';24import { fromCache } from 'storybook-root';25const { fromCache } = require('storybook-root');26const { fromCache } = require('storybook-root');27import { fromCache } from 'storybook-root';28import { fromCache } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fromCache } from 'storybook-root-decorator';2export default {3};4export const test = () => {5 `;6};7import { fromCache } from 'storybook-root-decorator';8export default {9};10export const test2 = () => {11 `;12};13import { addDecorator } from '@storybook/web-components';14import { withRootDecorator } from 'storybook-root-decorator';15addDecorator(withRootDecorator());

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fromCache } from 'storybook-root-decorator';2import { cacheStories } from 'storybook-root-decorator';3import { getStorybook } from 'storybook-root-decorator';4import { getStorybook } from 'storybook-root-decorator';5import { getStorybook } from 'storybook-root-decorator';6import { getStorybook } from 'storybook-root-decorator';7import { getStorybook } from 'storybook-root-decorator';8import { getStorybook } from 'storybook-root-decorator';9import { getStorybook } from 'storybook-root-decorator';10import { getStorybook } from 'storybook-root-decorator';11import { getStorybook } from 'storybook-root-decorator';12import { getStorybook } from 'storybook-root-decorator';13import { getStorybook } from 'storybook-root-decorator';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fromCache } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3storiesOf('Test', module)4 .add('Test', () => {5 const cached = fromCache('test', () => {6 return 'test';7 });8 return <div>{cached}</div>;9 });10import { fromCache } from 'storybook-root-decorator';11import { storiesOf } from '@storybook/react';12storiesOf('Test2', module)13 .add('Test2', () => {14 const cached = fromCache('test2', () => {15 return 'test2';16 });17 return <div>{cached}</div>;18 });19import { configure } from '@storybook/react';20import { withRootDecorator } from 'storybook-root-decorator';21const req = require.context('../src', true, /\.stories\.js$/);22function loadStories() {23 req.keys().forEach(filename => req(filename));24}25configure(loadStories, module);26withRootDecorator();27const path = require('path');28module.exports = async ({ config, mode }) => {29 config.module.rules.push(30 {31 {32 loader: require.resolve('@storybook/addon-storysource/loader'),33 options: { parser: 'javascript' }34 }35 include: [path.resolve(__dirname, '../src')],36 },37 );38 return config;39};40import '@storybook/addon-actions/register';41import '@storybook/addon-links/register';42import '@storybook/addon-knobs/register';43import '@storybook/addon-storysource/register';44import 'storybook-root-decorator/register';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fromCache } from 'storybook-root';2const cache = fromCache('test');3const myValue = cache.get('my-key');4console.log(myValue);5import { fromCache } from 'storybook-root';6const cache = fromCache('test');7const myValue = cache.get('my-key');8console.log(myValue);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fromCache } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3storiesOf('My Button', module)4 .add('with text', () => fromCache('MyButton', 'with text'))5 .add('with emoji', () => fromCache('MyButton', 'with emoji'));6import React from 'react';7import { storiesOf } from '@storybook/react';8import { withRootDecorator } from 'storybook-root-decorator';9import MyButton from './MyButton';10storiesOf('My Button', module)11 .addDecorator(withRootDecorator())12 .add('with text', () => <MyButton label="Hello Button" />)13 .add('with emoji', () => (14 ));15import React from 'react';16export default function MyButton({ label }) {17 return (18 {label}19 );20}21.button {22 font-size: 1rem;23 padding: 0.5rem 1rem;24 border: 2px solid #333;25 border-radius: 3px;26}27.button {28 background-color: #eee;29}30{31 {32 },33 {34 }35}36import { getStory

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful