Fixed network for bcoin.
This commit is contained in:
parent
07430955bd
commit
4563a8ffaa
@ -1,6 +1,5 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- 'v0.12.7'
|
- 'v8'
|
||||||
- 'v4'
|
|
||||||
install:
|
install:
|
||||||
- npm install
|
- npm install
|
||||||
|
|||||||
@ -7,6 +7,7 @@ function StatusController(node) {
|
|||||||
this.common = new Common({log: this.node.log});
|
this.common = new Common({log: this.node.log});
|
||||||
this._block = this.node.services.block;
|
this._block = this.node.services.block;
|
||||||
this._header = this.node.services.header;
|
this._header = this.node.services.header;
|
||||||
|
this._block = this.node.services.block;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusController.prototype.show = function(req, res) {
|
StatusController.prototype.show = function(req, res) {
|
||||||
|
|||||||
@ -14,6 +14,9 @@ function TxController(node) {
|
|||||||
this._block = this.node.services.block;
|
this._block = this.node.services.block;
|
||||||
this._transaction = this.node.services.transaction;
|
this._transaction = this.node.services.transaction;
|
||||||
this._address = this.node.services.address;
|
this._address = this.node.services.address;
|
||||||
|
if (this.node.network === 'livenet') {
|
||||||
|
this._network = 'main';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TxController.prototype.show = function(req, res) {
|
TxController.prototype.show = function(req, res) {
|
||||||
@ -125,7 +128,7 @@ TxController.prototype.transformInput = function(options, input, index) {
|
|||||||
|
|
||||||
var address = input.getAddress();
|
var address = input.getAddress();
|
||||||
if (address) {
|
if (address) {
|
||||||
address.network = this.node.network || 'main';
|
address.network = this._network || 'main';
|
||||||
transformed.addr = address.toString();
|
transformed.addr = address.toString();
|
||||||
} else {
|
} else {
|
||||||
transformed.addr = null;
|
transformed.addr = null;
|
||||||
@ -162,7 +165,7 @@ TxController.prototype.transformOutput = function(options, output, index) {
|
|||||||
|
|
||||||
var address = output.getAddress();
|
var address = output.getAddress();
|
||||||
if (address) {
|
if (address) {
|
||||||
address.network = this.node.network || 'main';
|
address.network = this._network || 'main';
|
||||||
transformed.scriptPubKey.addresses = [address.toString()];
|
transformed.scriptPubKey.addresses = [address.toString()];
|
||||||
transformed.scriptPubKey.type = address.getType();
|
transformed.scriptPubKey.type = address.getType();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,9 @@ var fs = require('fs');
|
|||||||
var async = require('async');
|
var async = require('async');
|
||||||
var RPC = require('bitcoind-rpc');
|
var RPC = require('bitcoind-rpc');
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
|
var bitcore = require('bitcore-lib');
|
||||||
|
var PrivateKey = bitcore.PrivateKey;
|
||||||
|
var Transaction = bitcore.Transaction;
|
||||||
|
|
||||||
var rpc1Address;
|
var rpc1Address;
|
||||||
var rpc2Address;
|
var rpc2Address;
|
||||||
@ -308,7 +311,7 @@ describe('Address', function() {
|
|||||||
function(next) {
|
function(next) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
startBitcore(next);
|
startBitcore(next);
|
||||||
}, 6000);
|
}, 8000);
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -325,6 +328,8 @@ describe('Address', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('should get address info correctly: /addr/:addr', function(done) {
|
it('should get address info correctly: /addr/:addr', function(done) {
|
||||||
|
|
||||||
|
|
||||||
@ -761,6 +766,122 @@ describe('Address', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should index addresses correctly', function(done) {
|
||||||
|
// if we send a tx that has an address in both the input and the output, does it index correctly?
|
||||||
|
var txid;
|
||||||
|
var pk1;
|
||||||
|
var tx;
|
||||||
|
async.waterfall([
|
||||||
|
function(next) {
|
||||||
|
rpc1.listUnspent(function(err, res) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
next(null, res.result[0]);
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(utxo, next) {
|
||||||
|
rpc1.dumpPrivKey(utxo.address, function(err, res) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
var pk = new PrivateKey(res.result);
|
||||||
|
pk1 = new PrivateKey('testnet');
|
||||||
|
var change = new PrivateKey('testnet');
|
||||||
|
var changeAddress = change.toAddress();
|
||||||
|
var from = {
|
||||||
|
txId: utxo.txid,
|
||||||
|
address: utxo.address,
|
||||||
|
script: utxo.scriptPubKey,
|
||||||
|
satoshis: utxo.amount * 1e8,
|
||||||
|
outputIndex: utxo.vout
|
||||||
|
};
|
||||||
|
tx = new Transaction().from(from).to(pk1.toAddress(), 2500000000).change(changeAddress).sign(pk);
|
||||||
|
|
||||||
|
rpc2.sendRawTransaction(tx.serialize(), function(err, res) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
txid = res.result;
|
||||||
|
console.log(txid);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
rpc2.generate(1, function() {
|
||||||
|
setTimeout(next, 2000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
var tx2 = new Transaction().from({
|
||||||
|
txId: txid,
|
||||||
|
satoshis: 2500000000,
|
||||||
|
outputIndex: 0,
|
||||||
|
script: tx.outputs[0].script.toHex(),
|
||||||
|
address: pk1.toAddress()
|
||||||
|
}).to(pk1.toAddress(), 2500000000 - 1000).sign(pk1);
|
||||||
|
rpc2.sendRawTransaction(tx2.serialize(), function(err, res) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
txid = res.result;
|
||||||
|
console.log(txid);
|
||||||
|
next();
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
rpc2.generate(1, function() {
|
||||||
|
setTimeout(next, 2000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = http.request('http://localhost:53001/api/addr/' + pk1.toAddress(), function(res) {
|
||||||
|
|
||||||
|
var error;
|
||||||
|
if (res.statusCode !== 200 && res.statusCode !== 201) {
|
||||||
|
if (error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return done('Error from bitcore-node webserver: ' + res.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
var resError;
|
||||||
|
var resData = '';
|
||||||
|
|
||||||
|
res.on('error', function(e) {
|
||||||
|
resError = e;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('data', function(data) {
|
||||||
|
resData += data;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end', function() {
|
||||||
|
if (error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var data = JSON.parse(resData);
|
||||||
|
console.log(data);
|
||||||
|
expect(data.transactions.length).to.equal(2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
request.write('');
|
||||||
|
request.end();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user