diff --git a/.dummy b/.dummy new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/certificate.pem b/test/fixtures/certificate.pem deleted file mode 100644 index 542541e1..00000000 --- a/test/fixtures/certificate.pem +++ /dev/null @@ -1,17 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICozCCAgwCCQCSX2bhri8GETANBgkqhkiG9w0BAQUFADCBlTELMAkGA1UEBhMC -SUUxEjAQBgNVBAgTCVdhdGVyZm9yZDESMBAGA1UEBxMJV2F0ZXJmb3JkMREwDwYD -VQQKEwhuZWFyRm9ybTEMMAoGA1UECxMDZGV2MRQwEgYDVQQDEwtQZXRlciBFbGdl -cjEnMCUGCSqGSIb3DQEJARYYcGV0ZXIuZWxnZXJAbmVhcmZvcm0uY29tMB4XDTE0 -MDEyMDExMjc1NloXDTE0MDIxOTExMjc1NlowgZUxCzAJBgNVBAYTAklFMRIwEAYD -VQQIEwlXYXRlcmZvcmQxEjAQBgNVBAcTCVdhdGVyZm9yZDERMA8GA1UEChMIbmVh -ckZvcm0xDDAKBgNVBAsTA2RldjEUMBIGA1UEAxMLUGV0ZXIgRWxnZXIxJzAlBgkq -hkiG9w0BCQEWGHBldGVyLmVsZ2VyQG5lYXJmb3JtLmNvbTCBnzANBgkqhkiG9w0B -AQEFAAOBjQAwgYkCgYEAtZBpc6ZpF3rVSOq0D2zD2PMgR4hBzka0tD7coEDRWgjH -CFCtwtB97yuV3zq6V0zcApogXIIM6NQm6vcSAna9hqEiQCJV18GEAylC7Z/AW7HP -L63kYTMAXhdoztLFrkczUbtHwCB6wyUehszSzWaozpS9+ESpf/bPxMJjfhuqOvcC -AwEAATANBgkqhkiG9w0BAQUFAAOBgQCF3oZsXXC4QIm5Say8AVPYlhyb0liUSmr8 -owvESnPFy2PYFHMwzLCE4wnVsXcRq4gK0rXiiuBQsNEw/v93RfLWV4DLAlf9DoB2 -sO3LA/LSj4ptjZ4Dki5NKfTK9b6QJoQkc/u68hEEOe/WYZPIxdaeki4aVCcnrv1v -zJ9YTluP7w== ------END CERTIFICATE----- diff --git a/test/fixtures/certrequest.csr b/test/fixtures/certrequest.csr deleted file mode 100644 index 9b36b045..00000000 --- a/test/fixtures/certrequest.csr +++ /dev/null @@ -1,13 +0,0 @@ ------BEGIN CERTIFICATE REQUEST----- -MIICBDCCAW0CAQAwgZUxCzAJBgNVBAYTAklFMRIwEAYDVQQIEwlXYXRlcmZvcmQx -EjAQBgNVBAcTCVdhdGVyZm9yZDERMA8GA1UEChMIbmVhckZvcm0xDDAKBgNVBAsT -A2RldjEUMBIGA1UEAxMLUGV0ZXIgRWxnZXIxJzAlBgkqhkiG9w0BCQEWGHBldGVy -LmVsZ2VyQG5lYXJmb3JtLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA -tZBpc6ZpF3rVSOq0D2zD2PMgR4hBzka0tD7coEDRWgjHCFCtwtB97yuV3zq6V0zc -ApogXIIM6NQm6vcSAna9hqEiQCJV18GEAylC7Z/AW7HPL63kYTMAXhdoztLFrkcz -UbtHwCB6wyUehszSzWaozpS9+ESpf/bPxMJjfhuqOvcCAwEAAaAuMBMGCSqGSIb3 -DQEJBzEGEwRhc2RmMBcGCSqGSIb3DQEJAjEKEwhuZWFyRm9ybTANBgkqhkiG9w0B -AQUFAAOBgQC0+vxHKcdpeiUYYXJjUVHUC9xSR19l+8F7FNtehXyGNoxmpMwmEVkM -J1TUokG/HgBoh9vy8TxleHldDdA+9jjWfaPHk8LaRIkNguJ9IMvv3yctjcCD39lJ -Yb1mQWOYaDOsgsEqiN/U2K6yUneYGGKIndA/PrEmd1aBMOTQ7R9Tvg== ------END CERTIFICATE REQUEST----- diff --git a/test/fixtures/privatekey.pem b/test/fixtures/privatekey.pem deleted file mode 100644 index a3e93ede..00000000 --- a/test/fixtures/privatekey.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXAIBAAKBgQC1kGlzpmkXetVI6rQPbMPY8yBHiEHORrS0PtygQNFaCMcIUK3C -0H3vK5XfOrpXTNwCmiBcggzo1Cbq9xICdr2GoSJAIlXXwYQDKULtn8Bbsc8vreRh -MwBeF2jO0sWuRzNRu0fAIHrDJR6GzNLNZqjOlL34RKl/9s/EwmN+G6o69wIDAQAB -AoGAS35aen3tIJgwavs8F1XQMTsWZuffBNgddvzUW8XXxqnzqB9zwJdUZcgnrwQK -SxZoPKS9Y/mnSIA+FmDZGjEpKEeLrFePYz9UHpSW3j3vmLwWNTyAFl/DjqyrCIpE -+qB309t9NYEdd7LTeJyfIfideyEDAZUaQ2VsVDQDypYeoUECQQDrNstTpkv24MLA -4rFiXSSiC5IT86QuXbmXeHNTdChhqFS8C5LVKqt4Prpq4QvwQksiHJkipp5zvy2V -zfvfVTNnAkEAxZvnnYR5XyIPMVRQtlV0iskbvnQovJ4l3B7UfHeP9DZ9uhAR4MUo -ttJGjDjUMo78w381KEAqePpKn+RhF70R8QJADqwEUtt0sZmjjFSXrAMTXehK3GO+ -QgYmpYQl7Xa5bh4J6xDtv85Bk+aVykTvcbUw6pfOFZM/Hwk11rpak7vE0QJAEFGD -mvppm3WQk55G3AfKi/t3kw68nnbg4YCaQ30MIjqtv0O8djdR2Wcb9FBtFY/BR9Ol -bCGAYGUq7HFLo041wQJBAL2x2OvwnYYtXXOBY27tox3B1hDye7jRI5Q/IvcRB7YE -00q8L0XVaV4lmyd7tfFDQq/bfDUgTuwvkSPnQcpJDDw= ------END RSA PRIVATE KEY----- diff --git a/test/mocks/config.js b/test/mocks/config.js deleted file mode 100644 index 5c249471..00000000 --- a/test/mocks/config.js +++ /dev/null @@ -1,14 +0,0 @@ -'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/config.json b/test/mocks/config.json deleted file mode 100644 index d5270c1c..00000000 --- a/test/mocks/config.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "exchanges": { - "settings": { - "compliance": { - "maximum": { - "limit": null - } - }, - "commission": 1, - "fastPoll": 5000, - "fastPollLimit": 10, - "tickerInterval": 5000, - "balanceInterval": 5000, - "tradeInterval": 5000, - "retryInterval": 5000, - "retries": 3, - "lowBalanceMargin": 1.05, - "transactionFee": 10000, - "tickerDelta": 0, - "minimumTradeFiat": 0, - "currency": "PLN", - "networkTimeout": 20000 - }, - "plugins": { - "current": { - "ticker": "mockTicker", - "trade": "mockTrader", - "wallet": "mockWallet", - "transfer": "mockWallet", - "idVerifier": "mockVerifier", - "info": "mockInfo" - }, - "settings": { - "bitpay": { }, - "bitstamp": { - "currency": "USD", - "key": "", - "secret": "", - "clientId": "" - }, - "blockchain": { - "retryInterval": 10000, - "retryTimeout": 60000, - "guid": "", - "password": "", - "fromAddress": "" - } - } - } - }, - "brain": { - "qrTimeout": 60000, - "goodbyeTimeout": 2000, - "billTimeout": 60000, - "completedTimeout": 60000, - "networkTimeout": 20000, - "triggerRetry": 5000, - "idleTime": 600000, - "checkIdleTime": 60000, - "maxProcessSize": 104857600, - "freeMemRatio": 0.15, - "unit": { - "ssn": "xx-1234-45", - "owner": "Lamassu, Inc. \/ Trofa \/ Portugal" - }, - "locale": { - "currency": "PLN", - "localeInfo": { - "primaryLocale": "pl-PL", - "primaryLocales": [ - "pl-PL" - ] - } - } - } -} diff --git a/test/mocks/db.js b/test/mocks/db.js deleted file mode 100644 index 66ca37e7..00000000 --- a/test/mocks/db.js +++ /dev/null @@ -1,53 +0,0 @@ -'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, - getPendingAmount: function(tx, cb) { - var cachedTx = txs[tx.txId]; - if (cachedTx) cb(null, cachedTx); - else { - txs[tx.txId] = tx; - cb(null, null); - } - }, - changeTxStatus: function(txId, newStatus, data, cb) { - cb = typeof cb === 'function' ? cb : function() {}; - cb(); - }, - 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; - }, - recordBill: function(fingerprint, trade) { }, - addOutgoingTx: function(session, tx, cb) { - cb(null, {satoshis: tx.satoshis}); - }, - sentCoins: function() {} -}; - - -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/info.js b/test/mocks/info.js deleted file mode 100644 index ba96e4cb..00000000 --- a/test/mocks/info.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = { - SUPPORTED_MODULES: ['info'], - NAME: 'Mock Info', - - config: function config() {}, - getAddressLastTx: function verifyUser() {}, - getTx: function verifyTransaction() {}, - checkAddress: function checkAddress() {} -}; diff --git a/test/mocks/plugins.js b/test/mocks/plugins.js deleted file mode 100644 index 393d58a2..00000000 --- a/test/mocks/plugins.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -exports.init = function init () { - -}; diff --git a/test/mocks/psql.js b/test/mocks/psql.js deleted file mode 100644 index 1e2b68ce..00000000 --- a/test/mocks/psql.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -var PostgresqlInterface = module.exports = function (conString) { -}; diff --git a/test/mocks/ticker.js b/test/mocks/ticker.js deleted file mode 100644 index 3a71c150..00000000 --- a/test/mocks/ticker.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -module.exports = { - SUPPORTED_MODULES: [ 'ticker' ], - NAME: 'Mock Ticker', - - config: function config() {}, - ticker: function ticker(currency, callback) { - tickerCalls++; - - var out = {}; - out[currency] = { - currency: currency, - rates: { - ask: 1001.0, - bid: 999.0 - } - }; - 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 deleted file mode 100644 index 0ae3986c..00000000 --- a/test/mocks/trader.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = { - SUPPORTED_MODULES: ['trader'], - NAME: 'Mock Trader', - - config: function config() {}, - balance: function balance() {}, - purchase: function purchase() {}, - sell: function sell() {} -}; diff --git a/test/mocks/verifier.js b/test/mocks/verifier.js deleted file mode 100644 index 67d00483..00000000 --- a/test/mocks/verifier.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -module.exports = { - SUPPORTED_MODULES: ['idVerifier'], - NAME: 'Mock Verifier', - - config: function config() {}, - verifyUser: function verifyUser() {}, - verifyTransaction: function verifyTransaction() {} -}; diff --git a/test/mocks/wallet.js b/test/mocks/wallet.js deleted file mode 100644 index ed73e2ae..00000000 --- a/test/mocks/wallet.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -module.exports = { - SUPPORTED_MODULES: ['wallet'], - NAME: 'Mock Wallet', - - 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); - } - }, - newAddress: function(info, cb) { - cb(null, ADDR); - } -}; - - -// 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 deleted file mode 100644 index 3dcbf87d..00000000 --- a/test/plugins.js +++ /dev/null @@ -1,240 +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.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') -var infoMock = require('./mocks/info') - -mockery.registerMock('lamassu-mockWallet', walletMock) -mockery.registerMock('lamassu-mockTicker', tickerMock) -mockery.registerMock('lamassu-mockTrader', traderMock) -mockery.registerMock('lamassu-mockVerifier', verifierMock) -mockery.registerMock('lamassu-mockInfo', infoMock) - -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') - infoMock.config = configTest('info') - - plugins.configure(config) - }) - - ;['wallet', 'ticker', 'trader', 'verifier', 'info'].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.getConfig() - 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.sendCoins(db.FINGERPRINT_NEW, txDetails, function (err, - response) { - should.not.exist(err) - should.exist(response) - /* jshint expr: true */ - response.should.be.an.Object - response.should.have.property('statusCode') - response.statusCode.should.equal(201) - /* 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 () {}) -})