diff --git a/CHANGELOG.md b/CHANGELOG.md index 60245b8b0fa..1fb86263fc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -419,3 +419,8 @@ Released with 1.0.0-beta.37 code base. ## [Unreleased] ## [1.5.1] + +### Added + +- `maxPriorityFeePerGas` and `maxFeePerGas` now included in `_txInputFormatter` (#4217) +- If `maxPriorityFeePerGas` of `maxFeePerGas` present `_txInputFormatter` deletes `tx.gasPrice` (fixes #4211) (#4217) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index eef58403a91..8947c68b94f 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -157,8 +157,12 @@ var _txInputFormatter = function (options) { if (options.gas || options.gasLimit) { options.gas = options.gas || options.gasLimit; } + + if (options.maxPriorityFeePerGas || options.maxFeePerGas) { + delete options.gasPrice; + } - ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { + ['gasPrice', 'gas', 'value', 'maxPriorityFeePerGas', 'maxFeePerGas', 'nonce'].filter(function (key) { return options[key] !== undefined; }).forEach(function (key) { options[key] = utils.numberToHex(options[key]); diff --git a/test/eth.accounts.signTransaction.js b/test/eth.accounts.signTransaction.js index 6d1331d9388..3c9eb2d229b 100644 --- a/test/eth.accounts.signTransaction.js +++ b/test/eth.accounts.signTransaction.js @@ -3,6 +3,7 @@ var Web3 = require('../packages/web3'); var Accounts = require("./../packages/web3-eth-accounts"); var chai = require('chai'); var assert = chai.assert; +var bn = require('bn.js'); var common = { baseChain: 'mainnet', @@ -649,6 +650,52 @@ var tests = [ transactionHash: "0xbc2c9edab3d4e3a795fa402b52d6149e874de15f0cc6c0858eb34e1fe1ef31fe", messageHash: "0xa3a2cdc45e9cefb9a614ead90ce65f68bcf8a90dbe0ccbd84c1b62403bd05346" }, + { + // test #28 + address: '0x2c7536E3605D9C16a7a3D7b1898e529396a65c23', + iban: 'XE0556YCRTEZ9JALZBSCXOK4UJ5F3HN03DV', + privateKey: '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318', + transaction: { + chainId: 1, + nonce: 0, + maxPriorityFeePerGas: new bn('0x3B9ACA00'), + maxFeePerGas: new bn('0xB2D05E00'), + gasLimit: '0x6A40', + to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', + toIban: 'XE04S1IRT2PR8A8422TPBL9SR6U0HODDCUT', // will be switched to "to" in the test + value: "1000000000", + data: "", + common: commonLondon + }, + // signature from eth_signTransaction + rawTransaction: "0x02f86e018084c733124884cb72ec20826a4094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca0080c001a08896fb9a5c033e0163b073cf7a951a1db2dca41b26b4188f13a05158eb26fd32a005e8855691199cd0b6dcae88f3325c374e2f0697b9c528a5c10d5bd8dfb6a3e3", + oldSignature: "0x02f86e018084c733124884cb72ec20826a4094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca0080c001a08896fb9a5c033e0163b073cf7a951a1db2dca41b26b4188f13a05158eb26fd32a005e8855691199cd0b6dcae88f3325c374e2f0697b9c528a5c10d5bd8dfb6a3e3", + transactionHash: "0xd5b7290a477b9c421d39e61d0f566ec33276fb49b9ff85cfd6152a18f1c92dab", + messageHash: "0x17e20e530a889ce52057de228b5b97edcad6002468d723346cd0b6b7a9943457" + }, + { + // test #29 + address: '0x2c7536E3605D9C16a7a3D7b1898e529396a65c23', + iban: 'XE0556YCRTEZ9JALZBSCXOK4UJ5F3HN03DV', + privateKey: '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318', + transaction: { + chainId: 1, + nonce: 0, + maxPriorityFeePerGas: '1000000000', + maxFeePerGas: '3000000000', + gasLimit: '0x6A40', + to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', + toIban: 'XE04S1IRT2PR8A8422TPBL9SR6U0HODDCUT', // will be switched to "to" in the test + value: "1000000000", + data: "", + common: commonLondon + }, + // signature from eth_signTransaction + rawTransaction: "0x02f86e0180843b9aca0084b2d05e00826a4094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca0080c080a0d1290a118d51918c1ca17e3af0267c45efcd745cf42e78eabc444c424d6bcf37a003c81e1fda169575023a94200ee034128747f91020e704abaee30dbcfc785c36", + oldSignature: "0x02f86e0180843b9aca0084b2d05e00826a4094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca0080c080a0d1290a118d51918c1ca17e3af0267c45efcd745cf42e78eabc444c424d6bcf37a003c81e1fda169575023a94200ee034128747f91020e704abaee30dbcfc785c36", + transactionHash: "0x82c19b39a6b7eaa0492863a8b236fad5018f267b4977c270ddd5228c4cbda60e", + messageHash: "0xe3beea0918f445c21eb2f42e3cbc3c5d54321ec642f47d12c473b2765df97f2b" + }, ]; describe("eth", function () { diff --git a/test/formatters.inputTransactionFormatter.js b/test/formatters.inputTransactionFormatter.js index 47c767e7c06..14e5ced9d15 100644 --- a/test/formatters.inputTransactionFormatter.js +++ b/test/formatters.inputTransactionFormatter.js @@ -1,5 +1,7 @@ +var bn = require('bn.js'); var chai = require('chai'); var assert = chai.assert; + var formatters = require('../packages/web3-core-helpers/src/formatters.js'); var tests = [{ @@ -98,6 +100,57 @@ var tests = [{ gas: '0x3e8', gasPrice: '0x3e8' } +}, { + input: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '1000', + maxFeePerGas: '1000' + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8' + } +}, { + input: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: 1000, + maxFeePerGas: 1000 + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8' + } +}, { + input: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: new bn(1000), + maxFeePerGas: new bn(1000) + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8' + } }]; describe('formatters', function () {