move BLOCK_GAS_LIMIT init to _prepare

This commit is contained in:
Alexey 2020-12-23 19:39:09 -06:00
parent 30b32a61d1
commit ab82b37e0d
3 changed files with 12 additions and 11 deletions

@ -116,6 +116,11 @@ class Transaction {
* @private
*/
async _prepare() {
if (!this.config.BLOCK_GAS_LIMIT) {
const lastBlock = await this._provider.getBlock('latest')
this.config.BLOCK_GAS_LIMIT = lastBlock.gasLimit.toNumber()
}
if (!this.tx.gasLimit || this.config.ESTIMATE_GAS) {
const gas = await this._wallet.estimateGas(this.tx)
if (!this.tx.gasLimit) {

@ -35,11 +35,7 @@ class TxManager {
*
* @param tx Transaction to send
*/
async createTx(tx) {
if (!this.config.BLOCK_GAS_LIMIT) {
const lastBlock = await this._provider.getBlock('latest')
this.config.BLOCK_GAS_LIMIT = lastBlock.gasLimit.toNumber()
}
createTx(tx) {
return new Transaction(tx, this)
}
}

@ -10,7 +10,7 @@ describe('TxManager', () => {
privateKey: PRIVATE_KEY,
rpcUrl: RPC_URL,
config: {
CONFIRMATIONS: 3,
CONFIRMATIONS: 1,
GAS_BUMP_INTERVAL: 1000 * 15,
},
})
@ -39,7 +39,7 @@ describe('TxManager', () => {
describe('#transaction', () => {
it('should work', async () => {
const tx = await manager.createTx(tx1)
const tx = manager.createTx(tx1)
const receipt = await tx
.send()
@ -51,7 +51,7 @@ describe('TxManager', () => {
})
it('should fetch gas price', async () => {
const tx = await manager.createTx(tx4)
const tx = manager.createTx(tx4)
const receipt = await tx
.send()
@ -63,7 +63,7 @@ describe('TxManager', () => {
})
it('should bump gas price', async () => {
const tx = await manager.createTx(tx2)
const tx = manager.createTx(tx2)
const receipt = await tx
.send()
@ -75,7 +75,7 @@ describe('TxManager', () => {
})
it('should cancel', async () => {
const tx = await manager.createTx(tx2)
const tx = manager.createTx(tx2)
setTimeout(() => tx.cancel(), 1000)
@ -89,7 +89,7 @@ describe('TxManager', () => {
})
it('should replace', async () => {
const tx = await manager.createTx(tx2)
const tx = manager.createTx(tx2)
setTimeout(() => tx.replace(tx3), 1000)