Merge pull request #104 from braydonf/bitcore-0.12.15

Update to bitcore v0.12.15 with publickey out signing.
This commit is contained in:
Patrick Nagurny 2015-08-05 12:43:44 -04:00
commit 8a5d4b014f
2 changed files with 41 additions and 64 deletions

View File

@ -16,6 +16,7 @@ if (process.env.BITCORENODE_ENV !== 'test') {
var chai = require('chai'); var chai = require('chai');
var bitcore = require('bitcore'); var bitcore = require('bitcore');
var BN = bitcore.crypto.BN; var BN = bitcore.crypto.BN;
var async = require('async');
var rimraf = require('rimraf'); var rimraf = require('rimraf');
var bitcoind; var bitcoind;
@ -26,7 +27,7 @@ var sinon = require('sinon');
var BitcoinRPC = require('bitcoind-rpc'); var BitcoinRPC = require('bitcoind-rpc');
var transactionData = []; var transactionData = [];
var blockHashes = []; var blockHashes = [];
var utxo; var utxos;
var client; var client;
var coinbasePrivateKey; var coinbasePrivateKey;
var privateKey = bitcore.PrivateKey(); var privateKey = bitcore.PrivateKey();
@ -96,66 +97,41 @@ describe('Daemon Binding Functionality', function() {
} }
blockHashes = response.result; blockHashes = response.result;
// The original coinbase transactions when using regtest spend to log.info('Preparing test data...');
// a non-standard pubkeyout instead of a pubkeyhashout.
// We'll construct a new transaction that will send funds
// to a new address with pubkeyhashout for later testing.
log.info('Preparing unspent outputs...'); // Get all of the unspent outputs
client.listUnspent(0, 150, function(err, response) {
utxos = response.result;
client.getBalance(function(err, response) { async.mapSeries(utxos, function(utxo, next) {
if (err) { async.series([
throw err; function(finished) {
} // Load all of the transactions for later testing
client.getTransaction(utxo.txid, function(err, txresponse) {
var amount = response.result; if (err) {
var fee = 0.01; throw err;
var network = bitcore.Networks.get('regtest'); }
var address = privateKey.toAddress(network); // add to the list of transactions for testing later
transactionData.push(txresponse.result.hex);
client.sendToAddress(address, amount - fee, '', '', function(err, response) { 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;
finished();
});
}
], next);
}, function(err) {
if (err) { if (err) {
throw err; throw err;
} }
done();
var txid = response.result;
client.getTransaction(txid, function(err, response) {
if (err) {
throw err;
}
var unspentTransaction = bitcore.Transaction();
var outputIndex;
unspentTransaction.fromString(response.result.hex);
// add to the list of transactions for testing later
transactionData.push(response.result.hex);
for (var i = 0; i < unspentTransaction.outputs.length; i++) {
var output = unspentTransaction.outputs[i];
if (output.script.toAddress(network).toString() === address.toString(network)) {
outputIndex = i;
}
}
utxo = {
txid: unspentTransaction.hash,
outputIndex: outputIndex,
script: unspentTransaction.outputs[outputIndex].script,
satoshis: unspentTransaction.outputs[outputIndex].satoshis
};
// Include this transaction in a block so that it can
// be spent in tests
client.generate(1, function(err, response) {
if (err) {
throw err;
}
log.info('Testing setup complete!');
done();
});
});
}); });
}); });
}); });
@ -207,7 +183,7 @@ describe('Daemon Binding Functionality', function() {
}); });
describe('get transactions by hash', function() { describe('get transactions by hash', function() {
[0].forEach(function(i) { [0,1,2,3,4,5,6,7,8,9].forEach(function(i) {
it('for tx ' + i, function(done) { it('for tx ' + i, function(done) {
var txhex = transactionData[i]; var txhex = transactionData[i];
var tx = new bitcore.Transaction(); var tx = new bitcore.Transaction();
@ -257,10 +233,10 @@ describe('Daemon Binding Functionality', function() {
// create and sign the transaction // create and sign the transaction
var tx = bitcore.Transaction(); var tx = bitcore.Transaction();
tx.from(utxo); tx.from(utxos[0]);
tx.change(privateKey.toAddress()); tx.change(privateKey.toAddress());
tx.to(destKey.toAddress(), 100000); tx.to(destKey.toAddress(), utxos[0].amount * 1e8 - 1000);
tx.sign(privateKey); tx.sign(bitcore.PrivateKey.fromWIF(utxos[0].privateKeyWIF));
// test sending the transaction // test sending the transaction
var hash = bitcoind.sendTransaction(tx.serialize()); var hash = bitcoind.sendTransaction(tx.serialize());
@ -280,7 +256,7 @@ describe('Daemon Binding Functionality', function() {
it('will get an event when the tip is new', function(done) { it('will get an event when the tip is new', function(done) {
this.timeout(4000); this.timeout(4000);
bitcoind.on('tip', function(height) { bitcoind.on('tip', function(height) {
height.should.equal(152); height.should.equal(151);
done(); done();
}); });
client.generate(1, function(err, response) { client.generate(1, function(err, response) {
@ -343,9 +319,10 @@ describe('Daemon Binding Functionality', function() {
describe('get transaction with block info', function() { describe('get transaction with block info', function() {
it('should include tx buffer, height and timestamp', function(done) { it('should include tx buffer, height and timestamp', function(done) {
bitcoind.getTransactionWithBlockInfo(utxo.txid, true, function(err, data) { bitcoind.getTransactionWithBlockInfo(utxos[0].txid, true, function(err, data) {
should.not.exist(err); should.not.exist(err);
data.height.should.equal(151); should.exist(data.height);
data.height.should.be.a('number');
should.exist(data.timestamp); should.exist(data.timestamp);
should.exist(data.buffer); should.exist(data.buffer);
done(); done();

View File

@ -41,6 +41,7 @@
"dependencies": { "dependencies": {
"async": "1.3.0", "async": "1.3.0",
"bindings": "^1.2.1", "bindings": "^1.2.1",
"bitcore": "^0.12.15",
"chainlib": "^0.1.1", "chainlib": "^0.1.1",
"errno": "^0.1.2", "errno": "^0.1.2",
"memdown": "^1.0.0", "memdown": "^1.0.0",
@ -52,7 +53,6 @@
"benchmark": "1.0.0", "benchmark": "1.0.0",
"bitcoin": "^2.3.2", "bitcoin": "^2.3.2",
"bitcoind-rpc": "^0.3.0", "bitcoind-rpc": "^0.3.0",
"bitcore": "^0.12.12",
"chai": "^3.0.0", "chai": "^3.0.0",
"mocha": "~1.16.2", "mocha": "~1.16.2",
"proxyquire": "^1.3.1", "proxyquire": "^1.3.1",