From 743da04f46e311dc9f74b677ba64561d0847a348 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 17:44:34 +1000 Subject: [PATCH 01/23] no message --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fbc8be0eb..dc36d591d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,9 +14,10 @@ node_js: - "v0.10.25" - "v0.12.7" - "v4" + - "v8.11.4" script: - npm run regtest - npm run test - npm run jshint after_success: - - npm run coveralls \ No newline at end of file + - npm run coveralls From c09fb174c741d819fae59ff912cd8262800b76c1 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 18:02:20 +1000 Subject: [PATCH 02/23] no message --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5df3e0bab..90283aeaa 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,9 @@ "litecoin", "litecoind" ], + "peerDependencies": { + "litecore-lib": "^0.13.22" + }, "dependencies": { "async": "^1.3.0", "body-parser": "^1.13.3", @@ -60,7 +63,6 @@ "express": "^4.13.3", "liftoff": "^2.2.0", "litecoind-rpc": "^0.7.1", - "litecore-lib": "^0.13.22", "lru-cache": "^4.0.1", "mkdirp": "0.5.0", "path-is-absolute": "^1.0.0", From cb9425921dce37537037c7147cbe6b8bfcaf775c Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 18:10:27 +1000 Subject: [PATCH 03/23] Remove deprecated NodeJS versions, fix travis error. --- .travis.yml | 3 --- lib/services/bitcoind.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc36d591d..d17ddd014 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,6 @@ addons: - gcc-4.8 - libzmq3-dev node_js: - - "v0.10.25" - - "v0.12.7" - - "v4" - "v8.11.4" script: - npm run regtest diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index c53dc4c86..e827c5863 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -1987,7 +1987,7 @@ Bitcoin.prototype.getDetailedTransaction = function(txid, callback) { // returns vsize for segwit-positive coins, // regular size if segwit is disbled - var size = result.vsize == null ? result.size : result.vsize; + var size = result.vsize === null ? result.size : result.vsize; var tx = { hex: result.hex, blockHash: result.blockhash, From c8dae550ac4fe2b5be405875f405eadd7fd49c7a Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 18:20:06 +1000 Subject: [PATCH 04/23] Fix address test issues. --- test/services/bitcoind.unit.js | 90 +++++++++++++++++----------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 63b9375ad..f414d8e57 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -228,25 +228,25 @@ describe('Bitcoin Service', function() { it('will add a valid address', function() { var bitcoind = new BitcoinService(baseConfig); var emitter = new EventEmitter(); - bitcoind.subscribeAddress(emitter, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - should.exist(bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); + bitcoind.subscribeAddress(emitter, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + should.exist(bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); }); it('will handle multiple address subscribers', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); var emitter2 = new EventEmitter(); - bitcoind.subscribeAddress(emitter1, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.subscribeAddress(emitter2, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - should.exist(bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(2); + bitcoind.subscribeAddress(emitter1, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.subscribeAddress(emitter2, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + should.exist(bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(2); }); it('will not add the same emitter twice', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); - bitcoind.subscribeAddress(emitter1, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.subscribeAddress(emitter1, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - should.exist(bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(1); + bitcoind.subscribeAddress(emitter1, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.subscribeAddress(emitter1, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + should.exist(bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(1); }); }); @@ -262,57 +262,57 @@ describe('Bitcoin Service', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); var emitter2 = new EventEmitter(); - bitcoind.subscribeAddress(emitter1, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.subscribeAddress(emitter2, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - should.exist(bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(2); - bitcoind.unsubscribeAddress(emitter1, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(1); + bitcoind.subscribeAddress(emitter1, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.subscribeAddress(emitter2, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + should.exist(bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(2); + bitcoind.unsubscribeAddress(emitter1, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(1); }); it('will unsubscribe subscriptions for an emitter', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); var emitter2 = new EventEmitter(); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'] = [emitter1, emitter2]; + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'] = [emitter1, emitter2]; bitcoind.unsubscribeAddress(emitter1); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(1); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(1); }); it('will NOT unsubscribe subscription with missing address', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); var emitter2 = new EventEmitter(); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'] = [emitter1, emitter2]; + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'] = [emitter1, emitter2]; bitcoind.unsubscribeAddress(emitter1, ['LWx1jmpcMAQMXou6pbLyfMU7zETnbhy3bo']); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(2); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(2); }); it('will NOT unsubscribe subscription with missing emitter', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); var emitter2 = new EventEmitter(); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'] = [emitter2]; - bitcoind.unsubscribeAddress(emitter1, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(1); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'][0].should.equal(emitter2); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'] = [emitter2]; + bitcoind.unsubscribeAddress(emitter1, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(1); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'][0].should.equal(emitter2); }); it('will remove empty addresses', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); var emitter2 = new EventEmitter(); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'] = [emitter1, emitter2]; - bitcoind.unsubscribeAddress(emitter1, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - bitcoind.unsubscribeAddress(emitter2, ['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); - should.not.exist(bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br']); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'] = [emitter1, emitter2]; + bitcoind.unsubscribeAddress(emitter1, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + bitcoind.unsubscribeAddress(emitter2, ['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); + should.not.exist(bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3']); }); it('will unsubscribe emitter for all addresses', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); var emitter2 = new EventEmitter(); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'] = [emitter1, emitter2]; + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'] = [emitter1, emitter2]; bitcoind.subscriptions.address['LWx1jmpcMAQMXou6pbLyfMU7zETnbhy3bo'] = [emitter1, emitter2]; sinon.spy(bitcoind, 'unsubscribeAddressAll'); bitcoind.unsubscribeAddress(emitter1); bitcoind.unsubscribeAddressAll.callCount.should.equal(1); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(1); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(1); bitcoind.subscriptions.address['LWx1jmpcMAQMXou6pbLyfMU7zETnbhy3bo'].length.should.equal(1); }); }); @@ -329,15 +329,15 @@ describe('Bitcoin Service', function() { var bitcoind = new BitcoinService(baseConfig); var emitter1 = new EventEmitter(); var emitter2 = new EventEmitter(); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'] = [emitter1, emitter2]; + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'] = [emitter1, emitter2]; bitcoind.subscriptions.address['LWx1jmpcMAQMXou6pbLyfMU7zETnbhy3bo'] = [emitter1, emitter2]; bitcoind.subscriptions.address['mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW'] = [emitter2]; - bitcoind.subscriptions.address['3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou'] = [emitter1]; + bitcoind.subscriptions.address['MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ'] = [emitter1]; bitcoind.unsubscribeAddress(emitter1); - bitcoind.subscriptions.address['2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'].length.should.equal(1); + bitcoind.subscriptions.address['mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'].length.should.equal(1); bitcoind.subscriptions.address['LWx1jmpcMAQMXou6pbLyfMU7zETnbhy3bo'].length.should.equal(1); bitcoind.subscriptions.address['mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW'].length.should.equal(1); - should.not.exist(bitcoind.subscriptions.address['3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou']); + should.not.exist(bitcoind.subscriptions.address['MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ']); }); }); @@ -1091,7 +1091,7 @@ describe('Bitcoin Service', function() { var wif = 'T872No3VhULcqFF6Sv1PSCRXZKVBPYWG2UtG4ECFK7nzaUUU8Kuj'; var privkey = bitcore.PrivateKey.fromWIF(wif); var inputAddress = privkey.toAddress(bitcore.Networks.testnet); - var outputAddress = bitcore.Address('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'); + var outputAddress = bitcore.Address('mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'); var tx = bitcore.Transaction(); tx.from({ txid: '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b', @@ -1139,7 +1139,7 @@ describe('Bitcoin Service', function() { it('will return unique values', function() { var bitcoind = new BitcoinService(baseConfig); var tx = bitcore.Transaction(); - var address = bitcore.Address('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'); + var address = bitcore.Address('mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'); tx.addOutput(bitcore.Transaction.Output({ script: bitcore.Script(address), satoshis: 5000000000 @@ -3318,32 +3318,32 @@ describe('Bitcoin Service', function() { it('will get address strings from bitcore addresses', function() { var addresses = [ bitcore.Address('LUVKqDPPVBQcjUwt1S21Pa5ybgPaDEZhXR'), - bitcore.Address('3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou'), + bitcore.Address('MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ'), ]; var bitcoind = new BitcoinService(baseConfig); var strings = bitcoind._getAddressStrings(addresses); strings[0].should.equal('LUVKqDPPVBQcjUwt1S21Pa5ybgPaDEZhXR'); - strings[1].should.equal('3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou'); + strings[1].should.equal('MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ'); }); it('will get address strings from strings', function() { var addresses = [ 'LUVKqDPPVBQcjUwt1S21Pa5ybgPaDEZhXR', - '3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou', + 'MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ', ]; var bitcoind = new BitcoinService(baseConfig); var strings = bitcoind._getAddressStrings(addresses); strings[0].should.equal('LUVKqDPPVBQcjUwt1S21Pa5ybgPaDEZhXR'); - strings[1].should.equal('3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou'); + strings[1].should.equal('MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ'); }); it('will get address strings from mixture of types', function() { var addresses = [ bitcore.Address('LUVKqDPPVBQcjUwt1S21Pa5ybgPaDEZhXR'), - '3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou', + 'MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ', ]; var bitcoind = new BitcoinService(baseConfig); var strings = bitcoind._getAddressStrings(addresses); strings[0].should.equal('LUVKqDPPVBQcjUwt1S21Pa5ybgPaDEZhXR'); - strings[1].should.equal('3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou'); + strings[1].should.equal('MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ'); }); it('will give error with unknown', function() { var addresses = [ @@ -4135,12 +4135,12 @@ describe('Bitcoin Service', function() { getBlockHash: getBlockHash } }); - bitcoind._maybeGetBlockHash('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br', function(err, hash) { + bitcoind._maybeGetBlockHash('mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3', function(err, hash) { if (err) { return done(err); } getBlockHash.callCount.should.equal(0); - hash.should.equal('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'); + hash.should.equal('mu5a17UQDh2hsRk9ZJzFkTfCbzZhMVBHY3'); done(); }); }); @@ -5033,4 +5033,4 @@ describe('Bitcoin Service', function() { }); }); -}); +}); \ No newline at end of file From f07c46f67bce75191f773e061f45f91e9a4db5a4 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 18:29:50 +1000 Subject: [PATCH 05/23] no message --- test/services/bitcoind.unit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index f414d8e57..c11543ac5 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -3318,12 +3318,12 @@ describe('Bitcoin Service', function() { it('will get address strings from bitcore addresses', function() { var addresses = [ bitcore.Address('LUVKqDPPVBQcjUwt1S21Pa5ybgPaDEZhXR'), - bitcore.Address('MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ'), + bitcore.Address('mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW'), ]; var bitcoind = new BitcoinService(baseConfig); var strings = bitcoind._getAddressStrings(addresses); strings[0].should.equal('LUVKqDPPVBQcjUwt1S21Pa5ybgPaDEZhXR'); - strings[1].should.equal('MJZWZqmykQ32rvH8vUnW9jEPbyGg7agWQZ'); + strings[1].should.equal('mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW'); }); it('will get address strings from strings', function() { var addresses = [ From 835fa7135440098fb179191e4c5013a9df482948 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 19:53:29 +1000 Subject: [PATCH 06/23] Fail tests fixed. --- test/logger.unit.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/logger.unit.js b/test/logger.unit.js index 755228145..fcdb90a62 100644 --- a/test/logger.unit.js +++ b/test/logger.unit.js @@ -41,10 +41,10 @@ describe('Logger', function() { console.error.callCount.should.equal(1); console.error.restore(); - sandbox.stub(console, 'log'); + sandbox.stub(console, 'debug'); logger.debug('Test debug log'); - console.log.callCount.should.equal(1); - console.log.restore(); + console.debug.callCount.should.equal(1); + console.debug.restore(); sandbox.stub(console, 'warn'); logger.warn('Test warn log'); @@ -67,11 +67,11 @@ describe('Logger', function() { console.error.args[0][0].should.be.instanceof(Error); console.error.restore(); - sandbox.stub(console, 'log'); + sandbox.stub(console, 'debug'); logger.debug('Test debug log'); - console.log.callCount.should.equal(1); - should.equal(console.log.args[0][0].match(/^\[/), null); - console.log.restore(); + console.debug.callCount.should.equal(1); + should.equal(console.debug.args[0][0].match(/^\[/), null); + console.debug.restore(); sandbox.stub(console, 'warn'); logger.warn('Test warn log'); From 7b776ecc4ff44afd7a15baa929f9118e1dfe704e Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 19:59:12 +1000 Subject: [PATCH 07/23] readme updates --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 48a71dd54..2e9c31807 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Note: For your convenience, we distribute bitcoind binaries for x86_64 Linux and ## Prerequisites - GNU/Linux x86_32/x86_64, or OSX 64bit *(for bitcoind distributed binaries)* -- Node.js v0.10, v0.12 or v4 +- Node.js v8.11.4 (LTS) - ZeroMQ *(libzmq3-dev for Ubuntu/Debian or zeromq on OSX)* - ~200GB of disk storage - ~8GB of RAM @@ -29,7 +29,7 @@ Note: For your convenience, we distribute bitcoind binaries for x86_64 Linux and Litecore includes a Command Line Interface (CLI) for managing, configuring and interfacing with your Litecore Node. ```bash -litecore-node create -d mynode +litecore-node create -d mynode cd mynode litecore-node install litecore-node install https://github.com/yourname/helloworld @@ -41,15 +41,15 @@ This will create a directory with configuration files for your node and install There are several add-on services available to extend the functionality of Bitcore: -- [Insight API](https://github.com/bitpay/insight-api) -- [Insight UI](https://github.com/bitpay/insight-ui) -- [Bitcore Wallet Service](https://github.com/bitpay/bitcore-wallet-service) +- [Insight Lite API](https://github.com/litecoin-project/insight-lite-api) +- [Insight Lite UI](https://github.com/litecoin-project/insight-lite-ui) +- [Litecore Wallet Service](https://github.com/litecoin-project/litecore-wallet-service) ## Documentation - [Upgrade Notes](docs/upgrade.md) - [Services](docs/services.md) - - [Bitcoind](docs/services/bitcoind.md) - Interface to Bitcoin Core + - [Bitcoind](docs/services/bitcoind.md) - Interface to Litecoin Core - [Web](docs/services/web.md) - Creates an express application over which services can expose their web/API content - [Development Environment](docs/development.md) - Guide for setting up a development environment - [Node](docs/node.md) - Details on the node constructor @@ -64,7 +64,7 @@ Please send pull requests for bug fixes, code optimization, and ideas for improv Code released under [the MIT license](https://github.com/litecoin-project/litecore-node/blob/master/LICENSE). -Copyright 2016 The Litecoin Core Developers +Copyright 2018 The Litecoin Core Developers - bitcore: Copyright (c) 2013-2015 BitPay, Inc. (MIT License) - bitcoin: Copyright (c) 2009-2015 Bitcoin Core Developers (MIT License) From a8a19d6870d719503d4dae566113d9585b60b1c5 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 20:21:56 +1000 Subject: [PATCH 08/23] Increase timeout to try and patch async related issue with travis. --- README.md | 6 +++--- regtest/node.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2e9c31807..64a0f2505 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ npm install -g litecore-node litecore-node start ``` -Note: For your convenience, we distribute bitcoind binaries for x86_64 Linux and x86_64 Mac OS X. Upon npm install, the binaries for your platform will be downloaded. For more detailed installation instructions, or if you want to compile the project yourself, then please see the Bitcore branch of [Litecoin Core with additional indexing](https://github.com/litecoin-project/litecore-litecoin). +Note: For your convenience, we distribute litecoind binaries for x86_64 Linux and x86_64 Mac OS X. Upon npm install, the binaries for your platform will be downloaded. For more detailed installation instructions, or if you want to compile the project yourself, then please see the Litecore branch of [Litecoin Core with additional indexing](https://github.com/litecoin-project/litecore-litecoin). ## Prerequisites -- GNU/Linux x86_32/x86_64, or OSX 64bit *(for bitcoind distributed binaries)* +- GNU/Linux x86_32/x86_64, or OSX 64bit *(for litecoind distributed binaries)* - Node.js v8.11.4 (LTS) - ZeroMQ *(libzmq3-dev for Ubuntu/Debian or zeromq on OSX)* - ~200GB of disk storage @@ -39,7 +39,7 @@ This will create a directory with configuration files for your node and install ## Add-on Services -There are several add-on services available to extend the functionality of Bitcore: +There are several add-on services available to extend the functionality of Litecore: - [Insight Lite API](https://github.com/litecoin-project/insight-lite-api) - [Insight Lite UI](https://github.com/litecoin-project/insight-lite-ui) diff --git a/regtest/node.js b/regtest/node.js index 9ea63ca94..46e63d4b6 100644 --- a/regtest/node.js +++ b/regtest/node.js @@ -684,7 +684,7 @@ describe('Node Functionality', function() { }); describe('Orphaned Transactions', function() { - this.timeout(8000); + this.timeout(20000); var orphanedTransaction; before(function(done) { From 119285b1a04e3d4022e40297efbdf46ff6d6e8ae Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 20:28:14 +1000 Subject: [PATCH 09/23] no message --- regtest/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regtest/node.js b/regtest/node.js index 46e63d4b6..1628a4f79 100644 --- a/regtest/node.js +++ b/regtest/node.js @@ -147,7 +147,7 @@ describe('Node Functionality', function() { var address; var unspentOutput; before(function(done) { - this.timeout(10000); + this.timeout(20000); address = testKey.toAddress(regtest).toString(); var startHeight = node.services.bitcoind.height; node.services.bitcoind.on('tip', function(height) { From e1a3fcfe7b22d196295937a8002ec7d94cb093ec Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Wed, 22 Aug 2018 20:44:36 +1000 Subject: [PATCH 10/23] set "--unsafe-perm=true" flag for new installations. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64a0f2505..f3af67d5a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A Litecoin full node for building applications and services with Node.js. A node ## Install ```bash -npm install -g litecore-node +npm install -g litecore-node --unsafe-perm=true litecore-node start ``` From 5c9e5086411c1497929703836f19a03fd0ae09f9 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 12:51:37 +1000 Subject: [PATCH 11/23] Updated Mocha to latest version, resolved critical package bugs from old Mocha version. Discovered new bugs in tests: test/scaffold/create.integration.js (fixed now) --- package.json | 4 ++-- test/scaffold/create.integration.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 90283aeaa..c4443c186 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "litecoind" ], "peerDependencies": { - "litecore-lib": "^0.13.22" + "litecore-lib": "^0.13.22" }, "dependencies": { "async": "^1.3.0", @@ -83,7 +83,7 @@ "istanbul": "^0.4.3", "jshint": "^2.9.2", "jshint-stylish": "^2.1.0", - "mocha": "^2.4.5", + "mocha": "^5.2.0", "proxyquire": "^1.3.1", "rimraf": "^2.4.2", "sinon": "^1.15.4" diff --git a/test/scaffold/create.integration.js b/test/scaffold/create.integration.js index 5d3a22ced..6b11328ff 100644 --- a/test/scaffold/create.integration.js +++ b/test/scaffold/create.integration.js @@ -71,8 +71,8 @@ describe('#create', function() { should.equal(fs.existsSync(packagePath), true); var config = JSON.parse(fs.readFileSync(configPath)); - config.services.should.deep.equal(['bitcoind', 'db', 'address', 'web']); - config.datadir.should.equal('./data'); + config.services.should.deep.equal(['bitcoind', 'web']); + config.servicesConfig.bitcoind.spawn.datadir.should.equal('./data'); config.network.should.equal('livenet'); var pack = JSON.parse(fs.readFileSync(packagePath)); From 43396febc626cab15647146607486c117a42c228 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 13:17:27 +1000 Subject: [PATCH 12/23] travis test --- regtest/p2p.js | 434 ++++++++++++++++++++++++------------------------ scripts/regtest | 2 +- 2 files changed, 218 insertions(+), 218 deletions(-) diff --git a/regtest/p2p.js b/regtest/p2p.js index bf8e53e35..608be58f5 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -1,217 +1,217 @@ -'use strict'; - -// To run the tests: $ mocha -R spec regtest/p2p.js - -var path = require('path'); -var index = require('..'); -var log = index.log; - -var p2p = require('litecore-p2p'); -var Peer = p2p.Peer; -var Messages = p2p.Messages; -var chai = require('chai'); -var bitcore = require('litecore-lib'); -var Transaction = bitcore.Transaction; -var BN = bitcore.crypto.BN; -var async = require('async'); -var rimraf = require('rimraf'); -var bitcoind; - -/* jshint unused: false */ -var should = chai.should(); -var assert = chai.assert; -var sinon = require('sinon'); -var BitcoinRPC = require('litecoind-rpc'); -var transactionData = []; -var blockHashes = []; -var txs = []; -var client; -var messages; -var peer; -var coinbasePrivateKey; -var privateKey = bitcore.PrivateKey(); -var destKey = bitcore.PrivateKey(); -var BufferUtil = bitcore.util.buffer; -var blocks; - -describe('P2P Functionality', function() { - - before(function(done) { - this.timeout(100000); - - // enable regtest - bitcore.Networks.enableRegtest(); - var regtestNetwork = bitcore.Networks.get('regtest'); - var datadir = __dirname + '/data'; - - rimraf(datadir + '/regtest', function(err) { - if (err) { - throw err; - } - - bitcoind = require('../').services.Bitcoin({ - spawn: { - datadir: datadir, - exec: path.resolve(__dirname, '../bin/litecoind') - }, - node: { - network: bitcore.Networks.testnet - } - }); - - bitcoind.on('error', function(err) { - log.error('error="%s"', err.message); - }); - - log.info('Waiting for Bitcoin Core to initialize...'); - - bitcoind.start(function(err) { - if (err) { - throw err; - } - log.info('Bitcoind started'); - - client = new BitcoinRPC({ - protocol: 'http', - host: '127.0.0.1', - port: 30331, - user: 'bitcoin', - pass: 'local321', - rejectUnauthorized: false - }); - - peer = new Peer({ - host: '127.0.0.1', - // port: regtestNetwork.port, // regtestNetwork will provide the port: 19444 - network: regtestNetwork - }); - - messages = new Messages({ - network: regtestNetwork - }); - - blocks = 500; - - log.info('Generating ' + blocks + ' blocks...'); - - // Generate enough blocks so that the initial coinbase transactions - // can be spent. - - setImmediate(function() { - client.generate(blocks, function(err, response) { - if (err) { - throw err; - } - blockHashes = response.result; - - log.info('Preparing test data...'); - - // Get all of the unspent outputs - client.listUnspent(0, blocks, function(err, response) { - var utxos = response.result; - - async.mapSeries(utxos, function(utxo, next) { - async.series([ - function(finished) { - // Load all of the transactions for later testing - client.getTransaction(utxo.txid, function(err, txresponse) { - if (err) { - throw err; - } - // add to the list of transactions for testing later - transactionData.push(txresponse.result.hex); - finished(); - }); - }, - function(finished) { - // Get the private key for each utxo - client.dumpPrivKey(utxo.address, function(err, privresponse) { - if (err) { - throw err; - } - utxo.privateKeyWIF = privresponse.result; - var tx = bitcore.Transaction(); - tx.from(utxo); - tx.change(privateKey.toAddress()); - tx.to(destKey.toAddress(), utxo.amount * 1e8 - 100000); - tx.sign(bitcore.PrivateKey.fromWIF(utxo.privateKeyWIF)); - txs.push(tx); - finished(); - }); - } - ], next); - }, function(err) { - if (err) { - throw err; - } - peer.on('ready', function() { - log.info('Peer ready'); - done(); - }); - log.info('Connecting to peer'); - peer.connect(); - }); - }); - }); - }); - }); - }); - - }); - - after(function(done) { - this.timeout(20000); - peer.on('disconnect', function() { - log.info('Peer disconnected'); - bitcoind.node.stopping = true; - bitcoind.stop(function(err, result) { - done(); - }); - }); - peer.disconnect(); - }); - - it('will be able to handle many inventory messages and be able to send getdata messages and received the txs', function(done) { - this.timeout(100000); - - var usedTxs = {}; - - bitcoind.on('tx', function(buffer) { - var txFromResult = new Transaction().fromBuffer(buffer); - var tx = usedTxs[txFromResult.id]; - should.exist(tx); - buffer.toString('hex').should.equal(tx.serialize()); - delete usedTxs[tx.id]; - if (Object.keys(usedTxs).length === 0) { - done(); - } - }); - - peer.on('getdata', function(message) { - var hash = message.inventory[0].hash; - var reversedHash = BufferUtil.reverse(hash).toString('hex'); - var tx = usedTxs[reversedHash]; - if (reversedHash === tx.id) { - var txMessage = messages.Transaction(tx); - peer.sendMessage(txMessage); - } - }); - async.whilst( - function() { - return txs.length > 0; - }, - function(callback) { - var tx = txs.pop(); - usedTxs[tx.id] = tx; - var message = messages.Inventory.forTransaction(tx.hash); - peer.sendMessage(message); - callback(); - }, - function(err) { - if (err) { - throw err; - } - }); - }); - -}); +//'use strict'; +// +//// To run the tests: $ mocha -R spec regtest/p2p.js +// +//var path = require('path'); +//var index = require('..'); +//var log = index.log; +// +//var p2p = require('litecore-p2p'); +//var Peer = p2p.Peer; +//var Messages = p2p.Messages; +//var chai = require('chai'); +//var bitcore = require('litecore-lib'); +//var Transaction = bitcore.Transaction; +//var BN = bitcore.crypto.BN; +//var async = require('async'); +//var rimraf = require('rimraf'); +//var bitcoind; +// +///* jshint unused: false */ +//var should = chai.should(); +//var assert = chai.assert; +//var sinon = require('sinon'); +//var BitcoinRPC = require('litecoind-rpc'); +//var transactionData = []; +//var blockHashes = []; +//var txs = []; +//var client; +//var messages; +//var peer; +//var coinbasePrivateKey; +//var privateKey = bitcore.PrivateKey(); +//var destKey = bitcore.PrivateKey(); +//var BufferUtil = bitcore.util.buffer; +//var blocks; +// +//describe('P2P Functionality', function() { +// +// before(function(done) { +// this.timeout(100000); +// +// // enable regtest +// bitcore.Networks.enableRegtest(); +// var regtestNetwork = bitcore.Networks.get('regtest'); +// var datadir = __dirname + '/data'; +// +// rimraf(datadir + '/regtest', function(err) { +// if (err) { +// throw err; +// } +// +// bitcoind = require('../').services.Bitcoin({ +// spawn: { +// datadir: datadir, +// exec: path.resolve(__dirname, '../bin/litecoind') +// }, +// node: { +// network: bitcore.Networks.testnet +// } +// }); +// +// bitcoind.on('error', function(err) { +// log.error('error="%s"', err.message); +// }); +// +// log.info('Waiting for Bitcoin Core to initialize...'); +// +// bitcoind.start(function(err) { +// if (err) { +// throw err; +// } +// log.info('Bitcoind started'); +// +// client = new BitcoinRPC({ +// protocol: 'http', +// host: '127.0.0.1', +// port: 30331, +// user: 'bitcoin', +// pass: 'local321', +// rejectUnauthorized: false +// }); +// +// peer = new Peer({ +// host: '127.0.0.1', +// // port: regtestNetwork.port, // regtestNetwork will provide the port: 19444 +// network: regtestNetwork +// }); +// +// messages = new Messages({ +// network: regtestNetwork +// }); +// +// blocks = 500; +// +// log.info('Generating ' + blocks + ' blocks...'); +// +// // Generate enough blocks so that the initial coinbase transactions +// // can be spent. +// +// setImmediate(function() { +// client.generate(blocks, function(err, response) { +// if (err) { +// throw err; +// } +// blockHashes = response.result; +// +// log.info('Preparing test data...'); +// +// // Get all of the unspent outputs +// client.listUnspent(0, blocks, function(err, response) { +// var utxos = response.result; +// +// async.mapSeries(utxos, function(utxo, next) { +// async.series([ +// function(finished) { +// // Load all of the transactions for later testing +// client.getTransaction(utxo.txid, function(err, txresponse) { +// if (err) { +// throw err; +// } +// // add to the list of transactions for testing later +// transactionData.push(txresponse.result.hex); +// finished(); +// }); +// }, +// function(finished) { +// // Get the private key for each utxo +// client.dumpPrivKey(utxo.address, function(err, privresponse) { +// if (err) { +// throw err; +// } +// utxo.privateKeyWIF = privresponse.result; +// var tx = bitcore.Transaction(); +// tx.from(utxo); +// tx.change(privateKey.toAddress()); +// tx.to(destKey.toAddress(), utxo.amount * 1e8 - 100000); +// tx.sign(bitcore.PrivateKey.fromWIF(utxo.privateKeyWIF)); +// txs.push(tx); +// finished(); +// }); +// } +// ], next); +// }, function(err) { +// if (err) { +// throw err; +// } +// peer.on('ready', function() { +// log.info('Peer ready'); +// done(); +// }); +// log.info('Connecting to peer'); +// peer.connect(); +// }); +// }); +// }); +// }); +// }); +// }); +// +// }); +// +// after(function(done) { +// this.timeout(20000); +// peer.on('disconnect', function() { +// log.info('Peer disconnected'); +// bitcoind.node.stopping = true; +// bitcoind.stop(function(err, result) { +// done(); +// }); +// }); +// peer.disconnect(); +// }); +// +// it('will be able to handle many inventory messages and be able to send getdata messages and received the txs', function(done) { +// this.timeout(100000); +// +// var usedTxs = {}; +// +// bitcoind.on('tx', function(buffer) { +// var txFromResult = new Transaction().fromBuffer(buffer); +// var tx = usedTxs[txFromResult.id]; +// should.exist(tx); +// buffer.toString('hex').should.equal(tx.serialize()); +// delete usedTxs[tx.id]; +// if (Object.keys(usedTxs).length === 0) { +// done(); +// } +// }); +// +// peer.on('getdata', function(message) { +// var hash = message.inventory[0].hash; +// var reversedHash = BufferUtil.reverse(hash).toString('hex'); +// var tx = usedTxs[reversedHash]; +// if (reversedHash === tx.id) { +// var txMessage = messages.Transaction(tx); +// peer.sendMessage(txMessage); +// } +// }); +// async.whilst( +// function() { +// return txs.length > 0; +// }, +// function(callback) { +// var tx = txs.pop(); +// usedTxs[tx.id] = tx; +// var message = messages.Inventory.forTransaction(tx.hash); +// peer.sendMessage(message); +// callback(); +// }, +// function(err) { +// if (err) { +// throw err; +// } +// }); +// }); +// +//}); diff --git a/scripts/regtest b/scripts/regtest index 96078911d..6978a2ce3 100755 --- a/scripts/regtest +++ b/scripts/regtest @@ -2,7 +2,7 @@ set -e -_mocha -R spec regtest/p2p.js + _mocha -R spec regtest/bitcoind.js _mocha -R spec regtest/cluster.js _mocha -R spec regtest/node.js From d8284c111ed25238209e0436afc7b8f1b4f6a50c Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 13:30:25 +1000 Subject: [PATCH 13/23] Catch error on bitcoind.stop --- regtest/p2p.js | 435 ++++++++++++++++++++++++------------------------ scripts/regtest | 2 +- 2 files changed, 219 insertions(+), 218 deletions(-) diff --git a/regtest/p2p.js b/regtest/p2p.js index 608be58f5..7d7308658 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -1,217 +1,218 @@ -//'use strict'; -// -//// To run the tests: $ mocha -R spec regtest/p2p.js -// -//var path = require('path'); -//var index = require('..'); -//var log = index.log; -// -//var p2p = require('litecore-p2p'); -//var Peer = p2p.Peer; -//var Messages = p2p.Messages; -//var chai = require('chai'); -//var bitcore = require('litecore-lib'); -//var Transaction = bitcore.Transaction; -//var BN = bitcore.crypto.BN; -//var async = require('async'); -//var rimraf = require('rimraf'); -//var bitcoind; -// -///* jshint unused: false */ -//var should = chai.should(); -//var assert = chai.assert; -//var sinon = require('sinon'); -//var BitcoinRPC = require('litecoind-rpc'); -//var transactionData = []; -//var blockHashes = []; -//var txs = []; -//var client; -//var messages; -//var peer; -//var coinbasePrivateKey; -//var privateKey = bitcore.PrivateKey(); -//var destKey = bitcore.PrivateKey(); -//var BufferUtil = bitcore.util.buffer; -//var blocks; -// -//describe('P2P Functionality', function() { -// -// before(function(done) { -// this.timeout(100000); -// -// // enable regtest -// bitcore.Networks.enableRegtest(); -// var regtestNetwork = bitcore.Networks.get('regtest'); -// var datadir = __dirname + '/data'; -// -// rimraf(datadir + '/regtest', function(err) { -// if (err) { -// throw err; -// } -// -// bitcoind = require('../').services.Bitcoin({ -// spawn: { -// datadir: datadir, -// exec: path.resolve(__dirname, '../bin/litecoind') -// }, -// node: { -// network: bitcore.Networks.testnet -// } -// }); -// -// bitcoind.on('error', function(err) { -// log.error('error="%s"', err.message); -// }); -// -// log.info('Waiting for Bitcoin Core to initialize...'); -// -// bitcoind.start(function(err) { -// if (err) { -// throw err; -// } -// log.info('Bitcoind started'); -// -// client = new BitcoinRPC({ -// protocol: 'http', -// host: '127.0.0.1', -// port: 30331, -// user: 'bitcoin', -// pass: 'local321', -// rejectUnauthorized: false -// }); -// -// peer = new Peer({ -// host: '127.0.0.1', -// // port: regtestNetwork.port, // regtestNetwork will provide the port: 19444 -// network: regtestNetwork -// }); -// -// messages = new Messages({ -// network: regtestNetwork -// }); -// -// blocks = 500; -// -// log.info('Generating ' + blocks + ' blocks...'); -// -// // Generate enough blocks so that the initial coinbase transactions -// // can be spent. -// -// setImmediate(function() { -// client.generate(blocks, function(err, response) { -// if (err) { -// throw err; -// } -// blockHashes = response.result; -// -// log.info('Preparing test data...'); -// -// // Get all of the unspent outputs -// client.listUnspent(0, blocks, function(err, response) { -// var utxos = response.result; -// -// async.mapSeries(utxos, function(utxo, next) { -// async.series([ -// function(finished) { -// // Load all of the transactions for later testing -// client.getTransaction(utxo.txid, function(err, txresponse) { -// if (err) { -// throw err; -// } -// // add to the list of transactions for testing later -// transactionData.push(txresponse.result.hex); -// finished(); -// }); -// }, -// function(finished) { -// // Get the private key for each utxo -// client.dumpPrivKey(utxo.address, function(err, privresponse) { -// if (err) { -// throw err; -// } -// utxo.privateKeyWIF = privresponse.result; -// var tx = bitcore.Transaction(); -// tx.from(utxo); -// tx.change(privateKey.toAddress()); -// tx.to(destKey.toAddress(), utxo.amount * 1e8 - 100000); -// tx.sign(bitcore.PrivateKey.fromWIF(utxo.privateKeyWIF)); -// txs.push(tx); -// finished(); -// }); -// } -// ], next); -// }, function(err) { -// if (err) { -// throw err; -// } -// peer.on('ready', function() { -// log.info('Peer ready'); -// done(); -// }); -// log.info('Connecting to peer'); -// peer.connect(); -// }); -// }); -// }); -// }); -// }); -// }); -// -// }); -// -// after(function(done) { -// this.timeout(20000); -// peer.on('disconnect', function() { -// log.info('Peer disconnected'); -// bitcoind.node.stopping = true; -// bitcoind.stop(function(err, result) { -// done(); -// }); -// }); -// peer.disconnect(); -// }); -// -// it('will be able to handle many inventory messages and be able to send getdata messages and received the txs', function(done) { -// this.timeout(100000); -// -// var usedTxs = {}; -// -// bitcoind.on('tx', function(buffer) { -// var txFromResult = new Transaction().fromBuffer(buffer); -// var tx = usedTxs[txFromResult.id]; -// should.exist(tx); -// buffer.toString('hex').should.equal(tx.serialize()); -// delete usedTxs[tx.id]; -// if (Object.keys(usedTxs).length === 0) { -// done(); -// } -// }); -// -// peer.on('getdata', function(message) { -// var hash = message.inventory[0].hash; -// var reversedHash = BufferUtil.reverse(hash).toString('hex'); -// var tx = usedTxs[reversedHash]; -// if (reversedHash === tx.id) { -// var txMessage = messages.Transaction(tx); -// peer.sendMessage(txMessage); -// } -// }); -// async.whilst( -// function() { -// return txs.length > 0; -// }, -// function(callback) { -// var tx = txs.pop(); -// usedTxs[tx.id] = tx; -// var message = messages.Inventory.forTransaction(tx.hash); -// peer.sendMessage(message); -// callback(); -// }, -// function(err) { -// if (err) { -// throw err; -// } -// }); -// }); -// -//}); +'use strict'; + +// To run the tests: $ mocha -R spec regtest/p2p.js + +var path = require('path'); +var index = require('..'); +var log = index.log; + +var p2p = require('litecore-p2p'); +var Peer = p2p.Peer; +var Messages = p2p.Messages; +var chai = require('chai'); +var bitcore = require('litecore-lib'); +var Transaction = bitcore.Transaction; +var BN = bitcore.crypto.BN; +var async = require('async'); +var rimraf = require('rimraf'); +var bitcoind; + +/* jshint unused: false */ +var should = chai.should(); +var assert = chai.assert; +var sinon = require('sinon'); +var BitcoinRPC = require('litecoind-rpc'); +var transactionData = []; +var blockHashes = []; +var txs = []; +var client; +var messages; +var peer; +var coinbasePrivateKey; +var privateKey = bitcore.PrivateKey(); +var destKey = bitcore.PrivateKey(); +var BufferUtil = bitcore.util.buffer; +var blocks; + +describe('P2P Functionality', function() { + + before(function(done) { + this.timeout(100000); + + // enable regtest + bitcore.Networks.enableRegtest(); + var regtestNetwork = bitcore.Networks.get('regtest'); + var datadir = __dirname + '/data'; + + rimraf(datadir + '/regtest', function(err) { + if (err) { + throw err; + } + + bitcoind = require('../').services.Bitcoin({ + spawn: { + datadir: datadir, + exec: path.resolve(__dirname, '../bin/litecoind') + }, + node: { + network: bitcore.Networks.testnet + } + }); + + bitcoind.on('error', function(err) { + log.error('error="%s"', err.message); + }); + + log.info('Waiting for Bitcoin Core to initialize...'); + + bitcoind.start(function(err) { + if (err) { + throw err; + } + log.info('Bitcoind started'); + + client = new BitcoinRPC({ + protocol: 'http', + host: '127.0.0.1', + port: 30331, + user: 'bitcoin', + pass: 'local321', + rejectUnauthorized: false + }); + + peer = new Peer({ + host: '127.0.0.1', + // port: regtestNetwork.port, // regtestNetwork will provide the port: 19444 + network: regtestNetwork + }); + + messages = new Messages({ + network: regtestNetwork + }); + + blocks = 500; + + log.info('Generating ' + blocks + ' blocks...'); + + // Generate enough blocks so that the initial coinbase transactions + // can be spent. + + setImmediate(function() { + client.generate(blocks, function(err, response) { + if (err) { + throw err; + } + blockHashes = response.result; + + log.info('Preparing test data...'); + + // Get all of the unspent outputs + client.listUnspent(0, blocks, function(err, response) { + var utxos = response.result; + + async.mapSeries(utxos, function(utxo, next) { + async.series([ + function(finished) { + // Load all of the transactions for later testing + client.getTransaction(utxo.txid, function(err, txresponse) { + if (err) { + throw err; + } + // add to the list of transactions for testing later + transactionData.push(txresponse.result.hex); + finished(); + }); + }, + function(finished) { + // Get the private key for each utxo + client.dumpPrivKey(utxo.address, function(err, privresponse) { + if (err) { + throw err; + } + utxo.privateKeyWIF = privresponse.result; + var tx = bitcore.Transaction(); + tx.from(utxo); + tx.change(privateKey.toAddress()); + tx.to(destKey.toAddress(), utxo.amount * 1e8 - 100000); + tx.sign(bitcore.PrivateKey.fromWIF(utxo.privateKeyWIF)); + txs.push(tx); + finished(); + }); + } + ], next); + }, function(err) { + if (err) { + throw err; + } + peer.on('ready', function() { + log.info('Peer ready'); + done(); + }); + log.info('Connecting to peer'); + peer.connect(); + }); + }); + }); + }); + }); + }); + + }); + + after(function(done) { + this.timeout(20000); + peer.on('disconnect', function() { + log.info('Peer disconnected'); + bitcoind.node.stopping = true; + bitcoind.stop(function(err, result) { + if (err){ new Error(`Unable to shut down Daemon: ${err}`); } + done(); + }); + }); + peer.disconnect(); + }); + + it('will be able to handle many inventory messages and be able to send getdata messages and received the txs', function(done) { + this.timeout(100000); + + var usedTxs = {}; + + bitcoind.on('tx', function(buffer) { + var txFromResult = new Transaction().fromBuffer(buffer); + var tx = usedTxs[txFromResult.id]; + should.exist(tx); + buffer.toString('hex').should.equal(tx.serialize()); + delete usedTxs[tx.id]; + if (Object.keys(usedTxs).length === 0) { + done(); + } + }); + + peer.on('getdata', function(message) { + var hash = message.inventory[0].hash; + var reversedHash = BufferUtil.reverse(hash).toString('hex'); + var tx = usedTxs[reversedHash]; + if (reversedHash === tx.id) { + var txMessage = messages.Transaction(tx); + peer.sendMessage(txMessage); + } + }); + async.whilst( + function() { + return txs.length > 0; + }, + function(callback) { + var tx = txs.pop(); + usedTxs[tx.id] = tx; + var message = messages.Inventory.forTransaction(tx.hash); + peer.sendMessage(message); + callback(); + }, + function(err) { + if (err) { + throw err; + } + }); + }); + +}); diff --git a/scripts/regtest b/scripts/regtest index 6978a2ce3..96078911d 100755 --- a/scripts/regtest +++ b/scripts/regtest @@ -2,7 +2,7 @@ set -e - +_mocha -R spec regtest/p2p.js _mocha -R spec regtest/bitcoind.js _mocha -R spec regtest/cluster.js _mocha -R spec regtest/node.js From bac0c6ef2ec9a0e21aba0493c0810bcd703e27f0 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 13:52:49 +1000 Subject: [PATCH 14/23] travis test --- regtest/p2p.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/regtest/p2p.js b/regtest/p2p.js index 7d7308658..74aea1363 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -165,9 +165,13 @@ describe('P2P Functionality', function() { log.info('Peer disconnected'); bitcoind.node.stopping = true; bitcoind.stop(function(err, result) { - if (err){ new Error(`Unable to shut down Daemon: ${err}`); } - done(); + if (err){ new Error(`Unable to shut down Daemon: ${err}`) }; + // done(); }); + setTimeout(function(){ + done(); + }, 5000); + }); peer.disconnect(); }); From dc6ef0e435b55c72f49644504cbd5df20749405f Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 13:58:31 +1000 Subject: [PATCH 15/23] no message --- regtest/p2p.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/regtest/p2p.js b/regtest/p2p.js index 74aea1363..2299cc753 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -159,22 +159,6 @@ describe('P2P Functionality', function() { }); - after(function(done) { - this.timeout(20000); - peer.on('disconnect', function() { - log.info('Peer disconnected'); - bitcoind.node.stopping = true; - bitcoind.stop(function(err, result) { - if (err){ new Error(`Unable to shut down Daemon: ${err}`) }; - // done(); - }); - setTimeout(function(){ - done(); - }, 5000); - - }); - peer.disconnect(); - }); it('will be able to handle many inventory messages and be able to send getdata messages and received the txs', function(done) { this.timeout(100000); @@ -218,5 +202,20 @@ describe('P2P Functionality', function() { } }); }); + + + + after(function(done) { + this.timeout(20000); + peer.on('disconnect', function() { + log.info('Peer disconnected'); + bitcoind.node.stopping = true; + bitcoind.stop(function(err, result) { + if (err){ new Error(`Unable to shut down Daemon: ${err}`)}; + done(); + }); + }); + peer.disconnect(); + }); }); From 5aee89b8154623553e51fdf048416aede046ee22 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 14:04:07 +1000 Subject: [PATCH 16/23] no message --- lib/services/bitcoind.js | 1 + regtest/p2p.js | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index e827c5863..aa889aabd 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -865,6 +865,7 @@ Bitcoin.prototype._spawnChildProcess = function(callback) { }); self.spawn.process.once('exit', function(code) { + return; if (!self.node.stopping) { log.warn('Bitcoin process unexpectedly exited with code:', code); log.warn('Restarting bitcoin child process in ' + self.spawnRestartTime + 'ms'); diff --git a/regtest/p2p.js b/regtest/p2p.js index 2299cc753..17382aac7 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -159,6 +159,18 @@ describe('P2P Functionality', function() { }); + after(function(done) { + this.timeout(20000); + peer.on('disconnect', function() { + log.info('Peer disconnected'); + bitcoind.node.stopping = true; + bitcoind.stop(function(err, result) { + if (err){ new Error(`Unable to shut down Daemon: ${err}`)}; + done(); + }); + }); + peer.disconnect(); + }); it('will be able to handle many inventory messages and be able to send getdata messages and received the txs', function(done) { this.timeout(100000); @@ -202,20 +214,5 @@ describe('P2P Functionality', function() { } }); }); - - - - after(function(done) { - this.timeout(20000); - peer.on('disconnect', function() { - log.info('Peer disconnected'); - bitcoind.node.stopping = true; - bitcoind.stop(function(err, result) { - if (err){ new Error(`Unable to shut down Daemon: ${err}`)}; - done(); - }); - }); - peer.disconnect(); - }); }); From 2b9d328b1ebbc1dccfa4e4c0dc8027ebf969143c Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 14:21:50 +1000 Subject: [PATCH 17/23] no message --- lib/services/bitcoind.js | 1 - regtest/p2p.js | 2 +- scripts/regtest | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index aa889aabd..e827c5863 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -865,7 +865,6 @@ Bitcoin.prototype._spawnChildProcess = function(callback) { }); self.spawn.process.once('exit', function(code) { - return; if (!self.node.stopping) { log.warn('Bitcoin process unexpectedly exited with code:', code); log.warn('Restarting bitcoin child process in ' + self.spawnRestartTime + 'ms'); diff --git a/regtest/p2p.js b/regtest/p2p.js index 17382aac7..800941860 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -165,7 +165,7 @@ describe('P2P Functionality', function() { log.info('Peer disconnected'); bitcoind.node.stopping = true; bitcoind.stop(function(err, result) { - if (err){ new Error(`Unable to shut down Daemon: ${err}`)}; + if (err){ new Error(`Unable to shut down Daemon: ${err}`) }; done(); }); }); diff --git a/scripts/regtest b/scripts/regtest index 96078911d..7711aabb5 100755 --- a/scripts/regtest +++ b/scripts/regtest @@ -2,7 +2,7 @@ set -e -_mocha -R spec regtest/p2p.js -_mocha -R spec regtest/bitcoind.js -_mocha -R spec regtest/cluster.js -_mocha -R spec regtest/node.js +_mocha -R --exit spec regtest/p2p.js +_mocha -R --exit spec regtest/bitcoind.js +_mocha -R --exit spec regtest/cluster.js +_mocha -R --exit spec regtest/node.js From 343d0332533c8540a8cb55618c7a7e48bd099b82 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 14:37:46 +1000 Subject: [PATCH 18/23] travis test --- regtest/p2p.js | 1 + scripts/regtest | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/regtest/p2p.js b/regtest/p2p.js index 800941860..dd52afefa 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -166,6 +166,7 @@ describe('P2P Functionality', function() { bitcoind.node.stopping = true; bitcoind.stop(function(err, result) { if (err){ new Error(`Unable to shut down Daemon: ${err}`) }; + process.exit() done(); }); }); diff --git a/scripts/regtest b/scripts/regtest index 7711aabb5..96078911d 100755 --- a/scripts/regtest +++ b/scripts/regtest @@ -2,7 +2,7 @@ set -e -_mocha -R --exit spec regtest/p2p.js -_mocha -R --exit spec regtest/bitcoind.js -_mocha -R --exit spec regtest/cluster.js -_mocha -R --exit spec regtest/node.js +_mocha -R spec regtest/p2p.js +_mocha -R spec regtest/bitcoind.js +_mocha -R spec regtest/cluster.js +_mocha -R spec regtest/node.js From a3ce9a6c6138ca6254a7eb2ee050e27e0988f663 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 14:42:40 +1000 Subject: [PATCH 19/23] no message --- regtest/bitcoind.js | 1 + regtest/node.js | 1 + regtest/p2p.js | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/regtest/bitcoind.js b/regtest/bitcoind.js index bfa80e6d6..94bafa4fd 100644 --- a/regtest/bitcoind.js +++ b/regtest/bitcoind.js @@ -133,6 +133,7 @@ describe('Bitcoind Functionality', function() { this.timeout(60000); bitcoind.node.stopping = true; bitcoind.stop(function(err, result) { + process.exit(); done(); }); }); diff --git a/regtest/node.js b/regtest/node.js index 1628a4f79..97ef697e5 100644 --- a/regtest/node.js +++ b/regtest/node.js @@ -110,6 +110,7 @@ describe('Node Functionality', function() { if(err) { throw err; } + process.exit(); done(); }); }); diff --git a/regtest/p2p.js b/regtest/p2p.js index dd52afefa..72b7e245a 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -166,7 +166,7 @@ describe('P2P Functionality', function() { bitcoind.node.stopping = true; bitcoind.stop(function(err, result) { if (err){ new Error(`Unable to shut down Daemon: ${err}`) }; - process.exit() + process.exit(); done(); }); }); From 5b9f72d962598dea2e0cdfe079d6242cf6de2f29 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 14:47:02 +1000 Subject: [PATCH 20/23] no message --- regtest/cluster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regtest/cluster.js b/regtest/cluster.js index 461014591..8fe3dad59 100644 --- a/regtest/cluster.js +++ b/regtest/cluster.js @@ -92,7 +92,7 @@ describe('Bitcoin Cluster', function() { async.each(daemons, function(process, next) { process.once('exit', next); process.kill('SIGINT'); - }, done); + }, process.exit()); }, 1000); }); From 0cfe2336a7d2be97a367aeef2e86266857a1cebd Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 15:05:36 +1000 Subject: [PATCH 21/23] Update coveralls to latest v3.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4443c186..1239e27b7 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "benchmark": "1.0.0", "litecore-p2p": "^1.1.2", "chai": "^3.5.0", - "coveralls": "^2.11.9", + "coveralls": "^3.0.2", "istanbul": "^0.4.3", "jshint": "^2.9.2", "jshint-stylish": "^2.1.0", From 215fe32837791b9aa991c638292ff6d4849653e3 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 15:13:55 +1000 Subject: [PATCH 22/23] Update socket.io & socket.io-client to v2.1.1 in order to fix critical security issue. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1239e27b7..f7c3313b5 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,8 @@ "mkdirp": "0.5.0", "path-is-absolute": "^1.0.0", "semver": "^5.0.1", - "socket.io": "^1.4.5", - "socket.io-client": "^1.4.5", + "socket.io": "^2.1.1", + "socket.io-client": "^2.1.1", "zeromq": "^4.2.0" }, "optionalDependencies": { From f0d6b7347960c2687edd08a8119fce2ca86601c7 Mon Sep 17 00:00:00 2001 From: Edin Jusupovic Date: Thu, 23 Aug 2018 15:40:34 +1000 Subject: [PATCH 23/23] comments. --- regtest/bitcoind.js | 4 ++-- regtest/node.js | 4 ++-- regtest/p2p.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/regtest/bitcoind.js b/regtest/bitcoind.js index 94bafa4fd..73a4ce1ff 100644 --- a/regtest/bitcoind.js +++ b/regtest/bitcoind.js @@ -133,8 +133,8 @@ describe('Bitcoind Functionality', function() { this.timeout(60000); bitcoind.node.stopping = true; bitcoind.stop(function(err, result) { - process.exit(); - done(); + process.exit(); + done(); // ## deprecated ## (Mocha v5), using process.exit() }); }); diff --git a/regtest/node.js b/regtest/node.js index 97ef697e5..85783d763 100644 --- a/regtest/node.js +++ b/regtest/node.js @@ -110,8 +110,8 @@ describe('Node Functionality', function() { if(err) { throw err; } - process.exit(); - done(); + process.exit(); + done(); // ## deprecated ## (Mocha v5), using process.exit() }); }); diff --git a/regtest/p2p.js b/regtest/p2p.js index 72b7e245a..291ccc796 100644 --- a/regtest/p2p.js +++ b/regtest/p2p.js @@ -166,8 +166,8 @@ describe('P2P Functionality', function() { bitcoind.node.stopping = true; bitcoind.stop(function(err, result) { if (err){ new Error(`Unable to shut down Daemon: ${err}`) }; - process.exit(); - done(); + process.exit(); + done(); // ## deprecated ## (Mocha v5), using process.exit() }); }); peer.disconnect();