@0x/contracts-exchange: Start work on isolated fill order tests.
				
					
				
			This commit is contained in:
		@@ -39,6 +39,7 @@
 | 
			
		||||
        "test/ReentrantERC20Token.sol",
 | 
			
		||||
        "test/TestAssetProxyDispatcher.sol",
 | 
			
		||||
        "test/TestExchangeInternals.sol",
 | 
			
		||||
        "test/TestExchangeIsolatedFillOrder.sol",
 | 
			
		||||
        "test/TestExchangeMath.sol",
 | 
			
		||||
        "test/TestLibExchangeRichErrorDecoder.sol",
 | 
			
		||||
        "test/TestSignatureValidator.sol",
 | 
			
		||||
 
 | 
			
		||||
@@ -529,7 +529,7 @@ contract MixinExchangeCore is
 | 
			
		||||
        address takerAddress,
 | 
			
		||||
        LibFillResults.FillResults memory fillResults
 | 
			
		||||
    )
 | 
			
		||||
        private
 | 
			
		||||
        internal
 | 
			
		||||
    {
 | 
			
		||||
        // Transfer taker -> maker
 | 
			
		||||
        _dispatchTransferFrom(
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,112 @@
 | 
			
		||||
/*
 | 
			
		||||
 | 
			
		||||
  Copyright 2019 ZeroEx Intl.
 | 
			
		||||
 | 
			
		||||
  Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
  you may not use this file except in compliance with the License.
 | 
			
		||||
  You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
    http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
  Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
  distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
  See the License for the specific language governing permissions and
 | 
			
		||||
  limitations under the License.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
pragma solidity ^0.5.5;
 | 
			
		||||
pragma experimental ABIEncoderV2;
 | 
			
		||||
 | 
			
		||||
import "../src/Exchange.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/// @dev A version of the Exchange contract where we override dependent
 | 
			
		||||
///      functions called by `_fillOrder()` to test what goes on inside of it.
 | 
			
		||||
contract TestExchangeIsolatedFillOrder is
 | 
			
		||||
    Exchange
 | 
			
		||||
{
 | 
			
		||||
    // solhint-disable no-unused-vars
 | 
			
		||||
    event UpdateFilledStateCalled(
 | 
			
		||||
        Order order,
 | 
			
		||||
        address takerAddress,
 | 
			
		||||
        bytes32 orderHash,
 | 
			
		||||
        uint256 orderTakerAssetAmount,
 | 
			
		||||
        FillResults fillResults
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    event SettleOrderCalled(
 | 
			
		||||
        bytes32 orderHash,
 | 
			
		||||
        LibOrder.Order order,
 | 
			
		||||
        address takerAddress,
 | 
			
		||||
        LibFillResults.FillResults fillResults
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // solhint-disable no-empty-blocks
 | 
			
		||||
    constructor ()
 | 
			
		||||
        public
 | 
			
		||||
        Exchange(1337)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    /// @dev Allow setting of `filled` state for an order hash.
 | 
			
		||||
    function setOrderTakerAssetFilledAmount(
 | 
			
		||||
        bytes32 orderHash,
 | 
			
		||||
        uint256 takerAssetFilledAmount
 | 
			
		||||
    )
 | 
			
		||||
        external
 | 
			
		||||
    {
 | 
			
		||||
        filled[orderHash] = takerAssetFilledAmount;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @dev Override that just logs arguments.
 | 
			
		||||
    function _updateFilledState(
 | 
			
		||||
        Order memory order,
 | 
			
		||||
        address takerAddress,
 | 
			
		||||
        bytes32 orderHash,
 | 
			
		||||
        uint256 orderTakerAssetFilledAmount,
 | 
			
		||||
        FillResults memory fillResults
 | 
			
		||||
    )
 | 
			
		||||
        internal
 | 
			
		||||
    {
 | 
			
		||||
        emit UpdateFilledStateCalled(
 | 
			
		||||
            order,
 | 
			
		||||
            takerAddress,
 | 
			
		||||
            orderHash,
 | 
			
		||||
            orderTakerAssetFilledAmount,
 | 
			
		||||
            fillResults
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @dev Override that just logs arguments.
 | 
			
		||||
    function _settleOrder(
 | 
			
		||||
        bytes32 orderHash,
 | 
			
		||||
        LibOrder.Order memory order,
 | 
			
		||||
        address takerAddress,
 | 
			
		||||
        LibFillResults.FillResults memory fillResults
 | 
			
		||||
    )
 | 
			
		||||
        internal
 | 
			
		||||
    {
 | 
			
		||||
        emit SettleOrderCalled(
 | 
			
		||||
            orderHash,
 | 
			
		||||
            order,
 | 
			
		||||
            takerAddress,
 | 
			
		||||
            fillResults
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @dev Override to log arguments and pass all empty signatures.
 | 
			
		||||
    function _isValidOrderWithHashSignature(
 | 
			
		||||
        Order memory order,
 | 
			
		||||
        bytes32 orderHash,
 | 
			
		||||
        address signerAddress,
 | 
			
		||||
        bytes memory signature
 | 
			
		||||
    )
 | 
			
		||||
        internal
 | 
			
		||||
        view
 | 
			
		||||
        returns (bool isValid)
 | 
			
		||||
    {
 | 
			
		||||
        // Pass if the signature is empty.
 | 
			
		||||
        return signature.length == 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -34,7 +34,7 @@
 | 
			
		||||
        "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
 | 
			
		||||
    },
 | 
			
		||||
    "config": {
 | 
			
		||||
        "abis": "./generated-artifacts/@(Exchange|ExchangeWrapper|IAssetProxyDispatcher|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|ISignatureValidator|ITransactions|IWallet|IWrapperFunctions|ReentrantERC20Token|TestAssetProxyDispatcher|TestExchangeInternals|TestExchangeMath|TestLibExchangeRichErrorDecoder|TestSignatureValidator|TestValidatorWallet|Whitelist).json",
 | 
			
		||||
        "abis": "./generated-artifacts/@(Exchange|ExchangeWrapper|IAssetProxyDispatcher|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|ISignatureValidator|ITransactions|IWallet|IWrapperFunctions|ReentrantERC20Token|TestAssetProxyDispatcher|TestExchangeInternals|TestExchangeIsolatedFillOrder|TestExchangeMath|TestLibExchangeRichErrorDecoder|TestSignatureValidator|TestValidatorWallet|Whitelist).json",
 | 
			
		||||
        "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
 | 
			
		||||
    },
 | 
			
		||||
    "repository": {
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ import * as IWrapperFunctions from '../generated-artifacts/IWrapperFunctions.jso
 | 
			
		||||
import * as ReentrantERC20Token from '../generated-artifacts/ReentrantERC20Token.json';
 | 
			
		||||
import * as TestAssetProxyDispatcher from '../generated-artifacts/TestAssetProxyDispatcher.json';
 | 
			
		||||
import * as TestExchangeInternals from '../generated-artifacts/TestExchangeInternals.json';
 | 
			
		||||
import * as TestExchangeIsolatedFillOrder from '../generated-artifacts/TestExchangeIsolatedFillOrder.json';
 | 
			
		||||
import * as TestExchangeMath from '../generated-artifacts/TestExchangeMath.json';
 | 
			
		||||
import * as TestLibExchangeRichErrorDecoder from '../generated-artifacts/TestLibExchangeRichErrorDecoder.json';
 | 
			
		||||
import * as TestSignatureValidator from '../generated-artifacts/TestSignatureValidator.json';
 | 
			
		||||
@@ -39,6 +40,7 @@ export const artifacts = {
 | 
			
		||||
    IWrapperFunctions: IWrapperFunctions as ContractArtifact,
 | 
			
		||||
    ReentrantERC20Token: ReentrantERC20Token as ContractArtifact,
 | 
			
		||||
    TestAssetProxyDispatcher: TestAssetProxyDispatcher as ContractArtifact,
 | 
			
		||||
    TestExchangeIsolatedFillOrder: TestExchangeIsolatedFillOrder as ContractArtifact,
 | 
			
		||||
    TestExchangeInternals: TestExchangeInternals as ContractArtifact,
 | 
			
		||||
    TestExchangeMath: TestExchangeMath as ContractArtifact,
 | 
			
		||||
    TestLibExchangeRichErrorDecoder: TestLibExchangeRichErrorDecoder as ContractArtifact,
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ export * from '../generated-wrappers/i_wrapper_functions';
 | 
			
		||||
export * from '../generated-wrappers/reentrant_erc20_token';
 | 
			
		||||
export * from '../generated-wrappers/test_asset_proxy_dispatcher';
 | 
			
		||||
export * from '../generated-wrappers/test_exchange_internals';
 | 
			
		||||
export * from '../generated-wrappers/test_exchange_isolated_fill_order';
 | 
			
		||||
export * from '../generated-wrappers/test_exchange_math';
 | 
			
		||||
export * from '../generated-wrappers/test_lib_exchange_rich_error_decoder';
 | 
			
		||||
export * from '../generated-wrappers/test_signature_validator';
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										49
									
								
								contracts/exchange/test/isolated_fill_order.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								contracts/exchange/test/isolated_fill_order.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
import {
 | 
			
		||||
    blockchainTests,
 | 
			
		||||
    constants,
 | 
			
		||||
    expect,
 | 
			
		||||
    FillResults,
 | 
			
		||||
    txDefaults,
 | 
			
		||||
} from '@0x/contracts-test-utils';
 | 
			
		||||
import { Order, SignedOrder } from '@0x/types';
 | 
			
		||||
import { BigNumber } from '@0x/utils';
 | 
			
		||||
 | 
			
		||||
import { artifacts, TestExchangeInternalsContract, TestExchangeMathContract } from '../src';
 | 
			
		||||
 | 
			
		||||
const emptyOrder: Order = {
 | 
			
		||||
    senderAddress: constants.NULL_ADDRESS,
 | 
			
		||||
    makerAddress: constants.NULL_ADDRESS,
 | 
			
		||||
    takerAddress: constants.NULL_ADDRESS,
 | 
			
		||||
    makerFee: new BigNumber(0),
 | 
			
		||||
    takerFee: new BigNumber(0),
 | 
			
		||||
    makerAssetAmount: new BigNumber(0),
 | 
			
		||||
    takerAssetAmount: new BigNumber(0),
 | 
			
		||||
    makerAssetData: '0x',
 | 
			
		||||
    takerAssetData: '0x',
 | 
			
		||||
    makerFeeAssetData: '0x',
 | 
			
		||||
    takerFeeAssetData: '0x',
 | 
			
		||||
    salt: new BigNumber(0),
 | 
			
		||||
    feeRecipientAddress: constants.NULL_ADDRESS,
 | 
			
		||||
    expirationTimeSeconds: new BigNumber(0),
 | 
			
		||||
    domain: {
 | 
			
		||||
        verifyingContractAddress: constants.NULL_ADDRESS,
 | 
			
		||||
        chainId: 0, // To be filled in later.
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const emptySignedOrder: SignedOrder = {
 | 
			
		||||
    ...emptyOrder,
 | 
			
		||||
    signature: '',
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
blockchainTests.only('Isolated fillOrder()', () => {
 | 
			
		||||
    it('foo', async () => {
 | 
			
		||||
        expect('foo').to.equal('foo');
 | 
			
		||||
    });
 | 
			
		||||
    blockchainTests.resets('inner', () => {
 | 
			
		||||
        it('bar', async () => {
 | 
			
		||||
            return expect(Promise.resolve(true)).to.eventually.be.ok;
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    require('./nested');
 | 
			
		||||
});
 | 
			
		||||
@@ -5,12 +5,11 @@ import {
 | 
			
		||||
    ERC721Wrapper,
 | 
			
		||||
    MultiAssetProxyContract,
 | 
			
		||||
} from '@0x/contracts-asset-proxy';
 | 
			
		||||
import { chaiSetup, constants, FillResults, orderUtils, signingUtils } from '@0x/contracts-test-utils';
 | 
			
		||||
import { constants, expect, FillResults, orderUtils, signingUtils } from '@0x/contracts-test-utils';
 | 
			
		||||
import { BalanceAndProxyAllowanceLazyStore, ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
 | 
			
		||||
import { Order, SignatureType, SignedOrder } from '@0x/types';
 | 
			
		||||
import { BigNumber, errorUtils, providerUtils, RevertError, StringRevertError } from '@0x/utils';
 | 
			
		||||
import { SupportedProvider, Web3Wrapper } from '@0x/web3-wrapper';
 | 
			
		||||
import * as chai from 'chai';
 | 
			
		||||
import { LogWithDecodedArgs, TxData } from 'ethereum-types';
 | 
			
		||||
import * as _ from 'lodash';
 | 
			
		||||
import 'make-promises-safe';
 | 
			
		||||
@@ -36,9 +35,6 @@ import { FillOrderError, FillOrderSimulator } from './fill_order_simulator';
 | 
			
		||||
import { OrderFactoryFromScenario } from './order_factory_from_scenario';
 | 
			
		||||
import { SimpleAssetBalanceAndProxyAllowanceFetcher } from './simple_asset_balance_and_proxy_allowance_fetcher';
 | 
			
		||||
 | 
			
		||||
chaiSetup.configure();
 | 
			
		||||
const expect = chai.expect;
 | 
			
		||||
 | 
			
		||||
const EMPTY_FILL_RESULTS = {
 | 
			
		||||
    takerAssetFilledAmount: constants.ZERO_AMOUNT,
 | 
			
		||||
    makerAssetFilledAmount: constants.ZERO_AMOUNT,
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@
 | 
			
		||||
        "generated-artifacts/ReentrantERC20Token.json",
 | 
			
		||||
        "generated-artifacts/TestAssetProxyDispatcher.json",
 | 
			
		||||
        "generated-artifacts/TestExchangeInternals.json",
 | 
			
		||||
        "generated-artifacts/TestExchangeIsolatedFillOrder.json",
 | 
			
		||||
        "generated-artifacts/TestExchangeMath.json",
 | 
			
		||||
        "generated-artifacts/TestLibExchangeRichErrorDecoder.json",
 | 
			
		||||
        "generated-artifacts/TestSignatureValidator.json",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user