diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-10 09:25:14 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-10 09:25:14 +0800 |
commit | 2bd8cbb80cadc922ca13582a1f15d63815118205 (patch) | |
tree | f81ae5e91e720fe228d83b0e8af0fc676f35b7c5 /packages/utils/test | |
parent | 941448d65cc42870a93e0430158bfd7ab52fd2cd (diff) | |
parent | afb34da72978b5272cfb5a235498e483c72556bc (diff) | |
download | dexon-sol-tools-2bd8cbb80cadc922ca13582a1f15d63815118205.tar dexon-sol-tools-2bd8cbb80cadc922ca13582a1f15d63815118205.tar.gz dexon-sol-tools-2bd8cbb80cadc922ca13582a1f15d63815118205.tar.bz2 dexon-sol-tools-2bd8cbb80cadc922ca13582a1f15d63815118205.tar.lz dexon-sol-tools-2bd8cbb80cadc922ca13582a1f15d63815118205.tar.xz dexon-sol-tools-2bd8cbb80cadc922ca13582a1f15d63815118205.tar.zst dexon-sol-tools-2bd8cbb80cadc922ca13582a1f15d63815118205.zip |
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/instant/redux-styles-container
Diffstat (limited to 'packages/utils/test')
-rw-r--r-- | packages/utils/test/sign_typed_data_utils_test.ts | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/packages/utils/test/sign_typed_data_utils_test.ts b/packages/utils/test/sign_typed_data_utils_test.ts new file mode 100644 index 000000000..dcba08b04 --- /dev/null +++ b/packages/utils/test/sign_typed_data_utils_test.ts @@ -0,0 +1,140 @@ +import * as chai from 'chai'; +import 'mocha'; + +import { signTypedDataUtils } from '../src/sign_typed_data_utils'; + +const expect = chai.expect; + +describe('signTypedDataUtils', () => { + describe('signTypedDataHash', () => { + const simpleSignTypedDataHashHex = '0xb460d69ca60383293877cd765c0f97bd832d66bca720f7e32222ce1118832493'; + const simpleSignTypedData = { + types: { + EIP712Domain: [ + { + name: 'name', + type: 'string', + }, + ], + Test: [ + { + name: 'testAddress', + type: 'address', + }, + { + name: 'testNumber', + type: 'uint256', + }, + ], + }, + domain: { + name: 'Test', + }, + message: { + testAddress: '0x0000000000000000000000000000000000000000', + testNumber: '12345', + }, + primaryType: 'Test', + }; + const orderSignTypedDataHashHex = '0x55eaa6ec02f3224d30873577e9ddd069a288c16d6fb407210eecbc501fa76692'; + const orderSignTypedData = { + types: { + EIP712Domain: [ + { + name: 'name', + type: 'string', + }, + { + name: 'version', + type: 'string', + }, + { + name: 'verifyingContract', + type: 'address', + }, + ], + Order: [ + { + name: 'makerAddress', + type: 'address', + }, + { + name: 'takerAddress', + type: 'address', + }, + { + name: 'feeRecipientAddress', + type: 'address', + }, + { + name: 'senderAddress', + type: 'address', + }, + { + name: 'makerAssetAmount', + type: 'uint256', + }, + { + name: 'takerAssetAmount', + type: 'uint256', + }, + { + name: 'makerFee', + type: 'uint256', + }, + { + name: 'takerFee', + type: 'uint256', + }, + { + name: 'expirationTimeSeconds', + type: 'uint256', + }, + { + name: 'salt', + type: 'uint256', + }, + { + name: 'makerAssetData', + type: 'bytes', + }, + { + name: 'takerAssetData', + type: 'bytes', + }, + ], + }, + domain: { + name: '0x Protocol', + version: '2', + verifyingContract: '0x0000000000000000000000000000000000000000', + }, + message: { + makerAddress: '0x0000000000000000000000000000000000000000', + takerAddress: '0x0000000000000000000000000000000000000000', + makerAssetAmount: '1000000000000000000', + takerAssetAmount: '1000000000000000000', + expirationTimeSeconds: '12345', + makerFee: '0', + takerFee: '0', + feeRecipientAddress: '0x0000000000000000000000000000000000000000', + senderAddress: '0x0000000000000000000000000000000000000000', + salt: '12345', + makerAssetData: '0x0000000000000000000000000000000000000000', + takerAssetData: '0x0000000000000000000000000000000000000000', + exchangeAddress: '0x0000000000000000000000000000000000000000', + }, + primaryType: 'Order', + }; + it('creates a hash of the test sign typed data', () => { + const hash = signTypedDataUtils.generateTypedDataHash(simpleSignTypedData).toString('hex'); + const hashHex = `0x${hash}`; + expect(hashHex).to.be.eq(simpleSignTypedDataHashHex); + }); + it('creates a hash of the order sign typed data', () => { + const hash = signTypedDataUtils.generateTypedDataHash(orderSignTypedData).toString('hex'); + const hashHex = `0x${hash}`; + expect(hashHex).to.be.eq(orderSignTypedDataHashHex); + }); + }); +}); |