Skip to content

Commit

Permalink
🐛 Fix: bug with gasLimit being set to block max (#1489)
Browse files Browse the repository at this point in the history
## Description

_Concise description of proposed changes_

## Testing

Explain the quality checks that have been done on the code changes

## Additional Information

- [ ] I read the [contributing docs](../docs/contributing.md) (if this
is your first contribution)

Your ENS/address:



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Corrected the handling of the `gasLimit` parameter in the
`@tevm/actions` package to ensure accurate simulation behavior.
  
- **New Features**
- Introduced a new TypeScript file for testing Ethereum transactions,
enhancing the testing framework with a memory client setup.

- **Improvements**
- Updated error handling and transaction execution logic in the
`executeCall` function to enforce unconditional skipping of balance
checks.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
roninjin10 authored Oct 25, 2024
1 parent 8ea0f89 commit 42590c1
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 162 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-balloons-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tevm/actions": patch
---

Fixed bug where gasLimit was set to block max when simulating calls
13 changes: 5 additions & 8 deletions packages/actions/src/Call/__snapshots__/callHandler.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ Version: 1.1.0.next-73],

exports[`callHandler > should handle insufficient balance error 1`] = `
[
[InsufficientBalanceError: sender doesn't have enough funds to send tx. The upfront cost is: 1000000000210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x063ee66a862cecf7793eb47603e910eab64f801107476b74d25d4cc2325623e0 nonce=0 value=1000000000000000000 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0)
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Details: /reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73],
{
"_tag": "InsufficientBalance",
"message": "Insufficientbalance: Account 0x6969696969696969696969696969696969696969 attempted to create a transaction with zero eth. Consider adding eth to account or using a different from or origin address",
"name": "InsufficientBalance",
},
]
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ exports[`callHandlerOpts > should handle empty params 1`] = `
}
`;

exports[`callHandlerOpts > should handle invalid state overrides 1`] = `
[
[InvalidParams: Invalid state override
Docs: https://tevm.sh/reference/tevm/errors/classes/invaliddeployedbytecodeerror/
Details: /reference/tevm/errors/classes/invaliddeployedbytecodeerror/
Version: 1.1.0.next-73],
]
`;

exports[`callHandlerOpts > should return an error for unknown block tag 1`] = `
[
[InvalidBlockError: Unknown blocktag unknown
Expand Down
18 changes: 5 additions & 13 deletions packages/actions/src/Call/__snapshots__/callProcedure.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,18 @@ exports[`callProcedure > should handle a call with state override 1`] = `

exports[`callProcedure > should handle errors from callHandler 1`] = `
{
"code": -32000,
"code": -32602,
"data": {
"errors": [
"sender doesn't have enough funds to send tx. The upfront cost is: 210000500 and the sender's account (0x4242424242424242424242424242424242424242) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x66575cf759d7c97e42f103bfc8de6f88f70ea97a785d0c1f558496abf977cae1 nonce=0 value=500 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0)
"Invalid Address 0x$asdf
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Details: /reference/tevm/errors/classes/insufficientfundserror/
Docs: https://tevm.sh/reference/tevm/errors/classes/invalidtoerror/
Version: 1.1.0.next-73",
],
},
"message": "sender doesn't have enough funds to send tx. The upfront cost is: 210000500 and the sender's account (0x4242424242424242424242424242424242424242) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x66575cf759d7c97e42f103bfc8de6f88f70ea97a785d0c1f558496abf977cae1 nonce=0 value=500 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0)
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73
"message": "Invalid Address 0x$asdf
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Details: /reference/tevm/errors/classes/insufficientfundserror/
Docs: https://tevm.sh/reference/tevm/errors/classes/invalidtoerror/
Version: 1.1.0.next-73",
}
`;
2 changes: 1 addition & 1 deletion packages/actions/src/Call/callProcedure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('callProcedure', () => {
id: 1,
params: [
{
to: `0x${'00'.repeat(20)}` as const, // Invalid address
to: '0x$asdf' as const, // Invalid address
from: `0x${'42'.repeat(20)}` as const,
data: '0x0',
value: numberToHex(500n),
Expand Down
3 changes: 2 additions & 1 deletion packages/actions/src/Call/executeCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const executeCall = async (client, evmInput, params) => {
skipBlockGasLimitValidation: true,
// we currently set the nonce ourselves user can't set it
skipNonce: true,
skipBalance: evmInput.skipBalance ?? false,
// we must skipBalance for now because we have no clue what the gasLimit should be so this initial run we set it to block maximum
skipBalance: true,
...(evmInput.block !== undefined ? { block: /** @type any*/ (evmInput.block) } : {}),
tx,
})
Expand Down

This file was deleted.

48 changes: 2 additions & 46 deletions packages/actions/src/__snapshots__/createHandlers.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,10 @@

exports[`createHandlers > should handle eth_call 1`] = `
{
"error": {
"code": -32000,
"data": {
"errors": [
"sender doesn't have enough funds to send tx. The upfront cost is: 210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x96171020921a6736a4e62d65c40b749609224fe43187d437cb37d19b3c011005 nonce=0 value=0 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0)
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Details: /reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73",
],
},
"message": "sender doesn't have enough funds to send tx. The upfront cost is: 210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x96171020921a6736a4e62d65c40b749609224fe43187d437cb37d19b3c011005 nonce=0 value=0 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0)
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Details: /reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73",
},
"id": 1,
"jsonrpc": "2.0",
"method": "eth_call",
"result": "0x",
}
`;

Expand All @@ -42,32 +20,10 @@ exports[`createHandlers > should handle eth_chainId 1`] = `

exports[`createHandlers > should handle eth_estimateGas 1`] = `
{
"error": {
"code": -32000,
"data": {
"errors": [
"sender doesn't have enough funds to send tx. The upfront cost is: 210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x96171020921a6736a4e62d65c40b749609224fe43187d437cb37d19b3c011005 nonce=0 value=0 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0)
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Details: /reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73",
],
},
"message": "sender doesn't have enough funds to send tx. The upfront cost is: 210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x96171020921a6736a4e62d65c40b749609224fe43187d437cb37d19b3c011005 nonce=0 value=0 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0)
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/
Details: /reference/tevm/errors/classes/insufficientfundserror/
Version: 1.1.0.next-73",
},
"id": 1,
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"result": "0x5208",
}
`;

Expand Down
120 changes: 60 additions & 60 deletions packages/memory-client/src/test/viem/__snapshots__/call.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,41 +1,68 @@
// Bun Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`call fee cap too high 1`] = `"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000084e6f745761676d69000000000000000000000000000000000000000000000000"`;

exports[`call fee cap too high 2`] = `[CallExecutionError: The fee cap (\`maxFeePerGas\` = 115792089237316195423570985008687907853269984665640564039457584007913.129639936 gwei) cannot be higher than the maximum allowed value (2^256-1).
exports[`call contract revert (contract error) 1`] = `
"Missing or invalid parameters.
Double check you have provided the correct parameters.
Raw Call Arguments:
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0xa0712d6800000000000000000000000000000000000000000000000000000000000001a4
maxFeePerGas: 115792089237316195423570985008687907853269984665640564039457584007913.129639936 gwei
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0xa0712d6800000000000000000000000000000000000000000000000000000000000001a4
Version: [email protected]]`;
Details: revert
exports[`call gas too low 1`] = `[CallExecutionError: Missing or invalid parameters.
Docs: https://tevm.sh/reference/tevm/errors/classes/reverterror/
Details: {"error":"revert","errorType":"EvmError"}
Version: 1.1.0.next-73
Version: [email protected]"
`;

exports[`call contract revert (insufficient params) 1`] = `
"Missing or invalid parameters.
Double check you have provided the correct parameters.
Raw Call Arguments:
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0xa0712d6800000000000000000000000000000000000000000000000000000000000001a4
gas: 100
data: 0xa0712d68
Details: revert
Docs: https://tevm.sh/reference/tevm/errors/classes/reverterror/
Details: {"error":"revert","errorType":"EvmError"}
Version: 1.1.0.next-73
Version: [email protected]]`;
Version: [email protected]"
`;

exports[`call gas too low 2`] = `[Function]`;
exports[`call duplicate address 1`] = `
"State for account "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2" is set multiple times.
exports[`call gas too high 1`] = `
{
"data": undefined,
}
Raw Call Arguments:
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0x06fdde03
State Override:
0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2:
stateDiff:
0x00000000000000000000000000000000000000000000000000000000000001a4: 0x00000000000000000000000000000000000000000000000000000000000001a4
0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2:
stateDiff:
0x00000000000000000000000000000000000000000000000000000000000001a4: 0x00000000000000000000000000000000000000000000000000000000000001a4
Version: [email protected]"
`;

exports[`call fee cap too high 1`] = `"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000084e6f745761676d69000000000000000000000000000000000000000000000000"`;

exports[`call fee cap too high 2`] = `[CallExecutionError: The fee cap (\`maxFeePerGas\` = 115792089237316195423570985008687907853269984665640564039457584007913.129639936 gwei) cannot be higher than the maximum allowed value (2^256-1).
Raw Call Arguments:
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0xa0712d6800000000000000000000000000000000000000000000000000000000000001a4
maxFeePerGas: 115792089237316195423570985008687907853269984665640564039457584007913.129639936 gwei
Version: [email protected]]`;

exports[`call gas fee is less than block base fee 1`] = `
{
"data": undefined,
Expand All @@ -48,66 +75,39 @@ exports[`call gas fee is less than block base fee 2`] = `
}
`;

exports[`call maxFeePerGas less than maxPriorityFeePerGas 1`] = `
"The provided tip (\`maxPriorityFeePerGas\` = 22 gwei) cannot be higher than the fee cap (\`maxFeePerGas\` = 20 gwei).
Raw Call Arguments:
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0xa0712d6800000000000000000000000000000000000000000000000000000000000001a4
maxFeePerGas: 20 gwei
maxPriorityFeePerGas: 22 gwei
Version: [email protected]"
exports[`call gas too high 1`] = `
{
"data": undefined,
}
`;

exports[`call contract revert (contract error) 1`] = `
"Missing or invalid parameters.
exports[`call gas too low 1`] = `[CallExecutionError: Missing or invalid parameters.
Double check you have provided the correct parameters.
Raw Call Arguments:
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0xa0712d6800000000000000000000000000000000000000000000000000000000000001a4
gas: 100
Details: revert
Docs: https://tevm.sh/reference/tevm/errors/classes/reverterror/
Details: {"error":"revert","errorType":"EvmError"}
Version: 1.1.0.next-73
Version: [email protected]"
`;

exports[`call contract revert (insufficient params) 1`] = `
"Missing or invalid parameters.
Double check you have provided the correct parameters.
Raw Call Arguments:
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0xa0712d68
Details: revert
Version: [email protected]]`;

Docs: https://tevm.sh/reference/tevm/errors/classes/reverterror/
Details: {"error":"revert","errorType":"EvmError"}
Version: 1.1.0.next-73
Version: [email protected]"
`;
exports[`call gas too low 2`] = `[Function]`;

exports[`call duplicate address 1`] = `
"State for account "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2" is set multiple times.
exports[`call maxFeePerGas less than maxPriorityFeePerGas 1`] = `
"The provided tip (\`maxPriorityFeePerGas\` = 22 gwei) cannot be higher than the fee cap (\`maxFeePerGas\` = 20 gwei).
Raw Call Arguments:
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0x06fdde03
State Override:
0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2:
stateDiff:
0x00000000000000000000000000000000000000000000000000000000000001a4: 0x00000000000000000000000000000000000000000000000000000000000001a4
0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2:
stateDiff:
0x00000000000000000000000000000000000000000000000000000000000001a4: 0x00000000000000000000000000000000000000000000000000000000000001a4
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2
data: 0xa0712d6800000000000000000000000000000000000000000000000000000000000001a4
maxFeePerGas: 20 gwei
maxPriorityFeePerGas: 22 gwei
Version: [email protected]"
`;
Expand Down
9 changes: 7 additions & 2 deletions packages/memory-client/src/test/viem/call.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ beforeEach(async () => {
mc = createMemoryClient({
common: mainnet,
fork: {
transport: transports.mainnet,
transport: {
request: (request) => {
console.log(request)
return transports.mainnet.request(request) as any
},
},
blockTag: forkBlock,
},
})
Expand All @@ -45,7 +50,7 @@ beforeEach(async () => {
const account = privateKeyToAccount('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80')

describe('call', () => {
it.todo(
it(
'should work',
async () => {
expect(
Expand Down
Loading

0 comments on commit 42590c1

Please sign in to comment.