protocol/packages/order-utils/test/eip712_utils_test.ts
Jacob Evans 9e8031d5e3
Throw and handle errors from Providers.
In web3 wrapper when a response contains an error field we throw this rather than return response.result which is often undefined.
In Signature Utils we handle the error thrown when a user rejects the signing dialogue to prevent double signing.
Exposed the ZeroExTransaction JSON schema.
In Website only use the MetamaskSubprovider if we can detect the provider is Metamask
2018-10-09 19:01:36 +11:00

45 lines
1.6 KiB
TypeScript

import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import 'mocha';
import { constants } from '../src/constants';
import { eip712Utils } from '../src/eip712_utils';
import { chaiSetup } from './utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
describe('EIP712 Utils', () => {
describe('createTypedData', () => {
it('adds in the EIP712DomainSeparator', () => {
const primaryType = 'Test';
const typedData = eip712Utils.createTypedData(
primaryType,
{ Test: [{ name: 'testValue', type: 'uint256' }] },
{ testValue: '1' },
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(typedData.primaryType).to.eq(primaryType);
});
});
describe('createTypedData', () => {
it('adds in the EIP712DomainSeparator', () => {
const typedData = eip712Utils.createZeroExTransactionTypedData(
{
salt: new BigNumber('0'),
data: constants.NULL_BYTES,
signerAddress: constants.NULL_ADDRESS,
},
constants.NULL_ADDRESS,
);
expect(typedData.primaryType).to.eq(constants.EIP712_ZEROEX_TRANSACTION_SCHEMA.name);
expect(typedData.types.EIP712Domain).to.not.be.undefined();
});
});
});