Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 4e5afa1

Browse files
Format transaction.type to hex. Add empty accessList is tx.type === '0x1' (#5979)
* Add type to numberToHex formatting for _txInputFormatter * Add test for type formatting * Add logic to add empty accesslist if type === '0x1' when sending transaction. Add test for same * Add input tx formatter test case * Add input tx formatter test case * Update CHANGELOG * Fix failing test cases * Update packages/web3-core-method/src/index.js Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> * Update CHANGELOG.md --------- Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com>
1 parent 9238e10 commit 4e5afa1

File tree

6 files changed

+277
-4
lines changed

6 files changed

+277
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,8 @@ Released with 1.0.0-beta.37 code base.
666666
### Fixed
667667

668668
- Improved the error propagation in `web3-providers-http` package to effectively propagate useful error infomation about failed HTTP connections (#5955)
669+
670+
### Changed
671+
672+
- `transaction.type` is now formatted to a hex string before being send to provider (#5979)
673+
- When sending a transaction, if `transaction.type === '0x1' && transaction.accessList === undefined`, then `transaction.accessList` is set to `[]` (#5979)

packages/web3-core-helpers/src/formatters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ var _txInputFormatter = function (options) {
162162
delete options.gasPrice;
163163
}
164164

165-
['gasPrice', 'gas', 'value', 'maxPriorityFeePerGas', 'maxFeePerGas', 'nonce'].filter(function (key) {
165+
['gasPrice', 'gas', 'value', 'maxPriorityFeePerGas', 'maxFeePerGas', 'nonce', 'type'].filter(function (key) {
166166
return options[key] !== undefined;
167167
}).forEach(function (key) {
168168
options[key] = utils.numberToHex(options[key]);

packages/web3-core-method/src/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,20 @@ Method.prototype.buildCall = function () {
795795
return method.requestManager.send(payload, sendTxCallback);
796796
};
797797

798-
// Send the actual transaction
799-
if (isSendTx
798+
const hasSendTxObject = isSendTx
800799
&& !!payload.params[0]
801-
&& typeof payload.params[0] === 'object'
800+
&& typeof payload.params[0] === 'object';
801+
802+
if (hasSendTxObject &&
803+
payload.params[0].type === '0x1'
804+
&& typeof payload.params[0].accessList === 'undefined'
805+
) {
806+
payload.params[0].accessList = [];
807+
}
808+
809+
810+
// Send the actual transaction
811+
if (hasSendTxObject
802812
&& (
803813
typeof payload.params[0].gasPrice === 'undefined'
804814
&& (

test/e2e.method.send.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ describe('method.send [ @E2E ]', function () {
3939
assert(web3.utils.isHexStrict(receipt.transactionHash));
4040
});
4141

42+
it('should yield 0x1 for type and add accessList property', async function() {
43+
// ganache does not support eth_signTransaction
44+
if (process.env.GANACHE || global.window ) return
45+
46+
var nonceVal = await web3.eth.getTransactionCount(accounts[0]);
47+
var receipt = await web3.eth.sendTransaction({
48+
to: accounts[1],
49+
from: accounts[0],
50+
nonce: nonceVal,
51+
value: web3.utils.toHex(web3.utils.toWei('0.1', 'ether')),
52+
gas: web3.utils.toHex(21000),
53+
type: 1
54+
});
55+
56+
assert(receipt.status === true);
57+
assert(receipt.type === '0x1');
58+
59+
var fetchedTransaction = await web3.eth.getTransaction(receipt.transactionHash);
60+
assert(fetchedTransaction.accessList.length === 0);
61+
});
62+
4263
it('returns a receipt (EIP-1559, maxFeePerGas and maxPriorityFeePerGas specified)', async function () {
4364
// ganache does not support eth_signTransaction
4465
if (process.env.GANACHE || global.window ) return

test/eth.sendTransaction.js

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,153 @@ var tests = [{
3636
},
3737
call: 'eth_'+ method
3838
},
39+
// test type
40+
{
41+
args: [{
42+
from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
43+
to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
44+
value: '1234567654321',
45+
gasPrice: '324234234234',
46+
// Testing 10 is formatted to '0xa'
47+
type: 10
48+
}],
49+
formattedArgs: [{
50+
from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
51+
to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
52+
value: "0x11f71f76bb1",
53+
gasPrice: "0x4b7dddc97a",
54+
type: '0xa'
55+
}],
56+
result: '0x1234567',
57+
formattedResult: '0x1234567',
58+
notification: {
59+
method: 'eth_subscription',
60+
params: {
61+
subscription: '0x1234567',
62+
result: {
63+
blockNumber: '0x10'
64+
}
65+
}
66+
},
67+
call: 'eth_'+ method
68+
},
69+
{
70+
args: [{
71+
from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
72+
to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
73+
value: '1234567654321',
74+
gasPrice: '324234234234',
75+
// Testing '10' is formatted to '0xa'
76+
type: '10'
77+
}],
78+
formattedArgs: [{
79+
from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
80+
to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
81+
value: "0x11f71f76bb1",
82+
gasPrice: "0x4b7dddc97a",
83+
type: '0xa'
84+
}],
85+
result: '0x1234567',
86+
formattedResult: '0x1234567',
87+
notification: {
88+
method: 'eth_subscription',
89+
params: {
90+
subscription: '0x1234567',
91+
result: {
92+
blockNumber: '0x10'
93+
}
94+
}
95+
},
96+
call: 'eth_'+ method
97+
},
98+
{
99+
args: [{
100+
from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
101+
to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
102+
value: '1234567654321',
103+
gasPrice: '324234234234',
104+
// Testing 0x10 is formatted to '0x10'
105+
type: 0x10
106+
}],
107+
formattedArgs: [{
108+
from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
109+
to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
110+
value: "0x11f71f76bb1",
111+
gasPrice: "0x4b7dddc97a",
112+
type: '0x10'
113+
}],
114+
result: '0x1234567',
115+
formattedResult: '0x1234567',
116+
notification: {
117+
method: 'eth_subscription',
118+
params: {
119+
subscription: '0x1234567',
120+
result: {
121+
blockNumber: '0x10'
122+
}
123+
}
124+
},
125+
call: 'eth_'+ method
126+
},
127+
{
128+
args: [{
129+
from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
130+
to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
131+
value: '1234567654321',
132+
gasPrice: '324234234234',
133+
// Testing 1 is formatted to '0x1'
134+
type: 1
135+
}],
136+
formattedArgs: [{
137+
from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
138+
to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
139+
value: "0x11f71f76bb1",
140+
gasPrice: "0x4b7dddc97a",
141+
type: '0x1',
142+
accessList: []
143+
}],
144+
result: '0x1234567',
145+
formattedResult: '0x1234567',
146+
notification: {
147+
method: 'eth_subscription',
148+
params: {
149+
subscription: '0x1234567',
150+
result: {
151+
blockNumber: '0x10'
152+
}
153+
}
154+
},
155+
call: 'eth_'+ method
156+
},
157+
{
158+
args: [{
159+
from: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
160+
to: '0xdbdbdB2cBD23b783741e8d7fcF51e459b497e4a6', // checksum address
161+
value: '1234567654321',
162+
gasPrice: '324234234234',
163+
// Testing "0xc0" is formatted to '0xc0'
164+
type: "0xc0"
165+
}],
166+
formattedArgs: [{
167+
from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
168+
to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6",
169+
value: "0x11f71f76bb1",
170+
gasPrice: "0x4b7dddc97a",
171+
type: '0xc0'
172+
}],
173+
result: '0x1234567',
174+
formattedResult: '0x1234567',
175+
notification: {
176+
method: 'eth_subscription',
177+
params: {
178+
subscription: '0x1234567',
179+
result: {
180+
blockNumber: '0x10'
181+
}
182+
}
183+
},
184+
call: 'eth_'+ method
185+
},
39186
// test with gasPrice missing
40187
{
41188
args: [{

test/formatters.inputTransactionFormatter.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,96 @@ var tests = [{
150150
gas: '0x3e8',
151151
maxPriorityFeePerGas: '0x3e8',
152152
maxFeePerGas: '0x3e8'
153+
},
154+
input: {
155+
data: '0x34234bf23bf4234',
156+
value: '0x64',
157+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
158+
gas: '0x3e8',
159+
maxPriorityFeePerGas: new bn(1000),
160+
maxFeePerGas: new bn(1000),
161+
type: 10
162+
},
163+
result: {
164+
data: '0x34234bf23bf4234',
165+
value: '0x64',
166+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
167+
gas: '0x3e8',
168+
maxPriorityFeePerGas: '0x3e8',
169+
maxFeePerGas: '0x3e8',
170+
type: '0xa'
171+
},
172+
input: {
173+
data: '0x34234bf23bf4234',
174+
value: '0x64',
175+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
176+
gas: '0x3e8',
177+
maxPriorityFeePerGas: new bn(1000),
178+
maxFeePerGas: new bn(1000),
179+
type: '10'
180+
},
181+
result: {
182+
data: '0x34234bf23bf4234',
183+
value: '0x64',
184+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
185+
gas: '0x3e8',
186+
maxPriorityFeePerGas: '0x3e8',
187+
maxFeePerGas: '0x3e8',
188+
type: '0xa'
189+
},
190+
input: {
191+
data: '0x34234bf23bf4234',
192+
value: '0x64',
193+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
194+
gas: '0x3e8',
195+
maxPriorityFeePerGas: new bn(1000),
196+
maxFeePerGas: new bn(1000),
197+
type: 0x10
198+
},
199+
result: {
200+
data: '0x34234bf23bf4234',
201+
value: '0x64',
202+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
203+
gas: '0x3e8',
204+
maxPriorityFeePerGas: '0x3e8',
205+
maxFeePerGas: '0x3e8',
206+
type: '0x10'
207+
},
208+
input: {
209+
data: '0x34234bf23bf4234',
210+
value: '0x64',
211+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
212+
gas: '0x3e8',
213+
maxPriorityFeePerGas: new bn(1000),
214+
maxFeePerGas: new bn(1000),
215+
type: "0xc0"
216+
},
217+
result: {
218+
data: '0x34234bf23bf4234',
219+
value: '0x64',
220+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
221+
gas: '0x3e8',
222+
maxPriorityFeePerGas: '0x3e8',
223+
maxFeePerGas: '0x3e8',
224+
type: '0xc0'
225+
},
226+
input: {
227+
data: '0x34234bf23bf4234',
228+
value: '0x64',
229+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
230+
gas: '0x3e8',
231+
maxPriorityFeePerGas: new bn(1000),
232+
maxFeePerGas: new bn(1000),
233+
type: 1
234+
},
235+
result: {
236+
data: '0x34234bf23bf4234',
237+
value: '0x64',
238+
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
239+
gas: '0x3e8',
240+
maxPriorityFeePerGas: '0x3e8',
241+
maxFeePerGas: '0x3e8',
242+
type: '0x1'
153243
}
154244
}];
155245

0 commit comments

Comments
 (0)