aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-07-03 23:22:17 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-07-05 21:58:41 +0800
commitab8544b0ff61c993d0366a906bd7b1aeed11b70a (patch)
tree9a7cd3813f1abaed5c95e19fe36c0d4ced13e501
parentb68d16820fbc2cab529a95a0dfabc645a9e2de34 (diff)
downloaddexon-sol-tools-ab8544b0ff61c993d0366a906bd7b1aeed11b70a.tar
dexon-sol-tools-ab8544b0ff61c993d0366a906bd7b1aeed11b70a.tar.gz
dexon-sol-tools-ab8544b0ff61c993d0366a906bd7b1aeed11b70a.tar.bz2
dexon-sol-tools-ab8544b0ff61c993d0366a906bd7b1aeed11b70a.tar.lz
dexon-sol-tools-ab8544b0ff61c993d0366a906bd7b1aeed11b70a.tar.xz
dexon-sol-tools-ab8544b0ff61c993d0366a906bd7b1aeed11b70a.tar.zst
dexon-sol-tools-ab8544b0ff61c993d0366a906bd7b1aeed11b70a.zip
Rearrange assertions t match parameter order
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts56
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts77
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts114
-rw-r--r--packages/contract-wrappers/test/exchange_wrapper_test.ts16
4 files changed, 118 insertions, 145 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
index e70d3381c..29c63564e 100644
--- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
@@ -54,20 +54,18 @@ export class ERC20TokenWrapper extends ContractWrapper {
public async getBalanceAsync(
tokenAddress: string,
ownerAddress: string,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<BigNumber> {
assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedOwnerAddress = ownerAddress.toLowerCase();
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- let balance = await tokenContract.balanceOf.callAsync(normalizedOwnerAddress, txData, defaultBlock);
+ let balance = await tokenContract.balanceOf.callAsync(normalizedOwnerAddress, txData, methodOpts.defaultBlock);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
balance = new BigNumber(balance);
return balance;
@@ -90,16 +88,14 @@ export class ERC20TokenWrapper extends ContractWrapper {
amountInBaseUnits: BigNumber,
txOpts: TransactionOpts = {},
): Promise<string> {
- assert.isETHAddressHex('spenderAddress', spenderAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper);
- if (!_.isUndefined(txOpts)) {
- assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
- }
+ assert.isETHAddressHex('spenderAddress', spenderAddress);
+ assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
+ assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
- const normalizedSpenderAddress = spenderAddress.toLowerCase();
const normalizedOwnerAddress = ownerAddress.toLowerCase();
- assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
+ const normalizedSpenderAddress = spenderAddress.toLowerCase();
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
const txHash = await tokenContract.approve.sendTransactionAsync(
@@ -152,26 +148,24 @@ export class ERC20TokenWrapper extends ContractWrapper {
tokenAddress: string,
ownerAddress: string,
spenderAddress: string,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<BigNumber> {
- assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
+ assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('spenderAddress', spenderAddress);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedOwnerAddress = ownerAddress.toLowerCase();
const normalizedSpenderAddress = spenderAddress.toLowerCase();
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
let allowanceInBaseUnits = await tokenContract.allowance.callAsync(
normalizedOwnerAddress,
normalizedSpenderAddress,
txData,
- defaultBlock,
+ methodOpts.defaultBlock,
);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits);
@@ -186,7 +180,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
public async getProxyAllowanceAsync(
tokenAddress: string,
ownerAddress: string,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<BigNumber> {
const proxyAddress = this._erc20ProxyWrapper.getContractAddress();
const allowanceInBaseUnits = await this.getAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, methodOpts);
@@ -259,15 +253,13 @@ export class ERC20TokenWrapper extends ContractWrapper {
txOpts: TransactionOpts = {},
): Promise<string> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
- assert.isETHAddressHex('toAddress', toAddress);
await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper);
- if (!_.isUndefined(txOpts)) {
- assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
- }
+ assert.isETHAddressHex('toAddress', toAddress);
+ assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
+ assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedFromAddress = fromAddress.toLowerCase();
const normalizedToAddress = toAddress.toLowerCase();
- assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
@@ -309,18 +301,16 @@ export class ERC20TokenWrapper extends ContractWrapper {
amountInBaseUnits: BigNumber,
txOpts: TransactionOpts = {},
): Promise<string> {
- assert.isETHAddressHex('toAddress', toAddress);
- assert.isETHAddressHex('fromAddress', fromAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
+ assert.isETHAddressHex('fromAddress', fromAddress);
+ assert.isETHAddressHex('toAddress', toAddress);
await assert.isSenderAddressAsync('senderAddress', senderAddress, this._web3Wrapper);
- if (!_.isUndefined(txOpts)) {
- assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
- }
+ assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
+ assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
const normalizedToAddress = toAddress.toLowerCase();
const normalizedFromAddress = fromAddress.toLowerCase();
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedSenderAddress = senderAddress.toLowerCase();
- assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
@@ -366,10 +356,10 @@ export class ERC20TokenWrapper extends ContractWrapper {
callback: EventCallback<ArgsType>,
): string {
assert.isETHAddressHex('tokenAddress', tokenAddress);
- const normalizedTokenAddress = tokenAddress.toLowerCase();
assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
+ const normalizedTokenAddress = tokenAddress.toLowerCase();
const subscriptionToken = this._subscribe<ArgsType>(
normalizedTokenAddress,
eventName,
@@ -409,10 +399,10 @@ export class ERC20TokenWrapper extends ContractWrapper {
indexFilterValues: IndexedFilterValues,
): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
- const normalizedTokenAddress = tokenAddress.toLowerCase();
assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
+ const normalizedTokenAddress = tokenAddress.toLowerCase();
const logs = await this._getLogsAsync<ArgsType>(
normalizedTokenAddress,
eventName,
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
index aad1a4621..b7e5519c4 100644
--- a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
@@ -54,20 +54,18 @@ export class ERC721TokenWrapper extends ContractWrapper {
public async getTokenCountAsync(
tokenAddress: string,
ownerAddress: string,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<BigNumber> {
- assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.isETHAddressHex('ownerAddress', ownerAddress);
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedOwnerAddress = ownerAddress.toLowerCase();
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- let balance = await tokenContract.balanceOf.callAsync(normalizedOwnerAddress, txData, defaultBlock);
+ let balance = await tokenContract.balanceOf.callAsync(normalizedOwnerAddress, txData, methodOpts.defaultBlock);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
balance = new BigNumber(balance);
return balance;
@@ -80,19 +78,21 @@ export class ERC721TokenWrapper extends ContractWrapper {
* @param methodOpts Optional arguments this method accepts.
* @return The address of the owner of the NFT
*/
- public async getOwnerOfAsync(tokenAddress: string, tokenId: BigNumber, methodOpts?: MethodOpts): Promise<string> {
+ public async getOwnerOfAsync(
+ tokenAddress: string,
+ tokenId: BigNumber,
+ methodOpts: MethodOpts = {},
+ ): Promise<string> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isBigNumber('tokenId', tokenId);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
try {
- const tokenOwner = await tokenContract.ownerOf.callAsync(tokenId, txData, defaultBlock);
+ const tokenOwner = await tokenContract.ownerOf.callAsync(tokenId, txData, methodOpts.defaultBlock);
return tokenOwner;
} catch (err) {
throw new Error(ContractWrappersError.ERC721OwnerNotFound);
@@ -110,26 +110,24 @@ export class ERC721TokenWrapper extends ContractWrapper {
tokenAddress: string,
ownerAddress: string,
operatorAddress: string,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<boolean> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('operatorAddress', operatorAddress);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedOwnerAddress = ownerAddress.toLowerCase();
const normalizedOperatorAddress = operatorAddress.toLowerCase();
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
const isApprovedForAll = await tokenContract.isApprovedForAll.callAsync(
normalizedOwnerAddress,
normalizedOperatorAddress,
txData,
- defaultBlock,
+ methodOpts.defaultBlock,
);
return isApprovedForAll;
}
@@ -143,19 +141,12 @@ export class ERC721TokenWrapper extends ContractWrapper {
public async isProxyApprovedForAllAsync(
tokenAddress: string,
ownerAddress: string,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<boolean> {
- assert.isETHAddressHex('tokenAddress', tokenAddress);
- assert.isETHAddressHex('ownerAddress', ownerAddress);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
- const normalizedTokenAddress = tokenAddress.toLowerCase();
- const normalizedOwnerAddress = ownerAddress.toLowerCase();
const proxyAddress = this._erc721ProxyWrapper.getContractAddress();
const isProxyApprovedForAll = await this.isApprovedForAllAsync(
- normalizedTokenAddress,
- normalizedOwnerAddress,
+ tokenAddress,
+ ownerAddress,
proxyAddress,
methodOpts,
);
@@ -172,19 +163,17 @@ export class ERC721TokenWrapper extends ContractWrapper {
public async getApprovedIfExistsAsync(
tokenAddress: string,
tokenId: BigNumber,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<string | undefined> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isBigNumber('tokenId', tokenId);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- const approvedAddress = await tokenContract.getApproved.callAsync(tokenId, txData, defaultBlock);
+ const approvedAddress = await tokenContract.getApproved.callAsync(tokenId, txData, methodOpts.defaultBlock);
if (approvedAddress === constants.NULL_ADDRESS) {
return undefined;
}
@@ -201,7 +190,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
public async isProxyApprovedAsync(
tokenAddress: string,
tokenId: BigNumber,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<boolean> {
const proxyAddress = this._erc721ProxyWrapper.getContractAddress();
const approvedAddress = await this.getApprovedIfExistsAsync(tokenAddress, tokenId, methodOpts);
@@ -230,9 +219,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper);
assert.isETHAddressHex('operatorAddress', operatorAddress);
assert.isBoolean('isApproved', isApproved);
- if (!_.isUndefined(txOpts)) {
- assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
- }
+ assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedOwnerAddress = ownerAddress.toLowerCase();
const normalizedOperatorAddress = operatorAddress.toLowerCase();
@@ -291,9 +278,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isETHAddressHex('approvedAddress', approvedAddress);
assert.isBigNumber('tokenId', tokenId);
- if (!_.isUndefined(txOpts)) {
- assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
- }
+ assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedApprovedAddress = approvedAddress.toLowerCase();
@@ -351,9 +336,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isETHAddressHex('receiverAddress', receiverAddress);
await assert.isSenderAddressAsync('senderAddress', senderAddress, this._web3Wrapper);
- if (!_.isUndefined(txOpts)) {
- assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
- }
+ assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase();
const normalizedReceiverAddress = receiverAddress.toLowerCase();
const normalizedSenderAddress = senderAddress.toLowerCase();
@@ -398,10 +381,10 @@ export class ERC721TokenWrapper extends ContractWrapper {
callback: EventCallback<ArgsType>,
): string {
assert.isETHAddressHex('tokenAddress', tokenAddress);
- const normalizedTokenAddress = tokenAddress.toLowerCase();
assert.doesBelongToStringEnum('eventName', eventName, ERC721TokenEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
+ const normalizedTokenAddress = tokenAddress.toLowerCase();
const subscriptionToken = this._subscribe<ArgsType>(
normalizedTokenAddress,
eventName,
@@ -441,10 +424,10 @@ export class ERC721TokenWrapper extends ContractWrapper {
indexFilterValues: IndexedFilterValues,
): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
- const normalizedTokenAddress = tokenAddress.toLowerCase();
assert.doesBelongToStringEnum('eventName', eventName, ERC721TokenEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
+ const normalizedTokenAddress = tokenAddress.toLowerCase();
const logs = await this._getLogsAsync<ArgsType>(
normalizedTokenAddress,
eventName,
diff --git a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
index 0377c4021..9d38e0c98 100644
--- a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
@@ -17,8 +17,8 @@ import { ContractWrapper } from './contract_wrapper';
import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated/exchange';
/**
- * This class includes all the functionality related to calling methods and subscribing to
- * events of the 0x Exchange smart contract.
+ * This class includes all the functionality related to calling methods, sending transactions and subscribing to
+ * events of the 0x V2 Exchange smart contract.
*/
export class ExchangeWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.Exchange.compilerOutput.abi;
@@ -42,15 +42,17 @@ export class ExchangeWrapper extends ContractWrapper {
* @param methodOpts Optional arguments this method accepts.
* @return The address of an asset proxy for a given signature
*/
- public async getAssetProxieBySignatureAsync(proxySignature: string, methodOpts?: MethodOpts): Promise<string> {
+ public async getAssetProxieBySignatureAsync(proxySignature: string, methodOpts: MethodOpts = {}): Promise<string> {
assert.isHexString('proxySignature', proxySignature);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const exchangeContract = await this._getExchangeContractAsync();
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- const assetProxy = await exchangeContract.getAssetProxy.callAsync(proxySignature, txData, defaultBlock);
+ const assetProxy = await exchangeContract.getAssetProxy.callAsync(
+ proxySignature,
+ txData,
+ methodOpts.defaultBlock,
+ );
return assetProxy;
}
/**
@@ -59,17 +61,17 @@ export class ExchangeWrapper extends ContractWrapper {
* @param methodOpts Optional arguments this method accepts.
* @return The amount of the order (in taker tokens) that has already been filled.
*/
- public async getFilledTakerAmountAsync(orderHash: string, methodOpts?: MethodOpts): Promise<BigNumber> {
+ public async getFilledTakerAmountAsync(orderHash: string, methodOpts: MethodOpts = {}): Promise<BigNumber> {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const exchangeContract = await this._getExchangeContractAsync();
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- let fillAmountInBaseUnits = await exchangeContract.filled.callAsync(orderHash, txData, defaultBlock);
- // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
- fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits);
+ const fillAmountInBaseUnits = await exchangeContract.filled.callAsync(
+ orderHash,
+ txData,
+ methodOpts.defaultBlock,
+ );
return fillAmountInBaseUnits;
}
/**
@@ -77,14 +79,15 @@ export class ExchangeWrapper extends ContractWrapper {
* @param methodOpts Optional arguments this method accepts.
* @return Current context address
*/
- public async getCurrentContextAddressAsync(methodOpts?: MethodOpts): Promise<string> {
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ public async getCurrentContextAddressAsync(methodOpts: MethodOpts = {}): Promise<string> {
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const exchangeContract = await this._getExchangeContractAsync();
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- const currentContextAddress = await exchangeContract.currentContextAddress.callAsync(txData, defaultBlock);
+ const currentContextAddress = await exchangeContract.currentContextAddress.callAsync(
+ txData,
+ methodOpts.defaultBlock,
+ );
return currentContextAddress;
}
/**
@@ -92,14 +95,12 @@ export class ExchangeWrapper extends ContractWrapper {
* @param methodOpts Optional arguments this method accepts.
* @return Version
*/
- public async getVersionAsync(methodOpts?: MethodOpts): Promise<string> {
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ public async getVersionAsync(methodOpts: MethodOpts = {}): Promise<string> {
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const exchangeContract = await this._getExchangeContractAsync();
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- const version = await exchangeContract.VERSION.callAsync(txData, defaultBlock);
+ const version = await exchangeContract.VERSION.callAsync(txData, methodOpts.defaultBlock);
return version;
}
/**
@@ -107,26 +108,24 @@ export class ExchangeWrapper extends ContractWrapper {
* @param makerAddress Maker address
* @param senderAddress Sender address
* @param methodOpts Optional arguments this method accepts.
- * @return Version
+ * @return Order epoch
*/
public async getOrderEpochAsync(
makerAddress: string,
senderAddress: string,
- methodOpts?: MethodOpts,
+ methodOpts: MethodOpts = {},
): Promise<BigNumber> {
assert.isETHAddressHex('makerAddress', makerAddress);
assert.isETHAddressHex('senderAddress', senderAddress);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const exchangeContract = await this._getExchangeContractAsync();
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
const orderEpoch = await exchangeContract.orderEpoch.callAsync(
makerAddress,
senderAddress,
txData,
- defaultBlock,
+ methodOpts.defaultBlock,
);
return orderEpoch;
}
@@ -137,24 +136,20 @@ export class ExchangeWrapper extends ContractWrapper {
* @param methodOpts Optional arguments this method accepts.
* @return If the order has been cancelled.
*/
- public async isCancelledAsync(orderHash: string, methodOpts?: MethodOpts): Promise<boolean> {
+ public async isCancelledAsync(orderHash: string, methodOpts: MethodOpts = {}): Promise<boolean> {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
- if (!_.isUndefined(methodOpts)) {
- assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
- }
+ assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
const exchangeContract = await this._getExchangeContractAsync();
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- const isCancelled = await exchangeContract.cancelled.callAsync(orderHash, txData, defaultBlock);
+ const isCancelled = await exchangeContract.cancelled.callAsync(orderHash, txData, methodOpts.defaultBlock);
return isCancelled;
}
/**
* Fills a signed order with an amount denominated in baseUnits of the taker asset.
* @param signedOrder An object that conforms to the SignedOrder interface.
- * @param fillTakerTokenAmount The amount of the order (in taker tokens baseUnits) that
+ * @param takerAssetFillAmount The amount of the order (in taker asset baseUnits) that
* you wish to fill.
- * @param shouldThrowOnInsufficientBalanceOrAllowance Whether or not you wish for the contract call to throw
- * if upon execution the tokens cannot be transferred.
* @param takerAddress The user Ethereum address who would like to fill this order.
* Must be available via the supplied Provider
* passed to 0x.js.
@@ -164,12 +159,12 @@ export class ExchangeWrapper extends ContractWrapper {
@decorators.asyncZeroExErrorHandler
public async fillOrderAsync(
signedOrder: SignedOrder,
- fillTakerTokenAmount: BigNumber,
+ takerAssetFillAmount: BigNumber,
takerAddress: string,
orderTransactionOpts: OrderTransactionOpts = {},
): Promise<string> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
- assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
+ assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
const normalizedTakerAddress = takerAddress.toLowerCase();
@@ -178,7 +173,7 @@ export class ExchangeWrapper extends ContractWrapper {
const txHash = await exchangeInstance.fillOrder.sendTransactionAsync(
signedOrder,
- fillTakerTokenAmount,
+ takerAssetFillAmount,
signedOrder.signature,
{
from: normalizedTakerAddress,
@@ -191,10 +186,8 @@ export class ExchangeWrapper extends ContractWrapper {
/**
* No-throw version of fillOrderAsync
* @param signedOrder An object that conforms to the SignedOrder interface.
- * @param fillTakerTokenAmount The amount of the order (in taker tokens baseUnits) that
+ * @param takerAssetFillAmount The amount of the order (in taker asset baseUnits) that
* you wish to fill.
- * @param shouldThrowOnInsufficientBalanceOrAllowance Whether or not you wish for the contract call to throw
- * if upon execution the tokens cannot be transferred.
* @param takerAddress The user Ethereum address who would like to fill this order.
* Must be available via the supplied Provider
* passed to 0x.js.
@@ -204,12 +197,12 @@ export class ExchangeWrapper extends ContractWrapper {
@decorators.asyncZeroExErrorHandler
public async fillOrderNoThrowAsync(
signedOrder: SignedOrder,
- fillTakerTokenAmount: BigNumber,
+ takerAssetFillAmount: BigNumber,
takerAddress: string,
orderTransactionOpts: OrderTransactionOpts = {},
): Promise<string> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
- assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
+ assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
const normalizedTakerAddress = takerAddress.toLowerCase();
@@ -218,7 +211,7 @@ export class ExchangeWrapper extends ContractWrapper {
const txHash = await exchangeInstance.fillOrderNoThrow.sendTransactionAsync(
signedOrder,
- fillTakerTokenAmount,
+ takerAssetFillAmount,
signedOrder.signature,
{
from: normalizedTakerAddress,
@@ -750,9 +743,14 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
}
const exchangeInstance = await this._getExchangeContractAsync();
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- const isPreSigned = await exchangeInstance.preSigned.callAsync(hash, signerAddress, txData, defaultBlock);
+ const isPreSigned = await exchangeInstance.preSigned.callAsync(
+ hash,
+ signerAddress,
+ txData,
+ methodOpts.defaultBlock,
+ );
return isPreSigned;
}
/**
@@ -784,14 +782,14 @@ export class ExchangeWrapper extends ContractWrapper {
* @returns Order info
*/
@decorators.asyncZeroExErrorHandler
- public async getOrderInfoAsync(order: Order, methodOpts?: MethodOpts): Promise<OrderInfo> {
+ public async getOrderInfoAsync(order: Order, methodOpts: MethodOpts = {}): Promise<OrderInfo> {
if (!_.isUndefined(methodOpts)) {
assert.doesConformToSchema('methodOpts', methodOpts, methodOptsSchema);
}
const exchangeInstance = await this._getExchangeContractAsync();
- const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+
const txData = {};
- const orderInfo = await exchangeInstance.getOrderInfo.callAsync(order, txData, defaultBlock);
+ const orderInfo = await exchangeInstance.getOrderInfo.callAsync(order, txData, methodOpts.defaultBlock);
return orderInfo;
}
/**
diff --git a/packages/contract-wrappers/test/exchange_wrapper_test.ts b/packages/contract-wrappers/test/exchange_wrapper_test.ts
index 615b4ab67..15927641b 100644
--- a/packages/contract-wrappers/test/exchange_wrapper_test.ts
+++ b/packages/contract-wrappers/test/exchange_wrapper_test.ts
@@ -80,7 +80,7 @@ describe('ExchangeWrapper', () => {
anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerAssetData,
takerAssetData,
- anotherMakerAddress,
+ makerAddress,
takerAddress,
fillableAmount,
);
@@ -244,7 +244,7 @@ describe('ExchangeWrapper', () => {
await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
});
});
- describe.skip('#batchCancelOrdersAsync', () => {
+ describe('#batchCancelOrdersAsync', () => {
it('should cancel a batch of valid orders', async () => {
const orders = [signedOrder, anotherSignedOrder];
txHash = await contractWrappers.exchange.batchCancelOrdersAsync(orders);
@@ -252,13 +252,15 @@ describe('ExchangeWrapper', () => {
});
});
describe('#cancelOrdersUpTo/getOrderEpochAsync', () => {
- it.skip('should cancel orders up to target order epoch', async () => {
+ it('should cancel orders up to target order epoch', async () => {
const targetOrderEpoch = new BigNumber(42);
- txHash = await contractWrappers.exchange.cancelOrdersUpToAsync(targetOrderEpoch, takerAddress);
+ txHash = await contractWrappers.exchange.cancelOrdersUpToAsync(targetOrderEpoch, makerAddress);
await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
- const senderAddress = constants.NULL_ADDRESS;
- const orderEpoch = await contractWrappers.exchange.getOrderEpochAsync(makerAddress, senderAddress);
- expect(orderEpoch).to.be.bignumber.equal(targetOrderEpoch);
+ const orderEpoch = await contractWrappers.exchange.getOrderEpochAsync(
+ makerAddress,
+ constants.NULL_ADDRESS,
+ );
+ expect(orderEpoch).to.be.bignumber.equal(targetOrderEpoch.plus(1));
});
});
});