aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/exchange/core.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-08-24 15:19:06 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-08-25 04:19:07 +0800
commit0a1ae2c31139e446b2fb3b7f03caf371c6668ae2 (patch)
tree3408f2db59daf3762dcb4244f52e3389c97849df /packages/contracts/test/exchange/core.ts
parentc5f8b9c2d2b1eed5789b40c4df07e98afe0431ab (diff)
downloaddexon-sol-tools-0a1ae2c31139e446b2fb3b7f03caf371c6668ae2.tar
dexon-sol-tools-0a1ae2c31139e446b2fb3b7f03caf371c6668ae2.tar.gz
dexon-sol-tools-0a1ae2c31139e446b2fb3b7f03caf371c6668ae2.tar.bz2
dexon-sol-tools-0a1ae2c31139e446b2fb3b7f03caf371c6668ae2.tar.lz
dexon-sol-tools-0a1ae2c31139e446b2fb3b7f03caf371c6668ae2.tar.xz
dexon-sol-tools-0a1ae2c31139e446b2fb3b7f03caf371c6668ae2.tar.zst
dexon-sol-tools-0a1ae2c31139e446b2fb3b7f03caf371c6668ae2.zip
Remove pragma experimental v0.5.0 and use staticcall is assembly
Diffstat (limited to 'packages/contracts/test/exchange/core.ts')
-rw-r--r--packages/contracts/test/exchange/core.ts59
1 files changed, 58 insertions, 1 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index bc2bad749..d3f9b95af 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
-import { RevertReason, SignedOrder } from '@0xproject/types';
+import { RevertReason, SignatureType, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
@@ -14,6 +14,7 @@ import { DummyNoReturnERC20TokenContract } from '../../generated_contract_wrappe
import { ERC20ProxyContract } from '../../generated_contract_wrappers/erc20_proxy';
import { ERC721ProxyContract } from '../../generated_contract_wrappers/erc721_proxy';
import { ExchangeCancelEventArgs, ExchangeContract } from '../../generated_contract_wrappers/exchange';
+import { TestStaticCallContract } from '../../generated_contract_wrappers/test_static_call';
import { artifacts } from '../utils/artifacts';
import { expectTransactionFailedAsync } from '../utils/assertions';
import { getLatestBlockTimestampAsync, increaseTimeAndMineBlockAsync } from '../utils/block_timestamp';
@@ -44,6 +45,8 @@ describe('Exchange core', () => {
let exchange: ExchangeContract;
let erc20Proxy: ERC20ProxyContract;
let erc721Proxy: ERC721ProxyContract;
+ let maliciousWallet: TestStaticCallContract;
+ let maliciousValidator: TestStaticCallContract;
let signedOrder: SignedOrder;
let erc20Balances: ERC20BalancesByOwner;
@@ -109,6 +112,12 @@ describe('Exchange core', () => {
constants.AWAIT_TRANSACTION_MINED_MS,
);
+ maliciousWallet = maliciousValidator = await TestStaticCallContract.deployFrom0xArtifactAsync(
+ artifacts.TestStaticCall,
+ provider,
+ txDefaults,
+ );
+
defaultMakerAssetAddress = erc20TokenA.address;
defaultTakerAssetAddress = erc20TokenB.address;
@@ -161,6 +170,54 @@ describe('Exchange core', () => {
RevertReason.OrderUnfillable,
);
});
+
+ it('should revert if `isValidSignature` tries to update state when SignatureType=Wallet', async () => {
+ const maliciousMakerAddress = maliciousWallet.address;
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20TokenA.setBalance.sendTransactionAsync(
+ maliciousMakerAddress,
+ constants.INITIAL_ERC20_BALANCE,
+ ),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await maliciousWallet.approveERC20.sendTransactionAsync(
+ erc20TokenA.address,
+ erc20Proxy.address,
+ constants.INITIAL_ERC20_ALLOWANCE,
+ ),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ signedOrder = await orderFactory.newSignedOrderAsync({
+ makerAddress: maliciousMakerAddress,
+ makerFee: constants.ZERO_AMOUNT,
+ });
+ signedOrder.signature = `0x0${SignatureType.Wallet}`;
+ await expectTransactionFailedAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
+ RevertReason.InvalidOrderSignature,
+ );
+ });
+
+ it('should revert if `isValidSignature` tries to update state when SignatureType=Validator', async () => {
+ const isApproved = true;
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await exchange.setSignatureValidatorApproval.sendTransactionAsync(
+ maliciousValidator.address,
+ isApproved,
+ { from: makerAddress },
+ ),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ signedOrder = await orderFactory.newSignedOrderAsync({
+ makerAddress: maliciousValidator.address,
+ });
+ signedOrder.signature = `${maliciousValidator.address}0${SignatureType.Validator}`;
+ await expectTransactionFailedAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
+ RevertReason.InvalidOrderSignature,
+ );
+ });
});
describe('Testing exchange of ERC20 tokens with no return values', () => {