From 5ec1afb89735810bb6b503447424c2f3f5be68e5 Mon Sep 17 00:00:00 2001 From: DhananjayPurohit Date: Mon, 11 Mar 2024 14:50:01 +0530 Subject: [PATCH 1/6] feat: add option for configuring testnet --- package.json | 2 +- src/controllers/api_controller.js | 10 ++++++++++ src/view/Home.jsx | 14 ++++++++------ src/view/modals/CreateSlotModal.jsx | 23 +++++++++++++++++++---- webpack.config.js | 4 ++++ 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f0daca9..c5e1d3d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "mainstay-mvc", "scripts": { "start": "HOST_API='localhost' PORT_API='4000' PORT='80' webpack-dev-server", - "dev": "HOST_API='localhost' PORT_API='4000' PORT='8080' webpack-dev-server", + "dev": "HOST_API='localhost' PORT_API='4000' PORT='8080' TESTNET='true' && webpack-dev-server", "test": "jest" }, "dependencies": { diff --git a/src/controllers/api_controller.js b/src/controllers/api_controller.js index 3205d27..4ebd42b 100644 --- a/src/controllers/api_controller.js +++ b/src/controllers/api_controller.js @@ -1304,6 +1304,16 @@ module.exports = { const data = JSON.parse(rawRequestData); const token_id = data[ARG_TOKEN_ID]; const slot_id = data[ARG_SLOT_ID]; + + if (token_id === undefined || token_id === '') { + const months = 12; // an year + const clientDetailsData = await create_slot_with_token(months); + reply_msg(res, { + auth_token: clientDetailsData.auth_token, + slot_id: clientDetailsData.client_position, + expiry_date: clientDetailsData.expiry_date + }, startTime); + } const tokenDetails = await models.tokenDetails.findOne({token_id: token_id}); if (tokenDetails.amount >= FEE_RATE_PER_MONTH_IN_EUR) { diff --git a/src/view/Home.jsx b/src/view/Home.jsx index 76c36b3..04b0b3c 100644 --- a/src/view/Home.jsx +++ b/src/view/Home.jsx @@ -38,12 +38,14 @@ class Home extends React.Component { toggleSlotDetailsModal = () => { this.setState({modalSlotDetails: !this.state.modalSlotDetails}); - this.setState({slot_details: { - auth_token: '', - slot_id: '', - expiry_date: '', - new_slot: true, - }}); + if (this.state.modalSlotDetails) { + this.setState({slot_details: { + auth_token: '', + slot_id: '', + expiry_date: '', + new_slot: true, + }}); + } }; setSlotDetails = (key, value) => { diff --git a/src/view/modals/CreateSlotModal.jsx b/src/view/modals/CreateSlotModal.jsx index 5577bfb..a0a970c 100644 --- a/src/view/modals/CreateSlotModal.jsx +++ b/src/view/modals/CreateSlotModal.jsx @@ -117,6 +117,14 @@ class CreateSlotModal extends React.PureComponent { }); } + handleTokenForTestnet = (event) => { + event.preventDefault(); + const token_id = this.props.slotDetails.token_id; + this.handleTokenForSpend(token_id); + this.props.toggleSlotDetailsModal(); + this.handleModalClose(); + }; + resetFormState = () => { this.formRef.current.reset(); this.setState({ @@ -199,10 +207,17 @@ class CreateSlotModal extends React.PureComponent { ) : null} - {this.state.invoice === '' ? ( - - ) : ( - + {process.env.TESTNET === 'true' && ( + + )} + {process.env.TESTNET !== 'true' && ( + this.state.invoice === '' ? ( + + ) : ( + + ) )} diff --git a/webpack.config.js b/webpack.config.js index 0194c0f..f011a37 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,6 +12,7 @@ module.exports = () => { const devServerHost = process.env.HOST || '0.0.0.0'; const devServerPort = parseInt(process.env.PORT) || 80; + const devServerTestnet = process.env.TESTNET || 'true'; return { mode: 'development', @@ -80,6 +81,9 @@ module.exports = () => { filename: './admin.html', chunks: ['admin'] }), + new webpack.DefinePlugin({ + 'process.env.TESTNET': JSON.stringify(devServerTestnet) + }), new webpack.HotModuleReplacementPlugin(), new webpack.ProgressPlugin() ], From d310c4b7f3ee7e45808c26b983e96fcd52464231 Mon Sep 17 00:00:00 2001 From: DhananjayPurohit Date: Mon, 11 Mar 2024 14:55:22 +0530 Subject: [PATCH 2/6] fix: set tesnet to false by default --- package.json | 2 +- webpack.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c5e1d3d..85a8622 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "mainstay-mvc", "scripts": { "start": "HOST_API='localhost' PORT_API='4000' PORT='80' webpack-dev-server", - "dev": "HOST_API='localhost' PORT_API='4000' PORT='8080' TESTNET='true' && webpack-dev-server", + "dev": "HOST_API='localhost' PORT_API='4000' PORT='8080' TESTNET='true' webpack-dev-server", "test": "jest" }, "dependencies": { diff --git a/webpack.config.js b/webpack.config.js index f011a37..9caee6f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,7 +12,7 @@ module.exports = () => { const devServerHost = process.env.HOST || '0.0.0.0'; const devServerPort = parseInt(process.env.PORT) || 80; - const devServerTestnet = process.env.TESTNET || 'true'; + const devServerTestnet = process.env.TESTNET || 'false'; return { mode: 'development', From 77c7135c47aa384db8c0c6a44ce8c9ca77824ffd Mon Sep 17 00:00:00 2001 From: DhananjayPurohit Date: Wed, 13 Mar 2024 16:55:27 +0530 Subject: [PATCH 3/6] chore: error handling for non hex and non 64 byte commitment --- src/controllers/api_controller.js | 7 ++---- src/controllers/ctrl_controller.js | 3 +++ test/controllers.test.js | 37 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/controllers/api_controller.js b/src/controllers/api_controller.js index 4ebd42b..9fbb20c 100644 --- a/src/controllers/api_controller.js +++ b/src/controllers/api_controller.js @@ -57,6 +57,7 @@ const { reply_err, reply_msg, } = require('../utils/controller_helpers'); +const { createParenthesizedType } = require('typescript'); const DATE_FORMAT = 'HH:mm:ss L z'; @@ -439,11 +440,7 @@ module.exports = { return reply_err(res, MISSING_PAYLOAD_TOKEN, startTime); } - - if (payload.commitment.length !== 64) { - return reply_err(res, BAD_COMMITMENT, startTime); - } - if (payload.commitment.split('').every(c => '0123456789ABCDEFabcdef'.indexOf(c) !== -1)) { + if (/[0-9A-Fa-f]{64}/g.test(payload.commitment) === false) { return reply_err(res, BAD_COMMITMENT, startTime); } diff --git a/src/controllers/ctrl_controller.js b/src/controllers/ctrl_controller.js index 0dece64..e47e8b4 100644 --- a/src/controllers/ctrl_controller.js +++ b/src/controllers/ctrl_controller.js @@ -150,6 +150,9 @@ module.exports = { if (payload.commitment === undefined) { return res.json({error: 'Incorrect commitment'}); } + if (/[0-9A-Fa-f]{64}/g.test(payload.commitment) === false) { + return res.json({error: 'Non hex or non 64 byte commitment'}); + } const data = await models.clientDetails.find({client_position: payload.position}); if (data.length === 0) { diff --git a/test/controllers.test.js b/test/controllers.test.js index 49d083c..21a5a37 100644 --- a/test/controllers.test.js +++ b/test/controllers.test.js @@ -3,6 +3,7 @@ const assert = require('assert'); const mockHttp = require('node-mocks-http'); const mongoose = require('mongoose'); const controllers = require('../src/controllers/api_controller'); +const ctrlControllers = require('../src/controllers/ctrl_controller'); const models = require('../src/models/models'); //////////////////////////////////////////////////////////////////////////////// /// Connect to MongoBD fot Test /// @@ -262,6 +263,42 @@ describe('Test Api Controllers', () => { controllers.commitment_send(req, res); }); + // non 64 byte string + it('Route: /api/v1/commitment/send', () => { + const req = mockHttp.createRequest( + { + method: 'POST', + url: '/api/v1/commitment/send', + body: { + position: 0, + token: '4c8c006d-4cee-4fef-8e06-bb8112db6314', + commitment: '1', + } + }); + const res = mockHttp.createResponse(); + ctrlControllers.ctrl_send_commitment(req, res); + const json = JSON.parse(res._getData()); + assert(json.error === 'Non hex or non 64 byte commitment'); + }); + + // non hex string + it('Route: /api/v1/commitment/send', () => { + const req = mockHttp.createRequest( + { + method: 'POST', + url: '/api/v1/commitment/send', + body: { + position: 0, + token: '4c8c006d-4cee-4fef-8e06-bb8112db6314', + commitment: 'f3d424bf830dbd59eebc3f0a23491a266b7158635188e47b0e2abf7dbcc8*&/', + } + }); + const res = mockHttp.createResponse(); + ctrlControllers.ctrl_send_commitment(req, res); + const json = JSON.parse(res._getData()); + assert(json.error === 'Non hex or non 64 byte commitment'); + }); + it('Route: /api/v1/slotexpiry?slot_id=0', async () => { const position = 0; const req = mockHttp.createRequest({method: 'GET', url: `/api/v1/slotexpiry?slot_id=${position}`}); From d51e7c57d0786af04fa1a06a5143bdea03870d22 Mon Sep 17 00:00:00 2001 From: DhananjayPurohit Date: Wed, 13 Mar 2024 16:57:21 +0530 Subject: [PATCH 4/6] chore: remove unused import --- src/controllers/api_controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/controllers/api_controller.js b/src/controllers/api_controller.js index 9fbb20c..3c8cb72 100644 --- a/src/controllers/api_controller.js +++ b/src/controllers/api_controller.js @@ -57,7 +57,6 @@ const { reply_err, reply_msg, } = require('../utils/controller_helpers'); -const { createParenthesizedType } = require('typescript'); const DATE_FORMAT = 'HH:mm:ss L z'; From 910bc56570825c9102d5aa2eafb71690136352f3 Mon Sep 17 00:00:00 2001 From: DhananjayPurohit Date: Wed, 13 Mar 2024 20:20:51 +0530 Subject: [PATCH 5/6] chore: remove signature from payload --- src/controllers/api_controller.js | 43 ------------------------- src/controllers/ctrl_controller.js | 21 ------------ src/view/Menu.jsx | 5 +-- src/view/modals/SendCommitmentModal.jsx | 5 +-- 4 files changed, 2 insertions(+), 72 deletions(-) diff --git a/src/controllers/api_controller.js b/src/controllers/api_controller.js index 3c8cb72..5e226da 100644 --- a/src/controllers/api_controller.js +++ b/src/controllers/api_controller.js @@ -443,8 +443,6 @@ module.exports = { return reply_err(res, BAD_COMMITMENT, startTime); } - - const signatureCommitment = data[MAINSTAY_SIGNATURE]; try { // try get client details const data = await models.clientDetails.find({client_position: payload.position}); @@ -458,26 +456,6 @@ module.exports = { return reply_err(res, EXPIRY_DATE_ERROR, startTime); } - if (data[0].pubkey && data[0].pubkey !== '') { - if (signatureCommitment === undefined) { - return reply_err(res, MISSING_ARG_SIGNATURE, startTime); - } - - try { - // get pubkey hex - const pubkey = ec.keyFromPublic(data[0].pubkey, 'hex'); - - // get base64 signature - let sig = Buffer.from(signatureCommitment, 'base64'); - - if (!ec.verify(payload.commitment, sig, pubkey)) { - return reply_err(res, SIGNATURE_INVALID, startTime); - } - } catch (error) { - return reply_err(res, SIGNATURE_INVALID, startTime); - } - } - if (data[0].service_level === 'free') { const latest_com = await models.clientCommitment.find({client_position: payload.position}); @@ -536,7 +514,6 @@ module.exports = { return reply_err(res, MISSING_PAYLOAD_TOKEN, startTime); } - const signatureCommitment = data[MAINSTAY_SIGNATURE]; try { // try get client details const data = await models.clientDetails.find({client_position: payload.position}); @@ -552,26 +529,6 @@ module.exports = { return reply_err(res, NO_ADDITIONS, startTime); } - if (data[0].pubkey && data[0].pubkey !== '') { - if (signatureCommitment === undefined) { - return reply_err(res, MISSING_ARG_SIGNATURE, startTime); - } - - try { - // get pubkey hex - const pubkey = ec.keyFromPublic(data[0].pubkey, 'hex'); - - // get base64 signature - let sig = Buffer.from(signatureCommitment, 'base64'); - - if (!ec.verify(payload.commitment, sig, pubkey)) { - return reply_err(res, SIGNATURE_INVALID, startTime); - } - } catch (error) { - return reply_err(res, SIGNATURE_INVALID, startTime); - } - } - //get all unconfirmed additions const addunconfirmed = await models.commitmentAdd.find({ client_position: payload.position, diff --git a/src/controllers/ctrl_controller.js b/src/controllers/ctrl_controller.js index e47e8b4..466ccfc 100644 --- a/src/controllers/ctrl_controller.js +++ b/src/controllers/ctrl_controller.js @@ -164,27 +164,6 @@ module.exports = { if (data[0].expiry_date && new Date(data[0].expiry_date) < new Date()) { return res.json({error: 'Expired token, renew it by paying for slot'}); } - if (data[0].pubkey && data[0].pubkey !== '') { - if (payload.signature === undefined) { - return res.json({error: 'signature'}); - } - try { - // get pubkey hex - const pubkey = ec.keyFromPublic(data[0].pubkey, 'hex'); - - // get base64 signature - const sig = Buffer.from(payload.signature, 'base64'); - if (!ec.verify(payload.commitment, sig, pubkey)) { - return res.json({error: 'signature'}); - } - - } catch (error) { - return res.json({ - error: SIGNATURE_INVALID, - message: error.message - }); - } - } if (data[0].service_level === 'free') { diff --git a/src/view/Menu.jsx b/src/view/Menu.jsx index 55cbdc8..9ac7354 100644 --- a/src/view/Menu.jsx +++ b/src/view/Menu.jsx @@ -16,7 +16,6 @@ const options = [ {label: 'Position', name: 'position'}, {label: 'Token', name: 'token'}, {label: 'Commitment', name: 'commitment'}, - {label: 'signature', name: 'signature'}, ]; class Menu extends Component { @@ -27,7 +26,6 @@ class Menu extends Component { position: undefined, token: undefined, commitment: undefined, - signature: undefined, isMenuOpened: false, }; } @@ -38,12 +36,11 @@ class Menu extends Component { handleSubmit = (event) => { event.preventDefault(); - const {position, token, commitment, signature} = this.state; + const {position, token, commitment} = this.state; apiService.axiosClient.post('/ctrl/sendcommitment', { position, token, commitment, - signature, }).then(res => { if (res.data?.error) { const errorMessage = res.data.error === 'undefined' diff --git a/src/view/modals/SendCommitmentModal.jsx b/src/view/modals/SendCommitmentModal.jsx index f0d4ec2..57e1999 100644 --- a/src/view/modals/SendCommitmentModal.jsx +++ b/src/view/modals/SendCommitmentModal.jsx @@ -9,7 +9,6 @@ const options = [ {label: 'Position*', name: 'position'}, {label: 'Token*', name: 'token'}, {label: 'Commitment*', name: 'commitment'}, - {label: 'Signature (optional)', name: 'signature'}, ]; class SendCommitmentModal extends React.PureComponent { @@ -21,7 +20,6 @@ class SendCommitmentModal extends React.PureComponent { position: undefined, token: undefined, commitment: undefined, - signature: undefined, } }; this.formRef = React.createRef(); @@ -50,7 +48,7 @@ class SendCommitmentModal extends React.PureComponent { handleSubmit = (event) => { event.preventDefault(); - const {position, token, commitment, signature} = this.state.inputs; + const {position, token, commitment} = this.state.inputs; if (!position || !position.trim()) { return this.showErrorAlert('Position is empty'); @@ -73,7 +71,6 @@ class SendCommitmentModal extends React.PureComponent { position, token, commitment, - signature, }).then(res => { if (res.data?.error) { if (this.props.onError) { From b26f6fd6dc309e70d4017992fb30ed8c6422d415 Mon Sep 17 00:00:00 2001 From: DhananjayPurohit Date: Wed, 13 Mar 2024 21:43:45 +0530 Subject: [PATCH 6/6] fix: doc and api endpoint --- doc/mainstay_api.md | 20 ++---- src/controllers/api_controller.js | 102 +++++++++++++----------------- test/controllers.test.js | 35 ++++++++-- 3 files changed, 79 insertions(+), 78 deletions(-) diff --git a/doc/mainstay_api.md b/doc/mainstay_api.md index 6d0864c..44672d2 100644 --- a/doc/mainstay_api.md +++ b/doc/mainstay_api.md @@ -575,27 +575,15 @@ const pvtKey = const commitment = 'F01111111111111111111111111111111111111111111111111111111111110F'; - -let keyPair = ec.keyFromPrivate("97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a"); -let privKey = keyPair.getPrivate("hex"); -let pubKey = keyPair.getPublic(); - -let signature = ec.sign(commitment, privKey, "hex", {canonical: true}).toDER('base64'); - var payload = { commitment: commitment, position: 0, token: '4c8c006d-4cee-4fef-8e06-bb8112db6314', }; -payload = new Buffer(JSON.stringify(payload)).toString('base64'); - const options = { url: url + route, - headers: { - 'X-MAINSTAY-PAYLOAD': payload, - 'X-MAINSTAY-SIGNATURE': signature - } + body: payload }; request.post(options, (error, response, body) => { @@ -607,7 +595,11 @@ request.post(options, (error, response, body) => { **Curl example** ```perl -curl --header "Content-Type: application/json" --request POST --data '{"X-MAINSTAY-PLAYLOAD":"eyJwb3NpdGlvbiI6MCwiY29tbWl0bWVudCI6IkYwMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMEYifQ==","X-MAINSTAY-SIGNATURE":"IJbqe50XtfZbQ1b0jr+J1tswSPfZlWwZugXCpYbwYMPuRl+htqSb7wTLYY9RtQ6Bw9Ym5dw0vMNRaDwR8pked2Y="}' http://localhost:9000/api/v1/commitment/send +curl --header "Content-Type: application/json" --request POST --data '{ + "position": "0", + "token": "4c8c006d-4cee-4fef-8e06-bb8112db6314", + "commitment": "f3d424bf830dbd59eebc3f0a23491a266b7158635188e47b0e2abf7dbcc8931", +}' http://localhost:9000/api/v1/commitment/send ``` *response* diff --git a/src/controllers/api_controller.js b/src/controllers/api_controller.js index 5e226da..5b7a5ea 100644 --- a/src/controllers/api_controller.js +++ b/src/controllers/api_controller.js @@ -408,77 +408,63 @@ module.exports = { commitment_send: async (req, res) => { const startTime = start_time(); - let rawRequestData = ''; - req.on('data', chunk => { - rawRequestData += chunk.toString(); - }); - req.on('end', async () => { - // test payload in base64 format and defined - let data; - let payload; - try { - data = JSON.parse(rawRequestData); - payload = JSON.parse(base64decode(data[MAINSTAY_PAYLOAD])); - } catch (e) { - return reply_err(res, BAD_ARG_PAYLOAD, startTime); - } + const payload = req.body; - if (payload === undefined) { - return reply_err(res, MISSING_ARG_PAYLOAD, startTime); - } + if (payload === undefined) { + return reply_err(res, MISSING_ARG_PAYLOAD, startTime); + } - // check payload components are defined - if (payload.commitment === undefined) { - return reply_err(res, MISSING_PAYLOAD_COMMITMENT, startTime); - } - if (payload.position === undefined) { - return reply_err(res, MISSING_PAYLOAD_POSITION, startTime); + // check payload components are defined + if (payload.commitment === undefined) { + return reply_err(res, MISSING_PAYLOAD_COMMITMENT, startTime); + } + if (payload.position === undefined) { + return reply_err(res, MISSING_PAYLOAD_POSITION, startTime); + } + if (payload.token === undefined) { + return reply_err(res, MISSING_PAYLOAD_TOKEN, startTime); + } + + if (/[0-9A-Fa-f]{64}/g.test(payload.commitment) === false) { + return reply_err(res, BAD_COMMITMENT, startTime); + } + + try { + // try get client details + const data = await models.clientDetails.find({client_position: payload.position}); + if (data.length === 0) { + return reply_err(res, POSITION_UNKNOWN, startTime); } - if (payload.token === undefined) { - return reply_err(res, MISSING_PAYLOAD_TOKEN, startTime); + if (data[0].auth_token !== payload.token) { + return reply_err(res, PAYLOAD_TOKEN_ERROR, startTime); } - - if (/[0-9A-Fa-f]{64}/g.test(payload.commitment) === false) { - return reply_err(res, BAD_COMMITMENT, startTime); + if (data[0].expiry_date && new Date(data[0].expiry_date) < new Date()) { + return reply_err(res, EXPIRY_DATE_ERROR, startTime); } - try { - // try get client details - const data = await models.clientDetails.find({client_position: payload.position}); - if (data.length === 0) { - return reply_err(res, POSITION_UNKNOWN, startTime); - } - if (data[0].auth_token !== payload.token) { - return reply_err(res, PAYLOAD_TOKEN_ERROR, startTime); - } - if (data[0].expiry_date && new Date(data[0].expiry_date) < new Date()) { - return reply_err(res, EXPIRY_DATE_ERROR, startTime); - } - - if (data[0].service_level === 'free') { + if (data[0].service_level === 'free') { - const latest_com = await models.clientCommitment.find({client_position: payload.position}); - let today = new Date().toLocaleDateString(); + const latest_com = await models.clientCommitment.find({client_position: payload.position}); + let today = new Date().toLocaleDateString(); - if (latest_com[0].date === today) { - return reply_err(res, FREE_TIER_LIMIT, startTime); - } else { - await models.clientCommitment.findOneAndUpdate({client_position: payload.position}, { - commitment: payload.commitment, - date: today - }, {upsert: true}); - reply_msg(res, 'Commitment added', startTime); - } + if (latest_com[0].date === today) { + return reply_err(res, FREE_TIER_LIMIT, startTime); } else { - await models.clientCommitment.findOneAndUpdate({client_position: payload.position}, {commitment: payload.commitment}, {upsert: true}); + await models.clientCommitment.findOneAndUpdate({client_position: payload.position}, { + commitment: payload.commitment, + date: today + }, {upsert: true}); reply_msg(res, 'Commitment added', startTime); } - - } catch (error) { - return reply_err(res, INTERNAL_ERROR_API, startTime); + } else { + await models.clientCommitment.findOneAndUpdate({client_position: payload.position}, {commitment: payload.commitment}, {upsert: true}); + reply_msg(res, 'Commitment added', startTime); } - }); + + } catch (error) { + return reply_err(res, INTERNAL_ERROR_API, startTime); + } }, commitment_add: async (req, res) => { diff --git a/test/controllers.test.js b/test/controllers.test.js index 21a5a37..9ca2ade 100644 --- a/test/controllers.test.js +++ b/test/controllers.test.js @@ -5,6 +5,7 @@ const mongoose = require('mongoose'); const controllers = require('../src/controllers/api_controller'); const ctrlControllers = require('../src/controllers/ctrl_controller'); const models = require('../src/models/models'); +const { BAD_COMMITMENT } = require('../src/utils/constants'); //////////////////////////////////////////////////////////////////////////////// /// Connect to MongoBD fot Test /// //////////////////////////////////////////////////////////////////////////////// @@ -249,26 +250,48 @@ describe('Test Api Controllers', () => { /// pubKey = 1CsSceq9GWnmozaky3DGa24UER6gRDgibf /// pvtKey = bac52bbea2194e7ea1cd3da6585b66d28f1a7a3683eca91af4ba6373d323d24f /// + + // non 64 byte string it('Route: /api/v1/commitment/send', () => { const req = mockHttp.createRequest( { method: 'POST', url: '/api/v1/commitment/send', - headers: { - 'X-MAINSTAY-PAYLOAD': 'b', - 'X-MAINSTAY-SIGNATURE': 'd' + body: { + position: 0, + token: '4c8c006d-4cee-4fef-8e06-bb8112db6314', + commitment: '1', } }); const res = mockHttp.createResponse(); controllers.commitment_send(req, res); + const json = JSON.parse(res._getData()); + assert(json.error === BAD_COMMITMENT); }); - // non 64 byte string it('Route: /api/v1/commitment/send', () => { const req = mockHttp.createRequest( { method: 'POST', url: '/api/v1/commitment/send', + body: { + position: 0, + token: '4c8c006d-4cee-4fef-8e06-bb8112db6314', + commitment: 'f3d424bf830dbd59eebc3f0a23491a266b7158635188e47b0e2abf7dbcc8*&/', + } + }); + const res = mockHttp.createResponse(); + controllers.commitment_send(req, res); + const json = JSON.parse(res._getData()); + assert(json.error === BAD_COMMITMENT); + }); + + // non 64 byte string + it('Route: /ctrl/sendcommitment', () => { + const req = mockHttp.createRequest( + { + method: 'POST', + url: '/ctrl/sendcommitment', body: { position: 0, token: '4c8c006d-4cee-4fef-8e06-bb8112db6314', @@ -282,11 +305,11 @@ describe('Test Api Controllers', () => { }); // non hex string - it('Route: /api/v1/commitment/send', () => { + it('Route: /ctrl/sendcommitment', () => { const req = mockHttp.createRequest( { method: 'POST', - url: '/api/v1/commitment/send', + url: '/ctrl/sendcommitment', body: { position: 0, token: '4c8c006d-4cee-4fef-8e06-bb8112db6314',