From eaaa54b7f9c559484af00bf4904f93dfe8243b11 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Wed, 11 May 2022 23:24:39 +1000 Subject: [PATCH] fix: configure EIP-1559 feature --- src/Transaction.js | 2 +- src/TxManager.js | 1 + test/TxManager.test.js | 44 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Transaction.js b/src/Transaction.js index 1e9acde..de80468 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -465,7 +465,7 @@ class Transaction { const block = await this._provider.getBlock('latest') // Check network support for EIP-1559 - if (block && block.baseFeePerGas) { + if (this.config.ENABLE_EIP1559 && block && block.baseFeePerGas) { const maxPriorityFeePerGas = await this._estimatePriorityFee(block.number) const maxFeePerGas = block.baseFeePerGas diff --git a/src/TxManager.js b/src/TxManager.js index 29bdb4b..18d143a 100644 --- a/src/TxManager.js +++ b/src/TxManager.js @@ -15,6 +15,7 @@ const defaultConfig = { ESTIMATE_GAS: true, THROW_ON_REVERT: true, BLOCK_GAS_LIMIT: null, + ENABLE_EIP1559: true, PRIORITY_FEE_GWEI: 3, BASE_FEE_RESERVE_PERCENTAGE: 50, } diff --git a/test/TxManager.test.js b/test/TxManager.test.js index 28afd4f..44a3c0e 100644 --- a/test/TxManager.test.js +++ b/test/TxManager.test.js @@ -1,19 +1,13 @@ require('dotenv').config() require('chai').should() +const { providers } = require('ethers') const { parseUnits } = require('ethers').utils const TxManager = require('../src/TxManager') // const Transaction = require('../src/Transaction') const { RPC_URL, PRIVATE_KEY } = process.env describe('TxManager', () => { - const manager = new TxManager({ - privateKey: PRIVATE_KEY, - rpcUrl: RPC_URL, - config: { - CONFIRMATIONS: 1, - GAS_BUMP_INTERVAL: 1000 * 20, - }, - }) + let manager const tx1 = { value: 1, @@ -45,6 +39,26 @@ describe('TxManager', () => { type: 2, } + before(async () => { + const provider = new providers.JsonRpcProvider(RPC_URL) + + const { name, chainId } = await provider.getNetwork() + console.log('\n\n', 'network', { name, chainId }, '\n\n') + + manager = new TxManager({ + privateKey: PRIVATE_KEY, + rpcUrl: RPC_URL, + config: { + CONFIRMATIONS: 1, + GAS_BUMP_INTERVAL: 1000 * 20, + }, + gasPriceOracleConfig: { + chainId: chainId, + defaultRpc: RPC_URL, + }, + }) + }) + describe('#transaction', () => { it('should work legacy tx', async () => { const tx = manager.createTx(tx1) @@ -138,6 +152,20 @@ describe('TxManager', () => { console.log('receipt', receipt) }) + it('should disable eip-1559 transactions', async () => { + manager.config.ENABLE_EIP1559 = false + + const tx = manager.createTx(tx3) + const receipt = await tx + .send() + .on('transactionHash', hash => console.log('hash', hash)) + .on('mined', receipt => console.log('Mined in block', receipt.blockNumber)) + .on('confirmations', confirmations => console.log('confirmations', confirmations)) + console.log('receipt', receipt) + + manager.config.ENABLE_EIP1559 = true + }) + it('should send multiple txs', async () => { const genTx = value => ({ value,