Refactor contracts-* exports so none in test dir so npmignore works as intended
This commit is contained in:
@@ -5,7 +5,7 @@ import { SignatureType, SignedZeroExTransaction, ZeroExTransaction } from '@0x/t
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
export type Constructor<T = {}> = new (...args: any[]) => T;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
|
||||
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
import { Actor, Constructor } from './base';
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import { BigNumber } from '@0x/utils';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
|
||||
import { Actor, actorAddressesByName, FeeRecipient, Maker } from '../actors';
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
import { deployCoordinatorAsync } from './deploy_coordinator';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { artifacts as exchangeArtifacts } from '@0x/contracts-exchange';
|
||||
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
/**
|
||||
* Deploys a Coordinator contract configured to work alongside the provided `deployment`.
|
||||
|
||||
@@ -3,7 +3,7 @@ import { artifacts, ForwarderContract } from '@0x/contracts-exchange-forwarder';
|
||||
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils';
|
||||
import { assetDataUtils } from '@0x/order-utils';
|
||||
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
/**
|
||||
* Deploys a Forwarder contract configured to work alongside the provided `deployment`.
|
||||
|
||||
@@ -21,7 +21,7 @@ import { ForwarderRevertErrors } from '@0x/order-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { Actor, actorAddressesByName, FeeRecipient, Maker } from '../actors';
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
import { deployForwarderAsync } from './deploy_forwarder';
|
||||
import { ForwarderTestFactory } from './forwarder_test_factory';
|
||||
|
||||
@@ -7,7 +7,7 @@ import { BigNumber, RevertError } from '@0x/utils';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
|
||||
import { Actor, FeeRecipient, Maker } from '../actors';
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
// Necessary bookkeeping to validate Forwarder results
|
||||
interface ForwarderFillState {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { constants as stakingConstants } from '@0x/contracts-staking';
|
||||
import { blockchainTests, expect } from '@0x/contracts-test-utils';
|
||||
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { Authorizable, Ownable } from '../utils/wrapper_interfaces';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
import { Authorizable, Ownable } from '../../src/wrapper_interfaces';
|
||||
|
||||
blockchainTests('Deployment Manager', env => {
|
||||
let owner: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { blockchainTests, constants, expect, filterLogsToArguments, getRandomInt
|
||||
import { BigNumber, StringRevertError } from '@0x/utils';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
|
||||
import { FunctionAssertion, Result } from '../utils/function_assertions';
|
||||
import { FunctionAssertion, Result } from '../../src/function_assertions';
|
||||
|
||||
import { artifacts } from '../artifacts';
|
||||
import { TestFrameworkContract, TestFrameworkEventEventArgs, TestFrameworkEvents } from '../wrappers';
|
||||
|
||||
@@ -33,7 +33,7 @@ import { AssetProxyId } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { TxData } from 'ethereum-types';
|
||||
|
||||
import { AssetProxyDispatcher, Authorizable, Ownable } from '../utils/wrapper_interfaces';
|
||||
import { AssetProxyDispatcher, Authorizable, Ownable } from '../../src/wrapper_interfaces';
|
||||
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
blockchainTests('Deployment and Configuration End to End Tests', env => {
|
||||
|
||||
@@ -30,7 +30,7 @@ import * as _ from 'lodash';
|
||||
|
||||
import { Actor } from '../actors/base';
|
||||
import { Maker } from '../actors/maker';
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
const { addFillResults, safeGetPartialAmountFloor } = ReferenceFunctions;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import { BigNumber } from '@0x/utils';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
|
||||
import { actorAddressesByName, FeeRecipient, Maker, OperatorStakerMaker, StakerKeeper, Taker } from '../actors';
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
import { DeploymentManager } from '../../src/deployment_manager';
|
||||
|
||||
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
|
||||
blockchainTests.resets('fillOrder integration tests', env => {
|
||||
|
||||
@@ -1,485 +0,0 @@
|
||||
import {
|
||||
artifacts as assetProxyArtifacts,
|
||||
ERC1155ProxyContract,
|
||||
ERC20ProxyContract,
|
||||
ERC721ProxyContract,
|
||||
MultiAssetProxyContract,
|
||||
StaticCallProxyContract,
|
||||
} from '@0x/contracts-asset-proxy';
|
||||
import { artifacts as ERC1155Artifacts, ERC1155MintableContract } from '@0x/contracts-erc1155';
|
||||
import { artifacts as ERC20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20';
|
||||
import { artifacts as ERC721Artifacts, DummyERC721TokenContract } from '@0x/contracts-erc721';
|
||||
import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts-exchange';
|
||||
import { artifacts as multisigArtifacts, ZeroExGovernorContract } from '@0x/contracts-multisig';
|
||||
import {
|
||||
artifacts as stakingArtifacts,
|
||||
StakingProxyContract,
|
||||
TestStakingContract,
|
||||
ZrxVaultContract,
|
||||
} from '@0x/contracts-staking';
|
||||
import { BlockchainTestsEnvironment, constants } from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { TxData } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { AssetProxyDispatcher, Authorizable, Ownable } from './wrapper_interfaces';
|
||||
|
||||
/**
|
||||
* Adds a batch of authorities to a list of authorizable contracts.
|
||||
* @param owner The owner of the authorizable contracts.
|
||||
* @param authorizers The authorizable contracts.
|
||||
* @param authorities A list of addresses to authorize in each authorizer contract.
|
||||
*/
|
||||
async function batchAddAuthorizedAddressAsync(
|
||||
owner: string,
|
||||
authorizers: Authorizable[],
|
||||
authorities: string[],
|
||||
): Promise<void> {
|
||||
for (const authorizer of authorizers) {
|
||||
for (const authority of authorities) {
|
||||
await authorizer.addAuthorizedAddress.awaitTransactionSuccessAsync(authority, { from: owner });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch registers asset proxies in a list of registry contracts.
|
||||
* @param owner The owner of the registry accounts.
|
||||
* @param registries The registries that the asset proxies should be registered in.
|
||||
* @param proxies A list of proxy contracts to register.
|
||||
*/
|
||||
async function batchRegisterAssetProxyAsync(
|
||||
owner: string,
|
||||
registries: AssetProxyDispatcher[],
|
||||
proxies: string[],
|
||||
): Promise<void> {
|
||||
for (const registry of registries) {
|
||||
for (const proxy of proxies) {
|
||||
await registry.registerAssetProxy.awaitTransactionSuccessAsync(proxy, { from: owner });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers ownership of several contracts from one address to another.
|
||||
* @param owner The address that currently owns the contract instances.
|
||||
* @param newOwner The address that will be given ownership of the contract instances.
|
||||
* @param ownedContracts The contracts whose ownership will be transferred.
|
||||
*/
|
||||
async function batchTransferOwnershipAsync(
|
||||
owner: string,
|
||||
newOwner: ZeroExGovernorContract,
|
||||
ownedContracts: Ownable[],
|
||||
): Promise<void> {
|
||||
for (const ownedContract of ownedContracts) {
|
||||
await ownedContract.transferOwnership.awaitTransactionSuccessAsync(newOwner.address, { from: owner });
|
||||
}
|
||||
}
|
||||
|
||||
// Contract wrappers for all of the asset proxies
|
||||
interface AssetProxyContracts {
|
||||
erc20Proxy: ERC20ProxyContract;
|
||||
erc721Proxy: ERC721ProxyContract;
|
||||
erc1155Proxy: ERC1155ProxyContract;
|
||||
multiAssetProxy: MultiAssetProxyContract;
|
||||
staticCallProxy: StaticCallProxyContract;
|
||||
}
|
||||
|
||||
// Contract wrappers for all of the staking contracts
|
||||
interface StakingContracts {
|
||||
stakingLogic: TestStakingContract;
|
||||
stakingProxy: StakingProxyContract;
|
||||
stakingWrapper: TestStakingContract;
|
||||
zrxVault: ZrxVaultContract;
|
||||
}
|
||||
|
||||
// Contract wrappers for tokens.
|
||||
interface TokenContracts {
|
||||
erc20: DummyERC20TokenContract[];
|
||||
erc721: DummyERC721TokenContract[];
|
||||
erc1155: ERC1155MintableContract[];
|
||||
weth: WETH9Contract;
|
||||
zrx: DummyERC20TokenContract;
|
||||
}
|
||||
|
||||
// Options to be passed to `deployAsync`
|
||||
export interface DeploymentOptions {
|
||||
owner: string;
|
||||
numErc1155TokensToDeploy: number;
|
||||
numErc20TokensToDeploy: number;
|
||||
numErc721TokensToDeploy: number;
|
||||
}
|
||||
|
||||
export class DeploymentManager {
|
||||
public static readonly protocolFeeMultiplier = new BigNumber(150000);
|
||||
public static readonly gasPrice = new BigNumber(1e9); // 1 Gwei
|
||||
public static readonly protocolFee = DeploymentManager.gasPrice.times(DeploymentManager.protocolFeeMultiplier);
|
||||
|
||||
/**
|
||||
* Fully deploy the 0x exchange and staking contracts and configure the system with the
|
||||
* asset proxy owner multisig.
|
||||
* @param environment A blockchain test environment to use for contracts deployment.
|
||||
* @param options Specifies the owner address and number of tokens to deploy.
|
||||
*/
|
||||
public static async deployAsync(
|
||||
environment: BlockchainTestsEnvironment,
|
||||
options: Partial<DeploymentOptions> = {},
|
||||
): Promise<DeploymentManager> {
|
||||
const chainId = await environment.getChainIdAsync();
|
||||
const accounts = await environment.getAccountAddressesAsync();
|
||||
|
||||
const owner = options.owner || (await environment.getAccountAddressesAsync())[0];
|
||||
const txDefaults = {
|
||||
...environment.txDefaults,
|
||||
from: owner,
|
||||
gasPrice: DeploymentManager.gasPrice,
|
||||
};
|
||||
|
||||
// Deploy the contracts using the same owner and environment.
|
||||
const assetProxies = await DeploymentManager._deployAssetProxyContractsAsync(environment, txDefaults);
|
||||
const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
|
||||
exchangeArtifacts.Exchange,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
{ ...ERC20Artifacts, ...exchangeArtifacts, ...stakingArtifacts },
|
||||
new BigNumber(chainId),
|
||||
);
|
||||
const governor = await ZeroExGovernorContract.deployFrom0xArtifactAsync(
|
||||
multisigArtifacts.ZeroExGovernor,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
multisigArtifacts,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[owner],
|
||||
new BigNumber(1),
|
||||
constants.ZERO_AMOUNT,
|
||||
);
|
||||
const tokens = await DeploymentManager._deployTokenContractsAsync(environment, txDefaults, options);
|
||||
const staking = await DeploymentManager._deployStakingContractsAsync(
|
||||
environment,
|
||||
owner,
|
||||
txDefaults,
|
||||
tokens,
|
||||
assetProxies,
|
||||
);
|
||||
|
||||
// Configure the asset proxies with the exchange and the exchange with the staking contracts.
|
||||
await DeploymentManager._configureAssetProxiesWithExchangeAsync(assetProxies, exchange, owner);
|
||||
await DeploymentManager._configureExchangeWithStakingAsync(exchange, staking, owner);
|
||||
|
||||
// Authorize the asset-proxy owner in the staking proxy and in the zrx vault.
|
||||
await staking.stakingProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(governor.address, {
|
||||
from: owner,
|
||||
});
|
||||
await staking.zrxVault.addAuthorizedAddress.awaitTransactionSuccessAsync(governor.address, {
|
||||
from: owner,
|
||||
});
|
||||
|
||||
// Remove authorization for the original owner address.
|
||||
await staking.stakingProxy.removeAuthorizedAddress.awaitTransactionSuccessAsync(owner, { from: owner });
|
||||
await staking.zrxVault.removeAuthorizedAddress.awaitTransactionSuccessAsync(owner, { from: owner });
|
||||
|
||||
// Transfer complete ownership of the system to the asset proxy owner.
|
||||
await batchTransferOwnershipAsync(owner, governor, [
|
||||
assetProxies.erc20Proxy,
|
||||
assetProxies.erc721Proxy,
|
||||
assetProxies.erc1155Proxy,
|
||||
assetProxies.multiAssetProxy,
|
||||
exchange,
|
||||
staking.stakingProxy,
|
||||
]);
|
||||
|
||||
return new DeploymentManager(assetProxies, governor, exchange, staking, tokens, chainId, accounts, txDefaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a set of asset proxies with an exchange contract.
|
||||
* @param assetProxies A set of asset proxies to be configured.
|
||||
* @param exchange An exchange contract to configure with the asset proxies.
|
||||
* @param owner An owner address to use when configuring the asset proxies.
|
||||
*/
|
||||
protected static async _configureAssetProxiesWithExchangeAsync(
|
||||
assetProxies: AssetProxyContracts,
|
||||
exchange: ExchangeContract,
|
||||
owner: string,
|
||||
): Promise<void> {
|
||||
// Register the asset proxies in the exchange contract.
|
||||
await batchRegisterAssetProxyAsync(
|
||||
owner,
|
||||
[exchange],
|
||||
[
|
||||
assetProxies.erc20Proxy.address,
|
||||
assetProxies.erc721Proxy.address,
|
||||
assetProxies.erc1155Proxy.address,
|
||||
assetProxies.multiAssetProxy.address,
|
||||
assetProxies.staticCallProxy.address,
|
||||
],
|
||||
);
|
||||
|
||||
// Register the asset proxies in the multi-asset proxy.
|
||||
await batchRegisterAssetProxyAsync(
|
||||
owner,
|
||||
[assetProxies.multiAssetProxy],
|
||||
[
|
||||
assetProxies.erc20Proxy.address,
|
||||
assetProxies.erc721Proxy.address,
|
||||
assetProxies.erc1155Proxy.address,
|
||||
assetProxies.staticCallProxy.address,
|
||||
],
|
||||
);
|
||||
|
||||
// Add the multi-asset proxy as an authorized address of the token proxies.
|
||||
await batchAddAuthorizedAddressAsync(
|
||||
owner,
|
||||
[assetProxies.erc20Proxy, assetProxies.erc721Proxy, assetProxies.erc1155Proxy],
|
||||
[assetProxies.multiAssetProxy.address],
|
||||
);
|
||||
|
||||
// Add the exchange as an authorized address in all of the proxies.
|
||||
await batchAddAuthorizedAddressAsync(
|
||||
owner,
|
||||
[
|
||||
assetProxies.erc20Proxy,
|
||||
assetProxies.erc721Proxy,
|
||||
assetProxies.erc1155Proxy,
|
||||
assetProxies.multiAssetProxy,
|
||||
],
|
||||
[exchange.address],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures an exchange contract with staking contracts
|
||||
* @param exchange The Exchange contract.
|
||||
* @param staking The Staking contracts.
|
||||
* @param owner An owner address to use when configuring the asset proxies.
|
||||
*/
|
||||
protected static async _configureExchangeWithStakingAsync(
|
||||
exchange: ExchangeContract,
|
||||
staking: StakingContracts,
|
||||
owner: string,
|
||||
): Promise<void> {
|
||||
// Configure the exchange for staking.
|
||||
await exchange.setProtocolFeeCollectorAddress.awaitTransactionSuccessAsync(staking.stakingProxy.address, {
|
||||
from: owner,
|
||||
});
|
||||
await exchange.setProtocolFeeMultiplier.awaitTransactionSuccessAsync(DeploymentManager.protocolFeeMultiplier);
|
||||
|
||||
// Register the exchange contract in staking.
|
||||
await staking.stakingWrapper.addExchangeAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner });
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy a set of asset proxy contracts.
|
||||
* @param environment The blockchain environment to use.
|
||||
* @param txDefaults Defaults to use when deploying the asset proxies.
|
||||
*/
|
||||
protected static async _deployAssetProxyContractsAsync(
|
||||
environment: BlockchainTestsEnvironment,
|
||||
txDefaults: Partial<TxData>,
|
||||
): Promise<AssetProxyContracts> {
|
||||
const erc20Proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(
|
||||
assetProxyArtifacts.ERC20Proxy,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
assetProxyArtifacts,
|
||||
);
|
||||
const erc721Proxy = await ERC721ProxyContract.deployFrom0xArtifactAsync(
|
||||
assetProxyArtifacts.ERC721Proxy,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
assetProxyArtifacts,
|
||||
);
|
||||
const erc1155Proxy = await ERC1155ProxyContract.deployFrom0xArtifactAsync(
|
||||
assetProxyArtifacts.ERC1155Proxy,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
assetProxyArtifacts,
|
||||
);
|
||||
const multiAssetProxy = await MultiAssetProxyContract.deployFrom0xArtifactAsync(
|
||||
assetProxyArtifacts.MultiAssetProxy,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
assetProxyArtifacts,
|
||||
);
|
||||
const staticCallProxy = await StaticCallProxyContract.deployFrom0xArtifactAsync(
|
||||
assetProxyArtifacts.StaticCallProxy,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
assetProxyArtifacts,
|
||||
);
|
||||
return {
|
||||
erc20Proxy,
|
||||
erc721Proxy,
|
||||
erc1155Proxy,
|
||||
multiAssetProxy,
|
||||
staticCallProxy,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy a set of staking contracts.
|
||||
* @param environment The blockchain environment to use.
|
||||
* @param owner An owner address to use when configuring the asset proxies.
|
||||
* @param txDefaults Defaults to use when deploying the asset proxies.
|
||||
* @param tokens A set of token contracts to use during deployment of the staking contracts.
|
||||
* @param assetProxies A set of asset proxies to use with the staking contracts.
|
||||
*/
|
||||
protected static async _deployStakingContractsAsync(
|
||||
environment: BlockchainTestsEnvironment,
|
||||
owner: string,
|
||||
txDefaults: Partial<TxData>,
|
||||
tokens: TokenContracts,
|
||||
assetProxies: AssetProxyContracts,
|
||||
): Promise<StakingContracts> {
|
||||
const zrxVault = await ZrxVaultContract.deployFrom0xArtifactAsync(
|
||||
stakingArtifacts.ZrxVault,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
stakingArtifacts,
|
||||
assetProxies.erc20Proxy.address,
|
||||
tokens.zrx.address,
|
||||
);
|
||||
const stakingLogic = await TestStakingContract.deployFrom0xArtifactAsync(
|
||||
stakingArtifacts.TestStaking,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
stakingArtifacts,
|
||||
tokens.weth.address,
|
||||
zrxVault.address,
|
||||
);
|
||||
const stakingProxy = await StakingProxyContract.deployFrom0xArtifactAsync(
|
||||
stakingArtifacts.StakingProxy,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
stakingArtifacts,
|
||||
stakingLogic.address,
|
||||
);
|
||||
|
||||
const stakingWrapper = new TestStakingContract(stakingProxy.address, environment.provider, txDefaults);
|
||||
|
||||
// Add the zrx vault and the weth contract to the staking proxy.
|
||||
await stakingWrapper.setWethContract.awaitTransactionSuccessAsync(tokens.weth.address, { from: owner });
|
||||
await stakingWrapper.setZrxVault.awaitTransactionSuccessAsync(zrxVault.address, { from: owner });
|
||||
|
||||
// Authorize the owner address in the staking proxy and the zrx vault.
|
||||
await stakingProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(owner, { from: owner });
|
||||
await zrxVault.addAuthorizedAddress.awaitTransactionSuccessAsync(owner, { from: owner });
|
||||
|
||||
// Authorize the zrx vault in the erc20 proxy
|
||||
await assetProxies.erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(zrxVault.address, {
|
||||
from: owner,
|
||||
});
|
||||
|
||||
// Configure the zrx vault and the staking contract.
|
||||
await zrxVault.setStakingProxy.awaitTransactionSuccessAsync(stakingProxy.address, { from: owner });
|
||||
|
||||
return {
|
||||
stakingLogic,
|
||||
stakingProxy,
|
||||
stakingWrapper,
|
||||
zrxVault,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy a set of token contracts.
|
||||
* @param environment The blockchain environment to use.
|
||||
* @param txDefaults Defaults to use when deploying the asset proxies.
|
||||
* @param options Specifies how many tokens of each standard to deploy.
|
||||
*/
|
||||
protected static async _deployTokenContractsAsync(
|
||||
environment: BlockchainTestsEnvironment,
|
||||
txDefaults: Partial<TxData>,
|
||||
options: Partial<DeploymentOptions>,
|
||||
): Promise<TokenContracts> {
|
||||
const numErc20TokensToDeploy =
|
||||
options.numErc20TokensToDeploy !== undefined
|
||||
? options.numErc20TokensToDeploy
|
||||
: constants.NUM_DUMMY_ERC20_TO_DEPLOY;
|
||||
const numErc721TokensToDeploy =
|
||||
options.numErc721TokensToDeploy !== undefined
|
||||
? options.numErc721TokensToDeploy
|
||||
: constants.NUM_DUMMY_ERC721_TO_DEPLOY;
|
||||
const numErc1155TokensToDeploy =
|
||||
options.numErc1155TokensToDeploy !== undefined
|
||||
? options.numErc1155TokensToDeploy
|
||||
: constants.NUM_DUMMY_ERC1155_CONTRACTS_TO_DEPLOY;
|
||||
|
||||
const erc20 = await Promise.all(
|
||||
_.times(numErc20TokensToDeploy, async () =>
|
||||
DummyERC20TokenContract.deployFrom0xArtifactAsync(
|
||||
ERC20Artifacts.DummyERC20Token,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
ERC20Artifacts,
|
||||
constants.DUMMY_TOKEN_NAME,
|
||||
constants.DUMMY_TOKEN_SYMBOL,
|
||||
constants.DUMMY_TOKEN_DECIMALS,
|
||||
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||
),
|
||||
),
|
||||
);
|
||||
const erc721 = await Promise.all(
|
||||
_.times(numErc721TokensToDeploy, async () =>
|
||||
DummyERC721TokenContract.deployFrom0xArtifactAsync(
|
||||
ERC721Artifacts.DummyERC721Token,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
ERC721Artifacts,
|
||||
constants.DUMMY_TOKEN_NAME,
|
||||
constants.DUMMY_TOKEN_SYMBOL,
|
||||
),
|
||||
),
|
||||
);
|
||||
const erc1155 = await Promise.all(
|
||||
_.times(numErc1155TokensToDeploy, async () =>
|
||||
ERC1155MintableContract.deployFrom0xArtifactAsync(
|
||||
ERC1155Artifacts.ERC1155Mintable,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
ERC1155Artifacts,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const weth = await WETH9Contract.deployFrom0xArtifactAsync(
|
||||
ERC20Artifacts.WETH9,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
ERC20Artifacts,
|
||||
);
|
||||
const zrx = await DummyERC20TokenContract.deployFrom0xArtifactAsync(
|
||||
ERC20Artifacts.DummyERC20Token,
|
||||
environment.provider,
|
||||
txDefaults,
|
||||
ERC20Artifacts,
|
||||
constants.DUMMY_TOKEN_NAME,
|
||||
constants.DUMMY_TOKEN_SYMBOL,
|
||||
constants.DUMMY_TOKEN_DECIMALS,
|
||||
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||
);
|
||||
|
||||
return {
|
||||
erc20,
|
||||
erc721,
|
||||
erc1155,
|
||||
weth,
|
||||
zrx,
|
||||
};
|
||||
}
|
||||
|
||||
protected constructor(
|
||||
public assetProxies: AssetProxyContracts,
|
||||
public governor: ZeroExGovernorContract,
|
||||
public exchange: ExchangeContract,
|
||||
public staking: StakingContracts,
|
||||
public tokens: TokenContracts,
|
||||
public chainId: number,
|
||||
public accounts: string[],
|
||||
public txDefaults: Partial<TxData>,
|
||||
) {}
|
||||
}
|
||||
// tslint:disable:max-file-line-count
|
||||
@@ -1,181 +0,0 @@
|
||||
import { PromiseWithTransactionHash } from '@0x/base-contract';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
// tslint:disable:max-classes-per-file
|
||||
|
||||
export interface ContractGetterFunction {
|
||||
callAsync: (...args: any[]) => Promise<any>;
|
||||
}
|
||||
|
||||
export interface ContractWrapperFunction extends ContractGetterFunction {
|
||||
awaitTransactionSuccessAsync?: (...args: any[]) => PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs>;
|
||||
}
|
||||
|
||||
export interface Result {
|
||||
data?: any;
|
||||
success: boolean;
|
||||
receipt?: TransactionReceiptWithDecodedLogs;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface represents a condition that can be placed on a contract function.
|
||||
* This can be used to represent the pre- and post-conditions of a "Hoare Triple" on a
|
||||
* given contract function. The "Hoare Triple" is a way to represent the way that a
|
||||
* function changes state.
|
||||
* @param before A function that will be run before a call to the contract wrapper
|
||||
* function. Ideally, this will be a "precondition."
|
||||
* @param after A function that will be run after a call to the contract wrapper
|
||||
* function.
|
||||
*/
|
||||
export interface Condition<TBefore> {
|
||||
before: (...args: any[]) => Promise<TBefore>;
|
||||
after: (beforeInfo: TBefore, result: Result, ...args: any[]) => Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* The basic unit of abstraction for testing. This just consists of a command that
|
||||
* can be run. For example, this can represent a simple command that can be run, or
|
||||
* it can represent a command that executes a "Hoare Triple" (this is what most of
|
||||
* our `Assertion` implementations will do in practice).
|
||||
* @param runAsync The function to execute for the assertion.
|
||||
*/
|
||||
export interface Assertion {
|
||||
executeAsync: (...args: any[]) => Promise<any>;
|
||||
}
|
||||
|
||||
export interface RunResult {
|
||||
beforeInfo: any;
|
||||
afterInfo: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class implements `Assertion` and represents a "Hoare Triple" that can be
|
||||
* executed.
|
||||
*/
|
||||
export class FunctionAssertion<TBefore> implements Assertion {
|
||||
// A condition that will be applied to `wrapperFunction`.
|
||||
public condition: Condition<TBefore>;
|
||||
|
||||
// The wrapper function that will be wrapped in assertions.
|
||||
public wrapperFunction: ContractWrapperFunction;
|
||||
|
||||
constructor(wrapperFunction: ContractWrapperFunction, condition: Partial<Condition<TBefore>> = {}) {
|
||||
this.condition = {
|
||||
before: _.noop.bind(this),
|
||||
after: _.noop.bind(this),
|
||||
...condition,
|
||||
};
|
||||
this.wrapperFunction = wrapperFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the wrapped function and fails if the before or after assertions fail.
|
||||
* @param ...args The args to the contract wrapper function.
|
||||
*/
|
||||
public async executeAsync(...args: any[]): Promise<RunResult> {
|
||||
// Call the before condition.
|
||||
const beforeInfo = await this.condition.before(...args);
|
||||
|
||||
// Initialize the callResult so that the default success value is true.
|
||||
const callResult: Result = { success: true };
|
||||
|
||||
// Try to make the call to the function. If it is successful, pass the
|
||||
// result and receipt to the after condition.
|
||||
try {
|
||||
callResult.data = await this.wrapperFunction.callAsync(...args);
|
||||
callResult.receipt =
|
||||
this.wrapperFunction.awaitTransactionSuccessAsync !== undefined
|
||||
? await this.wrapperFunction.awaitTransactionSuccessAsync(...args)
|
||||
: undefined;
|
||||
} catch (error) {
|
||||
callResult.data = error;
|
||||
callResult.success = false;
|
||||
callResult.receipt = undefined;
|
||||
}
|
||||
|
||||
// Call the after condition.
|
||||
const afterInfo = await this.condition.after(beforeInfo, callResult, ...args);
|
||||
|
||||
return {
|
||||
beforeInfo,
|
||||
afterInfo,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export type IndexGenerator = () => number;
|
||||
|
||||
export type InputGenerator = () => Promise<any[]>;
|
||||
|
||||
export interface AssertionGenerator {
|
||||
assertion: Assertion;
|
||||
generator: InputGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is an abstract way to represent collections of function assertions.
|
||||
* Using this, we can use closures to build up many useful collections with different
|
||||
* properties. Notably, this abstraction supports function assertion collections
|
||||
* that can be run continuously and also those that terminate in a finite number
|
||||
* of steps.
|
||||
*/
|
||||
class MetaAssertion implements Assertion {
|
||||
constructor(
|
||||
protected readonly assertionGenerators: AssertionGenerator[],
|
||||
protected readonly indexGenerator: IndexGenerator,
|
||||
) {}
|
||||
|
||||
public async executeAsync(): Promise<void> {
|
||||
let idx = this.indexGenerator();
|
||||
while (idx > 0) {
|
||||
const args = await this.assertionGenerators[idx].generator();
|
||||
await this.assertionGenerators[idx].assertion.executeAsync(...args);
|
||||
idx = this.indexGenerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a class that can execute a set of function assertions in sequence.
|
||||
* @param assertionGenerators A set of assertion generators to run in sequence.
|
||||
*/
|
||||
export function FunctionAssertionSequence(assertionGenerators: AssertionGenerator[]): MetaAssertion {
|
||||
let idx = 0;
|
||||
return new MetaAssertion(assertionGenerators, () => {
|
||||
if (idx < assertionGenerators.length) {
|
||||
return idx++;
|
||||
} else {
|
||||
idx = 0;
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export interface WeightedAssertionGenerator extends AssertionGenerator {
|
||||
weight?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a class that can execute a set of function assertions at random continuously.
|
||||
* This will not terminate unless the process that called `runAsync` terminates.
|
||||
* @param weightedAssertionGenerators A set of function assertions that have been
|
||||
* assigned weights.
|
||||
*/
|
||||
export function ContinuousFunctionAssertionSet(
|
||||
weightedAssertionGenerators: WeightedAssertionGenerator[],
|
||||
): MetaAssertion {
|
||||
// Construct an array of assertion generators that allows random sampling from a
|
||||
// uniform distribution to correctly bias assertion selection.
|
||||
let assertionGenerators: AssertionGenerator[] = [];
|
||||
for (const { assertion, generator, weight } of weightedAssertionGenerators) {
|
||||
const weightedAssertions: AssertionGenerator[] = [];
|
||||
_.fill(weightedAssertions, { assertion, generator }, 0, weight || 1);
|
||||
assertionGenerators = assertionGenerators.concat(weightedAssertions);
|
||||
}
|
||||
|
||||
// The index generator simply needs to sample from a uniform distribution.
|
||||
const indexGenerator = () => Math.round(Math.random() * (assertionGenerators.length - 1));
|
||||
|
||||
return new MetaAssertion(assertionGenerators, indexGenerator);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
import { PromiseWithTransactionHash } from '@0x/base-contract';
|
||||
import { AwaitTransactionSuccessOpts } from '@0x/types';
|
||||
import { BlockParam, CallData, TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
|
||||
|
||||
// Generated Wrapper Interfaces
|
||||
export interface AssetProxyDispatcher {
|
||||
registerAssetProxy: {
|
||||
awaitTransactionSuccessAsync: (
|
||||
assetProxy: string,
|
||||
txData?: Partial<TxData>,
|
||||
txOpts?: AwaitTransactionSuccessOpts,
|
||||
) => PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs>;
|
||||
};
|
||||
getAssetProxy: {
|
||||
callAsync(assetProxyId: string, callData?: Partial<CallData>, defaultBlock?: BlockParam): Promise<string>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Authorizable extends Ownable {
|
||||
addAuthorizedAddress: {
|
||||
awaitTransactionSuccessAsync: (
|
||||
target: string,
|
||||
txData?: Partial<TxData>,
|
||||
txOpts?: AwaitTransactionSuccessOpts,
|
||||
) => PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs>;
|
||||
};
|
||||
removeAuthorizedAddress: {
|
||||
awaitTransactionSuccessAsync: (
|
||||
target: string,
|
||||
txData?: Partial<TxData>,
|
||||
txOpts?: AwaitTransactionSuccessOpts,
|
||||
) => PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs>;
|
||||
};
|
||||
authorized: {
|
||||
callAsync(authority: string, callData?: Partial<CallData>, defaultBlock?: BlockParam): Promise<boolean>;
|
||||
};
|
||||
getAuthorizedAddresses: {
|
||||
callAsync(callData?: Partial<CallData>, defaultBlock?: BlockParam): Promise<string[]>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Ownable {
|
||||
transferOwnership: {
|
||||
awaitTransactionSuccessAsync: (
|
||||
newOwner: string,
|
||||
txData?: Partial<TxData>,
|
||||
txOpts?: AwaitTransactionSuccessOpts,
|
||||
) => PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs>;
|
||||
};
|
||||
owner: {
|
||||
callAsync(callData?: Partial<CallData>, defaultBlock?: BlockParam): Promise<string>;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user