From fc8e86d2258e6aba938c000a0097cac1831d3e5d Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 1 Apr 2023 10:48:16 -1000 Subject: [PATCH 1/9] Add type to numberToHex formatting for _txInputFormatter --- packages/web3-core-helpers/src/formatters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index e368f5b4d88..1c3ca61c288 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -162,7 +162,7 @@ var _txInputFormatter = function (options) { delete options.gasPrice; } - ['gasPrice', 'gas', 'value', 'maxPriorityFeePerGas', 'maxFeePerGas', 'nonce'].filter(function (key) { + ['gasPrice', 'gas', 'value', 'maxPriorityFeePerGas', 'maxFeePerGas', 'nonce', 'type'].filter(function (key) { return options[key] !== undefined; }).forEach(function (key) { options[key] = utils.numberToHex(options[key]); From 1d0b3362c9569ccce24eb741cdb735ca08086b1a Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 1 Apr 2023 10:48:51 -1000 Subject: [PATCH 2/9] Add test for type formatting --- test/eth.sendTransaction.js | 113 +++++++++++++++++++ test/formatters.inputTransactionFormatter.js | 72 ++++++++++++ 2 files changed, 185 insertions(+) diff --git a/test/eth.sendTransaction.js b/test/eth.sendTransaction.js index e7afb741f83..b9d3103c43b 100644 --- a/test/eth.sendTransaction.js +++ b/test/eth.sendTransaction.js @@ -36,6 +36,119 @@ var tests = [{ }, call: 'eth_'+ method }, +// test type +{ + args: [{ + from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + value: '1234567654321', + gasPrice: '324234234234', + type: 10 + }], + formattedArgs: [{ + from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + value: "0x11f71f76bb1", + gasPrice: "0x4b7dddc97a", + type: '0xa' + }], + result: '0x1234567', + formattedResult: '0x1234567', + notification: { + method: 'eth_subscription', + params: { + subscription: '0x1234567', + result: { + blockNumber: '0x10' + } + } + }, + call: 'eth_'+ method +}, +{ + args: [{ + from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + value: '1234567654321', + gasPrice: '324234234234', + type: '10' + }], + formattedArgs: [{ + from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + value: "0x11f71f76bb1", + gasPrice: "0x4b7dddc97a", + type: '0xa' + }], + result: '0x1234567', + formattedResult: '0x1234567', + notification: { + method: 'eth_subscription', + params: { + subscription: '0x1234567', + result: { + blockNumber: '0x10' + } + } + }, + call: 'eth_'+ method +}, +{ + args: [{ + from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + value: '1234567654321', + gasPrice: '324234234234', + type: 0x10 + }], + formattedArgs: [{ + from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + value: "0x11f71f76bb1", + gasPrice: "0x4b7dddc97a", + type: '0x10' + }], + result: '0x1234567', + formattedResult: '0x1234567', + notification: { + method: 'eth_subscription', + params: { + subscription: '0x1234567', + result: { + blockNumber: '0x10' + } + } + }, + call: 'eth_'+ method +}, +{ + args: [{ + from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + value: '1234567654321', + gasPrice: '324234234234', + type: 1 + }], + formattedArgs: [{ + from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + value: "0x11f71f76bb1", + gasPrice: "0x4b7dddc97a", + type: '0x1' + }], + result: '0x1234567', + formattedResult: '0x1234567', + notification: { + method: 'eth_subscription', + params: { + subscription: '0x1234567', + result: { + blockNumber: '0x10' + } + } + }, + call: 'eth_'+ method +}, // test with gasPrice missing { args: [{ diff --git a/test/formatters.inputTransactionFormatter.js b/test/formatters.inputTransactionFormatter.js index 14e5ced9d15..6f167bb14de 100644 --- a/test/formatters.inputTransactionFormatter.js +++ b/test/formatters.inputTransactionFormatter.js @@ -150,6 +150,78 @@ var tests = [{ gas: '0x3e8', maxPriorityFeePerGas: '0x3e8', maxFeePerGas: '0x3e8' + }, + input: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: new bn(1000), + maxFeePerGas: new bn(1000), + type: 10 + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8', + type: '0xa' + }, + input: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: new bn(1000), + maxFeePerGas: new bn(1000), + type: '10' + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8', + type: '0xa' + }, + input: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: new bn(1000), + maxFeePerGas: new bn(1000), + type: 0x10 + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8', + type: '0x10' + }, + input: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: new bn(1000), + maxFeePerGas: new bn(1000), + type: 1 + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8', + type: '0x1' } }]; From 1ce653a13457ca6c2cae27fd80d786f1c21ac293 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 1 Apr 2023 10:49:37 -1000 Subject: [PATCH 3/9] Add logic to add empty accesslist if type === '0x1' when sending transaction. Add test for same --- packages/web3-core-method/src/index.js | 17 ++++++++++++++--- test/e2e.method.send.js | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 73e864a546c..9b3961d69fc 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -795,10 +795,21 @@ Method.prototype.buildCall = function () { return method.requestManager.send(payload, sendTxCallback); }; - // Send the actual transaction - if (isSendTx + const hasSendTxObject = isSendTx && !!payload.params[0] - && typeof payload.params[0] === 'object' + && typeof payload.params[0] === 'object'; + + if (hasSendTxObject) { + if ( + payload.params[0].type === '0x1' + &&typeof payload.params[0].accessList === 'undefined' + ) { + payload.params[0].accessList = []; + } + } + + // Send the actual transaction + if (hasSendTxObject && ( typeof payload.params[0].gasPrice === 'undefined' && ( diff --git a/test/e2e.method.send.js b/test/e2e.method.send.js index 08f275384b1..4d8862cf11c 100644 --- a/test/e2e.method.send.js +++ b/test/e2e.method.send.js @@ -39,6 +39,27 @@ describe('method.send [ @E2E ]', function () { assert(web3.utils.isHexStrict(receipt.transactionHash)); }); + it('should yield 0x1 for type and add accessList property', async function() { + // ganache does not support eth_signTransaction + if (process.env.GANACHE || global.window ) return + + var nonceVal = await web3.eth.getTransactionCount(accounts[0]); + var receipt = await web3.eth.sendTransaction({ + to: accounts[1], + from: accounts[0], + nonce: nonceVal, + value: web3.utils.toHex(web3.utils.toWei('0.1', 'ether')), + gas: web3.utils.toHex(21000), + type: 1 + }); + + assert(receipt.status === true); + assert(receipt.type === '0x1'); + + var fetchedTransaction = await web3.eth.getTransaction(receipt.transactionHash); + assert(fetchedTransaction.accessList.length === 0); + }); + it('returns a receipt (EIP-1559, maxFeePerGas and maxPriorityFeePerGas specified)', async function () { // ganache does not support eth_signTransaction if (process.env.GANACHE || global.window ) return From 14a9949d4054560409ab64a81dc871466710e665 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 1 Apr 2023 10:53:50 -1000 Subject: [PATCH 4/9] Add input tx formatter test case --- test/eth.sendTransaction.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/eth.sendTransaction.js b/test/eth.sendTransaction.js index b9d3103c43b..4e6f3e5bb16 100644 --- a/test/eth.sendTransaction.js +++ b/test/eth.sendTransaction.js @@ -43,6 +43,7 @@ var tests = [{ to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address value: '1234567654321', gasPrice: '324234234234', + // Testing 10 is formatted to '0xa' type: 10 }], formattedArgs: [{ @@ -71,6 +72,7 @@ var tests = [{ to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address value: '1234567654321', gasPrice: '324234234234', + // Testing '10' is formatted to '0xa' type: '10' }], formattedArgs: [{ @@ -99,6 +101,7 @@ var tests = [{ to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address value: '1234567654321', gasPrice: '324234234234', + // Testing 0x10 is formatted to '0x10' type: 0x10 }], formattedArgs: [{ @@ -127,6 +130,7 @@ var tests = [{ to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address value: '1234567654321', gasPrice: '324234234234', + // Testing 1 is formatted to '0x1' type: 1 }], formattedArgs: [{ @@ -149,6 +153,35 @@ var tests = [{ }, call: 'eth_'+ method }, +{ + args: [{ + from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + value: '1234567654321', + gasPrice: '324234234234', + // Testing "0xc0" is formatted to '0xc0' + type: "0xc0" + }], + formattedArgs: [{ + from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + value: "0x11f71f76bb1", + gasPrice: "0x4b7dddc97a", + type: '0xc0' + }], + result: '0x1234567', + formattedResult: '0x1234567', + notification: { + method: 'eth_subscription', + params: { + subscription: '0x1234567', + result: { + blockNumber: '0x10' + } + } + }, + call: 'eth_'+ method +}, // test with gasPrice missing { args: [{ From 1e7d7a4997724dae66a78aa3ba03c418f25ef31e Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 1 Apr 2023 10:55:53 -1000 Subject: [PATCH 5/9] Add input tx formatter test case --- test/formatters.inputTransactionFormatter.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/formatters.inputTransactionFormatter.js b/test/formatters.inputTransactionFormatter.js index 6f167bb14de..b315a5675b0 100644 --- a/test/formatters.inputTransactionFormatter.js +++ b/test/formatters.inputTransactionFormatter.js @@ -205,6 +205,24 @@ var tests = [{ maxFeePerGas: '0x3e8', type: '0x10' }, + input: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: new bn(1000), + maxFeePerGas: new bn(1000), + type: "0xc0" + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8', + type: '0xc0' + }, input: { data: '0x34234bf23bf4234', value: '0x64', From 70d02257571c8848344e5cca4d8044cfc3fa26bb Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 1 Apr 2023 10:58:12 -1000 Subject: [PATCH 6/9] Update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07fc451e930..ba19a468f20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -666,3 +666,8 @@ Released with 1.0.0-beta.37 code base. ### Fixed - Improved the error propagation in `web3-providers-http` package to effectively propagate useful error infomation about failed HTTP connections (#5955) + +### Changed + + - `transaction.type` is now formatted to a hex string before being send to provider (#5979) + - When sending a transaction, if `transaction.type === '0x1' && transaction.accessList === []`, then `transaction.accessList` is set to `[]` (#5979) From 379b9b134992800b74f91675ba5248b8535a2375 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 1 Apr 2023 11:17:41 -1000 Subject: [PATCH 7/9] Fix failing test cases --- test/eth.sendTransaction.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/eth.sendTransaction.js b/test/eth.sendTransaction.js index 4e6f3e5bb16..9d47531a220 100644 --- a/test/eth.sendTransaction.js +++ b/test/eth.sendTransaction.js @@ -138,7 +138,8 @@ var tests = [{ to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", value: "0x11f71f76bb1", gasPrice: "0x4b7dddc97a", - type: '0x1' + type: '0x1', + accessList: [] }], result: '0x1234567', formattedResult: '0x1234567', From 7a6d85dabba32717ba69147c9fe5cd33d5800dbe Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Mon, 3 Apr 2023 02:46:28 -1000 Subject: [PATCH 8/9] Update packages/web3-core-method/src/index.js Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> --- packages/web3-core-method/src/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 9b3961d69fc..53646183321 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -799,14 +799,13 @@ Method.prototype.buildCall = function () { && !!payload.params[0] && typeof payload.params[0] === 'object'; - if (hasSendTxObject) { - if ( + if (hasSendTxObject && payload.params[0].type === '0x1' - &&typeof payload.params[0].accessList === 'undefined' + && typeof payload.params[0].accessList === 'undefined' ) { payload.params[0].accessList = []; } - } + // Send the actual transaction if (hasSendTxObject From 0771e419f76a093bc9617577a5aa7d1d2463a134 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Mon, 3 Apr 2023 09:50:34 -1000 Subject: [PATCH 9/9] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba19a468f20..e337e548cee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -670,4 +670,4 @@ Released with 1.0.0-beta.37 code base. ### Changed - `transaction.type` is now formatted to a hex string before being send to provider (#5979) - - When sending a transaction, if `transaction.type === '0x1' && transaction.accessList === []`, then `transaction.accessList` is set to `[]` (#5979) + - When sending a transaction, if `transaction.type === '0x1' && transaction.accessList === undefined`, then `transaction.accessList` is set to `[]` (#5979)