Add ApprovalFactory class
This commit is contained in:
@@ -7,13 +7,19 @@ import {
|
||||
web3Wrapper,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { transactionHashUtils } from '@0x/order-utils';
|
||||
import { RevertReason } from '@0x/types';
|
||||
import { RevertReason, SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
|
||||
import { artifacts, MixinSignatureValidatorContract, TECSignatureType, TECTransactionFactory } from '../src';
|
||||
import {
|
||||
ApprovalFactory,
|
||||
artifacts,
|
||||
hashUtils,
|
||||
TECSignatureType,
|
||||
TECTransactionFactory,
|
||||
TestMixinsContract,
|
||||
} from '../src';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
@@ -22,8 +28,10 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
describe('Mixins tests', () => {
|
||||
let transactionSignerAddress: string;
|
||||
let approvalSignerAddress: string;
|
||||
let signatureValidator: MixinSignatureValidatorContract;
|
||||
let mixins: TestMixinsContract;
|
||||
let transactionFactory: TECTransactionFactory;
|
||||
let approvalFactory: ApprovalFactory;
|
||||
let defaultOrder: SignedOrder;
|
||||
|
||||
before(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@@ -32,16 +40,29 @@ describe('Mixins tests', () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
signatureValidator = await MixinSignatureValidatorContract.deployFrom0xArtifactAsync(
|
||||
artifacts.MixinSignatureValidator,
|
||||
provider,
|
||||
txDefaults,
|
||||
);
|
||||
mixins = await TestMixinsContract.deployFrom0xArtifactAsync(artifacts.TestMixins, provider, txDefaults);
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
[transactionSignerAddress, approvalSignerAddress] = accounts.slice(0, 2);
|
||||
defaultOrder = {
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
makerAddress: constants.NULL_ADDRESS,
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
senderAddress: mixins.address,
|
||||
feeRecipientAddress: approvalSignerAddress,
|
||||
makerAssetData: constants.NULL_BYTES,
|
||||
takerAssetData: constants.NULL_BYTES,
|
||||
makerAssetAmount: constants.ZERO_AMOUNT,
|
||||
takerAssetAmount: constants.ZERO_AMOUNT,
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
expirationTimeSeconds: constants.ZERO_AMOUNT,
|
||||
salt: constants.ZERO_AMOUNT,
|
||||
signature: constants.NULL_BYTES,
|
||||
};
|
||||
const transactionSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[0];
|
||||
const approvalSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[1];
|
||||
transactionFactory = new TECTransactionFactory(transactionSignerPrivateKey, signatureValidator.address);
|
||||
transactionFactory = new TECTransactionFactory(transactionSignerPrivateKey, mixins.address);
|
||||
approvalFactory = new ApprovalFactory(approvalSignerPrivateKey);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@@ -54,21 +75,15 @@ describe('Mixins tests', () => {
|
||||
it('should return the correct address using the EthSign signature type', async () => {
|
||||
const data = constants.NULL_BYTES;
|
||||
const transaction = transactionFactory.newSignedTECTransaction(data, TECSignatureType.EthSign);
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
const signerAddress = await signatureValidator.getSignerAddress.callAsync(
|
||||
transactionHash,
|
||||
transaction.signature,
|
||||
);
|
||||
const transactionHash = hashUtils.getTransactionHashHex(transaction);
|
||||
const signerAddress = await mixins.getSignerAddress.callAsync(transactionHash, transaction.signature);
|
||||
expect(transaction.signerAddress).to.eq(signerAddress);
|
||||
});
|
||||
it('should return the correct address using the EIP712 signature type', async () => {
|
||||
const data = constants.NULL_BYTES;
|
||||
const transaction = transactionFactory.newSignedTECTransaction(data, TECSignatureType.EIP712);
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
const signerAddress = await signatureValidator.getSignerAddress.callAsync(
|
||||
transactionHash,
|
||||
transaction.signature,
|
||||
);
|
||||
const transactionHash = hashUtils.getTransactionHashHex(transaction);
|
||||
const signerAddress = await mixins.getSignerAddress.callAsync(transactionHash, transaction.signature);
|
||||
expect(transaction.signerAddress).to.eq(signerAddress);
|
||||
});
|
||||
it('should revert with with the Illegal signature type', async () => {
|
||||
@@ -79,9 +94,9 @@ describe('Mixins tests', () => {
|
||||
0,
|
||||
transaction.signature.length - 2,
|
||||
)}${illegalSignatureByte}`;
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
const transactionHash = hashUtils.getTransactionHashHex(transaction);
|
||||
expectContractCallFailedAsync(
|
||||
signatureValidator.getSignerAddress.callAsync(transactionHash, transaction.signature),
|
||||
mixins.getSignerAddress.callAsync(transactionHash, transaction.signature),
|
||||
RevertReason.SignatureIllegal,
|
||||
);
|
||||
});
|
||||
@@ -93,11 +108,15 @@ describe('Mixins tests', () => {
|
||||
0,
|
||||
transaction.signature.length - 2,
|
||||
)}${invalidSignatureByte}`;
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
const transactionHash = hashUtils.getTransactionHashHex(transaction);
|
||||
expectContractCallFailedAsync(
|
||||
signatureValidator.getSignerAddress.callAsync(transactionHash, transaction.signature),
|
||||
mixins.getSignerAddress.callAsync(transactionHash, transaction.signature),
|
||||
RevertReason.SignatureUnsupported,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('assertValidSingleOrderApproval', () => {});
|
||||
describe('assertValidBatchOrderApproval', () => {});
|
||||
describe('assertValidTECApproval', () => {});
|
||||
});
|
||||
|
Reference in New Issue
Block a user