aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/test/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contract-wrappers/test/utils')
-rw-r--r--packages/contract-wrappers/test/utils/chai_setup.ts13
-rw-r--r--packages/contract-wrappers/test/utils/constants.ts19
-rw-r--r--packages/contract-wrappers/test/utils/dutch_auction_utils.ts153
-rw-r--r--packages/contract-wrappers/test/utils/migrate.ts18
-rw-r--r--packages/contract-wrappers/test/utils/token_utils.ts35
-rw-r--r--packages/contract-wrappers/test/utils/web3_wrapper.ts12
6 files changed, 0 insertions, 250 deletions
diff --git a/packages/contract-wrappers/test/utils/chai_setup.ts b/packages/contract-wrappers/test/utils/chai_setup.ts
deleted file mode 100644
index 1a8733093..000000000
--- a/packages/contract-wrappers/test/utils/chai_setup.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import * as chai from 'chai';
-import chaiAsPromised = require('chai-as-promised');
-import ChaiBigNumber = require('chai-bignumber');
-import * as dirtyChai from 'dirty-chai';
-
-export const chaiSetup = {
- configure(): void {
- chai.config.includeStack = true;
- chai.use(ChaiBigNumber());
- chai.use(dirtyChai);
- chai.use(chaiAsPromised);
- },
-};
diff --git a/packages/contract-wrappers/test/utils/constants.ts b/packages/contract-wrappers/test/utils/constants.ts
deleted file mode 100644
index ca6c574e4..000000000
--- a/packages/contract-wrappers/test/utils/constants.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { BigNumber } from '@0x/utils';
-
-export const constants = {
- NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
- ROPSTEN_NETWORK_ID: 3,
- KOVAN_NETWORK_ID: 42,
- TESTRPC_NETWORK_ID: 50,
- AWAIT_TRANSACTION_MINED_MS: 0,
- KOVAN_RPC_URL: 'https://kovan.infura.io/',
- ROPSTEN_RPC_URL: 'https://ropsten.infura.io/',
- ZRX_DECIMALS: 18,
- DUMMY_TOKEN_NAME: '',
- DUMMY_TOKEN_SYMBOL: '',
- DUMMY_TOKEN_DECIMALS: 18,
- DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(10 ** 27), // tslint:disable-line:custom-no-magic-numbers
- NUM_DUMMY_ERC20_TO_DEPLOY: 3,
- NUM_DUMMY_ERC721_TO_DEPLOY: 1,
- ZERO_AMOUNT: new BigNumber(0),
-};
diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts
deleted file mode 100644
index 8e2aef217..000000000
--- a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts
+++ /dev/null
@@ -1,153 +0,0 @@
-import { DummyERC20TokenContract } from '@0x/abi-gen-wrappers';
-import * as artifacts from '@0x/contract-artifacts';
-import { assetDataUtils } from '@0x/order-utils';
-import { orderFactory } from '@0x/order-utils/lib/src/order_factory';
-import { SignedOrder } from '@0x/types';
-import { BigNumber } from '@0x/utils';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-
-import { DutchAuctionWrapper } from '../../src/contract_wrappers/dutch_auction_wrapper';
-
-import { constants } from './constants';
-
-export class DutchAuctionUtils {
- private readonly _web3Wrapper: Web3Wrapper;
- private readonly _coinbase: string;
- private readonly _exchangeAddress: string;
- private readonly _erc20ProxyAddress: string;
-
- constructor(web3Wrapper: Web3Wrapper, coinbase: string, exchangeAddress: string, erc20ProxyAddress: string) {
- this._web3Wrapper = web3Wrapper;
- this._coinbase = coinbase;
- this._exchangeAddress = exchangeAddress;
- this._erc20ProxyAddress = erc20ProxyAddress;
- }
- public async createSignedSellOrderAsync(
- auctionBeginTimeSections: BigNumber,
- acutionEndTimeSeconds: BigNumber,
- auctionBeginTakerAssetAmount: BigNumber,
- auctionEndTakerAssetAmount: BigNumber,
- makerAssetAmount: BigNumber,
- makerAssetData: string,
- takerAssetData: string,
- makerAddress: string,
- takerAddress: string,
- senderAddress?: string,
- makerFee?: BigNumber,
- takerFee?: BigNumber,
- feeRecipientAddress?: string,
- ): Promise<SignedOrder> {
- // Notes on sell order:
- // - The `takerAssetAmount` is set to the `auctionEndTakerAssetAmount`, which is the lowest amount the
- // the seller can expect to receive
- // - The `makerAssetData` is overloaded to include the auction begin time and begin taker asset amount
- const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData(
- makerAssetData,
- auctionBeginTimeSections,
- auctionBeginTakerAssetAmount,
- );
- const signedOrder = await orderFactory.createSignedOrderAsync(
- this._web3Wrapper.getProvider(),
- makerAddress,
- makerAssetAmount,
- makerAssetDataWithAuctionDetails,
- auctionEndTakerAssetAmount,
- takerAssetData,
- this._exchangeAddress,
- {
- takerAddress,
- senderAddress,
- makerFee,
- takerFee,
- feeRecipientAddress,
- expirationTimeSeconds: acutionEndTimeSeconds,
- },
- );
- const erc20AssetData = assetDataUtils.decodeERC20AssetData(makerAssetData);
- await this._increaseERC20BalanceAndAllowanceAsync(erc20AssetData.tokenAddress, makerAddress, makerAssetAmount);
- return signedOrder;
- }
- public async createSignedBuyOrderAsync(
- sellOrder: SignedOrder,
- buyerAddress: string,
- senderAddress?: string,
- makerFee?: BigNumber,
- takerFee?: BigNumber,
- feeRecipientAddress?: string,
- expirationTimeSeconds?: BigNumber,
- ): Promise<SignedOrder> {
- const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData);
- // Notes on buy order:
- // - The `makerAssetAmount` is set to `dutchAuctionData.beginAmount`, which is
- // the highest amount the buyer would have to pay out at any point during the auction.
- // - The `takerAssetAmount` is set to the seller's `makerAssetAmount`, as the buyer
- // receives the entire amount being sold by the seller.
- // - The `makerAssetData`/`takerAssetData` are reversed from the sell order
- const signedOrder = await orderFactory.createSignedOrderAsync(
- this._web3Wrapper.getProvider(),
- buyerAddress,
- dutchAuctionData.beginAmount,
- sellOrder.takerAssetData,
- sellOrder.makerAssetAmount,
- sellOrder.makerAssetData,
- sellOrder.exchangeAddress,
- {
- senderAddress,
- makerFee,
- takerFee,
- feeRecipientAddress,
- expirationTimeSeconds,
- },
- );
- const buyerERC20AssetData = assetDataUtils.decodeERC20AssetData(sellOrder.takerAssetData);
- await this._increaseERC20BalanceAndAllowanceAsync(
- buyerERC20AssetData.tokenAddress,
- buyerAddress,
- dutchAuctionData.beginAmount,
- );
- return signedOrder;
- }
- private async _increaseERC20BalanceAndAllowanceAsync(
- tokenAddress: string,
- address: string,
- amount: BigNumber,
- ): Promise<void> {
- if (amount.isZero() || address === constants.NULL_ADDRESS) {
- return; // noop
- }
- await Promise.all([
- this._increaseERC20BalanceAsync(tokenAddress, address, amount),
- this._increaseERC20AllowanceAsync(tokenAddress, address, amount),
- ]);
- }
- private async _increaseERC20BalanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
- const erc20Token = new DummyERC20TokenContract(
- artifacts.DummyERC20Token.compilerOutput.abi,
- tokenAddress,
- this._web3Wrapper.getProvider(),
- this._web3Wrapper.getContractDefaults(),
- );
- const txHash = await erc20Token.transfer.sendTransactionAsync(address, amount, {
- from: this._coinbase,
- });
- await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
- }
- private async _increaseERC20AllowanceAsync(
- tokenAddress: string,
- address: string,
- amount: BigNumber,
- ): Promise<void> {
- const erc20Token = new DummyERC20TokenContract(
- artifacts.DummyERC20Token.compilerOutput.abi,
- tokenAddress,
- this._web3Wrapper.getProvider(),
- this._web3Wrapper.getContractDefaults(),
- );
- const oldMakerAllowance = await erc20Token.allowance.callAsync(address, this._erc20ProxyAddress);
- const newMakerAllowance = oldMakerAllowance.plus(amount);
- const txHash = await erc20Token.approve.sendTransactionAsync(this._erc20ProxyAddress, newMakerAllowance, {
- from: address,
- });
- await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
- }
-}
diff --git a/packages/contract-wrappers/test/utils/migrate.ts b/packages/contract-wrappers/test/utils/migrate.ts
deleted file mode 100644
index 665ce0faa..000000000
--- a/packages/contract-wrappers/test/utils/migrate.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { ContractAddresses } from '@0x/contract-addresses';
-import { devConstants } from '@0x/dev-utils';
-import { runMigrationsOnceAsync } from '@0x/migrations';
-
-import { provider } from './web3_wrapper';
-
-/**
- * Configures and runs the migrations exactly once. Any subsequent times this is
- * called, it returns the cached addresses.
- * @returns The addresses of contracts that were deployed during the migrations.
- */
-export async function migrateOnceAsync(): Promise<ContractAddresses> {
- const txDefaults = {
- gas: devConstants.GAS_LIMIT,
- from: devConstants.TESTRPC_FIRST_ADDRESS,
- };
- return runMigrationsOnceAsync(provider, txDefaults);
-}
diff --git a/packages/contract-wrappers/test/utils/token_utils.ts b/packages/contract-wrappers/test/utils/token_utils.ts
deleted file mode 100644
index e390d2775..000000000
--- a/packages/contract-wrappers/test/utils/token_utils.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { DummyERC721TokenContract } from '@0x/abi-gen-wrappers';
-import { DummyERC721Token } from '@0x/contract-artifacts';
-import { generatePseudoRandomSalt } from '@0x/order-utils';
-import { BigNumber } from '@0x/utils';
-
-import { provider, txDefaults, web3Wrapper } from './web3_wrapper';
-
-// Those addresses come from migrations. They're deterministic so it's relatively safe to hard-code them here.
-// Before we were fetching them from the TokenRegistry but now we can't as it's deprecated and removed.
-// TODO(albrow): Import these from the migrations package instead of hard-coding them.
-const DUMMY_ERC_20_ADRESSES = [
- '0x34d402f14d58e001d8efbe6585051bf9706aa064',
- '0x25b8fe1de9daf8ba351890744ff28cf7dfa8f5e3',
- '0xcdb594a32b1cc3479d8746279712c39d18a07fc0',
- '0x1e2f9e10d02a6b8f8f69fcbf515e75039d2ea30d',
- '0xbe0037eaf2d64fe5529bca93c18c9702d3930376',
-];
-
-const DUMMY_ERC_721_ADRESSES = ['0x07f96aa816c1f244cbc6ef114bb2b023ba54a2eb'];
-
-export const tokenUtils = {
- getDummyERC20TokenAddresses(): string[] {
- return DUMMY_ERC_20_ADRESSES;
- },
- getDummyERC721TokenAddresses(): string[] {
- return DUMMY_ERC_721_ADRESSES;
- },
- async mintDummyERC721Async(address: string, tokenOwner: string): Promise<BigNumber> {
- const erc721 = new DummyERC721TokenContract(DummyERC721Token.compilerOutput.abi, address, provider, txDefaults);
- const tokenId = generatePseudoRandomSalt();
- const txHash = await erc721.mint.sendTransactionAsync(tokenOwner, tokenId);
- web3Wrapper.awaitTransactionSuccessAsync(txHash);
- return tokenId;
- },
-};
diff --git a/packages/contract-wrappers/test/utils/web3_wrapper.ts b/packages/contract-wrappers/test/utils/web3_wrapper.ts
deleted file mode 100644
index 4e86ebeba..000000000
--- a/packages/contract-wrappers/test/utils/web3_wrapper.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { devConstants, web3Factory } from '@0x/dev-utils';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-import { Provider } from 'ethereum-types';
-
-const txDefaults = {
- from: devConstants.TESTRPC_FIRST_ADDRESS,
- gas: devConstants.GAS_LIMIT,
-};
-const provider: Provider = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true });
-const web3Wrapper = new Web3Wrapper(provider);
-
-export { provider, web3Wrapper, txDefaults };