Fix last tests
This commit is contained in:
@@ -5,16 +5,16 @@ import {ZeroExError} from '../types';
|
|||||||
import {utils} from '../utils/utils';
|
import {utils} from '../utils/utils';
|
||||||
|
|
||||||
export class ContractWrapper {
|
export class ContractWrapper {
|
||||||
protected web3Wrapper: Web3Wrapper;
|
protected _web3Wrapper: Web3Wrapper;
|
||||||
constructor(web3Wrapper: Web3Wrapper) {
|
constructor(web3Wrapper: Web3Wrapper) {
|
||||||
this.web3Wrapper = web3Wrapper;
|
this._web3Wrapper = web3Wrapper;
|
||||||
}
|
}
|
||||||
protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise<ContractInstance> {
|
protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise<ContractInstance> {
|
||||||
const c = await contract(artifact);
|
const c = await contract(artifact);
|
||||||
const providerObj = this.web3Wrapper.getCurrentProvider();
|
const providerObj = this._web3Wrapper.getCurrentProvider();
|
||||||
c.setProvider(providerObj);
|
c.setProvider(providerObj);
|
||||||
|
|
||||||
const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync();
|
const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync();
|
||||||
const artifactNetworkConfigs = _.isUndefined(networkIdIfExists) ?
|
const artifactNetworkConfigs = _.isUndefined(networkIdIfExists) ?
|
||||||
undefined :
|
undefined :
|
||||||
artifact.networks[networkIdIfExists];
|
artifact.networks[networkIdIfExists];
|
||||||
@@ -26,7 +26,7 @@ export class ContractWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_.isUndefined(contractAddress)) {
|
if (!_.isUndefined(contractAddress)) {
|
||||||
const doesContractExist = await this.web3Wrapper.doesContractExistAtAddressAsync(contractAddress);
|
const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress);
|
||||||
if (!doesContractExist) {
|
if (!doesContractExist) {
|
||||||
throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST);
|
throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
@@ -140,7 +140,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema);
|
assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema);
|
||||||
assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount);
|
assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount);
|
||||||
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
|
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
|
||||||
await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper);
|
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
|
||||||
|
|
||||||
const exchangeInstance = await this._getExchangeContractAsync();
|
const exchangeInstance = await this._getExchangeContractAsync();
|
||||||
await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress);
|
await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress);
|
||||||
@@ -196,7 +196,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount);
|
assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount);
|
||||||
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
|
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
|
||||||
assert.doesConformToSchema('signedOrders', signedOrders, signedOrdersSchema);
|
assert.doesConformToSchema('signedOrders', signedOrders, signedOrdersSchema);
|
||||||
await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper);
|
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
|
||||||
for (const signedOrder of signedOrders) {
|
for (const signedOrder of signedOrders) {
|
||||||
await this._validateFillOrderAndThrowIfInvalidAsync(
|
await this._validateFillOrderAndThrowIfInvalidAsync(
|
||||||
signedOrder, takerTokenFillAmount, takerAddress);
|
signedOrder, takerTokenFillAmount, takerAddress);
|
||||||
@@ -262,7 +262,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
public async batchFillOrderAsync(orderFillRequests: OrderFillRequest[],
|
public async batchFillOrderAsync(orderFillRequests: OrderFillRequest[],
|
||||||
shouldCheckTransfer: boolean, takerAddress: string): Promise<void> {
|
shouldCheckTransfer: boolean, takerAddress: string): Promise<void> {
|
||||||
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
|
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
|
||||||
await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper);
|
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
|
||||||
assert.doesConformToSchema('orderFillRequests', orderFillRequests, orderFillRequestsSchema);
|
assert.doesConformToSchema('orderFillRequests', orderFillRequests, orderFillRequestsSchema);
|
||||||
for (const orderFillRequest of orderFillRequests) {
|
for (const orderFillRequest of orderFillRequests) {
|
||||||
await this._validateFillOrderAndThrowIfInvalidAsync(
|
await this._validateFillOrderAndThrowIfInvalidAsync(
|
||||||
@@ -327,7 +327,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
takerAddress: string): Promise<void> {
|
takerAddress: string): Promise<void> {
|
||||||
assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema);
|
assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema);
|
||||||
assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount);
|
assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount);
|
||||||
await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper);
|
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
|
||||||
|
|
||||||
const exchangeInstance = await this._getExchangeContractAsync();
|
const exchangeInstance = await this._getExchangeContractAsync();
|
||||||
await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress);
|
await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress);
|
||||||
@@ -371,7 +371,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
*/
|
*/
|
||||||
public async batchFillOrKillAsync(orderFillOrKillRequests: OrderFillOrKillRequest[],
|
public async batchFillOrKillAsync(orderFillOrKillRequests: OrderFillOrKillRequest[],
|
||||||
takerAddress: string): Promise<void> {
|
takerAddress: string): Promise<void> {
|
||||||
await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper);
|
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
|
||||||
assert.doesConformToSchema('orderFillOrKillRequests', orderFillOrKillRequests, orderFillOrKillRequestsSchema);
|
assert.doesConformToSchema('orderFillOrKillRequests', orderFillOrKillRequests, orderFillOrKillRequestsSchema);
|
||||||
const exchangeInstance = await this._getExchangeContractAsync();
|
const exchangeInstance = await this._getExchangeContractAsync();
|
||||||
for (const request of orderFillOrKillRequests) {
|
for (const request of orderFillOrKillRequests) {
|
||||||
@@ -428,7 +428,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
order: Order|SignedOrder, takerTokenCancelAmount: BigNumber.BigNumber): Promise<void> {
|
order: Order|SignedOrder, takerTokenCancelAmount: BigNumber.BigNumber): Promise<void> {
|
||||||
assert.doesConformToSchema('order', order, orderSchema);
|
assert.doesConformToSchema('order', order, orderSchema);
|
||||||
assert.isBigNumber('takerTokenCancelAmount', takerTokenCancelAmount);
|
assert.isBigNumber('takerTokenCancelAmount', takerTokenCancelAmount);
|
||||||
await assert.isSenderAddressAsync('order.maker', order.maker, this.web3Wrapper);
|
await assert.isSenderAddressAsync('order.maker', order.maker, this._web3Wrapper);
|
||||||
|
|
||||||
const exchangeInstance = await this._getExchangeContractAsync();
|
const exchangeInstance = await this._getExchangeContractAsync();
|
||||||
await this._validateCancelOrderAndThrowIfInvalidAsync(order, takerTokenCancelAmount);
|
await this._validateCancelOrderAndThrowIfInvalidAsync(order, takerTokenCancelAmount);
|
||||||
@@ -463,7 +463,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker);
|
const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker);
|
||||||
assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED);
|
assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED);
|
||||||
const maker = makers[0];
|
const maker = makers[0];
|
||||||
await assert.isSenderAddressAsync('maker', maker, this.web3Wrapper);
|
await assert.isSenderAddressAsync('maker', maker, this._web3Wrapper);
|
||||||
assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests,
|
assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests,
|
||||||
orderCancellationRequestsSchema);
|
orderCancellationRequestsSchema);
|
||||||
for (const cancellationRequest of orderCancellationRequests) {
|
for (const cancellationRequest of orderCancellationRequests) {
|
||||||
@@ -692,7 +692,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
|||||||
private async _isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber,
|
private async _isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber,
|
||||||
fillTakerAmount: BigNumber.BigNumber,
|
fillTakerAmount: BigNumber.BigNumber,
|
||||||
makerTokenAmount: BigNumber.BigNumber): Promise<boolean> {
|
makerTokenAmount: BigNumber.BigNumber): Promise<boolean> {
|
||||||
await assert.isUserAddressAvailableAsync(this.web3Wrapper);
|
await assert.isUserAddressAvailableAsync(this._web3Wrapper);
|
||||||
const exchangeInstance = await this._getExchangeContractAsync();
|
const exchangeInstance = await this._getExchangeContractAsync();
|
||||||
const isRoundingError = await exchangeInstance.isRoundingError.call(
|
const isRoundingError = await exchangeInstance.isRoundingError.call(
|
||||||
takerTokenAmount, fillTakerAmount, makerTokenAmount,
|
takerTokenAmount, fillTakerAmount, makerTokenAmount,
|
||||||
|
@@ -27,7 +27,7 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
public async getBalanceAsync(tokenAddress: string, ownerAddress: string): Promise<BigNumber.BigNumber> {
|
public async getBalanceAsync(tokenAddress: string, ownerAddress: string): Promise<BigNumber.BigNumber> {
|
||||||
assert.isETHAddressHex('ownerAddress', ownerAddress);
|
assert.isETHAddressHex('ownerAddress', ownerAddress);
|
||||||
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
||||||
await assert.isUserAddressAvailableAsync(this.web3Wrapper);
|
await assert.isUserAddressAvailableAsync(this._web3Wrapper);
|
||||||
|
|
||||||
const tokenContract = await this._getTokenContractAsync(tokenAddress);
|
const tokenContract = await this._getTokenContractAsync(tokenAddress);
|
||||||
let balance = await tokenContract.balanceOf.call(ownerAddress);
|
let balance = await tokenContract.balanceOf.call(ownerAddress);
|
||||||
@@ -46,7 +46,7 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
*/
|
*/
|
||||||
public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string,
|
public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string,
|
||||||
amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
|
amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
|
||||||
await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this.web3Wrapper);
|
await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper);
|
||||||
assert.isETHAddressHex('spenderAddress', spenderAddress);
|
assert.isETHAddressHex('spenderAddress', spenderAddress);
|
||||||
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
||||||
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
|
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
|
||||||
@@ -55,7 +55,7 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
// Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception
|
// Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception
|
||||||
// on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294
|
// on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294
|
||||||
// TODO: Debug issue in testrpc and submit a PR, then remove this hack
|
// TODO: Debug issue in testrpc and submit a PR, then remove this hack
|
||||||
const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync();
|
const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync();
|
||||||
const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined;
|
const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined;
|
||||||
await tokenContract.approve(spenderAddress, amountInBaseUnits, {
|
await tokenContract.approve(spenderAddress, amountInBaseUnits, {
|
||||||
from: ownerAddress,
|
from: ownerAddress,
|
||||||
@@ -72,7 +72,7 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) {
|
public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) {
|
||||||
assert.isETHAddressHex('ownerAddress', ownerAddress);
|
assert.isETHAddressHex('ownerAddress', ownerAddress);
|
||||||
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
||||||
await assert.isUserAddressAvailableAsync(this.web3Wrapper);
|
await assert.isUserAddressAvailableAsync(this._web3Wrapper);
|
||||||
|
|
||||||
const tokenContract = await this._getTokenContractAsync(tokenAddress);
|
const tokenContract = await this._getTokenContractAsync(tokenAddress);
|
||||||
let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress);
|
let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress);
|
||||||
@@ -120,7 +120,7 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string,
|
public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string,
|
||||||
amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
|
amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
|
||||||
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
||||||
await assert.isSenderAddressAsync('fromAddress', fromAddress, this.web3Wrapper);
|
await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper);
|
||||||
assert.isETHAddressHex('toAddress', toAddress);
|
assert.isETHAddressHex('toAddress', toAddress);
|
||||||
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
|
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
||||||
assert.isETHAddressHex('fromAddress', fromAddress);
|
assert.isETHAddressHex('fromAddress', fromAddress);
|
||||||
assert.isETHAddressHex('toAddress', toAddress);
|
assert.isETHAddressHex('toAddress', toAddress);
|
||||||
await assert.isSenderAddressAsync('senderAddress', senderAddress, this.web3Wrapper);
|
await assert.isSenderAddressAsync('senderAddress', senderAddress, this._web3Wrapper);
|
||||||
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
|
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
|
||||||
|
|
||||||
const tokenContract = await this._getTokenContractAsync(tokenAddress);
|
const tokenContract = await this._getTokenContractAsync(tokenAddress);
|
||||||
@@ -182,7 +182,7 @@ export class TokenWrapper extends ContractWrapper {
|
|||||||
return tokenContract;
|
return tokenContract;
|
||||||
}
|
}
|
||||||
private async _getProxyAddressAsync() {
|
private async _getProxyAddressAsync() {
|
||||||
const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync();
|
const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync();
|
||||||
const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ?
|
const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ?
|
||||||
undefined :
|
undefined :
|
||||||
(ProxyArtifacts as any).networks[networkIdIfExists];
|
(ProxyArtifacts as any).networks[networkIdIfExists];
|
||||||
|
@@ -13,13 +13,13 @@ describe('Assertion library', () => {
|
|||||||
it('throws when address is invalid', async () => {
|
it('throws when address is invalid', async () => {
|
||||||
const address = '0xdeadbeef';
|
const address = '0xdeadbeef';
|
||||||
const varName = 'address';
|
const varName = 'address';
|
||||||
return expect(assert.isSenderAddressAsync(varName, address, (zeroEx as any).web3Wrapper))
|
return expect(assert.isSenderAddressAsync(varName, address, (zeroEx as any)._web3Wrapper))
|
||||||
.to.be.rejectedWith(`Expected ${varName} to be of type ETHAddressHex, encountered: ${address}`);
|
.to.be.rejectedWith(`Expected ${varName} to be of type ETHAddressHex, encountered: ${address}`);
|
||||||
});
|
});
|
||||||
it('throws when address is unavailable', async () => {
|
it('throws when address is unavailable', async () => {
|
||||||
const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42';
|
const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42';
|
||||||
const varName = 'address';
|
const varName = 'address';
|
||||||
return expect(assert.isSenderAddressAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper))
|
return expect(assert.isSenderAddressAsync(varName, validUnrelatedAddress, (zeroEx as any)._web3Wrapper))
|
||||||
.to.be.rejectedWith(
|
.to.be.rejectedWith(
|
||||||
`Specified ${varName} ${validUnrelatedAddress} isn't available through the supplied web3 instance`,
|
`Specified ${varName} ${validUnrelatedAddress} isn't available through the supplied web3 instance`,
|
||||||
);
|
);
|
||||||
@@ -27,7 +27,7 @@ describe('Assertion library', () => {
|
|||||||
it('doesn\'t throw if address is available', async () => {
|
it('doesn\'t throw if address is available', async () => {
|
||||||
const availableAddress = (await zeroEx.getAvailableAddressesAsync())[0];
|
const availableAddress = (await zeroEx.getAvailableAddressesAsync())[0];
|
||||||
const varName = 'address';
|
const varName = 'address';
|
||||||
return expect(assert.isSenderAddressAsync(varName, availableAddress, (zeroEx as any).web3Wrapper))
|
return expect(assert.isSenderAddressAsync(varName, availableAddress, (zeroEx as any)._web3Wrapper))
|
||||||
.to.become(undefined);
|
.to.become(undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user