From 9f3acf8e2888b6105062e47664ecd5adaaf3c889 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Sun, 24 Dec 2017 19:02:01 -0500 Subject: Prevent getFeesAsync method on HttpClient from mutating input --- packages/connect/src/http_client.ts | 6 ------ packages/connect/src/utils/type_converters.ts | 5 ----- packages/connect/test/http_client_test.ts | 12 ++++++++++++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 924421f63..da052ba3c 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -112,12 +112,6 @@ export class HttpClient implements Client { */ public async getFeesAsync(request: FeesRequest): Promise { assert.doesConformToSchema('request', request, schemas.relayerApiFeesPayloadSchema); - typeConverters.convertBigNumberFieldsToStrings(request, [ - 'makerTokenAmount', - 'takerTokenAmount', - 'expirationUnixTimestampSec', - 'salt', - ]); const requestOpts = { payload: request, }; diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts index c136382fd..28810af1a 100644 --- a/packages/connect/src/utils/type_converters.ts +++ b/packages/connect/src/utils/type_converters.ts @@ -18,11 +18,6 @@ export const typeConverters = { 'salt', ]); }, - convertBigNumberFieldsToStrings(obj: object, fields: string[]): void { - _.each(fields, field => { - _.update(obj, field, (value: BigNumber) => value.toString()); - }); - }, convertStringsFieldsToBigNumbers(obj: object, fields: string[]): void { _.each(fields, field => { _.update(obj, field, (value: string) => new BigNumber(value)); diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 21e7abb69..db7077531 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -124,6 +124,18 @@ describe('HttpClient', () => { const fees = await relayerClient.getFeesAsync(request); expect(fees).to.be.deep.equal(feesResponse); }); + it('does not mutate input', async () => { + fetchMock.post(url, feesResponseJSON); + const makerTokenAmountBefore = new BigNumber(request.makerTokenAmount); + const takerTokenAmountBefore = new BigNumber(request.takerTokenAmount); + const saltBefore = new BigNumber(request.salt); + const expirationUnixTimestampSecBefore = new BigNumber(request.expirationUnixTimestampSec); + await relayerClient.getFeesAsync(request); + expect(makerTokenAmountBefore).to.be.deep.equal(request.makerTokenAmount); + expect(takerTokenAmountBefore).to.be.deep.equal(request.takerTokenAmount); + expect(saltBefore).to.be.deep.equal(request.salt); + expect(expirationUnixTimestampSecBefore).to.be.deep.equal(request.expirationUnixTimestampSec); + }); it('throws an error for invalid JSON response', async () => { fetchMock.post(url, {test: 'dummy'}); expect(relayerClient.getFeesAsync(request)).to.be.rejected(); -- cgit