diff --git a/test/contracts/core/extensions/coreIssuanceOrderScenarios.ts b/test/contracts/core/extensions/coreIssuanceOrderScenarios.ts deleted file mode 100644 index 66acca4fd..000000000 --- a/test/contracts/core/extensions/coreIssuanceOrderScenarios.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { - DEPLOYED_TOKEN_QUANTITY, - ZERO, -} from '../../../../utils/constants'; - -import { - ether, -} from '../../../../utils/units'; - -export const SCENARIOS = [ -{ - title: 'Base Case', - description: 'Maker pays for all components in the Set and receives Set in return.\ - Taker receives maker tokens and gives up component units.', - naturalUnit: ether(2), - componentUnit: ether(4), - tokenState: { - numberOfComponents: 2, - takerAmounts: [DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY], - makerAmounts: [ZERO, ZERO], - vault: [ZERO, ZERO], - }, - exchangeOrders: { - takerWeightsToTransfer: [1, 1], - subjectQuantityToIssue: ether(4), - }, - issuanceOrderParams: { - requiredComponentWeighting: [1, 1], - orderQuantity: ether(4), - makerTokenAmount: ether(10), - }, -}, -{ - title: 'Three Set Components Case', - description: 'Maker pays for all components in the Set and receives Set in return.\ - Taker receives maker tokens and gives up component units.', - naturalUnit: ether(2), - componentUnit: ether(4), - tokenState: { - numberOfComponents: 3, - takerAmounts: [DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY], - makerAmounts: [ZERO, ZERO, ZERO], - vault: [ZERO, ZERO, ZERO], - }, - exchangeOrders: { - takerWeightsToTransfer: [1, 1, 1], - subjectQuantityToIssue: ether(4), - }, - issuanceOrderParams: { - requiredComponentWeighting: [1, 1, 1], - orderQuantity: ether(4), - makerTokenAmount: ether(10), - }, -}, -{ - title: 'Maker Has One Component in Wallet', - description: 'Maker pays for two components in the Set and uses one of their own tokens to mint Set.\ - Taker receives maker tokens and gives up two component units.', - naturalUnit: ether(2), - componentUnit: ether(4), - tokenState: { - numberOfComponents: 3, - takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY], - makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), ZERO, ZERO], - vault: [ZERO, ZERO, ZERO], - }, - exchangeOrders: { - takerWeightsToTransfer: [0, 1, 1], - subjectQuantityToIssue: ether(4), - }, - issuanceOrderParams: { - requiredComponentWeighting: [0, 1, 1], - orderQuantity: ether(4), - makerTokenAmount: ether(10), - }, -}, -{ - title: 'Maker Has Two Components in Wallet', - description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set.\ - Taker receives maker tokens and gives up one component unit.', - naturalUnit: ether(2), - componentUnit: ether(4), - tokenState: { - numberOfComponents: 3, - takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY], - makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], - vault: [ZERO, ZERO, ZERO], - }, - exchangeOrders: { - takerWeightsToTransfer: [0, 0, 1], - subjectQuantityToIssue: ether(4), - }, - issuanceOrderParams: { - requiredComponentWeighting: [0, 0, 1], - orderQuantity: ether(4), - makerTokenAmount: ether(10), - }, -}, -{ - title: 'Maker Has One Component in Wallet, One in Vault', - description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set\ - (one in wallet and one in Vault). Taker receives maker tokens and gives up one component unit.', - naturalUnit: ether(2), - componentUnit: ether(4), - tokenState: { - numberOfComponents: 3, - takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY], - makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], - // Must have Vault amount declared in makerAmounts as well to make transfer go through - vault: [ZERO, DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], - }, - exchangeOrders: { - takerWeightsToTransfer: [0, 0, 1], - subjectQuantityToIssue: ether(4), - }, - issuanceOrderParams: { - requiredComponentWeighting: [0, 0, 1], - orderQuantity: ether(4), - makerTokenAmount: ether(10), - }, -}, -{ - title: 'Maker Has One Component in Wallet, One in Vault, Taker takes half', - description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set\ - (one in wallet and one in Vault). Taker receives maker tokens and gives up one component unit. Only\ - half of order is filled.', - naturalUnit: ether(2), - componentUnit: ether(4), - tokenState: { - numberOfComponents: 3, - takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY], - makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], - // Must have Vault amount declared in makerAmounts as well to make transfer go through - vault: [ZERO, DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], - }, - exchangeOrders: { - takerWeightsToTransfer: [0, 0, .5], - subjectQuantityToIssue: ether(2), - }, - issuanceOrderParams: { - requiredComponentWeighting: [0, 0, 1], - orderQuantity: ether(4), - makerTokenAmount: ether(10), - }, -}, -{ - title: 'Base Case with rounding errors', - description: 'Maker pays for all components in the Set and receives Set in return.\ - Taker receives maker tokens and gives up component units. Due to rounding errors amounts\ - received are not exact.', - naturalUnit: ether(2), - componentUnit: ether(4), - tokenState: { - numberOfComponents: 2, - takerAmounts: [DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY], - makerAmounts: [ZERO, ZERO], - vault: [ZERO, ZERO], - }, - exchangeOrders: { - takerWeightsToTransfer: [1, 1], - subjectQuantityToIssue: ether(4), - }, - issuanceOrderParams: { - requiredComponentWeighting: [1, 1], - orderQuantity: ether(6), - makerTokenAmount: ether(10), - }, -}, -]; diff --git a/test/contracts/core/exchange-wrappers/lib/zeroExOrderDataHandlerMock.spec.ts b/test/core/exchange-wrappers/lib/zeroExOrderDataHandlerMock.spec.ts similarity index 86% rename from test/contracts/core/exchange-wrappers/lib/zeroExOrderDataHandlerMock.spec.ts rename to test/core/exchange-wrappers/lib/zeroExOrderDataHandlerMock.spec.ts index 1325d2558..4ad605908 100644 --- a/test/contracts/core/exchange-wrappers/lib/zeroExOrderDataHandlerMock.spec.ts +++ b/test/core/exchange-wrappers/lib/zeroExOrderDataHandlerMock.spec.ts @@ -2,38 +2,24 @@ import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; import { SetProtocolUtils } from 'set-protocol-utils'; -// Types -import { Bytes32, Bytes } from '../../../../../types/common.js'; -import { ZeroExOrder } from '../../../../../types/zeroEx'; - -// Contract types -import { ZeroExOrderDataHandlerMockContract } from '../../../../../types/generated/zero_ex_order_data_handler_mock'; - -// Artifacts -const ZeroExOrderDataHandlerMock = artifacts.require('ZeroExOrderDataHandlerMock'); - +import ChaiSetup from '../../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; +import { ZeroExOrderDataHandlerMockContract } from '../../../../utils/contracts'; import { bufferZeroExOrder, createZeroExOrder, generateStandardZeroExOrderBytesArray, - generateERC20TokenAssetData, -} from '../../../../../utils/zeroExExchangeWrapper'; + generateERC20TokenAssetData +} from '../../../../utils/zeroExExchangeWrapper'; +import { expectRevertError } from '../../../../utils/tokenAssertions'; +import { Bytes32, Bytes } from '../../../../types/common.js'; +import { ZeroExOrder } from '../../../../types/zeroEx'; +import { LibraryMockWrapper } from '../../../../utils/libraryMockWrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; -import { - expectRevertError, -} from '../../../../../utils/tokenAssertions'; - -import { - DEFAULT_GAS, -} from '../../../../../utils/constants'; - contract('ZeroExOrderDataHandlerMock', accounts => { const [ @@ -44,6 +30,8 @@ contract('ZeroExOrderDataHandlerMock', accounts => { makerTokenAddress, takerTokenAddress, ] = accounts; + + const libraryMockWrapper: LibraryMockWrapper = new LibraryMockWrapper(ownerAccount); let zeroExExchangeWrapper: ZeroExOrderDataHandlerMockContract; // Signature @@ -78,14 +66,7 @@ contract('ZeroExOrderDataHandlerMock', accounts => { ); beforeEach(async () => { - const zeroExExchangeWrapperInstance = await ZeroExOrderDataHandlerMock.new( - { from: ownerAccount, gas: DEFAULT_GAS }, - ); - - zeroExExchangeWrapper = new ZeroExOrderDataHandlerMockContract( - web3.eth.contract(zeroExExchangeWrapperInstance.abi).at(zeroExExchangeWrapperInstance.address), - { from: ownerAccount }, - ); + zeroExExchangeWrapper = await libraryMockWrapper.deployZeroExOrderDataHandlerLibraryAsync(); }); describe('#parseOrderDataHeader', async () => { diff --git a/test/contracts/core/exchange-wrappers/takerWalletWrapper.spec.ts b/test/core/exchange-wrappers/takerWalletWrapper.spec.ts similarity index 86% rename from test/contracts/core/exchange-wrappers/takerWalletWrapper.spec.ts rename to test/core/exchange-wrappers/takerWalletWrapper.spec.ts index d01eb081a..7a4e66b43 100644 --- a/test/contracts/core/exchange-wrappers/takerWalletWrapper.spec.ts +++ b/test/core/exchange-wrappers/takerWalletWrapper.spec.ts @@ -1,38 +1,29 @@ -import * as chai from 'chai'; import * as _ from 'lodash'; - +import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -// Types -import { Address, Bytes } from '../../../../types/common.js'; - -// Contract types -import { StandardTokenMockContract } from '../../../../types/generated/standard_token_mock'; -import { TakerWalletWrapperContract } from '../../../../types/generated/taker_wallet_wrapper'; -import { TransferProxyContract } from '../../../../types/generated/transfer_proxy'; - -// Wrappers -import { CoreWrapper } from '../../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../../utils/erc20Wrapper'; -import { ExchangeWrapper } from '../../../../utils/exchangeWrapper'; -import { generateTakerWalletOrders } from '../../../../utils/orders'; - -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; -BigNumberSetup.configure(); -ChaiSetup.configure(); -const { expect } = chai; - +import ChaiSetup from '../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; +import { + StandardTokenMockContract, + TakerWalletWrapperContract, + TransferProxyContract +} from '../../../utils/contracts'; +import { Address, Bytes } from '../../../types/common.js'; +import { CoreWrapper } from '../../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; +import { ExchangeWrapper } from '../../../utils/exchangeWrapper'; +import { generateTakerWalletOrders } from '../../../utils/orders'; import { DEFAULT_GAS, DEPLOYED_TOKEN_QUANTITY, UNLIMITED_ALLOWANCE_IN_BASE_UNITS, -} from '../../../../utils/constants'; +} from '../../../utils/constants'; +import { expectRevertError } from '../../../utils/tokenAssertions'; -import { - expectRevertError, -} from '../../../../utils/tokenAssertions'; +BigNumberSetup.configure(); +ChaiSetup.configure(); +const { expect } = chai; contract('TakerWalletWrapper', accounts => { diff --git a/test/contracts/core/exchange-wrappers/zeroExExchangeWrapper.spec.ts b/test/core/exchange-wrappers/zeroExExchangeWrapper.spec.ts similarity index 71% rename from test/contracts/core/exchange-wrappers/zeroExExchangeWrapper.spec.ts rename to test/core/exchange-wrappers/zeroExExchangeWrapper.spec.ts index 9769becc1..af9875afa 100644 --- a/test/contracts/core/exchange-wrappers/zeroExExchangeWrapper.spec.ts +++ b/test/core/exchange-wrappers/zeroExExchangeWrapper.spec.ts @@ -7,29 +7,29 @@ import * as ABIDecoder from "abi-decoder"; import { BigNumber } from "bignumber.js"; // Types -import { Address, Bytes32, Log, UInt } from "../../../../types/common.js"; -import { ZeroExOrderHeader, ZeroExOrder } from "../../../../types/zeroEx"; +import { Address, Bytes32, Log, UInt } from "../../../types/common.js"; +import { ZeroExOrderHeader, ZeroExOrder } from "../../../types/zeroEx"; // Contract types -import { ZeroExExchangeWrapperContract } from "../../../../types/generated/zero_ex_exchange_wrapper"; +import { ZeroExExchangeWrapperContract } from "../../../types/generated/zero_ex_exchange_wrapper"; // Artifacts const ZeroExExchangeWrapper = artifacts.require("ZeroExExchangeWrapper"); import { createZeroExOrder, -} from "../../../../utils/zeroExExchangeWrapper"; +} from "../../../utils/zeroExExchangeWrapper"; // Testing Set up -import { BigNumberSetup } from "../../../../utils/bigNumberSetup"; -import ChaiSetup from "../../../../utils/chaiSetup"; +import { BigNumberSetup } from "../../../utils/bigNumberSetup"; +import ChaiSetup from "../../../utils/chaiSetup"; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect, assert } = chai; import { DEFAULT_GAS, -} from "../../../../utils/constants"; +} from "../../../utils/constants"; contract("ZeroExExchangeWrapper", (accounts) => { const [ownerAccount, takerAddress, feeRecipientAddress, senderAddress] = accounts; diff --git a/test/contracts/core/extensions/coreAccounting.spec.ts b/test/core/extensions/coreAccounting.spec.ts similarity index 94% rename from test/contracts/core/extensions/coreAccounting.spec.ts rename to test/core/extensions/coreAccounting.spec.ts index f5f07cd3f..378ce3688 100644 --- a/test/contracts/core/extensions/coreAccounting.spec.ts +++ b/test/core/extensions/coreAccounting.spec.ts @@ -1,38 +1,26 @@ -import * as chai from 'chai'; import * as _ from 'lodash'; - +import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -// Types -import { Address } from '../../../../types/common.js'; - -// Contract types -import { CoreContract } from '../../../../types/generated/core'; -import { SetTokenFactoryContract } from '../../../../types/generated/set_token_factory'; -import { StandardTokenMockContract } from '../../../../types/generated/standard_token_mock'; -import { TransferProxyContract } from '../../../../types/generated/transfer_proxy'; -import { VaultContract } from '../../../../types/generated/vault'; - -// Core wrapper -import { CoreWrapper } from '../../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../../utils/erc20Wrapper'; +import ChaiSetup from '../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; +import { + CoreContract, + SetTokenFactoryContract, + StandardTokenMockContract, + TransferProxyContract, + VaultContract +} from '../../../utils/contracts'; +import { Address } from '../../../types/common.js'; +import { assertTokenBalance, expectRevertError } from '../../../utils/tokenAssertions'; +import { DEPLOYED_TOKEN_QUANTITY, UNLIMITED_ALLOWANCE_IN_BASE_UNITS } from '../../../utils/constants'; +import { CoreWrapper } from '../../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; -import { - assertTokenBalance, - expectRevertError, -} from '../../../../utils/tokenAssertions'; - -import { - DEPLOYED_TOKEN_QUANTITY, - UNLIMITED_ALLOWANCE_IN_BASE_UNITS, -} from '../../../../utils/constants'; contract('CoreAccounting', accounts => { const [ diff --git a/test/contracts/core/extensions/coreExchangeDispatcher.spec.ts b/test/core/extensions/coreExchangeDispatcher.spec.ts similarity index 78% rename from test/contracts/core/extensions/coreExchangeDispatcher.spec.ts rename to test/core/extensions/coreExchangeDispatcher.spec.ts index 479e92680..191731f7b 100644 --- a/test/contracts/core/extensions/coreExchangeDispatcher.spec.ts +++ b/test/core/extensions/coreExchangeDispatcher.spec.ts @@ -3,34 +3,20 @@ import * as chai from 'chai'; import { SetProtocolUtils as Utils } from 'set-protocol-utils'; import { BigNumber } from 'bignumber.js'; -// Types -import { Address, Log } from '../../../../types/common.js'; +import ChaiSetup from '../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; +import { CoreContract } from '../../../utils/contracts'; +import { Address, Log } from '../../../types/common.js'; +import { expectRevertError } from '../../../utils/tokenAssertions'; +import { assertLogEquivalence, getFormattedLogsFromTxHash } from '../../../utils/logs'; +import { ExchangeRegistered } from '../../../utils/contract_logs/core'; +import { CoreWrapper } from '../../../utils/coreWrapper'; -// Contract types -import { CoreContract } from '../../../../types/generated/core'; - -// Artifacts -const Core = artifacts.require('Core'); - -// Core wrapper -import { CoreWrapper } from '../../../../utils/coreWrapper'; - -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; +const Core = artifacts.require('Core'); -import { - expectRevertError, -} from '../../../../utils/tokenAssertions'; - -import { - assertLogEquivalence, - getFormattedLogsFromTxHash -} from '../../../../utils/logs'; -import { ExchangeRegistered } from '../../../../utils/contract_logs/core'; contract('CoreExchangeDispatcher', accounts => { const [ diff --git a/test/contracts/core/extensions/coreFactory.spec.ts b/test/core/extensions/coreFactory.spec.ts similarity index 76% rename from test/contracts/core/extensions/coreFactory.spec.ts rename to test/core/extensions/coreFactory.spec.ts index 70998ac53..8d579941f 100644 --- a/test/contracts/core/extensions/coreFactory.spec.ts +++ b/test/core/extensions/coreFactory.spec.ts @@ -1,48 +1,23 @@ -import * as chai from 'chai'; - import * as ABIDecoder from 'abi-decoder'; +import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -// Types -import { Address, Log } from '../../../../types/common.js'; - -// Contract types -import { CoreContract } from '../../../../types/generated/core'; -import { SetTokenFactoryContract } from '../../../../types/generated/set_token_factory'; -import { StandardTokenMockContract } from '../../../../types/generated/standard_token_mock'; - -// Artifacts -const Core = artifacts.require('Core'); +import ChaiSetup from '../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; +import { CoreContract, SetTokenFactoryContract, StandardTokenMockContract } from '../../../utils/contracts'; +import { Address, Log } from '../../../types/common.js'; +import { expectRevertError } from '../../../utils/tokenAssertions'; +import { extractNewSetTokenAddressFromLogs, SetTokenCreated } from '../../../utils/contract_logs/core'; +import { assertLogEquivalence, getFormattedLogsFromTxHash } from '../../../utils/logs'; +import { NULL_ADDRESS, ONE } from '../../../utils/constants'; +import { CoreWrapper } from '../../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; -// Core wrapper -import { CoreWrapper } from '../../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../../utils/erc20Wrapper'; - -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; +const Core = artifacts.require('Core'); -import { - expectRevertError, -} from '../../../../utils/tokenAssertions'; - -import { - extractNewSetTokenAddressFromLogs, - SetTokenCreated, -} from '../../../../utils/contract_logs/core'; - -import { - assertLogEquivalence, - getFormattedLogsFromTxHash -} from '../../../../utils/logs'; - -import { - NULL_ADDRESS, - ONE, -} from '../../../../utils/constants'; contract('CoreFactory', accounts => { const [ diff --git a/test/contracts/core/extensions/coreInternal.spec.ts b/test/core/extensions/coreInternal.spec.ts similarity index 90% rename from test/contracts/core/extensions/coreInternal.spec.ts rename to test/core/extensions/coreInternal.spec.ts index 5a1516ca5..1b103dc62 100644 --- a/test/contracts/core/extensions/coreInternal.spec.ts +++ b/test/core/extensions/coreInternal.spec.ts @@ -1,39 +1,27 @@ -import * as chai from 'chai'; import * as _ from 'lodash'; - import * as ABIDecoder from 'abi-decoder'; +import * as chai from 'chai'; -// Types -import { Address } from '../../../../types/common.js'; - -// Contract types -import { CoreContract } from '../../../../types/generated/core'; -import { SetTokenContract } from '../../../../types/generated/set_token'; -import { SetTokenFactoryContract } from '../../../../types/generated/set_token_factory'; -import { TransferProxyContract } from '../../../../types/generated/transfer_proxy'; -import { VaultContract } from '../../../../types/generated/vault'; - -// Artifacts -const Core = artifacts.require('Core'); - -// Core wrapper -import { CoreWrapper } from '../../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../../utils/erc20Wrapper'; +import ChaiSetup from '../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; +import { + CoreContract, + SetTokenContract, + SetTokenFactoryContract, + TransferProxyContract, + VaultContract +} from '../../../utils/contracts'; +import { Address } from '../../../types/common.js'; +import { expectRevertError } from '../../../utils/tokenAssertions'; +import { STANDARD_NATURAL_UNIT } from '../../../utils/constants'; +import { CoreWrapper } from '../../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; +const Core = artifacts.require('Core'); -import { - expectRevertError, -} from '../../../../utils/tokenAssertions'; - -import { - STANDARD_NATURAL_UNIT, -} from '../../../../utils/constants'; contract('CoreInternal', accounts => { const [ diff --git a/test/contracts/core/extensions/coreIssuance.spec.ts b/test/core/extensions/coreIssuance.spec.ts similarity index 94% rename from test/contracts/core/extensions/coreIssuance.spec.ts rename to test/core/extensions/coreIssuance.spec.ts index 80c765a09..4e1376e2a 100644 --- a/test/contracts/core/extensions/coreIssuance.spec.ts +++ b/test/core/extensions/coreIssuance.spec.ts @@ -1,55 +1,32 @@ -import * as chai from 'chai'; import * as _ from 'lodash'; - import * as ABIDecoder from 'abi-decoder'; +import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -import { ether } from '../../../../utils/units'; - -// Types -import { Address, Log } from '../../../../types/common.js'; -// Contract types -import { CoreContract } from '../../../../types/generated/core'; -import { SetTokenContract } from '../../../../types/generated/set_token'; -import { SetTokenFactoryContract } from '../../../../types/generated/set_token_factory'; -import { StandardTokenMockContract } from '../../../../types/generated/standard_token_mock'; -import { TransferProxyContract } from '../../../../types/generated/transfer_proxy'; -import { VaultContract } from '../../../../types/generated/vault'; - -// Artifacts -const Core = artifacts.require('Core'); - -// Core wrapper -import { CoreWrapper } from '../../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../../utils/erc20Wrapper'; +import ChaiSetup from '../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; +import { + CoreContract, + SetTokenContract, + SetTokenFactoryContract, + StandardTokenMockContract, + TransferProxyContract, + VaultContract +} from '../../../utils/contracts'; +import { Address, Log } from '../../../types/common.js'; +import { ether } from '../../../utils/units'; +import { assertLogEquivalence, getFormattedLogsFromTxHash } from '../../../utils/logs'; +import { IssuanceComponentDeposited } from '../../../utils/contract_logs/core'; +import { assertTokenBalance, expectRevertError } from '../../../utils/tokenAssertions'; +import { DEFAULT_GAS, DEPLOYED_TOKEN_QUANTITY, NULL_ADDRESS, ZERO } from '../../../utils/constants'; +import { CoreWrapper } from '../../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; +const Core = artifacts.require('Core'); -import { - assertLogEquivalence, - getFormattedLogsFromTxHash -} from '../../../../utils/logs'; - -import { - IssuanceComponentDeposited, -} from '../../../../utils/contract_logs/core'; - -import { - assertTokenBalance, - expectRevertError, -} from '../../../../utils/tokenAssertions'; - -import { - DEFAULT_GAS, - DEPLOYED_TOKEN_QUANTITY, - NULL_ADDRESS, - ZERO, -} from '../../../../utils/constants'; contract('CoreIssuance', accounts => { const [ diff --git a/test/contracts/core/extensions/coreIssuanceOrder.spec.ts b/test/core/extensions/coreIssuanceOrder.spec.ts similarity index 93% rename from test/contracts/core/extensions/coreIssuanceOrder.spec.ts rename to test/core/extensions/coreIssuanceOrder.spec.ts index d75a8f4c9..c09101eca 100644 --- a/test/contracts/core/extensions/coreIssuanceOrder.spec.ts +++ b/test/core/extensions/coreIssuanceOrder.spec.ts @@ -4,61 +4,36 @@ import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; import { SetProtocolUtils as Utils } from 'set-protocol-utils'; -// Types -import { Address, Bytes32 } from '../../../../types/common.js'; - -// Contract types -import { CoreContract } from '../../../../types/generated/core'; -import { SetTokenContract } from '../../../../types/generated/set_token'; -import { SetTokenFactoryContract } from '../../../../types/generated/set_token_factory'; -import { StandardTokenMockContract } from '../../../../types/generated/standard_token_mock'; -import { TakerWalletWrapperContract } from '../../../../types/generated/taker_wallet_wrapper'; -import { TransferProxyContract } from '../../../../types/generated/transfer_proxy'; -import { VaultContract } from '../../../../types/generated/vault'; - -// Artifacts -const Core = artifacts.require('Core'); - -// Core wrapper -import { CoreWrapper } from '../../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../../utils/erc20Wrapper'; -import { ExchangeWrapper } from '../../../../utils/exchangeWrapper'; +import ChaiSetup from '../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; +import { + CoreContract, + SetTokenContract, + SetTokenFactoryContract, + StandardTokenMockContract, + TakerWalletWrapperContract, + TransferProxyContract, + VaultContract +} from '../../../utils/contracts'; +import { Address, Bytes32 } from '../../../types/common.js'; +import { ether } from '../../../utils/units'; +import { assertTokenBalance, expectRevertError } from '../../../utils/tokenAssertions'; +import { DEPLOYED_TOKEN_QUANTITY, ZERO, NULL_ADDRESS } from '../../../utils/constants'; +import { assertLogEquivalence, getFormattedLogsFromTxHash } from '../../../utils/logs'; +import { getExpectedFillLog, getExpectedCancelLog } from '../../../utils/contract_logs/coreIssuanceOrder'; +import { ExchangeWrapper } from '../../../utils/exchangeWrapper'; import { generateFillOrderParameters, generateOrdersDataWithIncorrectExchange, - generateOrdersDataWithTakerOrders, -} from '../../../../utils/orders'; - -// Log Testing Tools -import { - assertLogEquivalence, - getFormattedLogsFromTxHash -} from '../../../../utils/logs'; - -import { - getExpectedFillLog, - getExpectedCancelLog, -} from '../../../../utils/contract_logs/coreIssuanceOrder'; + generateOrdersDataWithTakerOrders +} from '../../../utils/orders'; +import { CoreWrapper } from '../../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; - -import { - assertTokenBalance, - expectRevertError, -} from '../../../../utils/tokenAssertions'; - -import { - DEPLOYED_TOKEN_QUANTITY, - ZERO, - NULL_ADDRESS, -} from '../../../../utils/constants'; - -import { ether } from '../../../../utils/units'; +const Core = artifacts.require('Core'); contract('CoreIssuanceOrder', accounts => { diff --git a/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts b/test/core/extensions/coreIssuanceOrderScenarios.spec.ts similarity index 87% rename from test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts rename to test/core/extensions/coreIssuanceOrderScenarios.spec.ts index 95d771406..40f2c7c4b 100644 --- a/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts +++ b/test/core/extensions/coreIssuanceOrderScenarios.spec.ts @@ -4,58 +4,33 @@ import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; import { SetProtocolUtils as Utils } from 'set-protocol-utils'; -import { ether } from '../../../../utils/units'; - -// Types -import { Address, Bytes32 } from '../../../../types/common.js'; - -// Contract types -import { CoreContract } from '../../../../types/generated/core'; -import { SetTokenContract } from '../../../../types/generated/set_token'; -import { SetTokenFactoryContract } from '../../../../types/generated/set_token_factory'; -import { StandardTokenMockContract } from '../../../../types/generated/standard_token_mock'; -import { TakerWalletWrapperContract } from '../../../../types/generated/taker_wallet_wrapper'; -import { TransferProxyContract } from '../../../../types/generated/transfer_proxy'; -import { VaultContract } from '../../../../types/generated/vault'; - -// Artifacts -const Core = artifacts.require('Core'); - -// Core wrapper -import { CoreWrapper } from '../../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../../utils/erc20Wrapper'; -import { ExchangeWrapper } from '../../../../utils/exchangeWrapper'; -import { - generateFillOrderParameters, - generateOrdersDataWithTakerOrders, -} from '../../../../utils/orders'; - -// Log Testing Tools -import { - assertLogEquivalence, - getFormattedLogsFromTxHash -} from '../../../../utils/logs'; - +import ChaiSetup from '../../../utils/chaiSetup'; +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; import { - getExpectedFillLog, -} from '../../../../utils/contract_logs/coreIssuanceOrder'; + CoreContract, + SetTokenContract, + SetTokenFactoryContract, + StandardTokenMockContract, + TakerWalletWrapperContract, + TransferProxyContract, + VaultContract +} from '../../../utils/contracts'; +import { Address, Bytes32 } from '../../../types/common.js'; +import { ether } from '../../../utils/units'; +import { assertTokenBalance } from '../../../utils/tokenAssertions'; +import { DEPLOYED_TOKEN_QUANTITY } from '../../../utils/constants'; +import { SCENARIOS } from './coreIssuanceOrderScenarios'; +import { ExchangeWrapper } from '../../../utils/exchangeWrapper'; +import { generateFillOrderParameters, generateOrdersDataWithTakerOrders } from '../../../utils/orders'; +import { assertLogEquivalence, getFormattedLogsFromTxHash } from '../../../utils/logs'; +import { getExpectedFillLog } from '../../../utils/contract_logs/coreIssuanceOrder'; +import { CoreWrapper } from '../../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; - -import { - assertTokenBalance, -} from '../../../../utils/tokenAssertions'; - -import { - DEPLOYED_TOKEN_QUANTITY, -} from '../../../../utils/constants'; - -import { SCENARIOS } from './coreIssuanceOrderScenarios'; +const Core = artifacts.require('Core'); contract('CoreIssuanceOrder::Scenarios', accounts => { diff --git a/test/core/extensions/coreIssuanceOrderScenarios.ts b/test/core/extensions/coreIssuanceOrderScenarios.ts new file mode 100644 index 000000000..aa5ae9ebe --- /dev/null +++ b/test/core/extensions/coreIssuanceOrderScenarios.ts @@ -0,0 +1,164 @@ +import { DEPLOYED_TOKEN_QUANTITY, ZERO } from '../../../utils/constants'; +import { ether } from '../../../utils/units'; + + +export const SCENARIOS = [ + { + title: 'Base Case', + description: 'Maker pays for all components in the Set and receives Set in return.\ + Taker receives maker tokens and gives up component units.', + naturalUnit: ether(2), + componentUnit: ether(4), + tokenState: { + numberOfComponents: 2, + takerAmounts: [DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY], + makerAmounts: [ZERO, ZERO], + vault: [ZERO, ZERO], + }, + exchangeOrders: { + takerWeightsToTransfer: [1, 1], + subjectQuantityToIssue: ether(4), + }, + issuanceOrderParams: { + requiredComponentWeighting: [1, 1], + orderQuantity: ether(4), + makerTokenAmount: ether(10), + }, + }, + { + title: 'Three Set Components Case', + description: 'Maker pays for all components in the Set and receives Set in return.\ + Taker receives maker tokens and gives up component units.', + naturalUnit: ether(2), + componentUnit: ether(4), + tokenState: { + numberOfComponents: 3, + takerAmounts: [DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY], + makerAmounts: [ZERO, ZERO, ZERO], + vault: [ZERO, ZERO, ZERO], + }, + exchangeOrders: { + takerWeightsToTransfer: [1, 1, 1], + subjectQuantityToIssue: ether(4), + }, + issuanceOrderParams: { + requiredComponentWeighting: [1, 1, 1], + orderQuantity: ether(4), + makerTokenAmount: ether(10), + }, + }, + { + title: 'Maker Has One Component in Wallet', + description: 'Maker pays for two components in the Set and uses one of their own tokens to mint Set.\ + Taker receives maker tokens and gives up two component units.', + naturalUnit: ether(2), + componentUnit: ether(4), + tokenState: { + numberOfComponents: 3, + takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY], + makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), ZERO, ZERO], + vault: [ZERO, ZERO, ZERO], + }, + exchangeOrders: { + takerWeightsToTransfer: [0, 1, 1], + subjectQuantityToIssue: ether(4), + }, + issuanceOrderParams: { + requiredComponentWeighting: [0, 1, 1], + orderQuantity: ether(4), + makerTokenAmount: ether(10), + }, + }, + { + title: 'Maker Has Two Components in Wallet', + description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set.\ + Taker receives maker tokens and gives up one component unit.', + naturalUnit: ether(2), + componentUnit: ether(4), + tokenState: { + numberOfComponents: 3, + takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY], + makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], + vault: [ZERO, ZERO, ZERO], + }, + exchangeOrders: { + takerWeightsToTransfer: [0, 0, 1], + subjectQuantityToIssue: ether(4), + }, + issuanceOrderParams: { + requiredComponentWeighting: [0, 0, 1], + orderQuantity: ether(4), + makerTokenAmount: ether(10), + }, + }, + { + title: 'Maker Has One Component in Wallet, One in Vault', + description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set\ + (one in wallet and one in Vault). Taker receives maker tokens and gives up one component unit.', + naturalUnit: ether(2), + componentUnit: ether(4), + tokenState: { + numberOfComponents: 3, + takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY], + makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], + // Must have Vault amount declared in makerAmounts as well to make transfer go through + vault: [ZERO, DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], + }, + exchangeOrders: { + takerWeightsToTransfer: [0, 0, 1], + subjectQuantityToIssue: ether(4), + }, + issuanceOrderParams: { + requiredComponentWeighting: [0, 0, 1], + orderQuantity: ether(4), + makerTokenAmount: ether(10), + }, + }, + { + title: 'Maker Has One Component in Wallet, One in Vault, Taker takes half', + description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set\ + (one in wallet and one in Vault). Taker receives maker tokens and gives up one component unit. Only\ + half of order is filled.', + naturalUnit: ether(2), + componentUnit: ether(4), + tokenState: { + numberOfComponents: 3, + takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY], + makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], + // Must have Vault amount declared in makerAmounts as well to make transfer go through + vault: [ZERO, DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], + }, + exchangeOrders: { + takerWeightsToTransfer: [0, 0, .5], + subjectQuantityToIssue: ether(2), + }, + issuanceOrderParams: { + requiredComponentWeighting: [0, 0, 1], + orderQuantity: ether(4), + makerTokenAmount: ether(10), + }, + }, + { + title: 'Base Case with rounding errors', + description: 'Maker pays for all components in the Set and receives Set in return.\ + Taker receives maker tokens and gives up component units. Due to rounding errors amounts\ + received are not exact.', + naturalUnit: ether(2), + componentUnit: ether(4), + tokenState: { + numberOfComponents: 2, + takerAmounts: [DEPLOYED_TOKEN_QUANTITY, DEPLOYED_TOKEN_QUANTITY], + makerAmounts: [ZERO, ZERO], + vault: [ZERO, ZERO], + }, + exchangeOrders: { + takerWeightsToTransfer: [1, 1], + subjectQuantityToIssue: ether(4), + }, + issuanceOrderParams: { + requiredComponentWeighting: [1, 1], + orderQuantity: ether(6), + makerTokenAmount: ether(10), + }, + }, +]; diff --git a/test/contracts/core/lib/orderLibrary.spec.ts b/test/core/lib/orderLibrary.spec.ts similarity index 89% rename from test/contracts/core/lib/orderLibrary.spec.ts rename to test/core/lib/orderLibrary.spec.ts index 2be465c01..33a5f2475 100644 --- a/test/contracts/core/lib/orderLibrary.spec.ts +++ b/test/core/lib/orderLibrary.spec.ts @@ -1,20 +1,14 @@ import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -// Types -import { Address } from '../../../../types/common.js'; - -// Contract types -import { OrderLibraryMockContract } from '../../../../types/generated/order_library_mock'; - -// Core wrapper -import { CoreWrapper } from '../../../../utils/coreWrapper'; -import { generateFillOrderParameters } from '../../../../utils/orders'; -import { ether } from '../../../../utils/units'; - -// Testing Set up -import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../../utils/chaiSetup'; +import { Address } from '../../../types/common.js'; +import { OrderLibraryMockContract } from '../../../utils/contracts'; +import { CoreWrapper } from '../../../utils/coreWrapper'; +import { generateFillOrderParameters } from '../../../utils/orders'; +import { ether } from '../../../utils/units'; + +import { BigNumberSetup } from '../../../utils/bigNumberSetup'; +import ChaiSetup from '../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; diff --git a/test/contracts/core/setToken.spec.ts b/test/core/setToken.spec.ts similarity index 94% rename from test/contracts/core/setToken.spec.ts rename to test/core/setToken.spec.ts index 00bfb5a43..142231cdc 100644 --- a/test/contracts/core/setToken.spec.ts +++ b/test/core/setToken.spec.ts @@ -1,40 +1,23 @@ -import * as chai from 'chai'; import * as _ from 'lodash'; - import * as ABIDecoder from 'abi-decoder'; +import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -import { ether } from '../../../utils/units'; -// Types -import { Address } from '../../../types/common.js'; +import ChaiSetup from '../../utils/chaiSetup'; +import { BigNumberSetup } from '../../utils/bigNumberSetup'; +import { StandardTokenMockContract, SetTokenFactoryContract, SetTokenContract } from '../../utils/contracts'; +import { Address } from '../../types/common.js'; +import { ether } from '../../utils/units'; +import { assertTokenBalance, expectRevertError } from '../../utils/tokenAssertions'; +import { NULL_ADDRESS, STANDARD_COMPONENT_UNIT, STANDARD_NATURAL_UNIT, ZERO } from '../../utils/constants'; +import { CoreWrapper } from '../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../utils/erc20Wrapper'; -// Contract types -import { StandardTokenMockContract } from '../../../types/generated/standard_token_mock'; -import { SetTokenFactoryContract } from '../../../types/generated/set_token_factory'; -import { SetTokenContract } from '../../../types/generated/set_token'; - -// Artifacts -const SetToken = artifacts.require('SetToken'); - -// Core wrapper -import { CoreWrapper } from '../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; - -// Testing Set up -import { BigNumberSetup } from '../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; +const SetToken = artifacts.require('SetToken'); -import { assertTokenBalance, expectRevertError } from '../../../utils/tokenAssertions'; - -import { - NULL_ADDRESS, - STANDARD_COMPONENT_UNIT, - STANDARD_NATURAL_UNIT, - ZERO, -} from '../../../utils/constants'; contract('SetToken', accounts => { const [ diff --git a/test/contracts/core/setTokenFactory.spec.ts b/test/core/setTokenFactory.spec.ts similarity index 82% rename from test/contracts/core/setTokenFactory.spec.ts rename to test/core/setTokenFactory.spec.ts index b941543cb..7e9d9c08e 100644 --- a/test/contracts/core/setTokenFactory.spec.ts +++ b/test/core/setTokenFactory.spec.ts @@ -1,31 +1,21 @@ -import * as chai from 'chai'; - import * as ABIDecoder from 'abi-decoder'; +import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -// Types -import { Address } from '../../../types/common.js'; - -// Contract types -import { StandardTokenMockContract } from '../../../types/generated/standard_token_mock'; -import { SetTokenFactoryContract } from '../../../types/generated/set_token_factory'; +import ChaiSetup from '../../utils/chaiSetup'; +import { BigNumberSetup } from '../../utils/bigNumberSetup'; +import { StandardTokenMockContract, SetTokenFactoryContract } from '../../utils/contracts'; +import { Address } from '../../types/common.js'; +import { expectRevertError } from '../../utils/tokenAssertions'; +import { ZERO } from '../../utils/constants'; +import { CoreWrapper } from '../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../utils/erc20Wrapper'; -// Artifacts -const SetTokenFactory = artifacts.require('SetTokenFactory'); - -// Core wrapper -import { CoreWrapper } from '../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; - -// Testing Set up -import { BigNumberSetup } from '../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; +const SetTokenFactory = artifacts.require('SetTokenFactory'); -import { expectRevertError } from '../../../utils/tokenAssertions'; -import { ZERO } from '../../../utils/constants'; contract('SetTokenFactory', accounts => { const [ diff --git a/test/contracts/core/transferProxy.spec.ts b/test/core/transferProxy.spec.ts similarity index 82% rename from test/contracts/core/transferProxy.spec.ts rename to test/core/transferProxy.spec.ts index 19a8bcb9f..92c984e77 100644 --- a/test/contracts/core/transferProxy.spec.ts +++ b/test/core/transferProxy.spec.ts @@ -1,41 +1,26 @@ -import * as chai from 'chai'; - import * as ABIDecoder from 'abi-decoder'; +import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -// Types -import { Address } from '../../../types/common.js'; - -// Contract types -import { InvalidReturnTokenMockContract } from '../../../types/generated/invalid_return_token_mock'; -import { NoXferReturnTokenMockContract } from '../../../types/generated/no_xfer_return_token_mock'; -import { StandardTokenMockContract } from '../../../types/generated/standard_token_mock'; -import { StandardTokenWithFeeMockContract } from '../../../types/generated/standard_token_with_fee_mock'; -import { TransferProxyContract } from '../../../types/generated/transfer_proxy'; - -// Artifacts -const TransferProxy = artifacts.require('TransferProxy'); - -// Core wrapper -import { CoreWrapper } from '../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; +import ChaiSetup from '../../utils/chaiSetup'; +import { BigNumberSetup } from '../../utils/bigNumberSetup'; +import { + InvalidReturnTokenMockContract, + NoXferReturnTokenMockContract, + StandardTokenMockContract, + StandardTokenWithFeeMockContract, + TransferProxyContract +} from '../../utils/contracts'; +import { Address } from '../../types/common.js'; +import { assertTokenBalance, expectRevertError } from '../../utils/tokenAssertions'; +import { DEPLOYED_TOKEN_QUANTITY, UNLIMITED_ALLOWANCE_IN_BASE_UNITS } from '../../utils/constants'; +import { CoreWrapper } from '../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../utils/erc20Wrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; - -import { - assertTokenBalance, - expectRevertError -} from '../../../utils/tokenAssertions'; - -import { - DEPLOYED_TOKEN_QUANTITY, - UNLIMITED_ALLOWANCE_IN_BASE_UNITS, -} from '../../../utils/constants'; +const TransferProxy = artifacts.require('TransferProxy'); contract('TransferProxy', accounts => { diff --git a/test/contracts/core/vault.spec.ts b/test/core/vault.spec.ts similarity index 92% rename from test/contracts/core/vault.spec.ts rename to test/core/vault.spec.ts index 74226de82..f22dfdeac 100644 --- a/test/contracts/core/vault.spec.ts +++ b/test/core/vault.spec.ts @@ -1,28 +1,25 @@ import * as chai from 'chai'; - import { BigNumber } from 'bignumber.js'; -// Types -import { Address } from '../../../types/common.js'; - -// Contract types -import { InvalidReturnTokenMockContract } from '../../../types/generated/invalid_return_token_mock'; -import { NoXferReturnTokenMockContract } from '../../../types/generated/no_xfer_return_token_mock'; -import { StandardTokenMockContract } from '../../../types/generated/standard_token_mock'; -import { StandardTokenWithFeeMockContract } from '../../../types/generated/standard_token_with_fee_mock'; -import { VaultContract } from '../../../types/generated/vault'; +import ChaiSetup from '../../utils/chaiSetup'; +import { BigNumberSetup } from '../../utils/bigNumberSetup'; +import { + InvalidReturnTokenMockContract, + NoXferReturnTokenMockContract, + StandardTokenMockContract, + StandardTokenWithFeeMockContract, + VaultContract +} from '../../utils/contracts'; +import { Address } from '../../types/common.js'; +import { assertTokenBalance, expectRevertError } from '../../utils/tokenAssertions'; +import { DEPLOYED_TOKEN_QUANTITY, NULL_ADDRESS, ZERO } from '../../utils/constants'; +import { CoreWrapper } from '../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../utils/erc20Wrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; -import { CoreWrapper } from '../../../utils/coreWrapper'; -import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; -import { assertTokenBalance, expectRevertError } from '../../../utils/tokenAssertions'; -import { DEPLOYED_TOKEN_QUANTITY, NULL_ADDRESS, ZERO } from '../../../utils/constants'; contract('Vault', accounts => { const [ diff --git a/test/contracts/lib/authorizable.spec.ts b/test/lib/authorizable.spec.ts similarity index 91% rename from test/contracts/lib/authorizable.spec.ts rename to test/lib/authorizable.spec.ts index a9b90b66a..65620c930 100644 --- a/test/contracts/lib/authorizable.spec.ts +++ b/test/lib/authorizable.spec.ts @@ -1,40 +1,21 @@ -import * as chai from 'chai'; - import * as ABIDecoder from 'abi-decoder'; +import * as chai from 'chai'; import { BigNumber } from 'bignumber.js'; -// Types -import { Address } from '../../../types/common.js'; - -// Contract types -import { AuthorizableContract } from '../../../types/generated/authorizable'; - -// Artifacts -const Authorizable = artifacts.require('Authorizable'); - -// Core wrapper -import { CoreWrapper } from '../../../utils/coreWrapper'; +import ChaiSetup from '../../utils/chaiSetup'; +import { BigNumberSetup } from '../../utils/bigNumberSetup'; +import { AuthorizableContract } from '../../utils/contracts'; +import { Address } from '../../types/common.js'; +import { assertLogEquivalence, getFormattedLogsFromTxHash } from '../../utils/logs'; +import { getExpectedAddAuthorizedLog, getExpectedRemoveAuthorizedLog } from '../../utils/contract_logs/authorizable'; +import { expectRevertError } from '../../utils/tokenAssertions'; +import { CoreWrapper } from '../../utils/coreWrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; +const Authorizable = artifacts.require('Authorizable'); -import { - assertLogEquivalence, - getFormattedLogsFromTxHash -} from '../../../utils/logs'; - -import { - getExpectedAddAuthorizedLog, - getExpectedRemoveAuthorizedLog, -} from '../../../utils/contract_logs/authorizable'; - -import { - expectRevertError, -} from '../../../utils/tokenAssertions'; contract('Authorizable', accounts => { const [ diff --git a/test/contracts/lib/commonMath.spec.ts b/test/lib/commonMath.spec.ts similarity index 72% rename from test/contracts/lib/commonMath.spec.ts rename to test/lib/commonMath.spec.ts index aea997142..2ef6d4a91 100644 --- a/test/contracts/lib/commonMath.spec.ts +++ b/test/lib/commonMath.spec.ts @@ -1,19 +1,12 @@ import * as chai from 'chai'; - import { BigNumber } from 'bignumber.js'; -// Types -import { Address } from '../../../types/common.js'; - -// Contract types -import { CommonMathMockContract } from '../../../types/generated/common_math_mock'; - -// Wrappers -import { LibraryMockWrapper } from '../../../utils/libraryMockWrapper'; +import ChaiSetup from '../../utils/chaiSetup'; +import { BigNumberSetup } from '../../utils/bigNumberSetup'; +import { Address } from '../../types/common.js'; +import { CommonMathMockContract } from '../../utils/contracts'; +import { LibraryMockWrapper } from '../../utils/libraryMockWrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; diff --git a/test/contracts/lib/erc20Wrapper.spec.ts b/test/lib/erc20Wrapper.spec.ts similarity index 84% rename from test/contracts/lib/erc20Wrapper.spec.ts rename to test/lib/erc20Wrapper.spec.ts index 0b9f07a54..9409a7b32 100644 --- a/test/contracts/lib/erc20Wrapper.spec.ts +++ b/test/lib/erc20Wrapper.spec.ts @@ -1,36 +1,24 @@ import * as chai from 'chai'; - import { BigNumber } from 'bignumber.js'; -import { ether } from '../../../utils/units'; - -// Types -import { Address } from '../../../types/common.js'; -// Contract types -import { InvalidReturnTokenMockContract } from '../../../types/generated/invalid_return_token_mock'; -import { ERC20WrapperMockContract } from '../../../types/generated/e_r_c20_wrapper_mock'; -import { StandardTokenMockContract } from '../../../types/generated/standard_token_mock'; - -// Wrappers -import { LibraryMockWrapper } from '../../../utils/libraryMockWrapper'; -import { ERC20Wrapper } from '../../../utils/erc20Wrapper'; +import ChaiSetup from '../../utils/chaiSetup'; +import { BigNumberSetup } from '../../utils/bigNumberSetup'; +import { + InvalidReturnTokenMockContract, + ERC20WrapperMockContract, + StandardTokenMockContract +} from '../../utils/contracts'; +import { ether } from '../../utils/units'; +import { Address } from '../../types/common.js'; +import { expectRevertError } from '../../utils/tokenAssertions'; +import { UNLIMITED_ALLOWANCE_IN_BASE_UNITS, ZERO } from '../../utils/constants'; +import { LibraryMockWrapper } from '../../utils/libraryMockWrapper'; +import { ERC20Wrapper } from '../../utils/erc20Wrapper'; -// Testing Set up -import { BigNumberSetup } from '../../../utils/bigNumberSetup'; -import ChaiSetup from '../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; -import { - expectRevertError -} from '../../../utils/tokenAssertions'; - -import { - UNLIMITED_ALLOWANCE_IN_BASE_UNITS, - ZERO, -} from '../../../utils/constants'; - contract('ERC20WrapperMock', accounts => { const [ diff --git a/utils/contracts.ts b/utils/contracts.ts new file mode 100644 index 000000000..7ac0a5e9e --- /dev/null +++ b/utils/contracts.ts @@ -0,0 +1,34 @@ +import { AuthorizableContract } from '../types/generated/authorizable'; +import { CommonMathMockContract } from '../types/generated/common_math_mock'; +import { CoreContract } from '../types/generated/core'; +import { ERC20WrapperMockContract } from '../types/generated/e_r_c20_wrapper_mock'; +import { InvalidReturnTokenMockContract } from '../types/generated/invalid_return_token_mock'; +import { NoXferReturnTokenMockContract } from '../types/generated/no_xfer_return_token_mock'; +import { OrderLibraryMockContract } from '../types/generated/order_library_mock'; +import { SetTokenContract } from '../types/generated/set_token'; +import { SetTokenFactoryContract } from '../types/generated/set_token_factory'; +import { StandardTokenMockContract } from '../types/generated/standard_token_mock'; +import { StandardTokenWithFeeMockContract } from '../types/generated/standard_token_with_fee_mock'; +import { TakerWalletWrapperContract } from '../types/generated/taker_wallet_wrapper'; +import { TransferProxyContract } from '../types/generated/transfer_proxy'; +import { VaultContract } from '../types/generated/vault'; +import { ZeroExOrderDataHandlerMockContract } from '../types/generated/zero_ex_order_data_handler_mock'; + + +export { + AuthorizableContract, + CommonMathMockContract, + CoreContract, + ERC20WrapperMockContract, + InvalidReturnTokenMockContract, + NoXferReturnTokenMockContract, + OrderLibraryMockContract, + SetTokenContract, + SetTokenFactoryContract, + StandardTokenMockContract, + StandardTokenWithFeeMockContract, + TakerWalletWrapperContract, + TransferProxyContract, + VaultContract, + ZeroExOrderDataHandlerMockContract +}; diff --git a/utils/libraryMockWrapper.ts b/utils/libraryMockWrapper.ts index 58393cd18..f8af756d3 100644 --- a/utils/libraryMockWrapper.ts +++ b/utils/libraryMockWrapper.ts @@ -1,14 +1,13 @@ -import * as _ from "lodash"; +import { + CommonMathMockContract, + ERC20WrapperMockContract, + ZeroExOrderDataHandlerMockContract +} from './contracts'; +import { Address } from '../types/common.js'; -import { CommonMathMockContract } from "../types/generated/common_math_mock"; -import { ERC20WrapperMockContract } from "../types/generated/e_r_c20_wrapper_mock"; - -import { BigNumber } from "bignumber.js"; -import { Address } from "../types/common.js"; -import { DEFAULT_GAS } from "./constants"; - -const ERC20WrapperMock = artifacts.require("ERC20WrapperMock"); -const CommonMathMock = artifacts.require("CommonMathMock"); +const ERC20WrapperMock = artifacts.require('ERC20WrapperMock'); +const CommonMathMock = artifacts.require('CommonMathMock'); +const ZeroExOrderDataHandlerMock = artifacts.require('ZeroExOrderDataHandlerMock'); export class LibraryMockWrapper { @@ -45,4 +44,17 @@ export class LibraryMockWrapper { { from }, ); } + + public async deployZeroExOrderDataHandlerLibraryAsync( + from: Address = this._contractOwnerAddress + ): Promise { + const zeroExExchangeWrapperInstance = await ZeroExOrderDataHandlerMock.new( + { from }, + ); + + return new ZeroExOrderDataHandlerMockContract( + web3.eth.contract(zeroExExchangeWrapperInstance.abi).at(zeroExExchangeWrapperInstance.address), + { from }, + ); + } }