aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/connect/CHANGELOG.md4
-rw-r--r--packages/connect/src/http_client.ts6
-rw-r--r--packages/connect/src/utils/type_converters.ts5
-rw-r--r--packages/connect/test/http_client_test.ts12
4 files changed, 16 insertions, 11 deletions
diff --git a/packages/connect/CHANGELOG.md b/packages/connect/CHANGELOG.md
index 5097aff40..16e343fb5 100644
--- a/packages/connect/CHANGELOG.md
+++ b/packages/connect/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+vx.x.x
+------------------------
+ * Prevent getFeesAsync method on HttpClient from mutating input (#296)
+
v0.3.0 - _December 8, 2017_
------------------------
* Expose WebSocketOrderbookChannel and associated types to public interface (#251)
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts
index 06b5d8ace..dcaf5d9a9 100644
--- a/packages/connect/src/http_client.ts
+++ b/packages/connect/src/http_client.ts
@@ -111,12 +111,6 @@ export class HttpClient implements Client {
*/
public async getFeesAsync(request: FeesRequest): Promise<FeesResponse> {
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 31abdc95c..ccbc40677 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 72d6ec0d6..b33b946c0 100644
--- a/packages/connect/test/http_client_test.ts
+++ b/packages/connect/test/http_client_test.ts
@@ -122,6 +122,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();