diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-02 08:13:02 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-02 08:13:02 +0800 |
commit | d3c64bd5b493dc1779a24c7c051c255106a4292a (patch) | |
tree | d1c818e64b75c1f4fed1c7d797892fb0d35dd779 /packages/contracts/src/utils/erc20_wrapper.ts | |
parent | 7024a7468a549a96cf120e6b7e287e79d7ad2d61 (diff) | |
parent | 62e60e2ba6d07b9b892b4f2e92a5421c54f5fa20 (diff) | |
download | dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.gz dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.bz2 dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.lz dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.xz dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.zst dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.zip |
Merge branch 'v2-prototype' into refactor/order-utils/for-v2
* v2-prototype:
Set contract expiration time to a constant 10 minutes
Remove unused promises array
Make erc20_wrapper and erc721_wrapper serial
Rename changelogs to changelog
Add CHANGELOG entry
Check that git branch is up to date before publishing
Move prepublish checks before building packages for publishing
Refactor changelog utils to a separate module
Diffstat (limited to 'packages/contracts/src/utils/erc20_wrapper.ts')
-rw-r--r-- | packages/contracts/src/utils/erc20_wrapper.ts | 48 |
1 files changed, 23 insertions, 25 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; |