Remove deployer from metacoin and contract tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
AbiDefinition,
|
AbiDefinition,
|
||||||
AbiType,
|
AbiType,
|
||||||
|
ConstructorAbi,
|
||||||
ContractAbi,
|
ContractAbi,
|
||||||
DataItem,
|
DataItem,
|
||||||
MethodAbi,
|
MethodAbi,
|
||||||
@@ -37,9 +38,40 @@ export class BaseContract {
|
|||||||
protected static _bigNumberToString(type: string, value: any): any {
|
protected static _bigNumberToString(type: string, value: any): any {
|
||||||
return _.isObject(value) && value.isBigNumber ? value.toString() : value;
|
return _.isObject(value) && value.isBigNumber ? value.toString() : value;
|
||||||
}
|
}
|
||||||
|
protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi {
|
||||||
|
const constructorAbiIfExists = _.find(
|
||||||
|
abi,
|
||||||
|
(abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Constructor,
|
||||||
|
) as ConstructorAbi | undefined;
|
||||||
|
if (!_.isUndefined(constructorAbiIfExists)) {
|
||||||
|
return constructorAbiIfExists;
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: AbiType.Constructor,
|
||||||
|
stateMutability: 'nonpayable',
|
||||||
|
payable: false,
|
||||||
|
inputs: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
protected static _bnToBigNumber(type: string, value: any): any {
|
protected static _bnToBigNumber(type: string, value: any): any {
|
||||||
return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value;
|
return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value;
|
||||||
}
|
}
|
||||||
|
protected static async _applyDefaultsToDeployTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
|
||||||
|
txData: T,
|
||||||
|
defaults: Partial<TxData>,
|
||||||
|
estimateGasAsync?: (txData: T) => Promise<number>,
|
||||||
|
): Promise<TxData> {
|
||||||
|
const txDataWithDefaults: TxData = {
|
||||||
|
...defaults,
|
||||||
|
...(txData as any),
|
||||||
|
};
|
||||||
|
if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) {
|
||||||
|
const estimatedGas = await estimateGasAsync(txData);
|
||||||
|
txDataWithDefaults.gas = estimatedGas;
|
||||||
|
}
|
||||||
|
return txDataWithDefaults;
|
||||||
|
}
|
||||||
protected async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
|
protected async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
|
||||||
txData: T,
|
txData: T,
|
||||||
estimateGasAsync?: (txData: T) => Promise<number>,
|
estimateGasAsync?: (txData: T) => Promise<number>,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { BaseContract } from '@0xproject/base-contract';
|
import { BaseContract } from '@0xproject/base-contract';
|
||||||
import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, Provider, TxData, TxDataPayable } from '@0xproject/types';
|
import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, Provider, TxData, TxDataPayable } from '@0xproject/types';
|
||||||
import { BigNumber, classUtils, promisify } from '@0xproject/utils';
|
import { BigNumber, classUtils, promisify } from '@0xproject/utils';
|
||||||
|
import { ContractArtifact } from '@0xproject/deployer';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as ethers from 'ethers';
|
import * as ethers from 'ethers';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@@ -39,6 +40,41 @@ export class {{contractName}}Contract extends BaseContract {
|
|||||||
{{> tx contractName=../contractName}}
|
{{> tx contractName=../contractName}}
|
||||||
{{/this.constant}}
|
{{/this.constant}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
public static async deploy0xArtifactAsync(
|
||||||
|
artifact: ContractArtifact,
|
||||||
|
provider: Provider,
|
||||||
|
defaults: Partial<TxData>,
|
||||||
|
{{> typed_params inputs=ctor.inputs}}
|
||||||
|
): Promise<{{contractName}}Contract> {
|
||||||
|
const bytecode = artifact.compilerOutput.evm.bytecode.object;
|
||||||
|
const abi = artifact.compilerOutput.abi;
|
||||||
|
return {{contractName}}Contract.deployAsync(bytecode, abi, provider, defaults, {{> params inputs=ctor.inputs}});
|
||||||
|
}
|
||||||
|
public static async deployAsync(
|
||||||
|
bytecode: string,
|
||||||
|
abi: ContractAbi,
|
||||||
|
provider: Provider,
|
||||||
|
defaults: Partial<TxData>,
|
||||||
|
{{> typed_params inputs=ctor.inputs}}
|
||||||
|
): Promise<{{contractName}}Contract> {
|
||||||
|
const constructorAbi = BaseContract._lookupConstructorAbi(abi);
|
||||||
|
[{{> params inputs=ctor.inputs}}] = BaseContract._formatABIDataItemList(
|
||||||
|
constructorAbi.inputs,
|
||||||
|
[{{> params inputs=ctor.inputs}}],
|
||||||
|
BaseContract._bigNumberToString,
|
||||||
|
);
|
||||||
|
const txData = ethers.Contract.getDeployTransaction(bytecode, abi, {{> params inputs=ctor.inputs}});
|
||||||
|
const web3Wrapper = new Web3Wrapper(provider);
|
||||||
|
const txDataWithDefaults = await BaseContract._applyDefaultsToDeployTxDataAsync(
|
||||||
|
txData,
|
||||||
|
defaults,
|
||||||
|
web3Wrapper.estimateGasAsync.bind(web3Wrapper),
|
||||||
|
);
|
||||||
|
const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults);
|
||||||
|
const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(txHash);
|
||||||
|
const contractInstance = new {{contractName}}Contract(abi, txReceipt.contractAddress as string, provider, defaults);
|
||||||
|
return contractInstance;
|
||||||
|
}
|
||||||
constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial<TxData>) {
|
constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial<TxData>) {
|
||||||
super(abi, address, provider, defaults);
|
super(abi, address, provider, defaults);
|
||||||
classUtils.bindAll(this, ['_ethersInterfacesByFunctionSignature', 'address', 'abi', '_web3Wrapper']);
|
classUtils.bindAll(this, ['_ethersInterfacesByFunctionSignature', 'address', 'abi', '_web3Wrapper']);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public {{this.tsName}} = {
|
|||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const self = this as any as {{contractName}}Contract;
|
const self = this as any as {{contractName}}Contract;
|
||||||
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
|
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
|
||||||
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(this));
|
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString);
|
||||||
const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}(
|
const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}(
|
||||||
{{> params inputs=inputs}}
|
{{> params inputs=inputs}}
|
||||||
).data;
|
).data;
|
||||||
@@ -51,7 +51,7 @@ public {{this.tsName}} = {
|
|||||||
): string {
|
): string {
|
||||||
const self = this as any as {{contractName}}Contract;
|
const self = this as any as {{contractName}}Contract;
|
||||||
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
|
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
|
||||||
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self));
|
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString);
|
||||||
const abiEncodedTransactionData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}(
|
const abiEncodedTransactionData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}(
|
||||||
{{> params inputs=inputs}}
|
{{> params inputs=inputs}}
|
||||||
).data;
|
).data;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
"test:circleci": "yarn test:coverage"
|
"test:circleci": "yarn test:coverage"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"abis": "../migrations/artifacts/1.0.0/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels).json"
|
"abis": "../migrations/artifacts/1.0.0/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels|WETH9|MaliciousToken).json"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import { BigNumber, promisify } from '@0xproject/utils';
|
|||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
|
|
||||||
|
import { WETH9Contract } from '../src/contract_wrappers/generated/weth9';
|
||||||
|
import { artifacts } from '../util/artifacts';
|
||||||
import { constants } from '../util/constants';
|
import { constants } from '../util/constants';
|
||||||
import { ContractName } from '../util/types';
|
import { ContractName } from '../util/types';
|
||||||
|
|
||||||
import { chaiSetup } from './utils/chai_setup';
|
import { chaiSetup } from './utils/chai_setup';
|
||||||
import { deployer } from './utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from './utils/web3_wrapper';
|
import { defaults, provider, web3Wrapper } from './utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -24,7 +26,7 @@ describe('EtherToken', () => {
|
|||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
account = accounts[0];
|
account = accounts[0];
|
||||||
|
|
||||||
const etherToken = await deployer.deployAsync(ContractName.EtherToken);
|
const etherToken = await WETH9Contract.deploy0xArtifactAsync(artifacts.EtherToken, provider, defaults);
|
||||||
etherTokenAddress = etherToken.address;
|
etherTokenAddress = etherToken.address;
|
||||||
zeroEx = new ZeroEx(provider, {
|
zeroEx = new ZeroEx(provider, {
|
||||||
gasPrice,
|
gasPrice,
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import {
|
|||||||
LogErrorContractEventArgs,
|
LogErrorContractEventArgs,
|
||||||
LogFillContractEventArgs,
|
LogFillContractEventArgs,
|
||||||
} from '../../src/contract_wrappers/generated/exchange';
|
} from '../../src/contract_wrappers/generated/exchange';
|
||||||
|
import { MaliciousTokenContract } from '../../src/contract_wrappers/generated/malicious_token';
|
||||||
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
||||||
|
import { artifacts } from '../../util/artifacts';
|
||||||
import { Balances } from '../../util/balances';
|
import { Balances } from '../../util/balances';
|
||||||
import { constants } from '../../util/constants';
|
import { constants } from '../../util/constants';
|
||||||
import { crypto } from '../../util/crypto';
|
import { crypto } from '../../util/crypto';
|
||||||
@@ -21,8 +23,8 @@ import { ExchangeWrapper } from '../../util/exchange_wrapper';
|
|||||||
import { OrderFactory } from '../../util/order_factory';
|
import { OrderFactory } from '../../util/order_factory';
|
||||||
import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types';
|
import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types';
|
||||||
import { chaiSetup } from '../utils/chai_setup';
|
import { chaiSetup } from '../utils/chai_setup';
|
||||||
import { deployer } from '../utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from '../utils/web3_wrapper';
|
import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -54,25 +56,47 @@ describe('Exchange', () => {
|
|||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
maker = accounts[0];
|
maker = accounts[0];
|
||||||
[tokenOwner, taker, feeRecipient] = accounts;
|
[tokenOwner, taker, feeRecipient] = accounts;
|
||||||
const [repInstance, dgdInstance, zrxInstance] = await Promise.all([
|
[rep, dgd, zrx] = await Promise.all([
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
artifacts.DummyToken,
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
|
||||||
]);
|
|
||||||
rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider);
|
|
||||||
dgd = new DummyTokenContract(dgdInstance.abi, dgdInstance.address, provider);
|
|
||||||
zrx = new DummyTokenContract(zrxInstance.abi, zrxInstance.address, provider);
|
|
||||||
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
|
|
||||||
tokenTransferProxy = new TokenTransferProxyContract(
|
|
||||||
tokenTransferProxyInstance.abi,
|
|
||||||
tokenTransferProxyInstance.address,
|
|
||||||
provider,
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.TokenTransferProxy,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
);
|
);
|
||||||
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
|
exchange = await ExchangeContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.Exchange,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
zrx.address,
|
zrx.address,
|
||||||
tokenTransferProxy.address,
|
tokenTransferProxy.address,
|
||||||
]);
|
);
|
||||||
exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
|
|
||||||
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
|
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
|
||||||
zeroEx = new ZeroEx(provider, {
|
zeroEx = new ZeroEx(provider, {
|
||||||
exchangeContractAddress: exchange.address,
|
exchangeContractAddress: exchange.address,
|
||||||
@@ -689,7 +713,11 @@ describe('Exchange', () => {
|
|||||||
|
|
||||||
it('should throw if getBalance or getAllowance attempts to change state and \
|
it('should throw if getBalance or getAllowance attempts to change state and \
|
||||||
shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
|
shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
|
||||||
const maliciousToken = await deployer.deployAsync(ContractName.MaliciousToken);
|
const maliciousToken = await MaliciousTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.MaliciousToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
);
|
||||||
await maliciousToken.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
|
await maliciousToken.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
|
||||||
from: taker,
|
from: taker,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,13 +11,18 @@ import {
|
|||||||
LogErrorContractEventArgs,
|
LogErrorContractEventArgs,
|
||||||
LogFillContractEventArgs,
|
LogFillContractEventArgs,
|
||||||
} from '../../src/contract_wrappers/generated/exchange';
|
} from '../../src/contract_wrappers/generated/exchange';
|
||||||
|
|
||||||
|
import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
|
||||||
|
import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry';
|
||||||
|
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
||||||
|
import { artifacts } from '../../util/artifacts';
|
||||||
import { constants } from '../../util/constants';
|
import { constants } from '../../util/constants';
|
||||||
import { ExchangeWrapper } from '../../util/exchange_wrapper';
|
import { ExchangeWrapper } from '../../util/exchange_wrapper';
|
||||||
import { OrderFactory } from '../../util/order_factory';
|
import { OrderFactory } from '../../util/order_factory';
|
||||||
import { ContractName } from '../../util/types';
|
import { ContractName } from '../../util/types';
|
||||||
import { chaiSetup } from '../utils/chai_setup';
|
import { chaiSetup } from '../utils/chai_setup';
|
||||||
import { deployer } from '../utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from '../utils/web3_wrapper';
|
import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -35,19 +40,53 @@ describe('Exchange', () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
[maker, feeRecipient] = accounts;
|
[maker, feeRecipient] = accounts;
|
||||||
const tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry);
|
const tokenRegistry = await TokenRegistryContract.deploy0xArtifactAsync(
|
||||||
const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
|
artifacts.TokenRegistry,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
);
|
||||||
|
const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.TokenTransferProxy,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
);
|
||||||
const [rep, dgd, zrx] = await Promise.all([
|
const [rep, dgd, zrx] = await Promise.all([
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
artifacts.DummyToken,
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
|
const exchange = await ExchangeContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.Exchange,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
zrx.address,
|
zrx.address,
|
||||||
tokenTransferProxy.address,
|
tokenTransferProxy.address,
|
||||||
]);
|
);
|
||||||
const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
|
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
|
||||||
await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
|
|
||||||
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
|
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
|
||||||
exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
|
exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
|
||||||
const defaultOrderParams = {
|
const defaultOrderParams = {
|
||||||
|
|||||||
@@ -15,14 +15,15 @@ import {
|
|||||||
} from '../../src/contract_wrappers/generated/exchange';
|
} from '../../src/contract_wrappers/generated/exchange';
|
||||||
import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry';
|
import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry';
|
||||||
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
||||||
|
import { artifacts } from '../../util/artifacts';
|
||||||
import { Balances } from '../../util/balances';
|
import { Balances } from '../../util/balances';
|
||||||
import { constants } from '../../util/constants';
|
import { constants } from '../../util/constants';
|
||||||
import { ExchangeWrapper } from '../../util/exchange_wrapper';
|
import { ExchangeWrapper } from '../../util/exchange_wrapper';
|
||||||
import { OrderFactory } from '../../util/order_factory';
|
import { OrderFactory } from '../../util/order_factory';
|
||||||
import { BalancesByOwner, ContractName } from '../../util/types';
|
import { BalancesByOwner, ContractName } from '../../util/types';
|
||||||
import { chaiSetup } from '../utils/chai_setup';
|
import { chaiSetup } from '../utils/chai_setup';
|
||||||
import { deployer } from '../utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from '../utils/web3_wrapper';
|
import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -54,27 +55,48 @@ describe('Exchange', () => {
|
|||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
tokenOwner = accounts[0];
|
tokenOwner = accounts[0];
|
||||||
[maker, taker, feeRecipient] = accounts;
|
[maker, taker, feeRecipient] = accounts;
|
||||||
const [repInstance, dgdInstance, zrxInstance] = await Promise.all([
|
[rep, dgd, zrx] = await Promise.all([
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
artifacts.DummyToken,
|
||||||
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
|
|
||||||
]);
|
|
||||||
rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider);
|
|
||||||
dgd = new DummyTokenContract(dgdInstance.abi, dgdInstance.address, provider);
|
|
||||||
zrx = new DummyTokenContract(zrxInstance.abi, zrxInstance.address, provider);
|
|
||||||
const tokenRegistryInstance = await deployer.deployAsync(ContractName.TokenRegistry);
|
|
||||||
tokenRegistry = new TokenRegistryContract(tokenRegistryInstance.abi, tokenRegistryInstance.address, provider);
|
|
||||||
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
|
|
||||||
tokenTransferProxy = new TokenTransferProxyContract(
|
|
||||||
tokenTransferProxyInstance.abi,
|
|
||||||
tokenTransferProxyInstance.address,
|
|
||||||
provider,
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
DummyTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
tokenRegistry = await TokenRegistryContract.deploy0xArtifactAsync(artifacts.TokenRegistry, provider, defaults);
|
||||||
|
tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.TokenTransferProxy,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
);
|
);
|
||||||
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
|
exchange = await ExchangeContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.Exchange,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
zrx.address,
|
zrx.address,
|
||||||
tokenTransferProxy.address,
|
tokenTransferProxy.address,
|
||||||
]);
|
);
|
||||||
exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
|
|
||||||
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
|
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
|
||||||
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
|
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
|
||||||
exWrapper = new ExchangeWrapper(exchange, zeroEx);
|
exWrapper = new ExchangeWrapper(exchange, zeroEx);
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ import { MultiSigWrapper } from '../util/multi_sig_wrapper';
|
|||||||
import { ContractName, SubmissionContractEventArgs } from '../util/types';
|
import { ContractName, SubmissionContractEventArgs } from '../util/types';
|
||||||
|
|
||||||
import { chaiSetup } from './utils/chai_setup';
|
import { chaiSetup } from './utils/chai_setup';
|
||||||
import { deployer } from './utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from './utils/web3_wrapper';
|
|
||||||
|
|
||||||
const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLockArtifact.compilerOutput.abi;
|
import { defaults, provider, web3Wrapper } from './utils/web3_wrapper';
|
||||||
|
|
||||||
|
const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLock.compilerOutput.abi;
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||||
@@ -47,15 +47,13 @@ describe('MultiSigWalletWithTimeLock', () => {
|
|||||||
describe('changeTimeLock', () => {
|
describe('changeTimeLock', () => {
|
||||||
describe('initially non-time-locked', async () => {
|
describe('initially non-time-locked', async () => {
|
||||||
before('deploy a wallet', async () => {
|
before('deploy a wallet', async () => {
|
||||||
const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
|
multiSig = await MultiSigWalletWithTimeLockContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.MultiSigWalletWithTimeLock,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
owners,
|
owners,
|
||||||
SIGNATURES_REQUIRED,
|
SIGNATURES_REQUIRED,
|
||||||
0,
|
new BigNumber(0),
|
||||||
]);
|
|
||||||
multiSig = new MultiSigWalletWithTimeLockContract(
|
|
||||||
multiSigInstance.abi,
|
|
||||||
multiSigInstance.address,
|
|
||||||
provider,
|
|
||||||
);
|
);
|
||||||
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
|
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
|
||||||
|
|
||||||
@@ -144,15 +142,13 @@ describe('MultiSigWalletWithTimeLock', () => {
|
|||||||
});
|
});
|
||||||
describe('initially time-locked', async () => {
|
describe('initially time-locked', async () => {
|
||||||
before('deploy a wallet', async () => {
|
before('deploy a wallet', async () => {
|
||||||
const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
|
multiSig = await MultiSigWalletWithTimeLockContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.MultiSigWalletWithTimeLock,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
owners,
|
owners,
|
||||||
SIGNATURES_REQUIRED,
|
SIGNATURES_REQUIRED,
|
||||||
SECONDS_TIME_LOCKED,
|
SECONDS_TIME_LOCKED,
|
||||||
]);
|
|
||||||
multiSig = new MultiSigWalletWithTimeLockContract(
|
|
||||||
multiSigInstance.abi,
|
|
||||||
multiSigInstance.address,
|
|
||||||
provider,
|
|
||||||
);
|
);
|
||||||
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
|
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LogWithDecodedArgs, ZeroEx } from '0x.js';
|
import { LogWithDecodedArgs, ZeroEx } from '0x.js';
|
||||||
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
|
||||||
import { AbiDecoder } from '@0xproject/utils';
|
import { AbiDecoder, BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
@@ -15,11 +15,11 @@ import { MultiSigWrapper } from '../util/multi_sig_wrapper';
|
|||||||
import { ContractName, SubmissionContractEventArgs, TransactionDataParams } from '../util/types';
|
import { ContractName, SubmissionContractEventArgs, TransactionDataParams } from '../util/types';
|
||||||
|
|
||||||
import { chaiSetup } from './utils/chai_setup';
|
import { chaiSetup } from './utils/chai_setup';
|
||||||
import { deployer } from './utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from './utils/web3_wrapper';
|
import { defaults, provider, web3Wrapper } from './utils/web3_wrapper';
|
||||||
const PROXY_ABI = artifacts.TokenTransferProxyArtifact.compilerOutput.abi;
|
const PROXY_ABI = artifacts.TokenTransferProxy.compilerOutput.abi;
|
||||||
const MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI =
|
const MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI =
|
||||||
artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact.compilerOutput.abi;
|
artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.compilerOutput.abi;
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -29,8 +29,8 @@ const abiDecoder = new AbiDecoder([MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_A
|
|||||||
describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
|
describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
|
||||||
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
|
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
|
||||||
let owners: string[];
|
let owners: string[];
|
||||||
const requiredApprovals = 2;
|
const requiredApprovals = new BigNumber(2);
|
||||||
const SECONDS_TIME_LOCKED = 1000000;
|
const SECONDS_TIME_LOCKED = new BigNumber(1000000);
|
||||||
|
|
||||||
// initialize fake addresses
|
// initialize fake addresses
|
||||||
let authorizedAddress: string;
|
let authorizedAddress: string;
|
||||||
@@ -46,23 +46,22 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
|
|||||||
owners = [accounts[0], accounts[1]];
|
owners = [accounts[0], accounts[1]];
|
||||||
[authorizedAddress, unauthorizedAddress] = accounts;
|
[authorizedAddress, unauthorizedAddress] = accounts;
|
||||||
const initialOwner = accounts[0];
|
const initialOwner = accounts[0];
|
||||||
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
|
tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync(
|
||||||
tokenTransferProxy = new TokenTransferProxyContract(
|
artifacts.TokenTransferProxy,
|
||||||
tokenTransferProxyInstance.abi,
|
|
||||||
tokenTransferProxyInstance.address,
|
|
||||||
provider,
|
provider,
|
||||||
|
defaults,
|
||||||
);
|
);
|
||||||
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, {
|
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, {
|
||||||
from: initialOwner,
|
from: initialOwner,
|
||||||
});
|
});
|
||||||
const multiSigInstance = await deployer.deployAsync(
|
multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deploy0xArtifactAsync(
|
||||||
ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,
|
artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,
|
||||||
[owners, requiredApprovals, SECONDS_TIME_LOCKED, tokenTransferProxy.address],
|
|
||||||
);
|
|
||||||
multiSig = new MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract(
|
|
||||||
multiSigInstance.abi,
|
|
||||||
multiSigInstance.address,
|
|
||||||
provider,
|
provider,
|
||||||
|
defaults,
|
||||||
|
owners,
|
||||||
|
requiredApprovals,
|
||||||
|
SECONDS_TIME_LOCKED,
|
||||||
|
tokenTransferProxy.address,
|
||||||
);
|
);
|
||||||
await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, {
|
await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, {
|
||||||
from: initialOwner,
|
from: initialOwner,
|
||||||
@@ -110,7 +109,11 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if tx destination is not the tokenTransferProxy', async () => {
|
it('should throw if tx destination is not the tokenTransferProxy', async () => {
|
||||||
const invalidTokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
|
const invalidTokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.TokenTransferProxy,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
);
|
||||||
const invalidDestination = invalidTokenTransferProxy.address;
|
const invalidDestination = invalidTokenTransferProxy.address;
|
||||||
const dataParams: TransactionDataParams = {
|
const dataParams: TransactionDataParams = {
|
||||||
name: 'removeAuthorizedAddress',
|
name: 'removeAuthorizedAddress',
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import * as _ from 'lodash';
|
|||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
import { TokenRegistryContract } from '../src/contract_wrappers/generated/token_registry';
|
import { TokenRegistryContract } from '../src/contract_wrappers/generated/token_registry';
|
||||||
|
import { artifacts } from '../util/artifacts';
|
||||||
import { constants } from '../util/constants';
|
import { constants } from '../util/constants';
|
||||||
import { TokenRegWrapper } from '../util/token_registry_wrapper';
|
import { TokenRegWrapper } from '../util/token_registry_wrapper';
|
||||||
import { ContractName } from '../util/types';
|
import { ContractName } from '../util/types';
|
||||||
|
|
||||||
import { chaiSetup } from './utils/chai_setup';
|
import { chaiSetup } from './utils/chai_setup';
|
||||||
import { deployer } from './utils/deployer';
|
import { defaults, provider, web3Wrapper } from './utils/web3_wrapper';
|
||||||
import { provider, web3Wrapper } from './utils/web3_wrapper';
|
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -29,8 +29,7 @@ describe('TokenRegistry', () => {
|
|||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
owner = accounts[0];
|
owner = accounts[0];
|
||||||
notOwner = accounts[1];
|
notOwner = accounts[1];
|
||||||
const tokenRegInstance = await deployer.deployAsync(ContractName.TokenRegistry);
|
tokenReg = await TokenRegistryContract.deploy0xArtifactAsync(artifacts.TokenRegistry, provider, defaults);
|
||||||
tokenReg = new TokenRegistryContract(tokenRegInstance.abi, tokenRegInstance.address, provider);
|
|
||||||
tokenRegWrapper = new TokenRegWrapper(tokenReg);
|
tokenRegWrapper = new TokenRegWrapper(tokenReg);
|
||||||
});
|
});
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import * as chai from 'chai';
|
|||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
||||||
|
import { artifacts } from '../../util/artifacts';
|
||||||
import { constants } from '../../util/constants';
|
import { constants } from '../../util/constants';
|
||||||
import { ContractName } from '../../util/types';
|
import { ContractName } from '../../util/types';
|
||||||
import { chaiSetup } from '../utils/chai_setup';
|
import { chaiSetup } from '../utils/chai_setup';
|
||||||
import { deployer } from '../utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from '../utils/web3_wrapper';
|
import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -23,11 +24,10 @@ describe('TokenTransferProxy', () => {
|
|||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
owner = address = accounts[0];
|
owner = address = accounts[0];
|
||||||
notOwner = accounts[1];
|
notOwner = accounts[1];
|
||||||
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
|
tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync(
|
||||||
tokenTransferProxy = new TokenTransferProxyContract(
|
artifacts.TokenTransferProxy,
|
||||||
tokenTransferProxyInstance.abi,
|
|
||||||
tokenTransferProxyInstance.address,
|
|
||||||
provider,
|
provider,
|
||||||
|
defaults,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import * as Web3 from 'web3';
|
|||||||
|
|
||||||
import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
|
import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
|
||||||
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
||||||
|
import { artifacts } from '../../util/artifacts';
|
||||||
import { Balances } from '../../util/balances';
|
import { Balances } from '../../util/balances';
|
||||||
import { constants } from '../../util/constants';
|
import { constants } from '../../util/constants';
|
||||||
import { ContractName } from '../../util/types';
|
import { ContractName } from '../../util/types';
|
||||||
import { chaiSetup } from '../utils/chai_setup';
|
import { chaiSetup } from '../utils/chai_setup';
|
||||||
import { deployer } from '../utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from '../utils/web3_wrapper';
|
import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -31,15 +32,20 @@ describe('TokenTransferProxy', () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
owner = notAuthorized = accounts[0];
|
owner = notAuthorized = accounts[0];
|
||||||
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
|
tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync(
|
||||||
tokenTransferProxy = new TokenTransferProxyContract(
|
artifacts.TokenTransferProxy,
|
||||||
tokenTransferProxyInstance.abi,
|
|
||||||
tokenTransferProxyInstance.address,
|
|
||||||
provider,
|
provider,
|
||||||
|
defaults,
|
||||||
|
);
|
||||||
|
rep = await DummyTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
);
|
);
|
||||||
const repInstance = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
|
|
||||||
rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider);
|
|
||||||
|
|
||||||
dmyBalances = new Balances([rep], [accounts[0], accounts[1]]);
|
dmyBalances = new Balances([rep], [accounts[0], accounts[1]]);
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, {
|
rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, {
|
||||||
|
|||||||
@@ -6,9 +6,13 @@ import * as chai from 'chai';
|
|||||||
import ethUtil = require('ethereumjs-util');
|
import ethUtil = require('ethereumjs-util');
|
||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
|
import { AccountLevelsContract } from '../../src/contract_wrappers/generated/account_levels';
|
||||||
import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage';
|
import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage';
|
||||||
|
import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
|
||||||
import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta';
|
import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta';
|
||||||
import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
|
import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
|
||||||
|
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
|
||||||
|
import { artifacts } from '../../util/artifacts';
|
||||||
import { Balances } from '../../util/balances';
|
import { Balances } from '../../util/balances';
|
||||||
import { constants } from '../../util/constants';
|
import { constants } from '../../util/constants';
|
||||||
import { crypto } from '../../util/crypto';
|
import { crypto } from '../../util/crypto';
|
||||||
@@ -16,8 +20,8 @@ import { ExchangeWrapper } from '../../util/exchange_wrapper';
|
|||||||
import { OrderFactory } from '../../util/order_factory';
|
import { OrderFactory } from '../../util/order_factory';
|
||||||
import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types';
|
import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types';
|
||||||
import { chaiSetup } from '../utils/chai_setup';
|
import { chaiSetup } from '../utils/chai_setup';
|
||||||
import { deployer } from '../utils/deployer';
|
|
||||||
import { provider, web3Wrapper } from '../utils/web3_wrapper';
|
import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -54,33 +58,61 @@ describe('Arbitrage', () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
[coinbase, maker, edMaker, edFrontRunner] = accounts;
|
[coinbase, maker, edMaker, edFrontRunner] = accounts;
|
||||||
weth = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
|
weth = await DummyTokenContract.deploy0xArtifactAsync(
|
||||||
zrx = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
|
artifacts.DummyToken,
|
||||||
const accountLevels = await deployer.deployAsync(ContractName.AccountLevels);
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
);
|
||||||
|
zrx = await DummyTokenContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
);
|
||||||
|
const accountLevels = await AccountLevelsContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.AccountLevels,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
);
|
||||||
const edAdminAddress = accounts[0];
|
const edAdminAddress = accounts[0];
|
||||||
const edMakerFee = 0;
|
const edMakerFee = new BigNumber(0);
|
||||||
const edTakerFee = 0;
|
const edTakerFee = new BigNumber(0);
|
||||||
const edFeeRebate = 0;
|
const edFeeRebate = new BigNumber(0);
|
||||||
const etherDeltaInstance = await deployer.deployAsync(ContractName.EtherDelta, [
|
etherDelta = await EtherDeltaContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.EtherDelta,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
edAdminAddress,
|
edAdminAddress,
|
||||||
feeRecipient,
|
feeRecipient,
|
||||||
accountLevels.address,
|
accountLevels.address,
|
||||||
edMakerFee,
|
edMakerFee,
|
||||||
edTakerFee,
|
edTakerFee,
|
||||||
edFeeRebate,
|
edFeeRebate,
|
||||||
]);
|
);
|
||||||
etherDelta = new EtherDeltaContract(etherDeltaInstance.abi, etherDeltaInstance.address, provider);
|
const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync(
|
||||||
const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
|
artifacts.TokenTransferProxy,
|
||||||
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
|
provider,
|
||||||
|
defaults,
|
||||||
|
);
|
||||||
|
const exchange = await ExchangeContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.Exchange,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
zrx.address,
|
zrx.address,
|
||||||
tokenTransferProxy.address,
|
tokenTransferProxy.address,
|
||||||
]);
|
);
|
||||||
await tokenTransferProxy.addAuthorizedAddress(exchangeInstance.address, { from: accounts[0] });
|
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
|
||||||
zeroEx = new ZeroEx(provider, {
|
zeroEx = new ZeroEx(provider, {
|
||||||
exchangeContractAddress: exchangeInstance.address,
|
exchangeContractAddress: exchange.address,
|
||||||
networkId: constants.TESTRPC_NETWORK_ID,
|
networkId: constants.TESTRPC_NETWORK_ID,
|
||||||
});
|
});
|
||||||
const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
|
|
||||||
exWrapper = new ExchangeWrapper(exchange, zeroEx);
|
exWrapper = new ExchangeWrapper(exchange, zeroEx);
|
||||||
|
|
||||||
makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
|
makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
|
||||||
@@ -97,12 +129,14 @@ describe('Arbitrage', () => {
|
|||||||
takerFee: new BigNumber(0),
|
takerFee: new BigNumber(0),
|
||||||
};
|
};
|
||||||
orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
|
orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
|
||||||
const arbitrageInstance = await deployer.deployAsync(ContractName.Arbitrage, [
|
arbitrage = await ArbitrageContract.deploy0xArtifactAsync(
|
||||||
|
artifacts.Arbitrage,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
exchange.address,
|
exchange.address,
|
||||||
etherDelta.address,
|
etherDelta.address,
|
||||||
tokenTransferProxy.address,
|
tokenTransferProxy.address,
|
||||||
]);
|
);
|
||||||
arbitrage = new ArbitrageContract(arbitrageInstance.abi, arbitrageInstance.address, provider);
|
|
||||||
// Enable arbitrage and withdrawals of tokens
|
// Enable arbitrage and withdrawals of tokens
|
||||||
await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase });
|
await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase });
|
||||||
await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase });
|
await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase });
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import * as chai from 'chai';
|
|||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
import { DummyTokenContract } from '../src/contract_wrappers/generated/dummy_token';
|
import { DummyTokenContract } from '../src/contract_wrappers/generated/dummy_token';
|
||||||
|
import { artifacts } from '../util/artifacts';
|
||||||
import { constants } from '../util/constants';
|
import { constants } from '../util/constants';
|
||||||
import { ContractName } from '../util/types';
|
import { ContractName } from '../util/types';
|
||||||
|
|
||||||
import { chaiSetup } from './utils/chai_setup';
|
import { chaiSetup } from './utils/chai_setup';
|
||||||
import { deployer } from './utils/deployer';
|
import { defaults, provider, web3Wrapper } from './utils/web3_wrapper';
|
||||||
import { provider, web3Wrapper } from './utils/web3_wrapper';
|
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -33,8 +33,15 @@ describe('UnlimitedAllowanceToken', () => {
|
|||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
owner = accounts[0];
|
owner = accounts[0];
|
||||||
spender = accounts[1];
|
spender = accounts[1];
|
||||||
const tokenInstance = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
|
token = await DummyTokenContract.deploy0xArtifactAsync(
|
||||||
token = new DummyTokenContract(tokenInstance.abi, tokenInstance.address, provider);
|
artifacts.DummyToken,
|
||||||
|
provider,
|
||||||
|
defaults,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
);
|
||||||
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner });
|
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner });
|
||||||
tokenAddress = token.address;
|
tokenAddress = token.address;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import { Deployer } from '@0xproject/deployer';
|
|
||||||
import { devConstants } from '@0xproject/dev-utils';
|
|
||||||
import * as path from 'path';
|
|
||||||
|
|
||||||
import { constants } from '../../util/constants';
|
|
||||||
|
|
||||||
import { web3 } from './web3_wrapper';
|
|
||||||
|
|
||||||
const deployerOpts = {
|
|
||||||
provider: web3.currentProvider,
|
|
||||||
artifactsDir: path.resolve('lib', 'src', 'artifacts'),
|
|
||||||
networkId: constants.TESTRPC_NETWORK_ID,
|
|
||||||
defaults: {
|
|
||||||
gas: devConstants.GAS_ESTIMATE,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deployer = new Deployer(deployerOpts);
|
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
import { web3Factory } from '@0xproject/dev-utils';
|
import { devConstants, web3Factory } from '@0xproject/dev-utils';
|
||||||
import { Provider } from '@0xproject/types';
|
import { Provider } from '@0xproject/types';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
|
|
||||||
|
export const defaults = {
|
||||||
|
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
||||||
|
gas: devConstants.GAS_ESTIMATE,
|
||||||
|
};
|
||||||
const providerConfigs = { shouldUseInProcessGanache: true };
|
const providerConfigs = { shouldUseInProcessGanache: true };
|
||||||
export const web3 = web3Factory.create(providerConfigs);
|
export const web3 = web3Factory.create(providerConfigs);
|
||||||
export const provider = web3.currentProvider;
|
export const provider = web3.currentProvider;
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import * as chai from 'chai';
|
|||||||
import * as Web3 from 'web3';
|
import * as Web3 from 'web3';
|
||||||
|
|
||||||
import { ZRXTokenContract } from '../src/contract_wrappers/generated/zrx_token';
|
import { ZRXTokenContract } from '../src/contract_wrappers/generated/zrx_token';
|
||||||
|
import { artifacts } from '../util/artifacts';
|
||||||
import { constants } from '../util/constants';
|
import { constants } from '../util/constants';
|
||||||
import { ContractName } from '../util/types';
|
import { ContractName } from '../util/types';
|
||||||
|
|
||||||
import { chaiSetup } from './utils/chai_setup';
|
import { chaiSetup } from './utils/chai_setup';
|
||||||
import { deployer } from './utils/deployer';
|
import { defaults, provider, web3Wrapper } from './utils/web3_wrapper';
|
||||||
import { provider, web3Wrapper } from './utils/web3_wrapper';
|
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
@@ -34,8 +34,7 @@ describe('ZRXToken', () => {
|
|||||||
zeroEx = new ZeroEx(provider, {
|
zeroEx = new ZeroEx(provider, {
|
||||||
networkId: constants.TESTRPC_NETWORK_ID,
|
networkId: constants.TESTRPC_NETWORK_ID,
|
||||||
});
|
});
|
||||||
const zrxInstance = await deployer.deployAsync(ContractName.ZRXToken);
|
zrx = await ZRXTokenContract.deploy0xArtifactAsync(artifacts.ZRX, provider, defaults);
|
||||||
zrx = new ZRXTokenContract(zrxInstance.abi, zrxInstance.address, provider);
|
|
||||||
zrxAddress = zrx.address;
|
zrxAddress = zrx.address;
|
||||||
MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
|
MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,25 +1,31 @@
|
|||||||
import { ContractArtifact } from '@0xproject/deployer';
|
import { ContractArtifact } from '@0xproject/deployer';
|
||||||
|
|
||||||
import * as DummyTokenArtifact from '../src/artifacts/DummyToken.json';
|
import * as AccountLevels from '../src/artifacts/AccountLevels.json';
|
||||||
import * as ExchangeArtifact from '../src/artifacts/Exchange.json';
|
import * as Arbitrage from '../src/artifacts/Arbitrage.json';
|
||||||
import * as MaliciousTokenArtifact from '../src/artifacts/MaliciousToken.json';
|
import * as DummyToken from '../src/artifacts/DummyToken.json';
|
||||||
import * as MultiSigWalletWithTimeLockArtifact from '../src/artifacts/MultiSigWalletWithTimeLock.json';
|
import * as EtherDelta from '../src/artifacts/EtherDelta.json';
|
||||||
import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact from '../src/artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json';
|
import * as Exchange from '../src/artifacts/Exchange.json';
|
||||||
import * as TokenArtifact from '../src/artifacts/Token.json';
|
import * as MaliciousToken from '../src/artifacts/MaliciousToken.json';
|
||||||
import * as TokenRegistryArtifact from '../src/artifacts/TokenRegistry.json';
|
import * as MultiSigWalletWithTimeLock from '../src/artifacts/MultiSigWalletWithTimeLock.json';
|
||||||
import * as TokenTransferProxyArtifact from '../src/artifacts/TokenTransferProxy.json';
|
import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress from '../src/artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json';
|
||||||
import * as EtherTokenArtifact from '../src/artifacts/WETH9.json';
|
import * as Token from '../src/artifacts/Token.json';
|
||||||
import * as ZRXArtifact from '../src/artifacts/ZRXToken.json';
|
import * as TokenRegistry from '../src/artifacts/TokenRegistry.json';
|
||||||
|
import * as TokenTransferProxy from '../src/artifacts/TokenTransferProxy.json';
|
||||||
|
import * as EtherToken from '../src/artifacts/WETH9.json';
|
||||||
|
import * as ZRX from '../src/artifacts/ZRXToken.json';
|
||||||
|
|
||||||
export const artifacts = {
|
export const artifacts = {
|
||||||
ZRXArtifact: (ZRXArtifact as any) as ContractArtifact,
|
AccountLevels: (AccountLevels as any) as ContractArtifact,
|
||||||
DummyTokenArtifact: (DummyTokenArtifact as any) as ContractArtifact,
|
Arbitrage: (Arbitrage as any) as ContractArtifact,
|
||||||
TokenArtifact: (TokenArtifact as any) as ContractArtifact,
|
EtherDelta: (EtherDelta as any) as ContractArtifact,
|
||||||
ExchangeArtifact: (ExchangeArtifact as any) as ContractArtifact,
|
ZRX: (ZRX as any) as ContractArtifact,
|
||||||
EtherTokenArtifact: (EtherTokenArtifact as any) as ContractArtifact,
|
DummyToken: (DummyToken as any) as ContractArtifact,
|
||||||
TokenRegistryArtifact: (TokenRegistryArtifact as any) as ContractArtifact,
|
Token: (Token as any) as ContractArtifact,
|
||||||
MaliciousTokenArtifact: (MaliciousTokenArtifact as any) as ContractArtifact,
|
Exchange: (Exchange as any) as ContractArtifact,
|
||||||
TokenTransferProxyArtifact: (TokenTransferProxyArtifact as any) as ContractArtifact,
|
EtherToken: (EtherToken as any) as ContractArtifact,
|
||||||
MultiSigWalletWithTimeLockArtifact: (MultiSigWalletWithTimeLockArtifact as any) as ContractArtifact,
|
TokenRegistry: (TokenRegistry as any) as ContractArtifact,
|
||||||
MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact as any) as ContractArtifact,
|
MaliciousToken: (MaliciousToken as any) as ContractArtifact,
|
||||||
|
TokenTransferProxy: (TokenTransferProxy as any) as ContractArtifact,
|
||||||
|
MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact,
|
||||||
|
MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress as any) as ContractArtifact,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
const DUMMY_TOKEN_NAME = '';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
const DUMMY_TOKEN_SYMBOL = '';
|
|
||||||
const DUMMY_TOKEN_DECIMALS = 18;
|
|
||||||
const DUMMY_TOKEN_TOTAL_SUPPLY = 0;
|
|
||||||
|
|
||||||
export const constants = {
|
export const constants = {
|
||||||
INVALID_OPCODE: 'invalid opcode',
|
INVALID_OPCODE: 'invalid opcode',
|
||||||
@@ -10,5 +7,8 @@ export const constants = {
|
|||||||
MAX_ETHERTOKEN_WITHDRAW_GAS: 43000,
|
MAX_ETHERTOKEN_WITHDRAW_GAS: 43000,
|
||||||
MAX_TOKEN_TRANSFERFROM_GAS: 80000,
|
MAX_TOKEN_TRANSFERFROM_GAS: 80000,
|
||||||
MAX_TOKEN_APPROVE_GAS: 60000,
|
MAX_TOKEN_APPROVE_GAS: 60000,
|
||||||
DUMMY_TOKEN_ARGS: [DUMMY_TOKEN_NAME, DUMMY_TOKEN_SYMBOL, DUMMY_TOKEN_DECIMALS, DUMMY_TOKEN_TOTAL_SUPPLY],
|
DUMMY_TOKEN_NAME: '',
|
||||||
|
DUMMY_TOKEN_SYMBOL: '',
|
||||||
|
DUMMY_TOKEN_DECIMALS: new BigNumber(18),
|
||||||
|
DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(0),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,13 +29,12 @@ If your project is in [TypeScript](https://www.typescriptlang.org/), add the fol
|
|||||||
**Import**
|
**Import**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { Deployer, Compiler } from '@0xproject/deployer';
|
import { Compiler } from '@0xproject/deployer';
|
||||||
```
|
```
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var Deployer = require('@0xproject/deployer').Deployer;
|
|
||||||
var Compiler = require('@0xproject/deployer').Compiler;
|
var Compiler = require('@0xproject/deployer').Compiler;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ export class Compiler {
|
|||||||
const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION;
|
const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION;
|
||||||
const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings);
|
const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings);
|
||||||
const didSourceChange = currentArtifact.sourceTreeHashHex !== sourceTreeHashHex;
|
const didSourceChange = currentArtifact.sourceTreeHashHex !== sourceTreeHashHex;
|
||||||
shouldCompile = isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange;
|
shouldCompile = !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange;
|
||||||
}
|
}
|
||||||
if (!shouldCompile) {
|
if (!shouldCompile) {
|
||||||
return;
|
return;
|
||||||
@@ -203,6 +203,20 @@ export class Compiler {
|
|||||||
}. Please make sure your contract has the same name as it's file name`,
|
}. Please make sure your contract has the same name as it's file name`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (!_.isUndefined(compiledData.evm)) {
|
||||||
|
if (!_.isUndefined(compiledData.evm.bytecode) && !_.isUndefined(compiledData.evm.bytecode.object)) {
|
||||||
|
compiledData.evm.bytecode.object = ethUtil.addHexPrefix(compiledData.evm.bytecode.object);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!_.isUndefined(compiledData.evm.deployedBytecode) &&
|
||||||
|
!_.isUndefined(compiledData.evm.deployedBytecode.object)
|
||||||
|
) {
|
||||||
|
compiledData.evm.deployedBytecode.object = ethUtil.addHexPrefix(
|
||||||
|
compiledData.evm.deployedBytecode.object,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const sourceCodes = _.mapValues(
|
const sourceCodes = _.mapValues(
|
||||||
compiled.sources,
|
compiled.sources,
|
||||||
(_1, sourceFilePath) => this._resolver.resolve(sourceFilePath).source,
|
(_1, sourceFilePath) => this._resolver.resolve(sourceFilePath).source,
|
||||||
|
|||||||
4
packages/metacoin/src/global.d.ts
vendored
Normal file
4
packages/metacoin/src/global.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
declare module '*.json' {
|
||||||
|
const value: any;
|
||||||
|
export default value;
|
||||||
|
}
|
||||||
@@ -1,15 +1,19 @@
|
|||||||
|
import { ContractArtifact } from '@0xproject/deployer';
|
||||||
import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils';
|
||||||
import { LogWithDecodedArgs } from '@0xproject/types';
|
import { LogWithDecodedArgs } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
|
|
||||||
|
import * as MetacoinArtifact from '../artifacts/Metacoin.json';
|
||||||
import { MetacoinContract, TransferContractEventArgs } from '../src/contract_wrappers/metacoin';
|
import { MetacoinContract, TransferContractEventArgs } from '../src/contract_wrappers/metacoin';
|
||||||
|
|
||||||
import { chaiSetup } from './utils/chai_setup';
|
import { chaiSetup } from './utils/chai_setup';
|
||||||
import { deployer } from './utils/deployer';
|
import { config } from './utils/config';
|
||||||
import { provider, web3Wrapper } from './utils/web3_wrapper';
|
import { provider, web3Wrapper } from './utils/web3_wrapper';
|
||||||
|
|
||||||
|
const artifact: ContractArtifact = MetacoinArtifact as any;
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const { expect } = chai;
|
const { expect } = chai;
|
||||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||||
@@ -19,9 +23,8 @@ describe('Metacoin', () => {
|
|||||||
const ownerAddress = devConstants.TESTRPC_FIRST_ADDRESS;
|
const ownerAddress = devConstants.TESTRPC_FIRST_ADDRESS;
|
||||||
const INITIAL_BALANCE = new BigNumber(10000);
|
const INITIAL_BALANCE = new BigNumber(10000);
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const metacoinInstance = await deployer.deployAsync('Metacoin');
|
metacoin = await MetacoinContract.deploy0xArtifactAsync(artifact, provider, config.defaults);
|
||||||
web3Wrapper.abiDecoder.addABI(metacoinInstance.abi);
|
web3Wrapper.abiDecoder.addABI(metacoin.abi);
|
||||||
metacoin = new MetacoinContract(metacoinInstance.abi, metacoinInstance.address, provider);
|
|
||||||
});
|
});
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await blockchainLifecycle.startAsync();
|
await blockchainLifecycle.startAsync();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { devConstants } from '@0xproject/dev-utils';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
@@ -5,5 +6,8 @@ export const config = {
|
|||||||
artifactsDir: path.resolve(__dirname, '../../artifacts'),
|
artifactsDir: path.resolve(__dirname, '../../artifacts'),
|
||||||
contractsDir: path.resolve(__dirname, '../../contracts'),
|
contractsDir: path.resolve(__dirname, '../../contracts'),
|
||||||
ganacheLogFile: 'ganache.log',
|
ganacheLogFile: 'ganache.log',
|
||||||
|
defaults: {
|
||||||
|
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
||||||
|
},
|
||||||
mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic',
|
mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import { Deployer } from '@0xproject/deployer';
|
|
||||||
import { devConstants } from '@0xproject/dev-utils';
|
|
||||||
import * as path from 'path';
|
|
||||||
|
|
||||||
import { config } from './config';
|
|
||||||
import { web3Wrapper } from './web3_wrapper';
|
|
||||||
|
|
||||||
const deployerOpts = {
|
|
||||||
provider: web3Wrapper.getProvider(),
|
|
||||||
artifactsDir: config.artifactsDir,
|
|
||||||
networkId: config.networkId,
|
|
||||||
defaults: {
|
|
||||||
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deployer = new Deployer(deployerOpts);
|
|
||||||
@@ -26,6 +26,7 @@ declare module 'ethers' {
|
|||||||
constructor(abi: any);
|
constructor(abi: any);
|
||||||
}
|
}
|
||||||
export class Contract {
|
export class Contract {
|
||||||
|
public static getDeployTransaction(bytecode: string, abi: any, ...args: any[]): any;
|
||||||
constructor(address: string, abi: any, provider: any);
|
constructor(address: string, abi: any, provider: any);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ yarn add @0xproject/deployer
|
|||||||
**Import**
|
**Import**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { Deployer, Compiler } from '@0xproject/deployer';
|
import { Compiler } from '@0xproject/deployer';
|
||||||
```
|
```
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var Deployer = require('@0xproject/deployer').Deployer;
|
|
||||||
var Compiler = require('@0xproject/deployer').Compiler;
|
var Compiler = require('@0xproject/deployer').Compiler;
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user