diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-23 04:53:32 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-30 23:01:36 +0800 |
commit | 387363283ca03ac1d6c9be5b7be2107790bbf79d (patch) | |
tree | 7f9ce518e2f4931321901dfeb2675d70854e996d /packages/contracts/util | |
parent | 709026bf1a49d468850b4ebed845c8598fa4fd75 (diff) | |
download | dexon-0x-contracts-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar dexon-0x-contracts-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.gz dexon-0x-contracts-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.bz2 dexon-0x-contracts-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.lz dexon-0x-contracts-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.xz dexon-0x-contracts-387363283ca03ac1d6c9be5b7be2107790bbf79d.tar.zst dexon-0x-contracts-387363283ca03ac1d6c9be5b7be2107790bbf79d.zip |
Remove truffle from tests
Diffstat (limited to 'packages/contracts/util')
-rw-r--r-- | packages/contracts/util/artifacts.ts | 55 | ||||
-rw-r--r-- | packages/contracts/util/balances.ts | 7 | ||||
-rw-r--r-- | packages/contracts/util/exchange_wrapper.ts | 59 | ||||
-rw-r--r-- | packages/contracts/util/multi_sig_wrapper.ts | 6 | ||||
-rw-r--r-- | packages/contracts/util/order.ts | 7 | ||||
-rw-r--r-- | packages/contracts/util/order_factory.ts | 7 | ||||
-rw-r--r-- | packages/contracts/util/token_registry_wrapper.ts | 8 | ||||
-rw-r--r-- | packages/contracts/util/types.ts | 35 |
8 files changed, 123 insertions, 61 deletions
diff --git a/packages/contracts/util/artifacts.ts b/packages/contracts/util/artifacts.ts index ecb18cbce..145b1db3b 100644 --- a/packages/contracts/util/artifacts.ts +++ b/packages/contracts/util/artifacts.ts @@ -1,28 +1,27 @@ -export class Artifacts { - public Migrations: any; - public TokenTransferProxy: any; - public TokenRegistry: any; - public MultiSigWalletWithTimeLock: any; - public Exchange: any; - public ZRXToken: any; - public DummyToken: any; - public DummyTokenV2: any; - public EtherToken: any; - public MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: any; - public MaliciousToken: any; - constructor(artifacts: any) { - this.Migrations = artifacts.require('Migrations'); - this.TokenTransferProxy = artifacts.require('TokenTransferProxy'); - this.TokenRegistry = artifacts.require('TokenRegistry'); - this.MultiSigWalletWithTimeLock = artifacts.require('MultiSigWalletWithTimeLock'); - this.Exchange = artifacts.require('Exchange'); - this.ZRXToken = artifacts.require('ZRXToken'); - this.DummyToken = artifacts.require('DummyToken'); - this.DummyTokenV2 = artifacts.require('DummyToken_v2'); - this.EtherToken = artifacts.require('WETH9'); - this.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = artifacts.require( - 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', - ); - this.MaliciousToken = artifacts.require('MaliciousToken'); - } -} +import * as DummyTokenArtifact from '../build/artifacts/DummyToken.json'; +import * as DummyTokenV2Artifact from '../build/artifacts/DummyToken_v2.json'; +import * as ExchangeArtifact from '../build/artifacts/Exchange.json'; +import * as MaliciousTokenArtifact from '../build/artifacts/MaliciousToken.json'; +import * as MultiSigWalletWithTimeLockArtifact from '../build/artifacts/MultiSigWalletWithTimeLock.json'; +import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact from '../build/artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json'; +import * as TokenArtifact from '../build/artifacts/Token.json'; +import * as TokenRegistryArtifact from '../build/artifacts/TokenRegistry.json'; +import * as TokenTransferProxyArtifact from '../build/artifacts/TokenTransferProxy.json'; +import * as EtherTokenArtifact from '../build/artifacts/WETH9.json'; +import * as ZRXArtifact from '../build/artifacts/ZRXToken.json'; + +import { Artifact } from './types'; + +export const artifacts = { + ZRXArtifact: (ZRXArtifact as any) as Artifact, + DummyTokenArtifact: (DummyTokenArtifact as any) as Artifact, + DummyTokenV2Artifact: (DummyTokenV2Artifact as any) as Artifact, + TokenArtifact: (TokenArtifact as any) as Artifact, + ExchangeArtifact: (ExchangeArtifact as any) as Artifact, + EtherTokenArtifact: (EtherTokenArtifact as any) as Artifact, + TokenRegistryArtifact: (TokenRegistryArtifact as any) as Artifact, + MaliciousTokenArtifact: (MaliciousTokenArtifact as any) as Artifact, + TokenTransferProxyArtifact: (TokenTransferProxyArtifact as any) as Artifact, + MultiSigWalletWithTimeLockArtifact: (MultiSigWalletWithTimeLockArtifact as any) as Artifact, + MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact as any) as Artifact, +}; diff --git a/packages/contracts/util/balances.ts b/packages/contracts/util/balances.ts index 6a1659ab1..5bcb5145f 100644 --- a/packages/contracts/util/balances.ts +++ b/packages/contracts/util/balances.ts @@ -1,12 +1,13 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; +import * as Web3 from 'web3'; -import { BalancesByOwner, ContractInstance } from './types'; +import { BalancesByOwner } from './types'; export class Balances { - private _tokenContractInstances: ContractInstance[]; + private _tokenContractInstances: Web3.ContractInstance[]; private _ownerAddresses: string[]; - constructor(tokenContractInstances: ContractInstance[], ownerAddresses: string[]) { + constructor(tokenContractInstances: Web3.ContractInstance[], ownerAddresses: string[]) { this._tokenContractInstances = tokenContractInstances; this._ownerAddresses = ownerAddresses; } diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts index ca79f92c4..2e10cd673 100644 --- a/packages/contracts/util/exchange_wrapper.ts +++ b/packages/contracts/util/exchange_wrapper.ts @@ -1,14 +1,17 @@ +import { ExchangeContractEventArgs, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; +import * as Web3 from 'web3'; import { formatters } from './formatters'; import { Order } from './order'; -import { ContractInstance } from './types'; export class ExchangeWrapper { - private _exchange: ContractInstance; - constructor(exchangeContractInstance: ContractInstance) { + private _exchange: Web3.ContractInstance; + private _zeroEx: ZeroEx; + constructor(exchangeContractInstance: Web3.ContractInstance, zeroEx: ZeroEx) { this._exchange = exchangeContractInstance; + this._zeroEx = zeroEx; } public async fillOrderAsync( order: Order, @@ -17,10 +20,10 @@ export class ExchangeWrapper { fillTakerTokenAmount?: BigNumber; shouldThrowOnInsufficientBalanceOrAllowance?: boolean; } = {}, - ) { + ): Promise<TransactionReceiptWithDecodedLogs<ExchangeContractEventArgs>> { const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance; const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount); - const tx = await this._exchange.fillOrder( + const txHash = await this._exchange.fillOrder( params.orderAddresses, params.orderValues, params.fillTakerTokenAmount, @@ -30,24 +33,36 @@ export class ExchangeWrapper { params.s, { from }, ); + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; } - public async cancelOrderAsync(order: Order, from: string, opts: { cancelTakerTokenAmount?: BigNumber } = {}) { + public async cancelOrderAsync( + order: Order, + from: string, + opts: { cancelTakerTokenAmount?: BigNumber } = {}, + ): Promise<TransactionReceiptWithDecodedLogs<ExchangeContractEventArgs>> { const params = order.createCancel(opts.cancelTakerTokenAmount); - const tx = await this._exchange.cancelOrder( + const txHash = await this._exchange.cancelOrder( params.orderAddresses, params.orderValues, params.cancelTakerTokenAmount, { from }, ); + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; } - public async fillOrKillOrderAsync(order: Order, from: string, opts: { fillTakerTokenAmount?: BigNumber } = {}) { + public async fillOrKillOrderAsync( + order: Order, + from: string, + opts: { fillTakerTokenAmount?: BigNumber } = {}, + ): Promise<TransactionReceiptWithDecodedLogs<ExchangeContractEventArgs>> { const shouldThrowOnInsufficientBalanceOrAllowance = true; const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount); - const tx = await this._exchange.fillOrKillOrder( + const txHash = await this._exchange.fillOrKillOrder( params.orderAddresses, params.orderValues, params.fillTakerTokenAmount, @@ -56,6 +71,8 @@ export class ExchangeWrapper { params.s, { from }, ); + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; } @@ -66,14 +83,14 @@ export class ExchangeWrapper { fillTakerTokenAmounts?: BigNumber[]; shouldThrowOnInsufficientBalanceOrAllowance?: boolean; } = {}, - ) { + ): Promise<TransactionReceiptWithDecodedLogs<ExchangeContractEventArgs>> { const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance; const params = formatters.createBatchFill( orders, shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmounts, ); - const tx = await this._exchange.batchFillOrders( + const txHash = await this._exchange.batchFillOrders( params.orderAddresses, params.orderValues, params.fillTakerTokenAmounts, @@ -83,6 +100,8 @@ export class ExchangeWrapper { params.s, { from }, ); + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; } @@ -90,9 +109,9 @@ export class ExchangeWrapper { orders: Order[], from: string, opts: { fillTakerTokenAmounts?: BigNumber[] } = {}, - ) { + ): Promise<TransactionReceiptWithDecodedLogs<ExchangeContractEventArgs>> { const params = formatters.createBatchFill(orders, undefined, opts.fillTakerTokenAmounts); - const tx = await this._exchange.batchFillOrKillOrders( + const txHash = await this._exchange.batchFillOrKillOrders( params.orderAddresses, params.orderValues, params.fillTakerTokenAmounts, @@ -101,6 +120,8 @@ export class ExchangeWrapper { params.s, { from }, ); + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; } @@ -111,14 +132,14 @@ export class ExchangeWrapper { fillTakerTokenAmount?: BigNumber; shouldThrowOnInsufficientBalanceOrAllowance?: boolean; } = {}, - ) { + ): Promise<TransactionReceiptWithDecodedLogs<ExchangeContractEventArgs>> { const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance; const params = formatters.createFillUpTo( orders, shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount, ); - const tx = await this._exchange.fillOrdersUpTo( + const txHash = await this._exchange.fillOrdersUpTo( params.orderAddresses, params.orderValues, params.fillTakerTokenAmount, @@ -128,6 +149,8 @@ export class ExchangeWrapper { params.s, { from }, ); + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; } @@ -135,14 +158,16 @@ export class ExchangeWrapper { orders: Order[], from: string, opts: { cancelTakerTokenAmounts?: BigNumber[] } = {}, - ) { + ): Promise<TransactionReceiptWithDecodedLogs<ExchangeContractEventArgs>> { const params = formatters.createBatchCancel(orders, opts.cancelTakerTokenAmounts); - const tx = await this._exchange.batchCancelOrders( + const txHash = await this._exchange.batchCancelOrders( params.orderAddresses, params.orderValues, params.cancelTakerTokenAmounts, { from }, ); + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; } diff --git a/packages/contracts/util/multi_sig_wrapper.ts b/packages/contracts/util/multi_sig_wrapper.ts index 0e2e671ec..0a066df53 100644 --- a/packages/contracts/util/multi_sig_wrapper.ts +++ b/packages/contracts/util/multi_sig_wrapper.ts @@ -3,10 +3,10 @@ import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; import * as Web3 from 'web3'; -import { ContractInstance, TransactionDataParams } from './types'; +import { TransactionDataParams } from './types'; export class MultiSigWrapper { - private _multiSig: ContractInstance; + private _multiSig: Web3.ContractInstance; public static encodeFnArgs(name: string, abi: Web3.AbiDefinition[], args: any[]) { const abiEntity = _.find(abi, { name }) as Web3.MethodAbi; if (_.isUndefined(abiEntity)) { @@ -21,7 +21,7 @@ export class MultiSigWrapper { }); return funcSig + argsData.join(''); } - constructor(multiSigContractInstance: ContractInstance) { + constructor(multiSigContractInstance: Web3.ContractInstance) { this._multiSig = multiSigContractInstance; } public async submitTransactionAsync( diff --git a/packages/contracts/util/order.ts b/packages/contracts/util/order.ts index e202d485b..702b2312c 100644 --- a/packages/contracts/util/order.ts +++ b/packages/contracts/util/order.ts @@ -1,4 +1,5 @@ import { BigNumber, promisify } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; import Web3 = require('web3'); @@ -12,8 +13,10 @@ const web3: Web3 = (global as any).web3; export class Order { public params: OrderParams; - constructor(params: OrderParams) { + private _web3Wrapper: Web3Wrapper; + constructor(web3Wrapper: Web3Wrapper, params: OrderParams) { this.params = params; + this._web3Wrapper = web3Wrapper; } public isValidSignature() { const { v, r, s } = this.params; @@ -32,7 +35,7 @@ export class Order { } public async signAsync() { const orderHash = this._getOrderHash(); - const signature = await promisify<string>(web3.eth.sign)(this.params.maker, orderHash); + const signature = await this._web3Wrapper.signTransactionAsync(this.params.maker, orderHash); const { v, r, s } = ethUtil.fromRpcSig(signature); this.params = _.assign(this.params, { orderHashHex: orderHash, diff --git a/packages/contracts/util/order_factory.ts b/packages/contracts/util/order_factory.ts index a45877de0..fa12889ca 100644 --- a/packages/contracts/util/order_factory.ts +++ b/packages/contracts/util/order_factory.ts @@ -1,5 +1,6 @@ import { ZeroEx } from '0x.js'; import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; import { Order } from './order'; @@ -7,8 +8,10 @@ import { DefaultOrderParams, OptionalOrderParams, OrderParams } from './types'; export class OrderFactory { private _defaultOrderParams: DefaultOrderParams; - constructor(defaultOrderParams: DefaultOrderParams) { + private _web3Wrapper: Web3Wrapper; + constructor(web3Wrapper: Web3Wrapper, defaultOrderParams: DefaultOrderParams) { this._defaultOrderParams = defaultOrderParams; + this._web3Wrapper = web3Wrapper; } public async newSignedOrderAsync(customOrderParams: OptionalOrderParams = {}) { const randomExpiration = new BigNumber(Math.floor((Date.now() + Math.random() * 100000000000) / 1000)); @@ -22,7 +25,7 @@ export class OrderFactory { this._defaultOrderParams, customOrderParams, ); - const order = new Order(orderParams); + const order = new Order(this._web3Wrapper, orderParams); await order.signAsync(); return order; } diff --git a/packages/contracts/util/token_registry_wrapper.ts b/packages/contracts/util/token_registry_wrapper.ts index 07a577dea..033b72d10 100644 --- a/packages/contracts/util/token_registry_wrapper.ts +++ b/packages/contracts/util/token_registry_wrapper.ts @@ -1,8 +1,10 @@ -import { ContractInstance, Token } from './types'; +import * as Web3 from 'web3'; + +import { Token } from './types'; export class TokenRegWrapper { - private _tokenReg: ContractInstance; - constructor(tokenRegContractInstance: ContractInstance) { + private _tokenReg: Web3.ContractInstance; + constructor(tokenRegContractInstance: Web3.ContractInstance) { this._tokenReg = tokenRegContractInstance; } public addTokenAsync(token: Token, from: string) { diff --git a/packages/contracts/util/types.ts b/packages/contracts/util/types.ts index e511ca9f4..baeb15577 100644 --- a/packages/contracts/util/types.ts +++ b/packages/contracts/util/types.ts @@ -7,6 +7,10 @@ export interface BalancesByOwner { }; } +export interface SubmissionContractEventArgs { + transactionId: BigNumber; +} + export interface BatchFillOrders { orderAddresses: string[][]; orderValues: BigNumber[][]; @@ -108,12 +112,37 @@ export interface TokenInfoByNetwork { live: Token[]; } -// Named type aliases to improve readability -export type ContractInstance = any; - export enum ExchangeContractErrs { ERROR_ORDER_EXPIRED, ERROR_ORDER_FULLY_FILLED_OR_CANCELLED, ERROR_ROUNDING_ERROR_TOO_LARGE, ERROR_INSUFFICIENT_BALANCE_OR_ALLOWANCE, } + +export type ArtifactContractName = + | 'TokenTransferProxy' + | 'TokenRegistry' + | 'MultiSigWalletWithTimeLock' + | 'Exchange' + | 'ZRXToken' + | 'DummyToken' + | 'DummyToken_v2' + | 'WETH9' + | 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress' + | 'MaliciousToken'; + +export interface Artifact { + contract_name: ArtifactContractName; + networks: { + [networkId: number]: { + abi: Web3.ContractAbi; + solc_version: string; + keccak256: string; + optimizer_enabled: number; + unlinked_binary: string; + updated_at: number; + address: string; + constructor_args: string; + }; + }; +} |