diff options
Diffstat (limited to 'packages/order-utils/test/eip712_utils_test.ts')
-rw-r--r-- | packages/order-utils/test/eip712_utils_test.ts | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/packages/order-utils/test/eip712_utils_test.ts b/packages/order-utils/test/eip712_utils_test.ts index fb9388fcc..4208e9beb 100644 --- a/packages/order-utils/test/eip712_utils_test.ts +++ b/packages/order-utils/test/eip712_utils_test.ts @@ -3,7 +3,12 @@ import * as chai from 'chai'; import 'mocha'; import { constants } from '../src/constants'; -import { eip712Utils } from '../src/eip712_utils'; +import { + eip712Utils, + EXCHANGE_DOMAIN_NAME, + EXCHANGE_DOMAIN_VERSION, + EXCHANGE_ZEROEX_TRANSACTION_SCHEMA, +} from '../src/eip712_utils'; import { chaiSetup } from './utils/chai_setup'; @@ -12,22 +17,42 @@ const expect = chai.expect; describe('EIP712 Utils', () => { describe('createTypedData', () => { - it('adds in the EIP712DomainSeparator', () => { + it('adds in the EIP712DomainSeparator with default values', () => { + const primaryType = 'Test'; + const typedData = eip712Utils.createTypedData( + primaryType, + { Test: [{ name: 'testValue', type: 'uint256' }] }, + { testValue: '1' }, + { verifyingContractAddress: constants.NULL_ADDRESS }, + ); + expect(typedData.domain).to.not.be.undefined(); + expect(typedData.types.EIP712Domain).to.not.be.undefined(); + const domainObject = typedData.domain; + expect(domainObject.name).to.eq(EXCHANGE_DOMAIN_NAME); + expect(domainObject.version).to.eq(EXCHANGE_DOMAIN_VERSION); + expect(domainObject.verifyingContract).to.eq(constants.NULL_ADDRESS); + expect(typedData.primaryType).to.eq(primaryType); + }); + it('adds in the EIP712DomainSeparator without default values', () => { const primaryType = 'Test'; + const domainName = 'testDomain'; + const domainVersion = 'testVersion'; const typedData = eip712Utils.createTypedData( primaryType, { Test: [{ name: 'testValue', type: 'uint256' }] }, { testValue: '1' }, - constants.NULL_ADDRESS, + { name: domainName, version: domainVersion, verifyingContractAddress: constants.NULL_ADDRESS }, ); expect(typedData.domain).to.not.be.undefined(); expect(typedData.types.EIP712Domain).to.not.be.undefined(); const domainObject = typedData.domain; - expect(domainObject.name).to.eq(constants.EIP712_DOMAIN_NAME); + expect(domainObject.name).to.eq(domainName); + expect(domainObject.version).to.eq(domainVersion); + expect(domainObject.verifyingContract).to.eq(constants.NULL_ADDRESS); expect(typedData.primaryType).to.eq(primaryType); }); }); - describe('createTypedData', () => { + describe('createZeroExTransactionTypedData', () => { it('adds in the EIP712DomainSeparator', () => { const typedData = eip712Utils.createZeroExTransactionTypedData({ salt: new BigNumber('0'), @@ -35,8 +60,12 @@ describe('EIP712 Utils', () => { signerAddress: constants.NULL_ADDRESS, verifyingContractAddress: constants.NULL_ADDRESS, }); - expect(typedData.primaryType).to.eq(constants.EIP712_ZEROEX_TRANSACTION_SCHEMA.name); + expect(typedData.primaryType).to.eq(EXCHANGE_ZEROEX_TRANSACTION_SCHEMA.name); expect(typedData.types.EIP712Domain).to.not.be.undefined(); + const domainObject = typedData.domain; + expect(domainObject.name).to.eq(EXCHANGE_DOMAIN_NAME); + expect(domainObject.version).to.eq(EXCHANGE_DOMAIN_VERSION); + expect(domainObject.verifyingContract).to.eq(constants.NULL_ADDRESS); }); }); }); |