aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/src/utils/erc20_wrapper.ts48
-rw-r--r--packages/contracts/src/utils/erc721_wrapper.ts56
-rw-r--r--packages/contracts/src/utils/order_factory.ts3
3 files changed, 52 insertions, 55 deletions
diff --git a/packages/contracts/src/utils/erc20_wrapper.ts b/packages/contracts/src/utils/erc20_wrapper.ts
index 0f45fb1e6..dceeceeea 100644
--- a/packages/contracts/src/utils/erc20_wrapper.ts
+++ b/packages/contracts/src/utils/erc20_wrapper.ts
@@ -16,18 +16,19 @@ export class ERC20Wrapper {
private _contractOwnerAddress: string;
private _web3Wrapper: Web3Wrapper;
private _provider: Provider;
- private _dummyTokenContracts?: DummyERC20TokenContract[];
+ private _dummyTokenContracts: DummyERC20TokenContract[];
private _proxyContract?: ERC20ProxyContract;
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
+ this._dummyTokenContracts = [];
this._web3Wrapper = new Web3Wrapper(provider);
this._provider = provider;
this._tokenOwnerAddresses = tokenOwnerAddresses;
this._contractOwnerAddress = contractOwnerAddress;
}
public async deployDummyTokensAsync(): Promise<DummyERC20TokenContract[]> {
- this._dummyTokenContracts = await Promise.all(
- _.times(constants.NUM_DUMMY_ERC20_TO_DEPLOY, async () =>
- DummyERC20TokenContract.deployFrom0xArtifactAsync(
+ for (let i = 0; i < constants.NUM_DUMMY_ERC20_TO_DEPLOY; i++) {
+ this._dummyTokenContracts.push(
+ await DummyERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC20Token,
this._provider,
txDefaults,
@@ -36,8 +37,8 @@ export class ERC20Wrapper {
constants.DUMMY_TOKEN_DECIMALS,
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
),
- ),
- );
+ );
+ }
return this._dummyTokenContracts;
}
public async deployProxyAsync(): Promise<ERC20ProxyContract> {
@@ -51,44 +52,41 @@ export class ERC20Wrapper {
public async setBalancesAndAllowancesAsync(): Promise<void> {
this._validateDummyTokenContractsExistOrThrow();
this._validateProxyContractExistsOrThrow();
- const setBalancePromises: Array<Promise<string>> = [];
- const setAllowancePromises: Array<Promise<string>> = [];
- _.forEach(this._dummyTokenContracts, dummyTokenContract => {
- _.forEach(this._tokenOwnerAddresses, tokenOwnerAddress => {
- setBalancePromises.push(
- dummyTokenContract.setBalance.sendTransactionAsync(
+ for (const dummyTokenContract of this._dummyTokenContracts) {
+ for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
+ await this._web3Wrapper.awaitTransactionSuccessAsync(
+ await dummyTokenContract.setBalance.sendTransactionAsync(
tokenOwnerAddress,
constants.INITIAL_ERC20_BALANCE,
{ from: this._contractOwnerAddress },
),
+ constants.AWAIT_TRANSACTION_MINED_MS,
);
- setAllowancePromises.push(
- dummyTokenContract.approve.sendTransactionAsync(
+ await this._web3Wrapper.awaitTransactionSuccessAsync(
+ await dummyTokenContract.approve.sendTransactionAsync(
(this._proxyContract as ERC20ProxyContract).address,
constants.INITIAL_ERC20_ALLOWANCE,
{ from: tokenOwnerAddress },
),
+ constants.AWAIT_TRANSACTION_MINED_MS,
);
- });
- });
- const txHashes = await Promise.all([...setBalancePromises, ...setAllowancePromises]);
- await Promise.all(_.map(txHashes, async txHash => this._web3Wrapper.awaitTransactionSuccessAsync(txHash)));
+ }
+ }
}
public async getBalancesAsync(): Promise<ERC20BalancesByOwner> {
this._validateDummyTokenContractsExistOrThrow();
const balancesByOwner: ERC20BalancesByOwner = {};
- const balancePromises: Array<Promise<BigNumber>> = [];
+ const balances: BigNumber[] = [];
const balanceInfo: Array<{ tokenOwnerAddress: string; tokenAddress: string }> = [];
- _.forEach(this._dummyTokenContracts, dummyTokenContract => {
- _.forEach(this._tokenOwnerAddresses, tokenOwnerAddress => {
- balancePromises.push(dummyTokenContract.balanceOf.callAsync(tokenOwnerAddress));
+ for (const dummyTokenContract of this._dummyTokenContracts) {
+ for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
+ balances.push(await dummyTokenContract.balanceOf.callAsync(tokenOwnerAddress));
balanceInfo.push({
tokenOwnerAddress,
tokenAddress: dummyTokenContract.address,
});
- });
- });
- const balances = await Promise.all(balancePromises);
+ }
+ }
_.forEach(balances, (balance, balanceIndex) => {
const tokenAddress = balanceInfo[balanceIndex].tokenAddress;
const tokenOwnerAddress = balanceInfo[balanceIndex].tokenOwnerAddress;
diff --git a/packages/contracts/src/utils/erc721_wrapper.ts b/packages/contracts/src/utils/erc721_wrapper.ts
index 11a012602..13fdf630e 100644
--- a/packages/contracts/src/utils/erc721_wrapper.ts
+++ b/packages/contracts/src/utils/erc721_wrapper.ts
@@ -17,27 +17,28 @@ export class ERC721Wrapper {
private _contractOwnerAddress: string;
private _web3Wrapper: Web3Wrapper;
private _provider: Provider;
- private _dummyTokenContracts?: DummyERC721TokenContract[];
+ private _dummyTokenContracts: DummyERC721TokenContract[];
private _proxyContract?: ERC721ProxyContract;
private _initialTokenIdsByOwner: ERC721TokenIdsByOwner = {};
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
this._web3Wrapper = new Web3Wrapper(provider);
this._provider = provider;
+ this._dummyTokenContracts = [];
this._tokenOwnerAddresses = tokenOwnerAddresses;
this._contractOwnerAddress = contractOwnerAddress;
}
public async deployDummyTokensAsync(): Promise<DummyERC721TokenContract[]> {
- this._dummyTokenContracts = await Promise.all(
- _.times(constants.NUM_DUMMY_ERC721_TO_DEPLOY, async () =>
- DummyERC721TokenContract.deployFrom0xArtifactAsync(
+ for (let i = 0; i < constants.NUM_DUMMY_ERC721_TO_DEPLOY; i++) {
+ this._dummyTokenContracts.push(
+ await DummyERC721TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC721Token,
this._provider,
txDefaults,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
),
- ),
- );
+ );
+ }
return this._dummyTokenContracts;
}
public async deployProxyAsync(): Promise<ERC721ProxyContract> {
@@ -51,17 +52,16 @@ export class ERC721Wrapper {
public async setBalancesAndAllowancesAsync(): Promise<void> {
this._validateDummyTokenContractsExistOrThrow();
this._validateProxyContractExistsOrThrow();
- const setBalancePromises: Array<Promise<string>> = [];
- const setAllowancePromises: Array<Promise<string>> = [];
this._initialTokenIdsByOwner = {};
- _.forEach(this._dummyTokenContracts, dummyTokenContract => {
- _.forEach(this._tokenOwnerAddresses, tokenOwnerAddress => {
- _.forEach(_.range(constants.NUM_ERC721_TOKENS_TO_MINT), () => {
+ for (const dummyTokenContract of this._dummyTokenContracts) {
+ for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
+ for (let i = 0; i < constants.NUM_ERC721_TOKENS_TO_MINT; i++) {
const tokenId = generatePseudoRandomSalt();
- setBalancePromises.push(
- dummyTokenContract.mint.sendTransactionAsync(tokenOwnerAddress, tokenId, {
+ await this._web3Wrapper.awaitTransactionSuccessAsync(
+ await dummyTokenContract.mint.sendTransactionAsync(tokenOwnerAddress, tokenId, {
from: this._contractOwnerAddress,
}),
+ constants.AWAIT_TRANSACTION_MINED_MS,
);
if (_.isUndefined(this._initialTokenIdsByOwner[tokenOwnerAddress])) {
this._initialTokenIdsByOwner[tokenOwnerAddress] = {
@@ -72,41 +72,39 @@ export class ERC721Wrapper {
this._initialTokenIdsByOwner[tokenOwnerAddress][dummyTokenContract.address] = [];
}
this._initialTokenIdsByOwner[tokenOwnerAddress][dummyTokenContract.address].push(tokenId);
- });
+ }
const shouldApprove = true;
- setAllowancePromises.push(
- dummyTokenContract.setApprovalForAll.sendTransactionAsync(
+ await this._web3Wrapper.awaitTransactionSuccessAsync(
+ await dummyTokenContract.setApprovalForAll.sendTransactionAsync(
(this._proxyContract as ERC721ProxyContract).address,
shouldApprove,
{ from: tokenOwnerAddress },
),
+ constants.AWAIT_TRANSACTION_MINED_MS,
);
- });
- });
- const txHashes = await Promise.all([...setBalancePromises, ...setAllowancePromises]);
- await Promise.all(_.map(txHashes, async txHash => this._web3Wrapper.awaitTransactionSuccessAsync(txHash)));
+ }
+ }
}
public async getBalancesAsync(): Promise<ERC721TokenIdsByOwner> {
this._validateDummyTokenContractsExistOrThrow();
this._validateBalancesAndAllowancesSetOrThrow();
const tokenIdsByOwner: ERC721TokenIdsByOwner = {};
- const tokenOwnerPromises: Array<Promise<string>> = [];
+ const tokenOwnerAddresses: string[] = [];
const tokenInfo: Array<{ tokenId: BigNumber; tokenAddress: string }> = [];
- _.forEach(this._dummyTokenContracts, dummyTokenContract => {
- _.forEach(this._tokenOwnerAddresses, tokenOwnerAddress => {
+ for (const dummyTokenContract of this._dummyTokenContracts) {
+ for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
const initialTokenOwnerIds = this._initialTokenIdsByOwner[tokenOwnerAddress][
dummyTokenContract.address
];
- _.forEach(initialTokenOwnerIds, tokenId => {
- tokenOwnerPromises.push(dummyTokenContract.ownerOf.callAsync(tokenId));
+ for (const tokenId of initialTokenOwnerIds) {
+ tokenOwnerAddresses.push(await dummyTokenContract.ownerOf.callAsync(tokenId));
tokenInfo.push({
tokenId,
tokenAddress: dummyTokenContract.address,
});
- });
- });
- });
- const tokenOwnerAddresses = await Promise.all(tokenOwnerPromises);
+ }
+ }
+ }
_.forEach(tokenOwnerAddresses, (tokenOwnerAddress, ownerIndex) => {
const tokenAddress = tokenInfo[ownerIndex].tokenAddress;
const tokenId = tokenInfo[ownerIndex].tokenId;
diff --git a/packages/contracts/src/utils/order_factory.ts b/packages/contracts/src/utils/order_factory.ts
index f704c26ec..e60f25605 100644
--- a/packages/contracts/src/utils/order_factory.ts
+++ b/packages/contracts/src/utils/order_factory.ts
@@ -19,7 +19,8 @@ export class OrderFactory {
customOrderParams: Partial<UnsignedOrder> = {},
signatureType: SignatureType = SignatureType.Ecrecover,
): SignedOrder {
- const randomExpiration = new BigNumber(Math.floor((Date.now() + Math.random() * 100000000000) / 1000));
+ const tenMinutes = 10 * 60 * 1000;
+ const randomExpiration = new BigNumber(Date.now() + tenMinutes);
const order = ({
senderAddress: constants.NULL_ADDRESS,
expirationTimeSeconds: randomExpiration,