diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-18 18:04:57 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-18 18:04:57 +0800 |
commit | 7f90f5ecd4d977a48b6239fa9fb78a50f52187b0 (patch) | |
tree | 7a0461d8164610c9a71155ab9d4e29a1fdfbbdd5 /packages/dev-utils/src | |
parent | 12f02b98143513d8309a9df7d4dcab46d60352da (diff) | |
parent | 56a4a374cde67e0e5c0c748ed6bee9bb2a084bd9 (diff) | |
download | dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.gz dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.bz2 dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.lz dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.xz dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.zst dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.zip |
merge v2-prototype
Diffstat (limited to 'packages/dev-utils/src')
-rw-r--r-- | packages/dev-utils/src/blockchain_lifecycle.ts | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/packages/dev-utils/src/blockchain_lifecycle.ts b/packages/dev-utils/src/blockchain_lifecycle.ts index 9bd65ee5d..a0424f01f 100644 --- a/packages/dev-utils/src/blockchain_lifecycle.ts +++ b/packages/dev-utils/src/blockchain_lifecycle.ts @@ -34,6 +34,12 @@ export class BlockchainLifecycle { blockNumber = await this._web3Wrapper.getBlockNumberAsync(); } this._snapshotIdsStack.push(blockNumber); + // HACK(albrow) It's possible that we applied a time offset but + // the transaction we mined to put that time offset into the + // blockchain was reverted. As a workaround, we mine a new dummy + // block so that the latest block timestamp accounts for any + // possible time offsets. + await this._mineDummyBlockAsync(); break; default: throw new Error(`Unknown node type: ${nodeType}`); @@ -59,22 +65,9 @@ export class BlockchainLifecycle { } private async _mineMinimumBlocksAsync(): Promise<void> { logUtils.warn('WARNING: minimum block number for tests not met. Mining additional blocks...'); - if (this._addresses.length === 0) { - this._addresses = await this._web3Wrapper.getAvailableAddressesAsync(); - if (this._addresses.length === 0) { - throw new Error('No accounts found'); - } - } while ((await this._web3Wrapper.getBlockNumberAsync()) < MINIMUM_BLOCKS) { logUtils.warn('Mining block...'); - await this._web3Wrapper.awaitTransactionMinedAsync( - await this._web3Wrapper.sendTransactionAsync({ - from: this._addresses[0], - to: this._addresses[0], - value: '0', - }), - 0, - ); + await this._mineDummyBlockAsync(); } logUtils.warn('Done mining the minimum number of blocks.'); } @@ -84,4 +77,22 @@ export class BlockchainLifecycle { } return this._nodeType; } + // Sends a transaction that has no real effect on the state and waits for it + // to be mined. + private async _mineDummyBlockAsync(): Promise<void> { + if (this._addresses.length === 0) { + this._addresses = await this._web3Wrapper.getAvailableAddressesAsync(); + if (this._addresses.length === 0) { + throw new Error('No accounts found'); + } + } + await this._web3Wrapper.awaitTransactionMinedAsync( + await this._web3Wrapper.sendTransactionAsync({ + from: this._addresses[0], + to: this._addresses[0], + value: '0', + }), + 0, + ); + } } |