wip on wallet regtest.

This commit is contained in:
Chris Kleeschulte 2017-04-24 17:09:12 -04:00
parent 0788da0e45
commit c7acf254b4
2 changed files with 51 additions and 56 deletions

View File

@ -45,7 +45,7 @@
"dependencies": { "dependencies": {
"async": "^1.3.0", "async": "^1.3.0",
"bitcoind-rpc": "^0.6.0", "bitcoind-rpc": "^0.6.0",
"bitcore-lib": "^0.13.13", "bitcore-lib": "^0.14",
"body-parser": "^1.13.3", "body-parser": "^1.13.3",
"colors": "^1.1.2", "colors": "^1.1.2",
"commander": "^2.8.1", "commander": "^2.8.1",

View File

@ -91,18 +91,7 @@ var bitcore = {
process: null process: null
}; };
var httpOpts = {
protocol: 'http:',
hostname: 'localhost',
port: bitcore.configFile.conf.port,
method: 'GET',
body: ''
};
var fee = 100000;
var rpc = new BitcoinRPC(rpcConfig); var rpc = new BitcoinRPC(rpcConfig);
var walletPassphrase = 'test'; var walletPassphrase = 'test';
var startingSatoshis = 0; var startingSatoshis = 0;
@ -110,7 +99,7 @@ var numberOfStartingTxs = 50;
var walletPrivKeys = []; var walletPrivKeys = [];
var initialTxs = []; var initialTxs = [];
var fee = 100000;
describe('Wallet Operations', function() { describe('Wallet Operations', function() {
@ -119,7 +108,7 @@ describe('Wallet Operations', function() {
afterEach(function(done) { afterEach(function(done) {
bitcore.process.kill(); bitcore.process.kill();
bitcoin.process.kill(); bitcoin.process.kill();
setTimeout(done, 2000); //we need this here to let bitcoin process clean up after itself setTimeout(done, 2000);
}); });
beforeEach(function(done) { beforeEach(function(done) {
@ -151,63 +140,70 @@ function toArgs(opts) {
} }
function waitForService(task, next) { function waitForService(task, next) {
var retryOpts = { times: 10, interval: 1000 }; var retryOpts = { times: 20, interval: 1000 };
async.retry(retryOpts, task, next); async.retry(retryOpts, task, next);
} }
function queryBitcoreNode(httpOpts, next) { function queryBitcoreNode(httpOpts, next) {
console.log('query bitcore node'); console.log('request', httpOpts);
console.log('called request');
var error; var error;
var request = http.request(httpOpts, function(res) { var request = http.request(httpOpts, function(res) {
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
return next(res.statusCode); console.log('status code: ', error, res.statusCode);
if (error) {
return;
} }
return next(res.statusCode);
}
var resError; var resError;
var resData = ''; var resData = '';
res.on('error', function(e) {
resError = e;
});
res.on('data', function(data) {
resData += data;
});
res.on('end', function() {
console.log('end');
if (error) {
return;
}
if (httpOpts.errorFilter) {
return httpOpts.errorFilter(resError, resData);
}
if (resError) {
return next(resError);
}
next('try again');
});
res.on('error', function(e) {
resError = e;
}); });
request.on('error', function(e) { res.on('data', function(data) {
error = e; resData += data;
return next(e);
}); });
request.write(''); res.on('end', function() {
request.end(); console.log('end: ', error);
if (error) {
return;
}
if (httpOpts.errorFilter) {
return next(httpOpts.errorFilter(resError, resData));
}
if (resError) {
return next(resError);
}
next();
});
});
request.on('error', function(e) {
error = e
next(error);
});
request.write('');
request.end();
} }
function waitForBitcoreNode(next) { function waitForBitcoreNode(next) {
console.log('wait'); bitcore.process.stdout.on('data', function(data) {
var errorFilter = function(err, res, next) { console.log(data.toString());
});
bitcore.process.stderr.on('data', function(data) {
console.log(data.toString());
});
var errorFilter = function(err, res) {
if (err || (res && !JSON.parse(res).result)) { if (err || (res && !JSON.parse(res).result)) {
return next('still syncing'); return 'still syncing';
} }
next();
}; };
var httpOpts = Object.assign({ var httpOpts = Object.assign({
@ -254,7 +250,6 @@ function initializeAndStartService(opts, next) {
} }
function startBitcoreNode(next) { function startBitcoreNode(next) {
console.log('start bitcore');
initializeAndStartService(bitcore, next); initializeAndStartService(bitcore, next);
} }
@ -306,9 +301,9 @@ function generateSpendingTx(privKey, utxo) {
var tx = new Transaction(); var tx = new Transaction();
tx.from(utxo); tx.from(utxo);
tx.to(toPrivKey.toAddress(), satsToPrivKey); tx.to(toPrivKey.toAddress().toString(), satsToPrivKey);
tx.fee(fee); tx.fee(fee);
tx.change(changePrivKey.toAddress()); tx.change(changePrivKey.toAddress().toString());
tx.sign(privKey); tx.sign(privKey);
walletPrivKeys.push(changePrivKey); walletPrivKeys.push(changePrivKey);