diff --git a/CHANGELOG.md b/CHANGELOG.md index 07fc451e930..e337e548cee 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 === undefined`, then `transaction.accessList` is set to `[]` (#5979) 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]); diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 73e864a546c..53646183321 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -795,10 +795,20 @@ 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 && + 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 diff --git a/test/eth.sendTransaction.js b/test/eth.sendTransaction.js index e7afb741f83..9d47531a220 100644 --- a/test/eth.sendTransaction.js +++ b/test/eth.sendTransaction.js @@ -36,6 +36,153 @@ var tests = [{ }, call: 'eth_'+ method }, +// test type +{ + args: [{ + from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address + value: '1234567654321', + gasPrice: '324234234234', + // Testing 10 is formatted to '0xa' + 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', + // Testing '10' is formatted to '0xa' + 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', + // Testing 0x10 is formatted to '0x10' + 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', + // Testing 1 is formatted to '0x1' + type: 1 + }], + formattedArgs: [{ + from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", + value: "0x11f71f76bb1", + gasPrice: "0x4b7dddc97a", + type: '0x1', + accessList: [] + }], + 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', + // 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: [{ diff --git a/test/formatters.inputTransactionFormatter.js b/test/formatters.inputTransactionFormatter.js index 14e5ced9d15..b315a5675b0 100644 --- a/test/formatters.inputTransactionFormatter.js +++ b/test/formatters.inputTransactionFormatter.js @@ -150,6 +150,96 @@ 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: "0xc0" + }, + result: { + data: '0x34234bf23bf4234', + value: '0x64', + from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', + gas: '0x3e8', + maxPriorityFeePerGas: '0x3e8', + maxFeePerGas: '0x3e8', + type: '0xc0' + }, + 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' } }];