diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2019-01-04 03:18:33 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2019-01-08 02:31:11 +0800 |
commit | 5720589515d321e2d2db87c8337ee3f6340a0ef8 (patch) | |
tree | 86529a52a614ac4abf4c1342b558b8f28b0bc778 /packages/order-utils/src | |
parent | 70508f52a1dd6bfcc891f145c3a06f1e66c3cda5 (diff) | |
download | dexon-sol-tools-5720589515d321e2d2db87c8337ee3f6340a0ef8.tar dexon-sol-tools-5720589515d321e2d2db87c8337ee3f6340a0ef8.tar.gz dexon-sol-tools-5720589515d321e2d2db87c8337ee3f6340a0ef8.tar.bz2 dexon-sol-tools-5720589515d321e2d2db87c8337ee3f6340a0ef8.tar.lz dexon-sol-tools-5720589515d321e2d2db87c8337ee3f6340a0ef8.tar.xz dexon-sol-tools-5720589515d321e2d2db87c8337ee3f6340a0ef8.tar.zst dexon-sol-tools-5720589515d321e2d2db87c8337ee3f6340a0ef8.zip |
Add tests for recursive MAP decoding
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r-- | packages/order-utils/src/asset_data_utils.ts | 30 | ||||
-rw-r--r-- | packages/order-utils/src/constants.ts | 1 |
2 files changed, 24 insertions, 7 deletions
diff --git a/packages/order-utils/src/asset_data_utils.ts b/packages/order-utils/src/asset_data_utils.ts index 3741a683e..b5ce87e3e 100644 --- a/packages/order-utils/src/asset_data_utils.ts +++ b/packages/order-utils/src/asset_data_utils.ts @@ -128,16 +128,32 @@ export const assetDataUtils = { */ decodeMultiAssetDataRecursively(assetData: string): MultiAssetDataWithRecursiveDecoding { const decodedAssetData = assetDataUtils.decodeMultiAssetData(assetData); - const decodedNestedAssetData = _.map(decodedAssetData.nestedAssetData as string[], nestedAssetDataElement => { - const decodedNestedAssetDataElement = assetDataUtils.decodeAssetDataOrThrow(nestedAssetDataElement); - return decodedNestedAssetDataElement.assetProxyId === AssetProxyId.MultiAsset - ? assetDataUtils.decodeMultiAssetDataRecursively(nestedAssetDataElement).nestedAssetData - : (decodedNestedAssetDataElement as SingleAssetData); - }); + const amounts: any[] = []; + const decodedNestedAssetData = _.map( + decodedAssetData.nestedAssetData as string[], + (nestedAssetDataElement, index) => { + const decodedNestedAssetDataElement = assetDataUtils.decodeAssetDataOrThrow(nestedAssetDataElement); + if (decodedNestedAssetDataElement.assetProxyId === AssetProxyId.MultiAsset) { + const recursivelyDecodedAssetData = assetDataUtils.decodeMultiAssetDataRecursively( + nestedAssetDataElement, + ); + amounts.push( + _.map(recursivelyDecodedAssetData.amounts as BigNumber[], amountElement => + amountElement.times(decodedAssetData.amounts[index]), + ), + ); + return recursivelyDecodedAssetData.nestedAssetData; + } else { + amounts.push(decodedAssetData.amounts[index]); + return decodedNestedAssetDataElement as SingleAssetData; + } + }, + ); + const flattenedAmounts = _.flattenDeep(amounts); const flattenedDecodedNestedAssetData = _.flattenDeep(decodedNestedAssetData); return { assetProxyId: decodedAssetData.assetProxyId, - amounts: decodedAssetData.amounts, + amounts: flattenedAmounts, nestedAssetData: flattenedDecodedNestedAssetData as SingleAssetData[], }; }, diff --git a/packages/order-utils/src/constants.ts b/packages/order-utils/src/constants.ts index be7f3a885..1248a5576 100644 --- a/packages/order-utils/src/constants.ts +++ b/packages/order-utils/src/constants.ts @@ -3,6 +3,7 @@ import { BigNumber } from '@0x/utils'; export const constants = { NULL_ADDRESS: '0x0000000000000000000000000000000000000000', NULL_BYTES: '0x', + NULL_ERC20_ASSET_DATA: '0xf47261b00000000000000000000000000000000000000000000000000000000000000000', // tslint:disable-next-line:custom-no-magic-numbers UNLIMITED_ALLOWANCE_IN_BASE_UNITS: new BigNumber(2).pow(256).minus(1), TESTRPC_NETWORK_ID: 50, |