diff --git a/__tests__/send-tx.test.js b/__tests__/send-tx.test.js index 8b638782..11d035f4 100644 --- a/__tests__/send-tx.test.js +++ b/__tests__/send-tx.test.js @@ -1,3 +1,4 @@ +import { HathorWallet } from '@hathor/wallet-lib'; import TestUtils from './test-utils'; import { MAX_DATA_SCRIPT_LENGTH } from '../src/constants'; @@ -321,4 +322,21 @@ describe('send-tx api', () => { expect(response2.body.hash).toBeTruthy(); expect(response2.body.success).toBeTruthy(); }); + + it('should log errors on send-tx when debug=true on req.body', async () => { + const spy = jest.spyOn(HathorWallet.prototype, 'sendManyOutputsTransaction').mockImplementation(() => { + throw new Error('Boom!'); + }); + const response = await TestUtils.request + .post('/wallet/send-tx') + .send({ + debug: true, + outputs: [{ address: 'WPynsVhyU6nP7RSZAkqfijEutC88KgAyFc', value: 1 }], + }) + .set({ 'x-wallet-id': walletId }); + expect(response.status).toBe(200); + expect(response.body.success).toBeFalsy(); + expect(response.body.error).toEqual('Boom!'); + spy.mockRestore(); + }); }); diff --git a/package-lock.json b/package-lock.json index 3cdb5bca..42b0793a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "hathor-wallet-headless", - "version": "0.19.1", + "version": "0.19.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index da1f5aef..5da5b599 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hathor-wallet-headless", - "version": "0.19.1", + "version": "0.19.2", "description": "Hathor Wallet Headless, i.e., without graphical user interface", "main": "index.js", "engines": { diff --git a/src/api-docs.js b/src/api-docs.js index 694a752c..54b7980e 100644 --- a/src/api-docs.js +++ b/src/api-docs.js @@ -6,7 +6,7 @@ const apiDoc = { info: { title: 'Headless Hathor Wallet API', description: 'This wallet is fully controlled through an HTTP API.', - version: '0.19.1', + version: '0.19.2', }, produces: ['application/json'], components: { diff --git a/src/controllers/wallet/wallet.controller.js b/src/controllers/wallet/wallet.controller.js index b9411303..d204a79a 100644 --- a/src/controllers/wallet/wallet.controller.js +++ b/src/controllers/wallet/wallet.controller.js @@ -5,13 +5,15 @@ * LICENSE file in the root directory of this source tree. */ +// import is used because there is an issue with winston logger when using require ref: #262 +import logger from '../../logger'; // eslint-disable-line import/no-import-module-exports + const { txApi, walletApi, constants: hathorLibConstants, helpersUtils, errors, tokensUtils, PartialTx } = require('@hathor/wallet-lib'); const { matchedData } = require('express-validator'); const { parametersValidation } = require('../../helpers/validations.helper'); const { lock, lockTypes } = require('../../lock'); const { cantSendTxErrorMessage, friendlyWalletState } = require('../../helpers/constants'); const { mapTxReturn, prepareTxFunds } = require('../../helpers/tx.helper'); -const logger = require('../../logger'); const { initializedWallets } = require('../../services/wallets.service'); function getStatus(req, res) { @@ -363,8 +365,8 @@ async function sendTx(req, res) { const ret = { success: false, error: err.message }; if (debug) { logger.debug('/send-tx failed', { - body: req.body, - response: ret, + body: JSON.stringify(req.body), + response: JSON.stringify(ret), }); } res.send(ret);