mocha test for transaction
This commit is contained in:
parent
848b485658
commit
5509e941ba
|
@ -5,7 +5,10 @@
|
||||||
*/
|
*/
|
||||||
var mongoose = require('mongoose'),
|
var mongoose = require('mongoose'),
|
||||||
Schema = mongoose.Schema,
|
Schema = mongoose.Schema,
|
||||||
async = require('async');
|
async = require('async'),
|
||||||
|
RpcClient = require('bitcore/RpcClient').class(),
|
||||||
|
config = require('../../config/config');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -31,14 +34,14 @@ TransactionSchema.statics.load = function(id, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TransactionSchema.statics.fromID = function(txid, cb) {
|
TransactionSchema.statics.fromId = function(txid, cb) {
|
||||||
this.findOne({
|
this.findOne({
|
||||||
txid: txid,
|
txid: txid,
|
||||||
}).exec(cb);
|
}).exec(cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionSchema.statics.fromIDWithInfo = function(txid, cb) {
|
TransactionSchema.statics.fromIdWithInfo = function(txid, cb) {
|
||||||
this.fromHash(hash, function(err, tx) {
|
this.fromId(txid, function(err, tx) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
tx.getInfo(function(err) { return cb(err,tx); } );
|
tx.getInfo(function(err) { return cb(err,tx); } );
|
||||||
|
@ -82,7 +85,7 @@ TransactionSchema.methods.getInfo = function (next) {
|
||||||
var that = this;
|
var that = this;
|
||||||
var rpc = new RpcClient(config.bitcoind);
|
var rpc = new RpcClient(config.bitcoind);
|
||||||
|
|
||||||
rpc.getRawTransaction(this.txid, function(err, txInfo) {
|
rpc.getRawTransaction(this.txid, 1, function(err, txInfo) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
that.info = txInfo.result;
|
that.info = txInfo.result;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
--require should
|
--require should
|
||||||
-R spec
|
-R spec
|
||||||
--ui bdd
|
--ui bdd
|
||||||
|
--recursive
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ var
|
||||||
|
|
||||||
mongoose.connection.on('error', function(err) { console.log(err); });
|
mongoose.connection.on('error', function(err) { console.log(err); });
|
||||||
|
|
||||||
describe('getInfo', function(){
|
describe('Block getInfo', function(){
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
mongoose.connect(config.db);
|
mongoose.connect(config.db);
|
||||||
|
@ -26,11 +26,18 @@ describe('getInfo', function(){
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should pool block\'s info from bitcoind', function(done) {
|
it('should poll block\'s info from mongoose', function(done) {
|
||||||
var block2 = Block.fromHashWithInfo(TESTING_BLOCK, function(err, b2) {
|
var block2 = Block.fromHashWithInfo(TESTING_BLOCK, function(err, b2) {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
|
|
||||||
assert.equal(b2.hash, TESTING_BLOCK);
|
assert.equal(b2.hash, TESTING_BLOCK);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should poll block\'s info from bitcoind', function(done) {
|
||||||
|
var block2 = Block.fromHashWithInfo(TESTING_BLOCK, function(err, b2) {
|
||||||
|
if (err) done(err);
|
||||||
assert.equal(b2.info.hash, TESTING_BLOCK);
|
assert.equal(b2.info.hash, TESTING_BLOCK);
|
||||||
assert.equal(b2.info.chainwork, '00000000000000000000000000000000000000000000000000446af21d50acd3');
|
assert.equal(b2.info.chainwork, '00000000000000000000000000000000000000000000000000446af21d50acd3');
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
|
|
||||||
|
var TESTING_TX = '9f4648538a8fd773029139f7e67cee51586bced78d7ff0388d10cb71096f2289';
|
||||||
|
|
||||||
|
var
|
||||||
|
mongoose= require('mongoose'),
|
||||||
|
assert = require('assert'),
|
||||||
|
config = require('../../config/config'),
|
||||||
|
Transaction = require('../../app/models/Transaction');
|
||||||
|
|
||||||
|
|
||||||
|
mongoose.connection.on('error', function(err) { console.log(err); });
|
||||||
|
|
||||||
|
describe('Transaction getInfo', function(){
|
||||||
|
|
||||||
|
before(function(done) {
|
||||||
|
mongoose.connect(config.db);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
mongoose.connection.close();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pool tx\'s object from mongoose', function(done) {
|
||||||
|
Transaction.fromIdWithInfo(TESTING_TX, function(err, tx) {
|
||||||
|
if (err) done(err);
|
||||||
|
assert.equal(tx.txid, TESTING_TX);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pool tx\'s info from bitcoind', function(done) {
|
||||||
|
Transaction.fromIdWithInfo(TESTING_TX, function(err, tx) {
|
||||||
|
if (err) done(err);
|
||||||
|
assert.equal(tx.info.txid, TESTING_TX);
|
||||||
|
assert.equal(tx.info.blockhash, '000000007af2a08af7ce4934167dc2afd7a2e6bfd31472332db02a6f38cb7b4d');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
var assert = require("assert")
|
|
||||||
describe('Array', function(){
|
|
||||||
describe('#indexOf()', function(){
|
|
||||||
it('should return -1 when the value is not present', function(){
|
|
||||||
assert.equal(-1, [1,2,3].indexOf(5));
|
|
||||||
assert.equal(-1, [1,2,3].indexOf(0));
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
Loading…
Reference in New Issue