Fix ExchangeWrapper

This commit is contained in:
Fabio Berger
2018-05-22 13:15:01 -07:00
parent 09d80b1e50
commit 9de9bf651b
6 changed files with 10 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
import { TransactionReceiptWithDecodedLogs } from '@0xproject/types';
import { Provider, TransactionReceiptWithDecodedLogs } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
@@ -14,9 +14,11 @@ import { AssetProxyId, OrderInfo, SignedOrder, SignedTransaction } from './types
export class ExchangeWrapper {
private _exchange: ExchangeContract;
private _web3Wrapper: Web3Wrapper;
private _logDecoder: LogDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID);
constructor(exchangeContract: ExchangeContract) {
constructor(exchangeContract: ExchangeContract, provider: Provider) {
this._exchange = exchangeContract;
this._web3Wrapper = new Web3Wrapper(provider);
}
public async fillOrderAsync(
signedOrder: SignedOrder,
@@ -245,7 +247,7 @@ export class ExchangeWrapper {
return tx;
}
private async _getTxWithDecodedExchangeLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
const tx = await Web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
const tx = await this._web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log));
return tx;

View File

@@ -60,8 +60,6 @@ describe('Exchange core', () => {
let defaultMakerAssetAddress: string;
let defaultTakerAssetAddress: string;
let zeroEx: ZeroEx;
before(async () => {
await blockchainLifecycle.startAsync();
});
@@ -92,11 +90,7 @@ describe('Exchange core', () => {
txDefaults,
assetProxyUtils.encodeERC20ProxyData(zrxToken.address),
);
zeroEx = new ZeroEx(provider, {
exchangeContractAddress: exchange.address,
networkId: constants.TESTRPC_NETWORK_ID,
});
exchangeWrapper = new ExchangeWrapper(exchange);
exchangeWrapper = new ExchangeWrapper(exchange, provider);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner);

View File

@@ -116,7 +116,7 @@ describe('matchOrders', () => {
txDefaults,
assetProxyUtils.encodeERC20ProxyData(zrxToken.address),
);
exchangeWrapper = new ExchangeWrapper(exchange);
exchangeWrapper = new ExchangeWrapper(exchange, provider);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner);
// Authorize ERC20 and ERC721 trades by exchange

View File

@@ -79,7 +79,7 @@ describe('Exchange transactions', () => {
txDefaults,
assetProxyUtils.encodeERC20ProxyData(zrxToken.address),
);
exchangeWrapper = new ExchangeWrapper(exchange);
exchangeWrapper = new ExchangeWrapper(exchange, provider);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
await web3Wrapper.awaitTransactionMinedAsync(

View File

@@ -83,7 +83,7 @@ describe('Exchange wrappers', () => {
txDefaults,
assetProxyUtils.encodeERC20ProxyData(zrxToken.address),
);
exchangeWrapper = new ExchangeWrapper(exchange);
exchangeWrapper = new ExchangeWrapper(exchange, provider);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner);

View File

@@ -115,7 +115,7 @@
// exchangeContractAddress: exchange.address,
// networkId: constants.TESTRPC_NETWORK_ID,
// });
// exWrapper = new ExchangeWrapper(exchange);
// exWrapper = new ExchangeWrapper(exchange, provider);
// makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
// takerTokenAmount = makerTokenAmount;