Added vows tests

This commit is contained in:
Bill Casarin 2011-04-18 10:09:27 -04:00
parent b87fb0278a
commit 5c3ff5fd41
5 changed files with 80 additions and 6 deletions

View File

@ -1,10 +1,10 @@
# node-bitcoin
node-bitcoin is a simple wrapper for the Bitcoin client's JSON-RPC API.
node-bitcoin is a simple wrapper for the Bitcoin client's JSON-RPC API.
The API is equivalent to the API document [here](http://www.bitcoin.org/wiki/doku.php?id=api#methods).
The methods are exposed as lower camelcase methods on the `bitcoin.Client`
The API is equivalent to the API document [here](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list).
The methods are exposed as lower camelcase methods on the `bitcoin.Client`
object.
## Install

View File

@ -15,6 +15,7 @@ var bitcoinAPI = {
getDifficulty: 'getdifficulty',
getGenerate: 'getgenerate',
getHashesPerSecond: 'gethashespersec',
getHashesPerSec: 'gethashespersec',
getInfo: 'getinfo',
getNewAddress: 'getnewaddress',
getReceivedByAccount: 'getreceivedbyaccount',

View File

@ -2,10 +2,13 @@
"name": "bitcoin",
"description": "Bitcoin client API library and related utilities",
"version": "0.0.2",
"contributors": [
"contributors": [
{ "name": "Bill Casarin", "email": "jb@jb55.com" },
],
"dependencies": { "underscore": ">= 1.0.3" },
"dependencies": {
"underscore": ">= 1.0.3",
"vows": ">= 0.4.0",
},
"directories": { "lib": "./lib/bitcoin" },
"engines": { "node": ">= 0.2.3" }
}

View File

@ -1,6 +1,6 @@
var bitcoin = require('./lib/bitcoin');
var client = new bitcoin.Client('localhost', 8355, 'jb55', 'thisisthepassword');
var client = new bitcoin.Client('localhost', 8332, 'jb55', 'thisisthepassword');
doCmd('getWork');

70
test/api.js Normal file
View File

@ -0,0 +1,70 @@
var path = require('path');
require.paths.unshift(path.join(__dirname, '..'));
var vows = require('vows'),
assert = require('assert');
var bitcoin = require('lib/bitcoin');
var nullError = function(cb) {
var self = this;
return function() {
var args = [].slice.call(arguments);
args.unshift(null);
cb.apply(self, args);
};
}
function makeClient() {
return new bitcoin.Client('localhost', 8332, 'jb55', 'thisisthepassword');
}
function clientTopic() {
var args = [].slice.call(arguments);
var cmd = args.shift();
return function(client){
args.push(nullError(this.callback));
client[cmd].apply(client, args);
}
}
function notEmpty(err, data) {
if (data === 0)
return;
assert.ok(data);
}
vows.describe('api').addBatch({
'client': {
topic: makeClient(),
'getTransaction': {
topic: clientTopic('getTransaction', "fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4"),
'should not be empty': notEmpty,
},
'getDifficulty': {
topic: clientTopic('getDifficulty'),
'should not be empty': notEmpty,
'is a number': function (err, data) { assert.isNumber(data) },
'is greater than 0': function (err, data) { assert.isTrue(data > 0); }
},
'getInfo': {
topic: clientTopic('getInfo'),
'should not be empty': notEmpty,
'info.errors should be empty': function (err, info) {
assert.isEmpty(info.errors);
},
},
'getHashesPerSec': {
topic: clientTopic('getHashesPerSec'),
'should not be empty': notEmpty,
'is a number': function (err, data) { assert.isNumber(data) },
},
'help': {
topic: clientTopic('help'),
'should not be empty': notEmpty,
}
},
}).run();