@0x/contracts-exchange: Rename WalletOrderValidator to OrderWallet signature type

`@0x/contracts-exchange`: Rename `SignatureWalletOrderValidatorError` to `SignatureOrderWalletError`
`@0x/contracts-exchange`: Add `IEIP1271Wallet` interface
`@0x/contracts-exchange`: Add `EIP1271Wallet` and `EIP1271OrderWallet` to `SignatureType`
`@0x/contracts-exchange`: Always check `OrderValidator`, `OrderWallet`, `EIP1271OrderWallet` signature types on every fill
`@0x/contracts-exchange`: Add tests for EIP1271 signature types.
`@0x/contracts-exchange`: Update `LibExchangeRichErrorDecoder` for new/renamed Error types.
This commit is contained in:
Lawrence Forman
2019-06-21 21:26:50 -04:00
committed by Amir Bandeali
parent bd5babf65d
commit 33df11b755
14 changed files with 570 additions and 95 deletions

View File

@@ -35,7 +35,6 @@ import { RevertReason, SignatureType, SignedOrder } from '@0x/types';
import { BigNumber, providerUtils, StringRevertError } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import * as crypto from 'crypto';
import { LogWithDecodedArgs } from 'ethereum-types';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
@@ -144,6 +143,7 @@ describe('Exchange core', () => {
artifacts.TestValidatorWallet,
provider,
txDefaults,
exchange.address,
);
reentrantErc20Token = await ReentrantERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.ReentrantERC20Token,
@@ -314,9 +314,9 @@ describe('Exchange core', () => {
return expect(tx).to.revertWith(expectedError);
});
it('should revert if `WalletOrderValidator` signature type rejects during a second fill', async () => {
it('should revert if `OrderWallet` signature type rejects during a second fill', async () => {
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.WalletOrderValidator]),
ethUtil.toBuffer([SignatureType.OrderWallet]),
]);
signedOrder.makerAddress = validatorWallet.address;
signedOrder.signature = ethUtil.bufferToHex(signature);
@@ -352,6 +352,45 @@ describe('Exchange core', () => {
);
return expect(tx).to.revertWith(expectedError);
});
it('should revert if `EIP1271OrderWallet` signature type rejects during a second fill', async () => {
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271OrderWallet]),
]);
signedOrder.makerAddress = validatorWallet.address;
signedOrder.signature = ethUtil.bufferToHex(signature);
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
// Allow the signature check for the first fill.
await validatorWallet.setValidateAction.awaitTransactionSuccessAsync(
orderHashHex,
ValidatorWalletAction.Accept,
signedOrder.makerAddress,
);
const fillAmount = signedOrder.takerAssetAmount.div(10);
await exchangeWrapper.fillOrderAsync(
signedOrder,
takerAddress,
{ takerAssetFillAmount: fillAmount },
);
// Reject the signature check for the second fill.
await validatorWallet.setValidateAction.awaitTransactionSuccessAsync(
orderHashHex,
ValidatorWalletAction.Reject,
signedOrder.makerAddress,
);
const tx = exchangeWrapper.fillOrderAsync(
signedOrder,
takerAddress,
{ takerAssetFillAmount: fillAmount },
);
const expectedError = new ExchangeRevertErrors.SignatureError(
ExchangeRevertErrors.SignatureErrorCode.BadSignature,
orderHashHex,
signedOrder.makerAddress,
signedOrder.signature,
);
return expect(tx).to.revertWith(expectedError);
});
});
it('should throw if fully filled', async () => {