Run prettier/linter

This commit is contained in:
Lawrence Forman 2019-06-21 21:44:26 -04:00 committed by Amir Bandeali
parent 33df11b755
commit 309dd7f300
5 changed files with 154 additions and 256 deletions

View File

@ -31,6 +31,7 @@ interface ISimplifiedExchange {
returns (bytes32 orderHash);
}
// solhint-disable no-unused-vars
contract TestValidatorWallet {
using LibBytes for bytes;
@ -53,8 +54,9 @@ contract TestValidatorWallet {
ValidateSignature,
NTypes
}
/// @dev The Exchange contract.
ISimplifiedExchange internal _EXCHANGE;
ISimplifiedExchange internal _exchange;
/// @dev Internal state to modify.
uint256 internal _state = 1;
/// @dev What action to execute when a hash is validated .
@ -63,7 +65,21 @@ contract TestValidatorWallet {
mapping (bytes32=>address) internal _validSignerForHash;
constructor(address exchange) public {
_EXCHANGE = ISimplifiedExchange(exchange);
_exchange = ISimplifiedExchange(exchange);
}
/// @dev Approves an ERC20 token to spend tokens from this address.
/// @param token Address of ERC20 token.
/// @param spender Address that will spend tokens.
/// @param value Amount of tokens spender is approved to spend.
function approveERC20(
address token,
address spender,
uint256 value
)
external
{
IERC20Token(token).approve(spender, value);
}
/// @dev Set the action to take when validating a hash.
@ -80,7 +96,7 @@ contract TestValidatorWallet {
external
{
if (uint8(action) >= uint8(ValidatorAction.NTypes)) {
revert('UNSUPPORTED_VALIDATE_ACTION');
revert("UNSUPPORTED_VALIDATE_ACTION");
}
_hashActions[hash] = action;
_validSignerForHash[hash] = allowedSigner;
@ -101,6 +117,7 @@ contract TestValidatorWallet {
{
bytes32 hash = _getOrderHashFromEIP1271Data(data);
ValidatorAction action = _hashActions[hash];
// solhint-disable-next-line no-empty-blocks
if (action == ValidatorAction.Reject) {
// NOOP.
} else if (action == ValidatorAction.Accept) {
@ -122,38 +139,6 @@ contract TestValidatorWallet {
}
}
function _getOrderHashFromEIP1271Data(bytes memory data)
private
returns (bytes32 hash)
{
if (data.length == 32) {
// `data` is an order hash.
hash = data.readBytes32(0);
} else {
// `data` is an abi-encoded Order.
LibOrder.Order memory order = _getOrderFromEIP1271Data(data);
// Use the Exchange contract to convert it into a hash.
hash = _EXCHANGE.getOrderHash(order);
}
}
function _getOrderFromEIP1271Data(bytes memory data)
private
returns (LibOrder.Order memory order)
{
require(data.length > 32, "INVALID_EIP1271_ORDER_DATA_LENGTH");
assembly {
// Skip past the length to find the first parameter.
let argsStart := add(data, 32)
order := add(argsStart, mload(argsStart))
// Destructively point the asset data fields to absolute locations.
for {let o := 0x140} lt(o, 0x1C0) {o := add(o, 0x20)} {
let arg := add(order, o)
mstore(arg, add(argsStart, add(mload(arg), 0x20)))
}
}
}
/// @dev Validates a hash with the `Validator` signature type.
/// @param hash Message hash that is signed.
/// @param signerAddress Address that should have signed the given hash.
@ -240,23 +225,9 @@ contract TestValidatorWallet {
}
}
/// @dev Approves an ERC20 token to spend tokens from this address.
/// @param token Address of ERC20 token.
/// @param spender Address that will spend tokens.
/// @param value Amount of tokens spender is approved to spend.
function approveERC20(
address token,
address spender,
uint256 value
)
external
{
IERC20Token(token).approve(spender, value);
}
/// @dev Increments state variable.
function _updateState()
internal
private
{
_state++;
}
@ -267,7 +238,7 @@ contract TestValidatorWallet {
bytes memory signature,
address signerAddress
)
internal
private
pure
returns (bool isSignedBy)
{
@ -289,4 +260,37 @@ contract TestValidatorWallet {
}
isSignedBy = recovered == signerAddress;
}
function _getOrderHashFromEIP1271Data(bytes memory data)
private
returns (bytes32 hash)
{
if (data.length == 32) {
// `data` is an order hash.
hash = data.readBytes32(0);
} else {
// `data` is an abi-encoded Order.
LibOrder.Order memory order = _getOrderFromEIP1271Data(data);
// Use the Exchange contract to convert it into a hash.
hash = _exchange.getOrderHash(order);
}
}
function _getOrderFromEIP1271Data(bytes memory data)
private
returns (LibOrder.Order memory order)
{
require(data.length > 32, "INVALID_EIP1271_ORDER_DATA_LENGTH");
assembly {
// Skip past the length to find the first parameter.
let argsStart := add(data, 32)
order := add(argsStart, mload(argsStart))
// Destructively point the asset data fields to absolute locations.
for {let o := 0x140} lt(o, 0x1C0) {o := add(o, 0x20)} {
let arg := add(order, o)
mstore(arg, add(argsStart, add(mload(arg), 0x20)))
}
}
}
}

View File

@ -264,11 +264,9 @@ describe('Exchange core', () => {
constants.INITIAL_ERC20_BALANCE,
);
// Approve the order validator.
await exchange.setOrderValidatorApproval.awaitTransactionSuccessAsync(
validatorWallet.address,
true,
{ from: makerAddress },
);
await exchange.setOrderValidatorApproval.awaitTransactionSuccessAsync(validatorWallet.address, true, {
from: makerAddress,
});
signedOrder = await orderFactory.newSignedOrderAsync({
makerFee: constants.ZERO_AMOUNT,
takerFee: constants.ZERO_AMOUNT,
@ -289,22 +287,16 @@ describe('Exchange core', () => {
makerAddress,
);
const fillAmount = signedOrder.takerAssetAmount.div(10);
await exchangeWrapper.fillOrderAsync(
signedOrder,
takerAddress,
{ takerAssetFillAmount: fillAmount },
);
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: fillAmount });
// Reject the signature check for the second fill.
await validatorWallet.setValidateAction.awaitTransactionSuccessAsync(
orderHashHex,
ValidatorWalletAction.Reject,
makerAddress,
);
const tx = exchangeWrapper.fillOrderAsync(
signedOrder,
takerAddress,
{ takerAssetFillAmount: fillAmount },
);
const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: fillAmount,
});
const expectedError = new ExchangeRevertErrors.SignatureError(
ExchangeRevertErrors.SignatureErrorCode.BadSignature,
orderHashHex,
@ -315,9 +307,7 @@ describe('Exchange core', () => {
});
it('should revert if `OrderWallet` signature type rejects during a second fill', async () => {
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.OrderWallet])]);
signedOrder.makerAddress = validatorWallet.address;
signedOrder.signature = ethUtil.bufferToHex(signature);
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
@ -328,22 +318,16 @@ describe('Exchange core', () => {
makerAddress,
);
const fillAmount = signedOrder.takerAssetAmount.div(10);
await exchangeWrapper.fillOrderAsync(
signedOrder,
takerAddress,
{ takerAssetFillAmount: fillAmount },
);
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: fillAmount });
// Reject the signature check for the second fill.
await validatorWallet.setValidateAction.awaitTransactionSuccessAsync(
orderHashHex,
ValidatorWalletAction.Reject,
makerAddress,
);
const tx = exchangeWrapper.fillOrderAsync(
signedOrder,
takerAddress,
{ takerAssetFillAmount: fillAmount },
);
const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: fillAmount,
});
const expectedError = new ExchangeRevertErrors.SignatureError(
ExchangeRevertErrors.SignatureErrorCode.BadSignature,
orderHashHex,
@ -354,9 +338,7 @@ describe('Exchange core', () => {
});
it('should revert if `EIP1271OrderWallet` signature type rejects during a second fill', async () => {
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271OrderWallet])]);
signedOrder.makerAddress = validatorWallet.address;
signedOrder.signature = ethUtil.bufferToHex(signature);
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
@ -367,22 +349,16 @@ describe('Exchange core', () => {
signedOrder.makerAddress,
);
const fillAmount = signedOrder.takerAssetAmount.div(10);
await exchangeWrapper.fillOrderAsync(
signedOrder,
takerAddress,
{ takerAssetFillAmount: fillAmount },
);
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 tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: fillAmount,
});
const expectedError = new ExchangeRevertErrors.SignatureError(
ExchangeRevertErrors.SignatureErrorCode.BadSignature,
orderHashHex,

View File

@ -81,9 +81,21 @@ describe('LibExchangeRichErrorDecoder', () => {
createDecodeTest(ExchangeRevertErrors.SignatureError, [errorCode, orderHash, signer, signature]);
createDecodeTest(ExchangeRevertErrors.SignatureValidatorNotApprovedError, [signer, validator]);
createDecodeTest(ExchangeRevertErrors.SignatureOrderValidatorNotApprovedError, [signer, validator]);
createDecodeTest(ExchangeRevertErrors.SignatureValidatorError, [orderHash, signer, validator, signature, errorData]);
createDecodeTest(ExchangeRevertErrors.SignatureValidatorError, [
orderHash,
signer,
validator,
signature,
errorData,
]);
createDecodeTest(ExchangeRevertErrors.SignatureWalletError, [orderHash, signer, signature, errorData]);
createDecodeTest(ExchangeRevertErrors.SignatureOrderValidatorError, [orderHash, signer, validator, signature, errorData]);
createDecodeTest(ExchangeRevertErrors.SignatureOrderValidatorError, [
orderHash,
signer,
validator,
signature,
errorData,
]);
createDecodeTest(ExchangeRevertErrors.SignatureOrderWalletError, [orderHash, signer, signature, errorData]);
})();

View File

@ -71,19 +71,21 @@ describe('MixinSignatureValidator', () => {
validatorWalletRevertReason = await validatorWallet.REVERT_REASON.callAsync();
// Approve the validator for both signers.
await Promise.all([signerAddress, notSignerAddress].map(async (addr: string) => {
const tx1 = signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
validatorWallet.address,
true,
{ from: addr },
);
const tx2 = signatureValidator.setOrderValidatorApproval.awaitTransactionSuccessAsync(
validatorWallet.address,
true,
{ from: addr },
);
return Promise.all([tx1, tx2]);
}));
await Promise.all(
[signerAddress, notSignerAddress].map(async (addr: string) => {
const tx1 = signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
validatorWallet.address,
true,
{ from: addr },
);
const tx2 = signatureValidator.setOrderValidatorApproval.awaitTransactionSuccessAsync(
validatorWallet.address,
true,
{ from: addr },
);
return Promise.all([tx1, tx2]);
}),
);
const defaultOrderParams = {
...constants.STATIC_ORDER_PARAMS,
@ -130,11 +132,7 @@ describe('MixinSignatureValidator', () => {
signedOrder.makerAddress,
emptySignature,
);
const tx = validateCallAsync(
signedOrder,
signedOrder.makerAddress,
emptySignature,
);
const tx = validateCallAsync(signedOrder, signedOrder.makerAddress, emptySignature);
return expect(tx).to.revertWith(expectedError);
});
@ -148,11 +146,7 @@ describe('MixinSignatureValidator', () => {
signedOrder.makerAddress,
unsupportedSignatureHex,
);
const tx = validateCallAsync(
signedOrder,
signedOrder.makerAddress,
unsupportedSignatureHex,
);
const tx = validateCallAsync(signedOrder, signedOrder.makerAddress, unsupportedSignatureHex);
return expect(tx).to.revertWith(expectedError);
});
@ -165,21 +159,13 @@ describe('MixinSignatureValidator', () => {
signedOrder.makerAddress,
illegalSignatureHex,
);
const tx = validateCallAsync(
signedOrder,
signedOrder.makerAddress,
illegalSignatureHex,
);
const tx = validateCallAsync(signedOrder, signedOrder.makerAddress, illegalSignatureHex);
return expect(tx).to.revertWith(expectedError);
});
it('should return false when SignatureType=Invalid and signature has a length of zero', async () => {
const signatureHex = `0x${Buffer.from([SignatureType.Invalid]).toString('hex')}`;
const isValidSignature = await validateCallAsync(
signedOrder,
signedOrder.makerAddress,
signatureHex,
);
const isValidSignature = await validateCallAsync(signedOrder, signedOrder.makerAddress, signatureHex);
expect(isValidSignature).to.be.false();
});
@ -195,21 +181,13 @@ describe('MixinSignatureValidator', () => {
signedOrder.makerAddress,
signatureHex,
);
const tx = validateCallAsync(
signedOrder,
signedOrder.makerAddress,
signatureHex,
);
const tx = validateCallAsync(signedOrder, signedOrder.makerAddress, signatureHex);
return expect(tx).to.revertWith(expectedError);
});
it('should return true when SignatureType=EIP712 and signature is valid', async () => {
// Validate signature
const isValidSignature = await validateCallAsync(
signedOrder,
signerAddress,
signedOrder.signature,
);
const isValidSignature = await validateCallAsync(signedOrder, signerAddress, signedOrder.signature);
expect(isValidSignature).to.be.true();
});
@ -221,11 +199,7 @@ describe('MixinSignatureValidator', () => {
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature.
// This will fail because `signerAddress` signed the message, but we're passing in `notSignerAddress`
const isValidSignature = await validateCallAsync(
signedOrder,
notSignerAddress,
signatureHex,
);
const isValidSignature = await validateCallAsync(signedOrder, notSignerAddress, signatureHex);
expect(isValidSignature).to.be.false();
});
@ -244,11 +218,7 @@ describe('MixinSignatureValidator', () => {
]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
signedOrder,
signerAddress,
signatureHex,
);
const isValidSignature = await validateCallAsync(signedOrder, signerAddress, signatureHex);
expect(isValidSignature).to.be.true();
});
@ -261,19 +231,13 @@ describe('MixinSignatureValidator', () => {
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature.
// This will fail because `signerAddress` signed the message, but we're passing in `notSignerAddress`
const isValidSignature = await validateCallAsync(
signedOrder,
signerAddress,
signatureHex,
);
const isValidSignature = await validateCallAsync(signedOrder, signerAddress, signatureHex);
expect(isValidSignature).to.be.false();
});
it('should return true when SignatureType=Wallet and signature is valid', async () => {
signedOrder.makerAddress = validatorWallet.address;
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.Wallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.Wallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
@ -287,9 +251,7 @@ describe('MixinSignatureValidator', () => {
it('should return false when SignatureType=Wallet and signature is invalid', async () => {
signedOrder.makerAddress = validatorWallet.address;
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.Wallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.Wallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
@ -304,9 +266,7 @@ describe('MixinSignatureValidator', () => {
it('should revert when validator attempts to update state and SignatureType=Wallet', async () => {
signedOrder.makerAddress = validatorWallet.address;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.Wallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.Wallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
const expectedError = new ExchangeRevertErrors.SignatureWalletError(
orderHashHex,
@ -326,9 +286,7 @@ describe('MixinSignatureValidator', () => {
it('should revert when validator reverts and SignatureType=Wallet', async () => {
signedOrder.makerAddress = validatorWallet.address;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.Wallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.Wallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
const expectedError = new ExchangeRevertErrors.SignatureWalletError(
orderHashHex,
@ -391,12 +349,7 @@ describe('MixinSignatureValidator', () => {
signatureHex,
constants.NULL_BYTES,
);
const tx = validateCallAsync(
signedOrder,
signerAddress,
signatureHex,
ValidatorWalletAction.UpdateState,
);
const tx = validateCallAsync(signedOrder, signerAddress, signatureHex, ValidatorWalletAction.UpdateState);
return expect(tx).to.revertWith(expectedError);
});
@ -415,12 +368,7 @@ describe('MixinSignatureValidator', () => {
signatureHex,
new StringRevertError(validatorWalletRevertReason).encode(),
);
const tx = validateCallAsync(
signedOrder,
signerAddress,
signatureHex,
ValidatorWalletAction.Revert,
);
const tx = validateCallAsync(signedOrder, signerAddress, signatureHex, ValidatorWalletAction.Revert);
return expect(tx).to.revertWith(expectedError);
});
@ -453,9 +401,7 @@ describe('MixinSignatureValidator', () => {
it('should return true when SignatureType=EIP1271Wallet and signature is valid', async () => {
signedOrder.makerAddress = validatorWallet.address;
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271Wallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271Wallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
@ -469,9 +415,7 @@ describe('MixinSignatureValidator', () => {
it('should return false when SignatureType=EIP1271Wallet and signature is invalid', async () => {
signedOrder.makerAddress = validatorWallet.address;
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271Wallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271Wallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
@ -486,9 +430,7 @@ describe('MixinSignatureValidator', () => {
it('should revert when validator attempts to update state and SignatureType=EIP1271Wallet', async () => {
signedOrder.makerAddress = validatorWallet.address;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271Wallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271Wallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
const expectedError = new ExchangeRevertErrors.SignatureWalletError(
orderHashHex,
@ -508,9 +450,7 @@ describe('MixinSignatureValidator', () => {
it('should revert when validator reverts and SignatureType=EIP1271Wallet', async () => {
signedOrder.makerAddress = validatorWallet.address;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271Wallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271Wallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
const expectedError = new ExchangeRevertErrors.SignatureWalletError(
orderHashHex,
@ -530,26 +470,20 @@ describe('MixinSignatureValidator', () => {
it('should return true when SignatureType=Presigned and signer has presigned hash', async () => {
// Presign hash
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
await signatureValidator.preSign.awaitTransactionSuccessAsync(orderHashHex, { from: signedOrder.makerAddress });
await signatureValidator.preSign.awaitTransactionSuccessAsync(orderHashHex, {
from: signedOrder.makerAddress,
});
// Validate presigned signature
const signature = ethUtil.toBuffer(`0x${SignatureType.PreSigned}`);
const signatureHex = ethUtil.bufferToHex(signature);
const isValidSignature = await validateCallAsync(
signedOrder,
signedOrder.makerAddress,
signatureHex,
);
const isValidSignature = await validateCallAsync(signedOrder, signedOrder.makerAddress, signatureHex);
expect(isValidSignature).to.be.true();
});
it('should return false when SignatureType=Presigned and signer has not presigned hash', async () => {
const signature = ethUtil.toBuffer(`0x${SignatureType.PreSigned}`);
const signatureHex = ethUtil.bufferToHex(signature);
const isValidSignature = await validateCallAsync(
signedOrder,
signedOrder.makerAddress,
signatureHex,
);
const isValidSignature = await validateCallAsync(signedOrder, signedOrder.makerAddress, signatureHex);
expect(isValidSignature).to.be.false();
});
};
@ -569,11 +503,7 @@ describe('MixinSignatureValidator', () => {
validSigner,
);
}
return signatureValidator.isValidHashSignature.callAsync(
orderHashHex,
order.makerAddress,
signatureHex,
);
return signatureValidator.isValidHashSignature.callAsync(orderHashHex, order.makerAddress, signatureHex);
};
beforeEach(async () => {
@ -652,11 +582,7 @@ describe('MixinSignatureValidator', () => {
validSigner,
);
}
return signatureValidator.isValidOrderSignature.callAsync(
order,
order.makerAddress,
signatureHex,
);
return signatureValidator.isValidOrderSignature.callAsync(order, order.makerAddress, signatureHex);
};
beforeEach(async () => {
@ -710,12 +636,7 @@ describe('MixinSignatureValidator', () => {
signatureHex,
constants.NULL_BYTES,
);
const tx = validateCallAsync(
signedOrder,
signerAddress,
signatureHex,
ValidatorWalletAction.UpdateState,
);
const tx = validateCallAsync(signedOrder, signerAddress, signatureHex, ValidatorWalletAction.UpdateState);
return expect(tx).to.revertWith(expectedError);
});
@ -734,12 +655,7 @@ describe('MixinSignatureValidator', () => {
signatureHex,
new StringRevertError(validatorWalletRevertReason).encode(),
);
const tx = validateCallAsync(
signedOrder,
signerAddress,
signatureHex,
ValidatorWalletAction.Revert,
);
const tx = validateCallAsync(signedOrder, signerAddress, signatureHex, ValidatorWalletAction.Revert);
return expect(tx).to.revertWith(expectedError);
});
@ -771,9 +687,7 @@ describe('MixinSignatureValidator', () => {
it('should return true when SignatureType=OrderWallet and signature is valid', async () => {
signedOrder.makerAddress = validatorWallet.address;
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.OrderWallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
@ -787,9 +701,7 @@ describe('MixinSignatureValidator', () => {
it('should return false when SignatureType=OrderWallet and signature is invalid', async () => {
signedOrder.makerAddress = validatorWallet.address;
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.OrderWallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
@ -804,9 +716,7 @@ describe('MixinSignatureValidator', () => {
it('should revert when validator attempts to update state and SignatureType=OrderWallet', async () => {
signedOrder.makerAddress = validatorWallet.address;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.OrderWallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
const expectedError = new ExchangeRevertErrors.SignatureOrderWalletError(
orderHashHex,
@ -826,9 +736,7 @@ describe('MixinSignatureValidator', () => {
it('should revert when validator reverts and SignatureType=OrderWallet', async () => {
signedOrder.makerAddress = validatorWallet.address;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.OrderWallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
const expectedError = new ExchangeRevertErrors.SignatureOrderWalletError(
orderHashHex,
@ -847,9 +755,7 @@ describe('MixinSignatureValidator', () => {
it('should return true when SignatureType=EIP1271OrderWallet and signature is valid', async () => {
signedOrder.makerAddress = validatorWallet.address;
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271OrderWallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
@ -863,9 +769,7 @@ describe('MixinSignatureValidator', () => {
it('should return false when SignatureType=EIP1271OrderWallet and signature is invalid', async () => {
signedOrder.makerAddress = validatorWallet.address;
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271OrderWallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
// Validate signature
const isValidSignature = await validateCallAsync(
@ -880,9 +784,7 @@ describe('MixinSignatureValidator', () => {
it('should revert when validator attempts to update state and SignatureType=EIP1271OrderWallet', async () => {
signedOrder.makerAddress = validatorWallet.address;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271OrderWallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
const expectedError = new ExchangeRevertErrors.SignatureOrderWalletError(
orderHashHex,
@ -902,9 +804,7 @@ describe('MixinSignatureValidator', () => {
it('should revert when validator reverts and SignatureType=EIP1271OrderWallet', async () => {
signedOrder.makerAddress = validatorWallet.address;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const signature = Buffer.concat([
ethUtil.toBuffer([SignatureType.EIP1271OrderWallet]),
]);
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271OrderWallet])]);
const signatureHex = ethUtil.bufferToHex(signature);
const expectedError = new ExchangeRevertErrors.SignatureOrderWalletError(
orderHashHex,
@ -935,8 +835,9 @@ describe('MixinSignatureValidator', () => {
},
);
expect(res.logs.length).to.equal(1);
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as
LogWithDecodedArgs<TestSignatureValidatorSignatureValidatorApprovalEventArgs>;
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<
TestSignatureValidatorSignatureValidatorApprovalEventArgs
>;
const logArgs = log.args;
expect(logArgs.signerAddress).to.equal(signerAddress);
expect(logArgs.validatorAddress).to.equal(validatorWallet.address);
@ -952,8 +853,9 @@ describe('MixinSignatureValidator', () => {
},
);
expect(res.logs.length).to.equal(1);
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as
LogWithDecodedArgs<TestSignatureValidatorSignatureValidatorApprovalEventArgs>;
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<
TestSignatureValidatorSignatureValidatorApprovalEventArgs
>;
const logArgs = log.args;
expect(logArgs.signerAddress).to.equal(signerAddress);
expect(logArgs.validatorAddress).to.equal(validatorWallet.address);
@ -969,8 +871,9 @@ describe('MixinSignatureValidator', () => {
},
);
expect(res.logs.length).to.equal(1);
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as
LogWithDecodedArgs<TestSignatureValidatorSignatureValidatorApprovalEventArgs>;
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<
TestSignatureValidatorSignatureValidatorApprovalEventArgs
>;
const logArgs = log.args;
expect(logArgs.signerAddress).to.equal(signerAddress);
expect(logArgs.validatorAddress).to.equal(validatorWallet.address);
@ -986,8 +889,9 @@ describe('MixinSignatureValidator', () => {
},
);
expect(res.logs.length).to.equal(1);
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as
LogWithDecodedArgs<TestSignatureValidatorSignatureValidatorApprovalEventArgs>;
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<
TestSignatureValidatorSignatureValidatorApprovalEventArgs
>;
const logArgs = log.args;
expect(logArgs.signerAddress).to.equal(signerAddress);
expect(logArgs.validatorAddress).to.equal(validatorWallet.address);

View File

@ -45,19 +45,21 @@ export class PromiseWithTransactionHash<T> implements Promise<T> {
this.txHashPromise = txHashPromise;
this._promise = promise;
}
// tslint:disable-next-line:async-suffix
// tslint:disable:promise-function-async
// tslint:disable:async-suffix
public then<TResult>(
onFulfilled?: (v: T) => TResult | Promise<TResult>,
onRejected?: (reason: any) => Promise<never>,
): Promise<TResult> {
return this._promise.then<TResult>(onFulfilled, onRejected);
}
// tslint:disable-next-line:async-suffix
public catch<TResult>(onRejected?: (reason: any) => Promise<TResult>): Promise<TResult | T> {
return this._promise.catch(onRejected);
}
// tslint:enable:promise-function-async
// tslint:enable:async-suffix
get [Symbol.toStringTag](): 'Promise' {
return this._promise[Symbol.toStringTag];
return this._promise[Symbol.toStringTag];
}
}