diff --git a/index.js b/index.js index 3dd1c20..1917cfe 100644 --- a/index.js +++ b/index.js @@ -100,6 +100,7 @@ switch (ACTIVE_EXCHANGE) { const krakenAPI = new KrakenAPI(KRAKEN_API_KEY, KRAKEN_API_SECRET); exchangeTumbler = new KrakenTumbler( krakenAPI, + notifications, MIN_WITHDRAWAL_AMOUNT, MAX_WITHDRAWAL_AMOUNT, KRAKEN_WITHDRAWAL_WALLET, @@ -110,6 +111,7 @@ switch (ACTIVE_EXCHANGE) { const okcoinAPI = new OkcoinAPI(OKCOIN_API_KEY, OKCOIN_API_SECRET, OKCOIN_API_PASSPHRASE); exchangeTumbler = new OkcoinTumbler( okcoinAPI, + notifications, MIN_WITHDRAWAL_AMOUNT, MAX_WITHDRAWAL_AMOUNT, OKCOIN_WITHDRAWAL_WALLET, diff --git a/model/exchanges/kraken.js b/model/exchanges/kraken.js index ec0c5f4..8dcced1 100644 --- a/model/exchanges/kraken.js +++ b/model/exchanges/kraken.js @@ -1,4 +1,5 @@ const KrakenAPI = require('../../api/kraken'); +const NotificationService = require('../notifications/notificationService'); /** * Rotates funds from a Kraken account @@ -6,6 +7,7 @@ const KrakenAPI = require('../../api/kraken'); class KrakenTumbler { /** * @param {KrakenAPI} krakenClient + * @param {NotificationService} notificationService * @param {number} minWithdrawalAmount * @param {number} maxWithdrawalAmount * @param {string} withdrawWallet @@ -13,12 +15,14 @@ class KrakenTumbler { */ constructor( krakenClient, + notificationService, minWithdrawalAmount, maxWithdrawalAmount, withdrawWallet, withdrawCurrency, ) { this.krakenClient = krakenClient; + this.notificationService = notificationService; this.minWithdrawalAmount = minWithdrawalAmount; this.maxWithdrawalAmount = maxWithdrawalAmount; this.withdrawWallet = withdrawWallet; diff --git a/model/exchanges/okcoin.js b/model/exchanges/okcoin.js index 7b17007..6ca6f10 100644 --- a/model/exchanges/okcoin.js +++ b/model/exchanges/okcoin.js @@ -6,6 +6,7 @@ const OkcoinAPI = require('../../api/okcoin'); class OkcoinTumbler { /** * @param {OkcoinAPI} okcoinClient + * @param {NotificationService} notificationService * @param {number} minWithdrawalAmount * @param {number} maxWithdrawalAmount * @param {string} withdrawWallet @@ -13,12 +14,14 @@ class OkcoinTumbler { */ constructor( okcoinClient, + notificationService, minWithdrawalAmount, maxWithdrawalAmount, withdrawWallet, withdrawCurrency, ) { this.okcoinClient = okcoinClient; + this.notificationService = notificationService; this.minWithdrawalAmount = minWithdrawalAmount; this.maxWithdrawalAmount = maxWithdrawalAmount; this.withdrawWallet = withdrawWallet; diff --git a/test/kraken-tumbler.js b/test/kraken-tumbler.js index b27cf52..243d849 100644 --- a/test/kraken-tumbler.js +++ b/test/kraken-tumbler.js @@ -2,6 +2,7 @@ const sinon = require('sinon'); const assert = require('assert'); const KrakenAPI = require('../api/kraken'); const KrakenTumbler = require('../model/exchanges/kraken'); +const NotificationService = require('../model/notifications/notificationService'); const getMockKrakenAPI = (accountBalance) => { const api = new KrakenAPI('', ''); @@ -24,10 +25,20 @@ const getMockKrakenAPI = (accountBalance) => { }; describe('KrakenTumbler', () => { + let api = new KrakenAPI('', ''); + let notificationService = new NotificationService(); + let krakenTumbler = new KrakenTumbler(api, notificationService, 0.01, 1, 'test', 'XBT'); + + beforeEach(() => { + api = new KrakenAPI('', ''); + notificationService = new NotificationService(); + krakenTumbler = new KrakenTumbler(api, notificationService, 0.01, 1, 'test', 'XBT'); + }); + describe('#withdrawAvailableFunds()', () => { it('should not withdraw funds if balance is too low', async () => { const { api } = getMockKrakenAPI(0.001); - const krakenTumbler = new KrakenTumbler(api, 0.01, 1, 'test', 'XBT'); + krakenTumbler = new KrakenTumbler(api, notificationService, 0.01, 1, 'test', 'XBT'); const res = await krakenTumbler.withdrawAvailableFunds(); @@ -42,7 +53,7 @@ describe('KrakenTumbler', () => { const maxWithdrawalAmount = 1; const { api, stubWithdrawFunds } = getMockKrakenAPI(accountBalance); - const krakenTumbler = new KrakenTumbler(api, minWithdrawalAmount, maxWithdrawalAmount, withdrawWalllet, withdrawCurrency); + krakenTumbler = new KrakenTumbler(api, notificationService, minWithdrawalAmount, maxWithdrawalAmount, withdrawWalllet, withdrawCurrency); const res = await krakenTumbler.withdrawAvailableFunds(); @@ -58,7 +69,7 @@ describe('KrakenTumbler', () => { const maxWithdrawalAmount = 1; const { api, stubWithdrawFunds } = getMockKrakenAPI(accountBalance); - const krakenTumbler = new KrakenTumbler(api, minWithdrawalAmount, maxWithdrawalAmount, withdrawWalllet, withdrawCurrency); + krakenTumbler = new KrakenTumbler(api, notificationService, minWithdrawalAmount, maxWithdrawalAmount, withdrawWalllet, withdrawCurrency); const res = await krakenTumbler.withdrawAvailableFunds(); assert.ok(res); diff --git a/test/satminer.js b/test/satminer.js index 4e5142b..db272b7 100644 --- a/test/satminer.js +++ b/test/satminer.js @@ -134,7 +134,7 @@ describe('Satminer', () => { assert(signRawTxSpy.calledWith(mockSatExtractorApiResponse.tx)); assert(sendTxSpy.calledOnce); assert(sendTxSpy.calledWith('signedtx')); - assert(notificationSpy.calledTwice); + assert(notificationSpy.calledThrice); }); it('should send common sats to exchange wallet', async () => { @@ -197,7 +197,7 @@ describe('Satminer', () => { assert(signRawTxSpy.calledWith(mockSatExtractorApiResponse.tx)); assert(sendTxSpy.calledOnce); assert(sendTxSpy.calledWith('signedtx')); - assert(notificationSpy.calledTwice); + assert(notificationSpy.calledThrice); }); it('should throw if common sats sent to exchange wallet if below min deposit amount', async () => { @@ -260,7 +260,7 @@ describe('Satminer', () => { assert(signRawTxSpy.notCalled); assert(sendTxSpy.notCalled); assert(sendTxSpy.notCalled); - assert(notificationSpy.calledTwice); + assert(notificationSpy.calledThrice); }); it('should throw if any funds go to non-user controlled addresses', async () => { @@ -324,7 +324,7 @@ describe('Satminer', () => { assert(signRawTxSpy.notCalled); assert(sendTxSpy.notCalled); assert(sendTxSpy.notCalled); - assert(notificationSpy.calledTwice); + assert(notificationSpy.calledThrice); }); it('should finish quietly when address is empty', async () => { @@ -353,7 +353,7 @@ describe('Satminer', () => { const res = await satminer.extractSatsAndRotateFunds(); assert(stubExtract.calledOnce); - assert(spySlack.notCalled); + assert(spySlack.calledTwice); assert(decodeRawTxSpy.notCalled); assert(signRawTxSpy.notCalled); assert(sendTxSpy.notCalled); @@ -399,7 +399,7 @@ describe('Satminer', () => { ); await assert.rejects(async () => satminer.extractSatsAndRotateFunds(), { message: 'fee higher than max allowed 1000' }); - assert(notificationSpy.calledOnce); + assert(notificationSpy.calledTwice); }); });