add example tests
This commit is contained in:
parent
25c95cdb47
commit
56c12a03b9
|
@ -1,7 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
|
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
||||||
var Address = require('../Address');
|
var Address = require('../Address');
|
||||||
|
|
||||||
var addrs = [
|
var addrs = [
|
||||||
|
@ -17,3 +18,10 @@ addrs.forEach(function(addr) {
|
||||||
var valid = addr.isValid();
|
var valid = addr.isValid();
|
||||||
console.log(addr.data + ' is ' + (valid ? '' : 'not ') + 'valid');
|
console.log(addr.data + ' is ' + (valid ? '' : 'not ') + 'valid');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
|
@ -1,37 +1,31 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
var networks = require('../networks');
|
var networks = require('../networks');
|
||||||
var Peer = require('../Peer');
|
var Peer = require('../Peer');
|
||||||
var PeerManager = require('soop').load('../PeerManager',
|
var PeerManager = require('soop').load('../PeerManager', {
|
||||||
{network: networks.testnet});
|
network: networks.testnet
|
||||||
|
});
|
||||||
|
|
||||||
var handleBlock = function(info) {
|
var handleBlock = function(info) {
|
||||||
|
|
||||||
console.log('** Block Received **');
|
console.log('** Block Received **');
|
||||||
console.log(info.message);
|
console.log(info.message);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var handleTx = function(info) {
|
var handleTx = function(info) {
|
||||||
|
|
||||||
var tx = info.message.tx.getStandardizedObject();
|
var tx = info.message.tx.getStandardizedObject();
|
||||||
|
|
||||||
console.log('** Block TX **');
|
console.log('** TX Received **');
|
||||||
console.log(tx);
|
console.log(tx);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var handleInv = function(info) {
|
var handleInv = function(info) {
|
||||||
|
console.log('** Inv **');
|
||||||
console.log('** Block Inv **');
|
|
||||||
console.log(info.message);
|
console.log(info.message);
|
||||||
|
|
||||||
var invs = info.message.invs;
|
var invs = info.message.invs;
|
||||||
info.conn.sendGetData(invs);
|
info.conn.sendGetData(invs);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var peerman = new PeerManager();
|
var peerman = new PeerManager();
|
||||||
|
@ -45,3 +39,9 @@ peerman.on('connection', function(conn) {
|
||||||
});
|
});
|
||||||
|
|
||||||
peerman.start();
|
peerman.start();
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
var RpcClient = require('../RpcClient');
|
var RpcClient = require('../RpcClient');
|
||||||
var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';
|
var hash = '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
protocol: 'http',
|
protocol: 'http',
|
||||||
|
@ -17,13 +16,16 @@ var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191d
|
||||||
var rpc = new RpcClient(config);
|
var rpc = new RpcClient(config);
|
||||||
|
|
||||||
rpc.getBlock(hash, function(err, ret) {
|
rpc.getBlock(hash, function(err, ret) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("An error occured fetching block", hash);
|
console.error('An error occured fetching block', hash);
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(ret);
|
console.log(ret);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
|
@ -1,28 +1,29 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
||||||
|
|
||||||
var networks = require('../networks');
|
var networks = require('../networks');
|
||||||
var Peer = require('../Peer');
|
var Peer = require('../Peer');
|
||||||
var Transaction = require('../Transaction');
|
var Transaction = require('../Transaction');
|
||||||
var Address = require('../Address');
|
var Address = require('../Address');
|
||||||
var Script = require('../Script');
|
var Script = require('../Script');
|
||||||
var coinUtil = require('../util/util');
|
var coinUtil = require('../util/util');
|
||||||
var PeerManager = require('soop').load('../PeerManager',
|
var PeerManager = require('soop').load('../PeerManager', {
|
||||||
{network: networks.testnet});
|
network: networks.testnet
|
||||||
|
});
|
||||||
|
|
||||||
var createTx = function() {
|
var createTx = function() {
|
||||||
|
|
||||||
var TXIN = 'd05f35e0bbc495f6dcab03e599c8f5e32a07cdb4bc76964de201d06a2a7d8265';
|
var TXIN = 'd05f35e0bbc495f6dcab03e599c8f5e32a07cdb4bc76964de201d06a2a7d8265';
|
||||||
var TXIN_N = 0;
|
var TXIN_N = 0;
|
||||||
var ADDR = 'muHct3YZ9Nd5Pq7uLYYhXRAxeW4EnpcaLz';
|
var ADDR = 'muHct3YZ9Nd5Pq7uLYYhXRAxeW4EnpcaLz';
|
||||||
var VAL = '1.234';
|
var VAL = '0.001';
|
||||||
|
|
||||||
var txobj = {
|
var txobj = {
|
||||||
version: 1,
|
version: 1,
|
||||||
lock_time: 0,
|
lock_time: 0,
|
||||||
ins: [],
|
ins: [],
|
||||||
outs: []
|
outs: []
|
||||||
}
|
};
|
||||||
|
|
||||||
var txin = {
|
var txin = {
|
||||||
s: coinUtil.EMPTY_BUFFER, // Add signature
|
s: coinUtil.EMPTY_BUFFER, // Add signature
|
||||||
|
@ -30,7 +31,6 @@ var createTx = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
var hash = new Buffer(TXIN.split('').reverse(), 'hex');
|
var hash = new Buffer(TXIN.split('').reverse(), 'hex');
|
||||||
|
|
||||||
var vout = parseInt(TXIN_N);
|
var vout = parseInt(TXIN_N);
|
||||||
var voutBuf = new Buffer(4);
|
var voutBuf = new Buffer(4);
|
||||||
|
|
||||||
|
@ -56,18 +56,20 @@ var createTx = function() {
|
||||||
var peerman = new PeerManager();
|
var peerman = new PeerManager();
|
||||||
peerman.addPeer(new Peer('127.0.0.1', 18333));
|
peerman.addPeer(new Peer('127.0.0.1', 18333));
|
||||||
|
|
||||||
peerman.on('connect', function(conn) {
|
peerman.on('connect', function() {
|
||||||
|
|
||||||
var conn = peerman.getActiveConnection();
|
var conn = peerman.getActiveConnection();
|
||||||
|
|
||||||
if (conn) {
|
if (conn) {
|
||||||
conn.sendTx(createTx());
|
conn.sendTx(createTx());
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.on('reject', function() {
|
conn.on('reject', function() {
|
||||||
console.log('Transaction Rejected');
|
console.log('Transaction Rejected');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
peerman.start();
|
peerman.start();
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var backup = console.log;
|
||||||
|
var nop = function() {};
|
||||||
|
var mute = function() {
|
||||||
|
console.log = nop;
|
||||||
|
};
|
||||||
|
|
||||||
|
var unmute = function() {
|
||||||
|
console.log = backup;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.mute = mute;
|
||||||
|
module.exports.unmute = unmute;
|
|
@ -0,0 +1,24 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var chai = chai || require('chai');
|
||||||
|
var should = chai.should();
|
||||||
|
var mute = require('./mute').mute;
|
||||||
|
var unmute = require('./mute').unmute;
|
||||||
|
|
||||||
|
var examples = [
|
||||||
|
'Address',
|
||||||
|
'PeerManager',
|
||||||
|
'Rpc',
|
||||||
|
'SendTx',
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('Examples run', function() {
|
||||||
|
before(mute);
|
||||||
|
after(unmute);
|
||||||
|
examples.forEach(function(example) {
|
||||||
|
it('valid '+example, function() {
|
||||||
|
var ex = require('../examples/'+example);
|
||||||
|
ex.run.should.not.throw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue