Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ordinariusprof committed Mar 23, 2024
1 parent b1609ba commit 5561ef7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions model/exchanges/kraken.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
const KrakenAPI = require('../../api/kraken');
const NotificationService = require('../notifications/notificationService');

/**
* Rotates funds from a Kraken account
*/
class KrakenTumbler {
/**
* @param {KrakenAPI} krakenClient
* @param {NotificationService} notificationService
* @param {number} minWithdrawalAmount
* @param {number} maxWithdrawalAmount
* @param {string} withdrawWallet
* @param {string} withdrawCurrency
*/
constructor(
krakenClient,
notificationService,
minWithdrawalAmount,
maxWithdrawalAmount,
withdrawWallet,
withdrawCurrency,
) {
this.krakenClient = krakenClient;
this.notificationService = notificationService;
this.minWithdrawalAmount = minWithdrawalAmount;
this.maxWithdrawalAmount = maxWithdrawalAmount;
this.withdrawWallet = withdrawWallet;
Expand Down
3 changes: 3 additions & 0 deletions model/exchanges/okcoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ const OkcoinAPI = require('../../api/okcoin');
class OkcoinTumbler {
/**
* @param {OkcoinAPI} okcoinClient
* @param {NotificationService} notificationService
* @param {number} minWithdrawalAmount
* @param {number} maxWithdrawalAmount
* @param {string} withdrawWallet
* @param {string} withdrawCurrency
*/
constructor(
okcoinClient,
notificationService,
minWithdrawalAmount,
maxWithdrawalAmount,
withdrawWallet,
withdrawCurrency,
) {
this.okcoinClient = okcoinClient;
this.notificationService = notificationService;
this.minWithdrawalAmount = minWithdrawalAmount;
this.maxWithdrawalAmount = maxWithdrawalAmount;
this.withdrawWallet = withdrawWallet;
Expand Down
17 changes: 14 additions & 3 deletions test/kraken-tumbler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('', '');
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions test/satminer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 5561ef7

Please sign in to comment.