Skip to content

Commit

Permalink
fix: resolves #2055 (#2063)
Browse files Browse the repository at this point in the history
* fix: resolves #2055

* tests: update

* chore: changeset
  • Loading branch information
jxom committed Apr 3, 2024
1 parent 0309572 commit f539b0d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-yaks-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed issue where the `transactionRequest` formatter would supply redundant properties.
2 changes: 1 addition & 1 deletion src/op-stack/actions/depositTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ test('error: small gas', async () => {
[ContractFunctionExecutionError: Transaction creation failed.
URL: http://localhost
Request body: {"method":"eth_estimateGas","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","data":"0xe9e05c42000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005208000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000","gas":"0x45","to":"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e"}]}
Request body: {"method":"eth_estimateGas","params":[{"data":"0xe9e05c42000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005208000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x45","to":"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e"}]}
Estimate Gas Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
Expand Down
2 changes: 1 addition & 1 deletion src/op-stack/actions/finalizeWithdrawal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ test('error: small gas', async () => {
[ContractFunctionExecutionError: Transaction creation failed.
URL: http://localhost
Request body: {"method":"eth_estimateGas","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","data":"0x8c3152e900000000000000000000000000000000000000000000000000000000000000200001000000000000000000000000000000000000000000000000000000002d51000000000000000000000000420000000000000000000000000000000000000700000000000000000000000025ace71c97b33cc4729cf772ae268934f7ab5fa1000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000004638800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001a4d764ad0b0001000000000000000000000000000000000000000000000000000000002d51000000000000000000000000420000000000000000000000000000000000001000000000000000000000000099c9fc46f92e8a1c0dec1b1747d010903e884be1000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000a41635f5fd000000000000000000000000160d7aa81e6fc30210aeb915c3bb1f55bfa86b37000000000000000000000000160d7aa81e6fc30210aeb915c3bb1f55bfa86b37000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","gas":"0x45","to":"0xbEb5Fc579115071764c7423A4f12eDde41f106Ed"}]}
Request body: {"method":"eth_estimateGas","params":[{"data":"0x8c3152e900000000000000000000000000000000000000000000000000000000000000200001000000000000000000000000000000000000000000000000000000002d51000000000000000000000000420000000000000000000000000000000000000700000000000000000000000025ace71c97b33cc4729cf772ae268934f7ab5fa1000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000004638800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001a4d764ad0b0001000000000000000000000000000000000000000000000000000000002d51000000000000000000000000420000000000000000000000000000000000001000000000000000000000000099c9fc46f92e8a1c0dec1b1747d010903e884be1000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000a41635f5fd000000000000000000000000160d7aa81e6fc30210aeb915c3bb1f55bfa86b37000000000000000000000000160d7aa81e6fc30210aeb915c3bb1f55bfa86b37000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x45","to":"0xbEb5Fc579115071764c7423A4f12eDde41f106Ed"}]}
Estimate Gas Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
Expand Down
4 changes: 2 additions & 2 deletions src/op-stack/actions/initiateWithdrawal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test('error: insufficient funds', async () => {
[ContractFunctionExecutionError: Transaction creation failed.
URL: http://localhost
Request body: {"method":"eth_estimateGas","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","data":"0xc2b3e5ac000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000520800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000","gas":"0x45","to":"0x4200000000000000000000000000000000000016","value":"0x43c33c1937564800000"}]}
Request body: {"method":"eth_estimateGas","params":[{"data":"0xc2b3e5ac000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000520800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x45","to":"0x4200000000000000000000000000000000000016","value":"0x43c33c1937564800000"}]}
Estimate Gas Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
Expand Down Expand Up @@ -142,7 +142,7 @@ test('error: small gas', async () => {
[ContractFunctionExecutionError: Transaction creation failed.
URL: http://localhost
Request body: {"method":"eth_estimateGas","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","data":"0xc2b3e5ac000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000520800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000","gas":"0x45","to":"0x4200000000000000000000000000000000000016","value":"0xde0b6b3a7640000"}]}
Request body: {"method":"eth_estimateGas","params":[{"data":"0xc2b3e5ac000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000520800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x45","to":"0x4200000000000000000000000000000000000016","value":"0xde0b6b3a7640000"}]}
Estimate Gas Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
Expand Down
30 changes: 24 additions & 6 deletions src/utils/formatters/transactionRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ test('eip4844 transaction', () => {
"value": "0x1",
}
`)

expect(
formatTransactionRequest({
...base,
blobs: [Uint8Array.from([0xab, 0xc])],
from: '0x0000000000000000000000000000000000000000',
maxFeePerBlobGas: 69n,
type: 'eip4844',
} as TransactionRequestEIP4844),
).toMatchInlineSnapshot(`
{
"blobs": [
"0xab0c",
],
"data": "0x1",
"from": "0x0000000000000000000000000000000000000000",
"gas": "0x4234584",
"maxFeePerBlobGas": "0x45",
"nonce": "0x1",
"to": "0x1",
"type": "0x3",
"value": "0x1",
}
`)
})

test('nullish gas', () => {
Expand All @@ -151,7 +175,6 @@ test('nullish gas', () => {
{
"data": "0x1",
"from": "0x1",
"gas": undefined,
"nonce": "0x1",
"to": "0x1",
"value": "0x1",
Expand All @@ -170,7 +193,6 @@ test('nullish gasPrice', () => {
"data": "0x1",
"from": "0x1",
"gas": "0x4234584",
"gasPrice": undefined,
"nonce": "0x1",
"to": "0x1",
"value": "0x1",
Expand All @@ -189,7 +211,6 @@ test('nullish maxFeePerGas', () => {
"data": "0x1",
"from": "0x1",
"gas": "0x4234584",
"maxFeePerGas": undefined,
"nonce": "0x1",
"to": "0x1",
"value": "0x1",
Expand All @@ -208,7 +229,6 @@ test('nullish maxPriorityFeePerGas', () => {
"data": "0x1",
"from": "0x1",
"gas": "0x4234584",
"maxPriorityFeePerGas": undefined,
"nonce": "0x1",
"to": "0x1",
"value": "0x1",
Expand All @@ -227,7 +247,6 @@ test('nullish nonce', () => {
"data": "0x1",
"from": "0x1",
"gas": "0x4234584",
"nonce": undefined,
"to": "0x1",
"value": "0x1",
}
Expand All @@ -247,7 +266,6 @@ test('nullish value', () => {
"gas": "0x4234584",
"nonce": "0x1",
"to": "0x1",
"value": undefined,
}
`)
})
Expand Down
19 changes: 13 additions & 6 deletions src/utils/formatters/transactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ export type FormatTransactionRequestErrorType = ErrorType
export function formatTransactionRequest(
request: ExactPartial<TransactionRequest>,
) {
const rpcRequest = { ...request } as RpcTransactionRequest
const rpcRequest = {} as RpcTransactionRequest

if (
typeof request.blobs !== 'undefined' &&
typeof request.blobs[0] !== 'string'
)
rpcRequest.blobs = (request.blobs as ByteArray[]).map((x) => bytesToHex(x))
if (typeof request.accessList !== 'undefined')
rpcRequest.accessList = request.accessList
if (typeof request.blobs !== 'undefined') {
if (typeof request.blobs[0] !== 'string')
rpcRequest.blobs = (request.blobs as ByteArray[]).map((x) =>
bytesToHex(x),
)
else rpcRequest.blobs = request.blobs
}
if (typeof request.data !== 'undefined') rpcRequest.data = request.data
if (typeof request.from !== 'undefined') rpcRequest.from = request.from
if (typeof request.gas !== 'undefined')
rpcRequest.gas = numberToHex(request.gas)
if (typeof request.gasPrice !== 'undefined')
Expand All @@ -49,6 +55,7 @@ export function formatTransactionRequest(
rpcRequest.maxPriorityFeePerGas = numberToHex(request.maxPriorityFeePerGas)
if (typeof request.nonce !== 'undefined')
rpcRequest.nonce = numberToHex(request.nonce)
if (typeof request.to !== 'undefined') rpcRequest.to = request.to
if (typeof request.type !== 'undefined')
rpcRequest.type = rpcTransactionType[request.type]
if (typeof request.value !== 'undefined')
Expand Down

0 comments on commit f539b0d

Please sign in to comment.