|
| 1 | +const utils = require('web3-utils') |
| 2 | +const { assert } = require('chai') |
| 3 | +const conf = require('./config') |
| 4 | +const helpers = require('./helpers') |
| 5 | +const web3 = conf.web3 |
| 6 | + |
| 7 | +it('updates the gas price', async () => { |
| 8 | + let gasPrice = await web3.eth.getGasPrice() |
| 9 | + assert.equal(gasPrice, 2n * conf.minGasPrice) |
| 10 | + |
| 11 | + let receiver = web3.eth.accounts.create() |
| 12 | + |
| 13 | + // make sure receiver balance is initially 0 |
| 14 | + let receiverWei = await web3.eth.getBalance(receiver.address) |
| 15 | + assert.equal(receiverWei, 0n) |
| 16 | + |
| 17 | + // get sender balance |
| 18 | + let senderBalance = await web3.eth.getBalance(conf.eoa.address) |
| 19 | + assert.equal(senderBalance, utils.toWei(conf.fundedAmount, 'ether')) |
| 20 | + |
| 21 | + let txCount = await web3.eth.getTransactionCount(conf.eoa.address) |
| 22 | + assert.equal(0n, txCount) |
| 23 | + |
| 24 | + let transferValue = utils.toWei('2.5', 'ether') |
| 25 | + // assert that the minimum acceptable gas price has been multiplied by the surge factor |
| 26 | + try { |
| 27 | + let transfer = await helpers.signAndSend({ |
| 28 | + from: conf.eoa.address, |
| 29 | + to: receiver.address, |
| 30 | + value: transferValue, |
| 31 | + gasPrice: gasPrice - 10n, |
| 32 | + gasLimit: 55_000, |
| 33 | + }) |
| 34 | + assert.fail('should not have gotten here') |
| 35 | + } catch (e) { |
| 36 | + assert.include( |
| 37 | + e.message, |
| 38 | + `the minimum accepted gas price for transactions is: ${gasPrice}` |
| 39 | + ) |
| 40 | + } |
| 41 | + |
| 42 | + let transfer = await helpers.signAndSend({ |
| 43 | + from: conf.eoa.address, |
| 44 | + to: receiver.address, |
| 45 | + value: transferValue, |
| 46 | + gasPrice: gasPrice, |
| 47 | + gasLimit: 55_000, |
| 48 | + }) |
| 49 | + assert.equal(transfer.receipt.status, conf.successStatus) |
| 50 | + assert.equal(transfer.receipt.from, conf.eoa.address) |
| 51 | + assert.equal(transfer.receipt.to, receiver.address) |
| 52 | + |
| 53 | + let latestBlockNumber = await web3.eth.getBlockNumber() |
| 54 | + let latestBlock = await web3.eth.getBlock(latestBlockNumber) |
| 55 | + assert.equal(latestBlock.transactions.length, 2) |
| 56 | + |
| 57 | + let transferTx = await web3.eth.getTransactionFromBlock(latestBlockNumber, 0) |
| 58 | + let transferTxReceipt = await web3.eth.getTransactionReceipt(transferTx.hash) |
| 59 | + assert.equal(transferTxReceipt.effectiveGasPrice, gasPrice) |
| 60 | + |
| 61 | + let coinbaseFeesTx = await web3.eth.getTransactionFromBlock(latestBlockNumber, 1) |
| 62 | + assert.equal(coinbaseFeesTx.value, transferTxReceipt.gasUsed * gasPrice) |
| 63 | +}) |
0 commit comments