Fix merge issues

This commit is contained in:
Fabio Berger
2018-06-26 08:43:37 +02:00
parent 9219f9d8ae
commit 105b927397
5 changed files with 21 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
import { assetProxyUtils } from '@0xproject/order-utils'; import { assetProxyUtils } from '@0xproject/order-utils';
import { AssetProxyId } from '@0xproject/types';
import { BigNumber, errorUtils } from '@0xproject/utils'; import { BigNumber, errorUtils } from '@0xproject/utils';
import * as _ from 'lodash'; import * as _ from 'lodash';
@@ -9,7 +10,7 @@ import { ERC20Wrapper } from './erc20_wrapper';
import { ERC721Wrapper } from './erc721_wrapper'; import { ERC721Wrapper } from './erc721_wrapper';
interface ProxyIdToAssetWrappers { interface ProxyIdToAssetWrappers {
[proxyId: number]: AbstractAssetWrapper; [proxyId: string]: AbstractAssetWrapper;
} }
/** /**
@@ -28,12 +29,12 @@ export class AssetWrapper {
public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> { public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
const proxyId = assetProxyUtils.decodeAssetDataId(assetData); const proxyId = assetProxyUtils.decodeAssetDataId(assetData);
switch (proxyId) { switch (proxyId) {
case constants.ERC20_PROXY_ID: { case AssetProxyId.ERC20: {
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper; const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
const balance = await erc20Wrapper.getBalanceAsync(userAddress, assetData); const balance = await erc20Wrapper.getBalanceAsync(userAddress, assetData);
return balance; return balance;
} }
case constants.ERC721_PROXY_ID: { case AssetProxyId.ERC721: {
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper; const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
const assetProxyData = assetProxyUtils.decodeERC721AssetData(assetData); const assetProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
const isOwner = await assetWrapper.isOwnerAsync( const isOwner = await assetWrapper.isOwnerAsync(
@@ -51,12 +52,12 @@ export class AssetWrapper {
public async setBalanceAsync(userAddress: string, assetData: string, desiredBalance: BigNumber): Promise<void> { public async setBalanceAsync(userAddress: string, assetData: string, desiredBalance: BigNumber): Promise<void> {
const proxyId = assetProxyUtils.decodeAssetDataId(assetData); const proxyId = assetProxyUtils.decodeAssetDataId(assetData);
switch (proxyId) { switch (proxyId) {
case constants.ERC20_PROXY_ID: { case AssetProxyId.ERC20: {
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper; const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
await erc20Wrapper.setBalanceAsync(userAddress, assetData, desiredBalance); await erc20Wrapper.setBalanceAsync(userAddress, assetData, desiredBalance);
return; return;
} }
case constants.ERC721_PROXY_ID: { case AssetProxyId.ERC721: {
if (!desiredBalance.eq(0) && !desiredBalance.eq(1)) { if (!desiredBalance.eq(0) && !desiredBalance.eq(1)) {
throw new Error(`Balance for ERC721 token can only be set to 0 or 1. Got: ${desiredBalance}`); throw new Error(`Balance for ERC721 token can only be set to 0 or 1. Got: ${desiredBalance}`);
} }
@@ -102,12 +103,12 @@ export class AssetWrapper {
public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> { public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
const proxyId = assetProxyUtils.decodeAssetDataId(assetData); const proxyId = assetProxyUtils.decodeAssetDataId(assetData);
switch (proxyId) { switch (proxyId) {
case constants.ERC20_PROXY_ID: { case AssetProxyId.ERC20: {
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper; const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
const allowance = await erc20Wrapper.getProxyAllowanceAsync(userAddress, assetData); const allowance = await erc20Wrapper.getProxyAllowanceAsync(userAddress, assetData);
return allowance; return allowance;
} }
case constants.ERC721_PROXY_ID: { case AssetProxyId.ERC721: {
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper; const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
const erc721ProxyData = assetProxyUtils.decodeERC721AssetData(assetData); const erc721ProxyData = assetProxyUtils.decodeERC721AssetData(assetData);
const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync( const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(
@@ -136,12 +137,12 @@ export class AssetWrapper {
): Promise<void> { ): Promise<void> {
const proxyId = assetProxyUtils.decodeAssetDataId(assetData); const proxyId = assetProxyUtils.decodeAssetDataId(assetData);
switch (proxyId) { switch (proxyId) {
case constants.ERC20_PROXY_ID: { case AssetProxyId.ERC20: {
const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper; const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper;
await erc20Wrapper.setAllowanceAsync(userAddress, assetData, desiredAllowance); await erc20Wrapper.setAllowanceAsync(userAddress, assetData, desiredAllowance);
return; return;
} }
case constants.ERC721_PROXY_ID: { case AssetProxyId.ERC721: {
if ( if (
!desiredAllowance.eq(0) && !desiredAllowance.eq(0) &&
!desiredAllowance.eq(1) && !desiredAllowance.eq(1) &&

View File

@@ -515,7 +515,7 @@ export class CoreCombinatorialUtils {
const takerAssetProxyId = assetProxyUtils.decodeAssetDataId(signedOrder.takerAssetData); const takerAssetProxyId = assetProxyUtils.decodeAssetDataId(signedOrder.takerAssetData);
const makerAssetProxyId = assetProxyUtils.decodeAssetDataId(signedOrder.makerAssetData); const makerAssetProxyId = assetProxyUtils.decodeAssetDataId(signedOrder.makerAssetData);
const isEitherAssetERC721 = const isEitherAssetERC721 =
takerAssetProxyId === constants.ERC721_PROXY_ID || makerAssetProxyId === constants.ERC721_PROXY_ID; takerAssetProxyId === AssetProxyId.ERC721 || makerAssetProxyId === AssetProxyId.ERC721;
if (isEitherAssetERC721) { if (isEitherAssetERC721) {
throw new Error( throw new Error(
'Cannot test `TakerAssetFillAmountScenario.LessThanRemainingFillableTakerAssetAmount` together with ERC721 assets since orders involving ERC721 must always be filled exactly.', 'Cannot test `TakerAssetFillAmountScenario.LessThanRemainingFillableTakerAssetAmount` together with ERC721 assets since orders involving ERC721 must always be filled exactly.',

View File

@@ -19,7 +19,7 @@ export class ERC20Wrapper {
private _provider: Provider; private _provider: Provider;
private _dummyTokenContracts: DummyERC20TokenContract[]; private _dummyTokenContracts: DummyERC20TokenContract[];
private _proxyContract?: ERC20ProxyContract; private _proxyContract?: ERC20ProxyContract;
private _proxyIdIfExists?: number; private _proxyIdIfExists?: string;
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) { constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
this._dummyTokenContracts = []; this._dummyTokenContracts = [];
this._web3Wrapper = new Web3Wrapper(provider); this._web3Wrapper = new Web3Wrapper(provider);
@@ -55,9 +55,9 @@ export class ERC20Wrapper {
this._proxyIdIfExists = await this._proxyContract.getProxyId.callAsync(); this._proxyIdIfExists = await this._proxyContract.getProxyId.callAsync();
return this._proxyContract; return this._proxyContract;
} }
public getProxyId(): number { public getProxyId(): string {
this._validateProxyContractExistsOrThrow(); this._validateProxyContractExistsOrThrow();
return this._proxyIdIfExists as number; return this._proxyIdIfExists as string;
} }
public async setBalancesAndAllowancesAsync(): Promise<void> { public async setBalancesAndAllowancesAsync(): Promise<void> {
this._validateDummyTokenContractsExistOrThrow(); this._validateDummyTokenContractsExistOrThrow();

View File

@@ -19,7 +19,7 @@ export class ERC721Wrapper {
private _provider: Provider; private _provider: Provider;
private _dummyTokenContracts: DummyERC721TokenContract[]; private _dummyTokenContracts: DummyERC721TokenContract[];
private _proxyContract?: ERC721ProxyContract; private _proxyContract?: ERC721ProxyContract;
private _proxyIdIfExists?: number; private _proxyIdIfExists?: string;
private _initialTokenIdsByOwner: ERC721TokenIdsByOwner = {}; private _initialTokenIdsByOwner: ERC721TokenIdsByOwner = {};
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) { constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
this._web3Wrapper = new Web3Wrapper(provider); this._web3Wrapper = new Web3Wrapper(provider);
@@ -51,9 +51,9 @@ export class ERC721Wrapper {
this._proxyIdIfExists = await this._proxyContract.getProxyId.callAsync(); this._proxyIdIfExists = await this._proxyContract.getProxyId.callAsync();
return this._proxyContract; return this._proxyContract;
} }
public getProxyId(): number { public getProxyId(): string {
this._validateProxyContractExistsOrThrow(); this._validateProxyContractExistsOrThrow();
return this._proxyIdIfExists as number; return this._proxyIdIfExists as string;
} }
public async setBalancesAndAllowancesAsync(): Promise<void> { public async setBalancesAndAllowancesAsync(): Promise<void> {
this._validateDummyTokenContractsExistOrThrow(); this._validateDummyTokenContractsExistOrThrow();

View File

@@ -62,7 +62,10 @@ describe('Asset Transfer Proxies', () => {
erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner); erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner);
erc721Wrapper = new ERC721Wrapper(provider, usedAddresses, owner); erc721Wrapper = new ERC721Wrapper(provider, usedAddresses, owner);
[zrxToken] = await erc20Wrapper.deployDummyTokensAsync(); [zrxToken] = await erc20Wrapper.deployDummyTokensAsync(
constants.NUM_DUMMY_ERC20_TO_DEPLOY,
constants.DUMMY_TOKEN_DECIMALS,
);
erc20Proxy = await erc20Wrapper.deployProxyAsync(); erc20Proxy = await erc20Wrapper.deployProxyAsync();
await erc20Wrapper.setBalancesAndAllowancesAsync(); await erc20Wrapper.setBalancesAndAllowancesAsync();
await web3Wrapper.awaitTransactionSuccessAsync( await web3Wrapper.awaitTransactionSuccessAsync(