From 53646c9191d721410c45f626ffd665c9df1b62e4 Mon Sep 17 00:00:00 2001 From: Damian Mee Date: Wed, 3 Sep 2014 19:38:48 +0200 Subject: [PATCH 1/3] test(server): Initial set of tests and travis integration added --- .travis.yml | 7 + package.json | 1 + test/helpers/create-https-server.js | 14 -- test/index.js | 139 -------------- test/mocks/config.js | 14 ++ test/mocks/db.js | 44 +++++ test/mocks/plugins.js | 5 + test/mocks/psql.js | 4 + test/mocks/ticker.js | 15 +- test/mocks/trader.js | 8 +- test/mocks/verifier.js | 6 +- test/mocks/wallet.js | 39 +++- test/plugins.js | 272 ++++++++++++++++++++++++++++ test/unit/traderApiTest.js | 54 ------ test/unit/traderFiatBalanceTest.js | 107 ----------- test/unit/traderSendTest.js | 77 -------- test/unit/traderTickerTest.js | 52 ------ 17 files changed, 400 insertions(+), 458 deletions(-) create mode 100644 .travis.yml delete mode 100644 test/helpers/create-https-server.js delete mode 100644 test/index.js create mode 100644 test/mocks/config.js create mode 100644 test/mocks/db.js create mode 100644 test/mocks/plugins.js create mode 100644 test/mocks/psql.js create mode 100644 test/plugins.js delete mode 100644 test/unit/traderApiTest.js delete mode 100644 test/unit/traderFiatBalanceTest.js delete mode 100644 test/unit/traderSendTest.js delete mode 100644 test/unit/traderTickerTest.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..e03282f3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - '0.11' + - '0.10' + +env: + - TRAVIS=true diff --git a/package.json b/package.json index 31e19b33..a7ac5e8b 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ }, "devDependencies": { "chai": "^1.9.1", + "chai-http": "^0.5.0", "git-rev": "^0.2.1", "lodash": "^2.4.1", "mocha": "^1.21.4", diff --git a/test/helpers/create-https-server.js b/test/helpers/create-https-server.js deleted file mode 100644 index d003ebcb..00000000 --- a/test/helpers/create-https-server.js +++ /dev/null @@ -1,14 +0,0 @@ -// var fs = require('fs'); -// var path = require('path'); -// var https = require('https'); -// var fixtures = path.join(__dirname, '..', 'fixtures'); - -// module.exports = function(handler, callback) { -// var server = https.createServer({ -// key: fs.readFileSync(path.join(fixtures, 'privatekey.pem')), -// cert: fs.readFileSync(path.join(fixtures, 'certificate.pem')) -// }, handler); -// server.listen(0, function() { -// callback(null, server); -// }); -// }; diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 1a6e9c79..00000000 --- a/test/index.js +++ /dev/null @@ -1,139 +0,0 @@ -/* global describe, it, before, afterEach */ - -'use strict'; - -var _ = require('lodash'); -var should = require('chai').should(); -var mockery = require('mockery'); - - -var config = require('./mocks/config'); -var CONFIG = _.cloneDeep(config); -function requireFreshConfig() { - return _.cloneDeep(CONFIG); -} - - -var walletMock = require('./mocks/wallet'); -var tickerMock = require('./mocks/ticker'); -var traderMock = require('./mocks/trader'); -var verifierMock = require('./mocks/verifier'); - -mockery.registerMock('lamassu-mockWallet', walletMock); -mockery.registerMock('lamassu-mockTicker', tickerMock); -mockery.registerMock('lamassu-mockTrader', traderMock); -mockery.registerMock('lamassu-mockVerifier', verifierMock); - - -describe('Plugins', function() { - var plugins = null; - - before(function() { - mockery.enable({ - useCleanCache: true, - warnOnReplace: false, - warnOnUnregistered: false - }); - - plugins = require('../lib/plugins'); - }); - - afterEach(function() { - config = requireFreshConfig(); - }); - - it('should properly load', function() { - should.exist(plugins); - }); - - it('should throw when db is not provided', function() { - plugins.init.should.throw(/db.*required/); - }); - - it('should throw when invalid balance margin', function() { - config.exchanges.settings.lowBalanceMargin = 0.99; - - function configurer() { - plugins.configure(config); - } - configurer.should.throw(/lowBalanceMargin/); - }); - - it('should throw when module is not installed', function() { - config.exchanges.plugins.current.ticker = 'inexistent-plugin'; - - function configurer() { - plugins.configure(config); - } - configurer.should.throw(/module.*not installed/); - }); - - it('should throw when used plugin has no SUPPORTED_MODULES', function() { - var tmp = tickerMock.SUPPORTED_MODULES; - delete tickerMock.SUPPORTED_MODULES; - - function configurer() { - plugins.configure(config); - } - configurer.should.throw(/required.*SUPPORTED_MODULES/); - - tickerMock.SUPPORTED_MODULES = tmp; - }); - - it('should throw when used plugin has required method missing', function() { - var tmp = tickerMock.ticker; - delete tickerMock.ticker; - - function configurer() { - plugins.configure(config); - } - configurer.should.throw(/fails.*implement.*method/); - - tickerMock.ticker = tmp; - }); - - describe('should configure all enabled plugins', function() { - var confList = {}; - - before(function() { - function configTest(name) { - return function config(localConfig) { - should.exist(config); - /* jshint expr: true */ - localConfig.should.be.an.Object; - /* jshint expr: true */ - confList[name] = config; - }; - } - - walletMock.config = configTest('wallet'); - tickerMock.config = configTest('ticker'); - traderMock.config = configTest('trader'); - verifierMock.config = configTest('verifier'); - - plugins.configure(config); - }); - - ['wallet', 'ticker', 'trader', 'verifier'].forEach(function(name) { - it('should configure ' + name, function() { - confList.should.have.property(name); - should.exist(confList[name]); - /* jshint expr: true */ - confList[name].should.be.an.Object; - /* jshint expr: true */ - }); - }); - - }); - - this.timeout(9000); - - describe('Ticker', function() { - it('should have .ticker() called at least once', function() { - tickerMock.tickerCalls.should.be.at.least(1); - }); - - }); - -}); - diff --git a/test/mocks/config.js b/test/mocks/config.js new file mode 100644 index 00000000..5c249471 --- /dev/null +++ b/test/mocks/config.js @@ -0,0 +1,14 @@ +'use strict'; + +var LamassuConfig = module.exports = function (conString, pairingTokenTTL) { +}; +LamassuConfig.prototype.load = function load() { + +}; +LamassuConfig.prototype.on = function on() { + +}; + +LamassuConfig.prototype.isAuthorized = function isAuthorized(fingerprint, cb) { + cb(null, true); +}; diff --git a/test/mocks/db.js b/test/mocks/db.js new file mode 100644 index 00000000..cfc875d6 --- /dev/null +++ b/test/mocks/db.js @@ -0,0 +1,44 @@ +'use strict'; + +var FINGERPRINT_NEW = 'XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX'; +var FINGERPRINT_FUNDS = 'YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY:YY'; + +var txs = {}; + + +module.exports = { + FINGERPRINT_NEW: FINGERPRINT_NEW, + FINGERPRINT_FUNDS: FINGERPRINT_FUNDS, + summonTransaction: function(fingerprint, tx, cb) { + var cachedTx = txs[tx.txId]; + if (cachedTx) cb(null, cachedTx); + else { + txs[tx.txId] = tx; + cb(null, null); + } + }, + reportTransactionError: function(tx, err, status) { + txs[tx.txId].err = err; + txs[tx.txId].status = status; + calls.fail = true; + }, + completeTransaction: function(tx, txHash) { + calls.status = true; + } +}; + + +var calls = {}; +module.exports.wasErrorReported = function() { + return calls.fail; +}; +module.exports.wasStatusReported = function() { + return calls.status; +}; +module.exports.resetCalls = function() { + calls = { + status: false, + fail: false + } +}; +module.exports.resetCalls(); diff --git a/test/mocks/plugins.js b/test/mocks/plugins.js new file mode 100644 index 00000000..393d58a2 --- /dev/null +++ b/test/mocks/plugins.js @@ -0,0 +1,5 @@ +'use strict'; + +exports.init = function init () { + +}; diff --git a/test/mocks/psql.js b/test/mocks/psql.js new file mode 100644 index 00000000..1e2b68ce --- /dev/null +++ b/test/mocks/psql.js @@ -0,0 +1,4 @@ +'use strict'; + +var PostgresqlInterface = module.exports = function (conString) { +}; diff --git a/test/mocks/ticker.js b/test/mocks/ticker.js index 65addc3e..e4c64f5f 100644 --- a/test/mocks/ticker.js +++ b/test/mocks/ticker.js @@ -4,11 +4,9 @@ module.exports = { SUPPORTED_MODULES: [ 'ticker' ], NAME: 'Mock Ticker', - tickerCalls: 0, - - config: function() {}, - ticker: function(currency, callback) { - this.tickerCalls++; + config: function config() {}, + ticker: function ticker(currency, callback) { + tickerCalls++; var out = {}; out[currency] = { @@ -21,3 +19,10 @@ module.exports = { callback(null, out); } }; + + +// mock stuff +var tickerCalls = 0; +module.exports.getTickerCalls = function() { + return tickerCalls; +} diff --git a/test/mocks/trader.js b/test/mocks/trader.js index 86359c7d..0ae3986c 100644 --- a/test/mocks/trader.js +++ b/test/mocks/trader.js @@ -4,8 +4,8 @@ module.exports = { SUPPORTED_MODULES: ['trader'], NAME: 'Mock Trader', - config: function() {}, - balance: function() {}, - purchase: function() {}, - sell: function() {} + config: function config() {}, + balance: function balance() {}, + purchase: function purchase() {}, + sell: function sell() {} }; diff --git a/test/mocks/verifier.js b/test/mocks/verifier.js index 9e3ef7b5..67d00483 100644 --- a/test/mocks/verifier.js +++ b/test/mocks/verifier.js @@ -4,7 +4,7 @@ module.exports = { SUPPORTED_MODULES: ['idVerifier'], NAME: 'Mock Verifier', - config: function() {}, - verifyUser: function() {}, - verifyTransaction: function() {} + config: function config() {}, + verifyUser: function verifyUser() {}, + verifyTransaction: function verifyTransaction() {} }; diff --git a/test/mocks/wallet.js b/test/mocks/wallet.js index 7fc3ae59..c3d93968 100644 --- a/test/mocks/wallet.js +++ b/test/mocks/wallet.js @@ -4,7 +4,40 @@ module.exports = { SUPPORTED_MODULES: ['wallet'], NAME: 'Mock Wallet', - config: function() {}, - balance: function() {}, - sendBitcoins: function() {} + config: function config() {}, + balance: function balance(callback) { + calls.balance++; + + callback(null, { + BTC: 1e8 + }); + }, + sendBitcoins: function(addr, satoshis, fee, cb) { + calls.send = true; + + if (satoshis <= 1e8) cb(null, TX_HASH); + else { + var e = new Error('Insufficient funds'); + e.name = 'InsufficientFunds'; + cb(e); + } + } }; + + +// mock stuff +var calls = { + balance: 0, + send: false +}; +var ADDR = module.exports.ADDR = '12sENwECeRSmTeDwyLNqwh47JistZqFmW8'; +var TX_HASH = module.exports.TX_HASH = '1c12443203a48f42cdf7b1acee5b4b1c1fedc144cb909a3bf5edbffafb0cd204'; + +module.exports.getBalanceCalls = function() { + return calls.balance; +}; +module.exports.wasSendCalled = function() { + return calls.send; +} + + diff --git a/test/plugins.js b/test/plugins.js new file mode 100644 index 00000000..b4f02e98 --- /dev/null +++ b/test/plugins.js @@ -0,0 +1,272 @@ +/* global describe, it, before, afterEach */ + +'use strict'; + +var _ = require('lodash'); +var should = require('chai').should(); +var mockery = require('mockery'); + + +var config = require('./mocks/config.json'); +var CONFIG = _.cloneDeep(config); +function requireFreshConfig() { + return _.cloneDeep(CONFIG); +} + + +var walletMock = require('./mocks/wallet'); +var tickerMock = require('./mocks/ticker'); +var traderMock = require('./mocks/trader'); +var verifierMock = require('./mocks/verifier'); + +mockery.registerMock('lamassu-mockWallet', walletMock); +mockery.registerMock('lamassu-mockTicker', tickerMock); +mockery.registerMock('lamassu-mockTrader', traderMock); +mockery.registerMock('lamassu-mockVerifier', verifierMock); + + +describe('Plugins', function() { + var plugins = null; + + before(function() { + mockery.enable({ + useCleanCache: true, + warnOnReplace: false, + warnOnUnregistered: false + }); + + plugins = require('../lib/plugins'); + }); + + afterEach(function() { + config = requireFreshConfig(); + }); + + it('should properly load', function() { + should.exist(plugins); + }); + + it('should throw when db is not provided', function() { + plugins.init.should.throw(/db.*required/); + }); + + it('should throw when invalid balance margin', function() { + config.exchanges.settings.lowBalanceMargin = 0.99; + + function configurer() { + plugins.configure(config); + } + configurer.should.throw(/lowBalanceMargin/); + }); + + it('should throw when module is not installed', function() { + config.exchanges.plugins.current.ticker = 'inexistent-plugin'; + + function configurer() { + plugins.configure(config); + } + configurer.should.throw(/module.*not installed/); + }); + + it('should throw when used plugin has no SUPPORTED_MODULES', function() { + var tmp = tickerMock.SUPPORTED_MODULES; + delete tickerMock.SUPPORTED_MODULES; + + function configurer() { + plugins.configure(config); + } + configurer.should.throw(/required.*SUPPORTED_MODULES/); + + tickerMock.SUPPORTED_MODULES = tmp; + }); + + it('should throw when used plugin has required method missing', function() { + var tmp = tickerMock.ticker; + delete tickerMock.ticker; + + function configurer() { + plugins.configure(config); + } + configurer.should.throw(/fails.*implement.*method/); + + tickerMock.ticker = tmp; + }); + + describe('should configure all enabled plugins', function() { + var confList = {}; + + before(function() { + function configTest(name) { + return function config(localConfig) { + should.exist(config); + /* jshint expr: true */ + localConfig.should.be.an.Object; + /* jshint expr: false */ + confList[name] = config; + }; + } + + walletMock.config = configTest('wallet'); + tickerMock.config = configTest('ticker'); + traderMock.config = configTest('trader'); + verifierMock.config = configTest('verifier'); + + plugins.configure(config); + }); + + ['wallet', 'ticker', 'trader', 'verifier'].forEach(function(name) { + it('should configure ' + name, function() { + confList.should.have.property(name); + should.exist(confList[name]); + /* jshint expr: true */ + confList[name].should.be.an.Object; + /* jshint expr: false */ + }); + }); + + it('should return config', function() { + var config = plugins.getCachedConfig(); + should.exist(config); + /* jshint expr: true */ + config.should.be.an.Object; + /* jshint expr: false */ + + }); + + }); + + + describe('Ticker', function() { + it('should have called .ticker() at least once', function() { + tickerMock.getTickerCalls().should.be.at.least(1); + }); + + it('should return last ticker price', function() { + var rate = plugins.getDeviceRate(); + should.exist(rate); + /* jshint expr: true */ + rate.should.be.an.Object; + /* jshint expr: false */ + rate.should.have.property('currency'); + rate.should.have.property('rates'); + + var rates = rate.rates; + /* jshint expr: true */ + rate.should.be.an.Object; + /* jshint expr: false */ + rates.should.have.property('ask'); + rates.should.have.property('bid'); + }); + }); + + + describe('Wallet', function() { + + var db = require('./mocks/db'); + + before(function() { + plugins.init(db); + }); + + it('should have called .balance() at least once', function() { + walletMock.getBalanceCalls().should.be.at.least(1); + }); + + it('should return BTC balance', function() { + var balance = plugins.getBalance(); + should.exist(balance); + /* jshint expr: true */ + balance.should.be.an.Object; + /* jshint expr: false */ + balance.should.have.property('BTC'); + balance.BTC.should.equal(1e8); + }); + + it('should return fiat balance', function() { + var fiatBalance = plugins.fiatBalance(); + should.exist(fiatBalance); + /* jshint expr: true */ + fiatBalance.should.be.a.Number; + /* jshint expr: false */ + fiatBalance.should.be.below(999); + }); + + describe('Send Bitcoins', function() { + + before(function() { + plugins.trade({currency: 'USD', satoshis: 1e7}, db.FINGERPRINT_NEW); + }); + + it('should send bitcoins successfully', function(done) { + var txDetails = { + txId: 1, + toAddress: walletMock.ADDR, + satoshis: 1e7 + }; + + plugins.sendBitcoins(db.FINGERPRINT_NEW, txDetails, function(err, txHash) { + should.not.exist(err); + should.exist(txHash); + /* jshint expr: true */ + txHash.should.be.a.String; + txHash.should.equal(walletMock.TX_HASH); + + walletMock.wasSendCalled().should.be.true; + + db.wasStatusReported().should.be.true; + db.wasErrorReported().should.be.false; + /* jshint expr: false */ + + done(); + }); + }); + + function notEnoughFundsTx(done) { + db.resetCalls(); + var txDetails = { + txId: 2, + toAddress: walletMock.ADDR, + satoshis: 1e9 + }; + plugins.sendBitcoins(db.FINGERPRINT_FUNDS, txDetails, function(err, txHash) { + should.exist(err); + err.should.be.instanceof(Error); + err.name.should.equal('InsufficientFunds'); + + /* jshint expr: true */ + walletMock.wasSendCalled().should.be.true; + db.wasStatusReported().should.be.false; + /* jshint expr: false */ + + done(); + }); + } + + // this fail comes from external plugin + it('should fail when not enough funds', function(done) { + notEnoughFundsTx(function() { + + /* jshint expr: true */ + db.wasErrorReported().should.be.true; + /* jshint expr: false */ + done(); + }); + }); + + // this once comes from plugins.js + it('should fail again', function(done) { + notEnoughFundsTx(function() { + + /* jshint expr: true */ + db.wasErrorReported().should.be.false; // should not report error again + /* jshint expr: false */ + done(); + }); + }); + }); + + }); + + describe('Trader', function() {}); +}); + diff --git a/test/unit/traderApiTest.js b/test/unit/traderApiTest.js deleted file mode 100644 index 215c61e6..00000000 --- a/test/unit/traderApiTest.js +++ /dev/null @@ -1,54 +0,0 @@ -// 'use strict'; - -// var assert = require('chai').assert; -// var Trader = require('../../lib/trader.js'); -// var PostgresqlInterface = require('../../lib/postgresql_interface.js'); - -// var db = 'psql://lamassu:lamassu@localhost/lamassu-test'; -// var psqlInterface = new PostgresqlInterface(db); - -// describe('trader/api', function () { -// it('should throw when trying to create a trader with no DB', function () { -// assert.throws(function () { -// new Trader(); -// }); -// }); - -// it('should throw when trying to configure a trader with `lowBalanceMargin` < 1', function () { -// var trader = new Trader(psqlInterface); -// assert.throws(function () { -// trader.configure({ -// exchanges: { -// settings: { -// lowBalanceMargin: 0.8 -// } -// } -// }); -// }); -// }); - -// it('should find and instantiate ticker and trade exchanges', function () { -// var trader = new Trader(psqlInterface); -// trader.configure({ -// exchanges: { -// plugins: { -// current: { -// ticker: 'bitpay', -// transfer: 'blockchain' -// }, -// settings: { -// bitpay: {}, -// blockchain: {} -// } -// }, -// settings: { -// currency: 'USD', -// lowBalanceMargin: 2 -// } -// } -// }); - -// assert.ok(trader.tickerExchange); -// assert.ok(trader.transferExchange); -// }); -// }); diff --git a/test/unit/traderFiatBalanceTest.js b/test/unit/traderFiatBalanceTest.js deleted file mode 100644 index a4003c88..00000000 --- a/test/unit/traderFiatBalanceTest.js +++ /dev/null @@ -1,107 +0,0 @@ -// /*global describe, it */ -// 'use strict'; - -// var assert = require('chai').assert; -// var Trader = require('../../lib/trader.js'); - -// var db = 'psql://lamassu:lamassu@localhost/lamassu-test'; - -// var RATE = 101; -// var CURRENCY = 'USD'; -// var SATOSHI_FACTOR = 1e8; -// var LOW_BALANCE_MARGIN = 1.2; -// var COMMISSION = 1.1; -// var FINGERPRINT = '00:7A:5A:B3:02:F1:44:46:E2:EA:24:D3:A8:29:DE:22:BA:1B:F9:50'; - -// var settings = { -// currency: CURRENCY, -// lowBalanceMargin: LOW_BALANCE_MARGIN, -// commission: COMMISSION -// }; - -// describe('trader/fiatBalance', function() { -// it('should calculate balance correctly with transfer exchange only', function() { -// var trader = new Trader(db); -// trader.configure({ -// exchanges: { -// plugins: { -// current: { -// transfer: 'blockchain', -// ticker: 'bitpay' -// }, -// settings: { blockchain: {}, bitpay: {} } -// }, -// settings: settings -// } -// }); - -// // We have 3 bitcoins, want to trade 1 bitcoin for 100 fiat -// trader.balance = { -// transferBalance: 3 * SATOSHI_FACTOR, -// tradeBalance: null -// }; -// trader.rates[CURRENCY] = { rate: RATE }; -// trader.rateInfo = {rates: {USD: {rate: RATE}}}; -// var fiatBalance = trader.fiatBalance(FINGERPRINT); -// assert.equal(fiatBalance, (3 * RATE * COMMISSION / LOW_BALANCE_MARGIN)); -// }); - -// it('should calculate balance correctly with transfer and trade exchange', function() { -// var trader = new Trader(db); -// trader.configure({ -// exchanges: { -// plugins: { -// current: { -// transfer: 'blockchain', -// ticker: 'bitpay', -// trade: 'bitstamp' -// }, -// settings: { blockchain: {}, bitpay: {}, bitstamp: {} } -// }, -// settings: settings -// } -// }); - -// // We have 3 bitcoins in transfer, worth 3 * RATE * COMMISSION = 333.3 -// // We have 150 USD in trade -// trader.balance = { -// transferBalance: 3 * SATOSHI_FACTOR, -// tradeBalance: 150 -// }; -// trader.rates[CURRENCY] = { rate: RATE }; -// trader.rateInfo = {rates: {USD: {rate: RATE}}}; -// var fiatBalance = trader.fiatBalance(FINGERPRINT); -// assert.equal(fiatBalance, 150 / LOW_BALANCE_MARGIN); -// }); - -// it('should calculate balance correctly with transfer and ' + -// 'trade exchange with different currencies', function() { -// var trader = new Trader(db); -// trader.configure({ -// exchanges: { -// plugins: { -// current: { -// transfer: 'blockchain', -// ticker: 'bitpay', -// trade: 'bitstamp' -// }, -// settings: { blockchain: {}, bitpay: {}, bitstamp: {} } -// }, -// settings: settings -// } -// }); - -// // We have 6 bitcoins in transfer, worth 6 * RATE * COMMISSION = 666.6 -// // We have 150 USD in trade, 1 USD = 4 ILS => 600 ILS in trade -// trader.balance = { -// transferBalance: 6 * SATOSHI_FACTOR, -// tradeBalance: 600 -// }; -// trader.rates = {USD: {rate: RATE}, ILS: {rate: RATE * 4} }; -// trader.rateInfo = {rates: {USD: {rate: RATE}}}; -// var fiatBalance = trader.fiatBalance(FINGERPRINT); -// assert.equal(fiatBalance, 600 / LOW_BALANCE_MARGIN); -// }); - -// }); - diff --git a/test/unit/traderSendTest.js b/test/unit/traderSendTest.js deleted file mode 100644 index d3faea58..00000000 --- a/test/unit/traderSendTest.js +++ /dev/null @@ -1,77 +0,0 @@ -// 'use strict'; - -// var assert = require('chai').assert; -// var hock = require('hock'); -// var uuid = require('node-uuid').v4; -// var Trader = require('../../lib/trader.js'); -// var PostgresqlInterface = require('../../lib/postgresql_interface.js'); - -// var db = 'psql://lamassu:lamassu@localhost/lamassu-test'; -// var psqlInterface = new PostgresqlInterface(db); - -// var TRANSACTION_FEE = 1; -// var FINGERPRINT = 'CB:3D:78:49:03:39:BA:47:0A:33:29:3E:31:25:F7:C6:4F:74:71:D7'; -// var TXID = '216dabdb692670bae940deb71e59486038a575f637903d3c9af601ddd48057fc'; -// var ADDRESS = '1LhkU2R8nJaU8Zj6jB8VjWrMpvVKGqCZ64'; -// var SATOSHIS = 1337; -// var CURRENCY = 'USD'; - -// var OUR_TXID = uuid(); - -// describe('trader/send', function () { -// var trader = new Trader(psqlInterface); -// trader.config = { -// exchanges: { -// settings: { -// transactionFee: TRANSACTION_FEE -// } -// } -// }; - -// trader.pollRate = function () {}; - -// it('should call `sendBitcoins` on the transfer exchange', function (done) { -// trader.transferExchange = { -// sendBitcoins: function (address, satoshis, transactionFee, callback) { -// assert.equal(ADDRESS, address); -// assert.equal(SATOSHIS, satoshis); -// assert.equal(transactionFee, TRANSACTION_FEE); -// callback(null, TXID); -// }, -// balance: function () {} -// }; - -// trader.sendBitcoins(FINGERPRINT, { -// fiat: 100, -// txId: OUR_TXID, -// currencyCode: CURRENCY, -// toAddress: ADDRESS, -// satoshis: SATOSHIS -// }, function (err, txId) { -// assert.notOk(err); -// assert.equal(txId, TXID); -// done(); -// }); -// }); - -// it('should not call `sendBitcoins` on the transfer exchange with same send', function (done) { -// trader.transferExchange = { -// sendBitcoins: function () { -// throw new Error('This should not have been called'); -// }, -// balance: function () {} -// }; - -// trader.sendBitcoins(FINGERPRINT, { -// fiat: 100, -// txId: OUR_TXID, -// currencyCode: CURRENCY, -// toAddress: ADDRESS, -// satoshis: SATOSHIS -// }, function (err, txId) { -// assert.notOk(err); -// assert.equal(txId, TXID); -// done(); -// }); -// }); -// }); diff --git a/test/unit/traderTickerTest.js b/test/unit/traderTickerTest.js deleted file mode 100644 index 026e797b..00000000 --- a/test/unit/traderTickerTest.js +++ /dev/null @@ -1,52 +0,0 @@ -// /*global describe, it */ -// 'use strict'; - -// var assert = require('chai').assert; -// var Trader = require('../../lib/trader.js'); -// var PostgresqlInterface = require('../../lib/postgresql_interface.js'); - -// var db = 'psql://lamassu:lamassu@localhost/lamassu-test'; -// var psqlInterface = new PostgresqlInterface(db); - -// var CURRENCY = 'USD'; - -// describe('trader/send', function () { -// var trader = new Trader(psqlInterface); -// trader.config = { -// exchanges: { -// settings: { currency: CURRENCY } -// } -// }; - -// it('should call `balance` on the transfer exchange', function (done) { -// trader.transferExchange = { -// balance: function (callback) { -// callback(null, 100); -// } -// }; - -// trader.pollBalance(function (err) { -// assert.notOk(err); -// assert.equal(trader.balance.transferBalance, 100); -// assert.ok(trader.balance.timestamp); -// done(); -// }); -// }); - -// it('should call `ticker` on the ticker exchange', function (done) { -// trader.tickerExchange = { -// ticker: function (currencies, callback) { -// assert.equal(currencies[0], CURRENCY); -// callback(null, {USD: {rate: 100}}); -// } -// }; - -// trader.pollRate(function (err) { -// assert.notOk(err); -// var rate = trader.rate(CURRENCY); -// assert.equal(rate.rate, 100); -// assert.ok(rate.timestamp); -// done(); -// }); -// }); -// }); From d657afa2a12988a59d47b01779631f729a44c254 Mon Sep 17 00:00:00 2001 From: Damian Mee Date: Wed, 3 Sep 2014 19:58:17 +0200 Subject: [PATCH 2/3] test(travis): node@0.11 build temp disabled due to lack of gyp support --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e03282f3..3056a3f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - '0.11' + # - '0.11' - '0.10' env: From a7aadc923aae8a1717963e99e8fa522eba6f504d Mon Sep 17 00:00:00 2001 From: Damian Mee Date: Thu, 4 Sep 2014 01:19:23 +0200 Subject: [PATCH 3/3] style(jshint): jshint compatibility increased --- test/mocks/db.js | 2 +- test/mocks/ticker.js | 2 +- test/mocks/wallet.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/mocks/db.js b/test/mocks/db.js index cfc875d6..61a71309 100644 --- a/test/mocks/db.js +++ b/test/mocks/db.js @@ -39,6 +39,6 @@ module.exports.resetCalls = function() { calls = { status: false, fail: false - } + }; }; module.exports.resetCalls(); diff --git a/test/mocks/ticker.js b/test/mocks/ticker.js index e4c64f5f..3a71c150 100644 --- a/test/mocks/ticker.js +++ b/test/mocks/ticker.js @@ -25,4 +25,4 @@ module.exports = { var tickerCalls = 0; module.exports.getTickerCalls = function() { return tickerCalls; -} +}; diff --git a/test/mocks/wallet.js b/test/mocks/wallet.js index c3d93968..289a7090 100644 --- a/test/mocks/wallet.js +++ b/test/mocks/wallet.js @@ -38,6 +38,6 @@ module.exports.getBalanceCalls = function() { }; module.exports.wasSendCalled = function() { return calls.send; -} +};