aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-18 17:32:01 +0800
committerFabio Berger <me@fabioberger.com>2018-07-18 17:32:01 +0800
commit25160d7344f9e1616654dfe09a24d8fc69fa8036 (patch)
tree2ec339700c0a1da1453671719e055692142c5efd /packages/contracts/test/utils
parent50ed7d2af26d6210f869352ed41084875d2af3d0 (diff)
downloaddexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.gz
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.bz2
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.lz
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.xz
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.zst
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.zip
Move encodeUint256 & decodeUint256 out of assetDataUtils since we don't want them exported
Diffstat (limited to 'packages/contracts/test/utils')
-rw-r--r--packages/contracts/test/utils/constants.ts2
-rw-r--r--packages/contracts/test/utils/type_encoding_utils.ts21
2 files changed, 23 insertions, 0 deletions
diff --git a/packages/contracts/test/utils/constants.ts b/packages/contracts/test/utils/constants.ts
index e8995f9d6..7dac38f56 100644
--- a/packages/contracts/test/utils/constants.ts
+++ b/packages/contracts/test/utils/constants.ts
@@ -17,6 +17,7 @@ const TESTRPC_PRIVATE_KEYS_STRINGS = [
];
export const constants = {
+ BASE_16: 16,
INVALID_OPCODE: 'invalid opcode',
TESTRPC_NETWORK_ID: 50,
// Note(albrow): In practice V8 and most other engines limit the minimum
@@ -47,4 +48,5 @@ export const constants = {
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
},
+ WORD_LENGTH: 32,
};
diff --git a/packages/contracts/test/utils/type_encoding_utils.ts b/packages/contracts/test/utils/type_encoding_utils.ts
new file mode 100644
index 000000000..75307b9bd
--- /dev/null
+++ b/packages/contracts/test/utils/type_encoding_utils.ts
@@ -0,0 +1,21 @@
+import { BigNumber } from '@0xproject/utils';
+import BN = require('bn.js');
+import ethUtil = require('ethereumjs-util');
+
+import { constants } from './constants';
+
+export const typeEncodingUtils = {
+ encodeUint256(value: BigNumber): Buffer {
+ const base = 10;
+ const formattedValue = new BN(value.toString(base));
+ const encodedValue = ethUtil.toBuffer(formattedValue);
+ // tslint:disable-next-line:custom-no-magic-numbers
+ const paddedValue = ethUtil.setLengthLeft(encodedValue, constants.WORD_LENGTH);
+ return paddedValue;
+ },
+ decodeUint256(encodedValue: Buffer): BigNumber {
+ const formattedValue = ethUtil.bufferToHex(encodedValue);
+ const value = new BigNumber(formattedValue, constants.BASE_16);
+ return value;
+ },
+};