mirror of https://github.com/BTCPrivate/copay.git
Adding test to Insight
This commit is contained in:
parent
a0aee4a48a
commit
27e0a8a560
|
@ -14,8 +14,8 @@ var log = require('../util/log.js');
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This class lets interfaces with the blockchain, making general queries and
|
This class lets interface with the blockchain, making general queries and
|
||||||
subscribing to transactions on adressess and blocks.
|
subscribing to transactions on addresses and blocks.
|
||||||
|
|
||||||
Opts:
|
Opts:
|
||||||
- url
|
- url
|
||||||
|
|
|
@ -128,8 +128,12 @@ describe('Insight model', function() {
|
||||||
|
|
||||||
sinon.stub(blockchain, "requestPost", function(url, data, cb) {
|
sinon.stub(blockchain, "requestPost", function(url, data, cb) {
|
||||||
url.should.be.equal('/api/tx/send');
|
url.should.be.equal('/api/tx/send');
|
||||||
var res = {statusCode: 200};
|
var res = {
|
||||||
var body = {txid: 1234};
|
statusCode: 200
|
||||||
|
};
|
||||||
|
var body = {
|
||||||
|
txid: 1234
|
||||||
|
};
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
cb(null, res, body);
|
cb(null, res, body);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
@ -145,11 +149,16 @@ describe('Insight model', function() {
|
||||||
it('should get a transaction by id', function(done) {
|
it('should get a transaction by id', function(done) {
|
||||||
var blockchain = new Insight(FAKE_OPTS);
|
var blockchain = new Insight(FAKE_OPTS);
|
||||||
var txid = '123321';
|
var txid = '123321';
|
||||||
var tx = {txid: txid, more: 'something'};
|
var tx = {
|
||||||
|
txid: txid,
|
||||||
|
more: 'something'
|
||||||
|
};
|
||||||
|
|
||||||
sinon.stub(blockchain, "request", function(url, cb) {
|
sinon.stub(blockchain, "request", function(url, cb) {
|
||||||
url.should.be.equal('/api/tx/' + txid);
|
url.should.be.equal('/api/tx/' + txid);
|
||||||
var res = {statusCode: 200};
|
var res = {
|
||||||
|
statusCode: 200
|
||||||
|
};
|
||||||
var body = JSON.stringify(tx);
|
var body = JSON.stringify(tx);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
cb(null, res, body);
|
cb(null, res, body);
|
||||||
|
@ -171,7 +180,9 @@ describe('Insight model', function() {
|
||||||
|
|
||||||
sinon.stub(blockchain, "request", function(url, cb) {
|
sinon.stub(blockchain, "request", function(url, cb) {
|
||||||
url.should.be.equal('/api/tx/' + txid);
|
url.should.be.equal('/api/tx/' + txid);
|
||||||
var res = {statusCode: 404};
|
var res = {
|
||||||
|
statusCode: 404
|
||||||
|
};
|
||||||
var body = '';
|
var body = '';
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
cb(null, res, body);
|
cb(null, res, body);
|
||||||
|
@ -191,7 +202,9 @@ describe('Insight model', function() {
|
||||||
|
|
||||||
sinon.stub(blockchain, "request", function(url, cb) {
|
sinon.stub(blockchain, "request", function(url, cb) {
|
||||||
url.should.be.equal('/api/tx/' + txid);
|
url.should.be.equal('/api/tx/' + txid);
|
||||||
var res = {statusCode: 200};
|
var res = {
|
||||||
|
statusCode: 200
|
||||||
|
};
|
||||||
var body = null;
|
var body = null;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
cb(null, res, body);
|
cb(null, res, body);
|
||||||
|
@ -211,7 +224,9 @@ describe('Insight model', function() {
|
||||||
|
|
||||||
sinon.stub(blockchain, "request", function(url, cb) {
|
sinon.stub(blockchain, "request", function(url, cb) {
|
||||||
url.should.be.equal('/api/tx/' + txid);
|
url.should.be.equal('/api/tx/' + txid);
|
||||||
var res = {statusCode: 200};
|
var res = {
|
||||||
|
statusCode: 200
|
||||||
|
};
|
||||||
var body = null;
|
var body = null;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
cb(null, res, body);
|
cb(null, res, body);
|
||||||
|
@ -233,8 +248,13 @@ describe('Insight model', function() {
|
||||||
url.should.be.equal('/api/addrs/txs?from=0');
|
url.should.be.equal('/api/addrs/txs?from=0');
|
||||||
data.addrs.should.be.equal('2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM,2NE9hTCffeugo5gQtfB4owq98gyTeWC56yb');
|
data.addrs.should.be.equal('2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM,2NE9hTCffeugo5gQtfB4owq98gyTeWC56yb');
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var res = {statusCode: 200};
|
var res = {
|
||||||
var body = { totalItems: 3, items: [1, 2, 3] };
|
statusCode: 200
|
||||||
|
};
|
||||||
|
var body = {
|
||||||
|
totalItems: 3,
|
||||||
|
items: [1, 2, 3]
|
||||||
|
};
|
||||||
cb(null, res, body);
|
cb(null, res, body);
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
@ -254,7 +274,9 @@ describe('Insight model', function() {
|
||||||
url.should.be.equal('/api/addrs/utxo');
|
url.should.be.equal('/api/addrs/utxo');
|
||||||
data.addrs.should.be.equal('2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM,2NE9hTCffeugo5gQtfB4owq98gyTeWC56yb,2N9D5bcCQ2bPWUDByQ6Qb5bMgMtgsk1rw3x');
|
data.addrs.should.be.equal('2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM,2NE9hTCffeugo5gQtfB4owq98gyTeWC56yb,2N9D5bcCQ2bPWUDByQ6Qb5bMgMtgsk1rw3x');
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var res = {statusCode: 200};
|
var res = {
|
||||||
|
statusCode: 200
|
||||||
|
};
|
||||||
var body = UNSPENT;
|
var body = UNSPENT;
|
||||||
cb(null, res, body);
|
cb(null, res, body);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
@ -364,7 +386,9 @@ describe('Insight model', function() {
|
||||||
blockchain.on('connect', function() {
|
blockchain.on('connect', function() {
|
||||||
var socket = blockchain.getSocket();
|
var socket = blockchain.getSocket();
|
||||||
socket.emit('2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY', '1123');
|
socket.emit('2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY', '1123');
|
||||||
setTimeout(function() { done(); }, 20);
|
setTimeout(function() {
|
||||||
|
done();
|
||||||
|
}, 20);
|
||||||
});
|
});
|
||||||
|
|
||||||
blockchain.on('tx', function(ev) {
|
blockchain.on('tx', function(ev) {
|
||||||
|
@ -392,5 +416,17 @@ describe('Insight model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('setCompleteUrl', function() {
|
||||||
|
it('should check setCompleteUrl', function() {
|
||||||
|
var url;
|
||||||
|
expect(Insight.setCompleteUrl(url)).to.be.undefined;
|
||||||
|
url = '';
|
||||||
|
Insight.setCompleteUrl(url).should.be.equal(url);
|
||||||
|
url = 'http://mydomain.com';
|
||||||
|
Insight.setCompleteUrl(url).should.be.equal('http://mydomain.com:80');
|
||||||
|
url = 'https://mydomain.com';
|
||||||
|
Insight.setCompleteUrl(url).should.be.equal('https://mydomain.com:443');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue