mocha test for transaction

This commit is contained in:
Matias Alejo Garcia 2014-01-08 17:04:45 -03:00
parent 848b485658
commit 5509e941ba
5 changed files with 66 additions and 18 deletions

View File

@ -5,7 +5,10 @@
*/
var mongoose = require('mongoose'),
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({
txid: txid,
}).exec(cb);
};
TransactionSchema.statics.fromIDWithInfo = function(txid, cb) {
this.fromHash(hash, function(err, tx) {
TransactionSchema.statics.fromIdWithInfo = function(txid, cb) {
this.fromId(txid, function(err, tx) {
if (err) return cb(err);
tx.getInfo(function(err) { return cb(err,tx); } );
@ -82,7 +85,7 @@ TransactionSchema.methods.getInfo = function (next) {
var that = this;
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);
that.info = txInfo.result;

View File

@ -1,4 +1,5 @@
--require should
-R spec
--ui bdd
--recursive

View File

@ -14,7 +14,7 @@ var
mongoose.connection.on('error', function(err) { console.log(err); });
describe('getInfo', function(){
describe('Block getInfo', function(){
before(function(done) {
mongoose.connect(config.db);
@ -26,15 +26,22 @@ describe('getInfo', function(){
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) {
if (err) done(err);
assert.equal(b2.hash, TESTING_BLOCK);
assert.equal(b2.info.hash, TESTING_BLOCK);
assert.equal(b2.info.chainwork, '00000000000000000000000000000000000000000000000000446af21d50acd3');
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.chainwork, '00000000000000000000000000000000000000000000000000446af21d50acd3');
done();
});
});
});

46
test/model/transaction.js Normal file
View File

@ -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();
});
});
});

View File

@ -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));
})
})
})