var path = require('path');

// test variables

var test = {
    account: "test"
};

var config = {
    host: 'localhost',
    port: 8332,
    user: 'jb55',
    pass: 'thisisthepassword'
};

// end test variables

var vows = require('vows'),
    assert = require('assert');

var bitcoin = require('../lib/bitcoin');

function makeClient() {
  return new bitcoin.Client(config.host, config.port, config.user, config.pass);
}

function notEmpty(data) {
  if (data === 0)
    return;
  assert.ok(data);
}

vows.describe('api').addBatch({
  '': {
    topic: makeClient,
    'an account address': {
      topic: function(client){
        client.getAccountAddress(test.account, this.callback);
      },
      'is valid': function(address){
        assert.ok(address);
      },
      'after getting the account name again': {
        topic: function(address, client) {
          client.getAccount(address, this.callback);
        },
        'should be the same as the original': function(account) {
          assert.equal(account, test.account);
        }
      },
    },
    'listTransactions with specific amount': {
      topic: function(client){
        client.listTransactions(test.account, 15, this.callback);
      },
      'should not be empty': function(txs){ assert.ok(txs); },
      'is an array': function(txs) { assert.isTrue(txs instanceof Array); }
    },
    'listTransactions without specific amount': {
      topic: function(client){
        client.listTransactions(test.account, this.callback);
      },
      'should not be empty': function(txs){ assert.ok(txs); },
      'is an array': function(txs) { assert.isTrue(txs instanceof Array); }
    },
    'account addresses': {
      topic: function(client){
        client.getAddressesByAccount(test.account, this.callback);
      },
      'is not empty': function(addresses) {
        assert.isTrue(addresses && addresses.length > 0);
      }
    },
    'getDifficulty': {
      topic: function(client) { client.getDifficulty(this.callback); },
      'should not be empty': notEmpty,
      'is a number': function (data) {
        assert.isNumber(data);
      },
      'is greater than 0': function (data) { assert.isTrue(data > 0); }
    },
    'getInfo': {
      topic: function(client) { client.getInfo(this.callback); },
      'should not be empty': notEmpty,
      'info.errors should be empty': function (info) {
        assert.isEmpty(info.errors);
      },
    },
    'getHashesPerSec': {
      topic: function(client) { client.getHashesPerSec(this.callback); },
      'should not be empty': notEmpty,
      'is a number': function (data) { assert.isNumber(data) },
    },
    'help': {
      topic: function(client) { client.help(this.callback); },
      'should not be empty': notEmpty,
    },
    'getWork': {
      topic: function(client) { client.getWork(this.callback); },
      'should not be empty': notEmpty,
    },
    'getTransaction': {
      topic: "TODO: get valid transaction",
      'should not be empty': notEmpty,
    },
    'client creation with single object': {
      topic: function(client){
        var client2 = new bitcoin.Client(config);
        var self = this;
        client2.getWork(function(err, work) {
          self.callback(err, work, client2, client);
        });
      },
      'should have same params': function(err, work, client2, client) {
        assert.isNull(err);
        assert.equal(client2.host, client.host);
        assert.equal(client2.port, client.port);
        assert.equal(client2.user, client.user);
        assert.equal(client2.pass, client.pass);
      },
      'getWork should be an object': function(work) {
        assert.isObject(work);
      }
    },
  },

}).export(module);



@@ -3678,16 +3678,774 @@
 %0A    %7D,%0A
+    'getblocknumber is deprecated': %7B%0A      topic: function(client) %7B%0A        client.cmd('getblocknumber', this.callback);%0A      %7D,%0A      'and has been replaced by getblockcount': %7B%0A        topic: function(number, client) %7B%0A          client.cmd('getblockcount', this.callback);%0A        %7D,%0A        'getBlockNumber uses getblockcount': %7B%0A          topic: function(count, number, client) %7B%0A            var self = this;%0A            client.getBlockNumber(function(err, number2) %7B%0A              self.callback(err, number2, count, number);%0A            %7D);%0A          %7D,%0A          'and should match both': function(err, number2, count, number) %7B%0A            assert.equal(number2, count);%0A            assert.equal(number2, number);%0A          %7D%0A        %7D%0A      %7D%0A    %7D%0A
   %7D,%0A%0A%7D)

add test for getblocknumber deprecation