Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(evm): debug_traceCall method implemented #2022

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#2017](https://github.com/NibiruChain/nibiru/pull/2017) - fix(evm): Fix DynamicFeeTx gas cap parameters
- [#2019](https://github.com/NibiruChain/nibiru/pull/2019) - chore(evm): enabled debug rpc api on localnet.
- [#2020](https://github.com/NibiruChain/nibiru/pull/2020) - test(evm): e2e tests for debug namespace
- [#2022](https://github.com/NibiruChain/nibiru/pull/2022) - feat(evm): debug_traceCall method implemented
- [#2023](https://github.com/NibiruChain/nibiru/pull/2023) - fix(evm)!: adjusted generation and parsing of the block bloom events

#### Dapp modules: perp, spot, oracle, etc
Expand Down
24 changes: 20 additions & 4 deletions e2e/evm/test/debug_queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, expect, it, beforeAll } from "@jest/globals"
import { TransactionReceipt, parseEther } from "ethers"
import { provider } from "./setup"
import { alice, deployContractTestERC20 } from "./utils"
import { alice, deployContractTestERC20, hexify } from "./utils"
import { TestERC20Compiled__factory } from "../types/ethers-contracts"

describe("debug queries", () => {
let contractAddress: string
Expand All @@ -28,16 +29,15 @@ describe("debug queries", () => {
blockHash = receipt.blockHash
}, 20e3)

// TODO: impl in EVM: remove skip
it.skip("debug_traceBlockByNumber", async () => {
it("debug_traceBlockByNumber", async () => {
const traceResult = await provider.send("debug_traceBlockByNumber", [
blockNumber,
])
expectTrace(traceResult)
})

// TODO: impl in EVM: remove skip
it.skip("debug_traceBlockByHash", async () => {
it("debug_traceBlockByHash", async () => {
const traceResult = await provider.send("debug_traceBlockByHash", [
blockHash,
])
Expand All @@ -50,6 +50,22 @@ describe("debug queries", () => {
expectTrace([{ result: traceResult }])
})

it("debug_traceCall", async () => {
const contractInterface = TestERC20Compiled__factory.createInterface()
const callData = contractInterface.encodeFunctionData("totalSupply")
const tx = {
to: contractAddress,
data: callData,
gas: hexify(1000_000),
}
const traceResult = await provider.send("debug_traceCall", [
tx,
"latest",
{},
])
expectTrace([{ result: traceResult }])
})

// TODO: impl in EVM: remove skip
it.skip("debug_getBadBlocks", async () => {
const traceResult = await provider.send("debug_getBadBlocks", [txHash])
Expand Down
5 changes: 5 additions & 0 deletions eth/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ type EVMBackend interface {
config *evm.TraceConfig,
block *tmrpctypes.ResultBlock,
) ([]*evm.TxTraceResult, error)
TraceCall(
txArgs evm.JsonTxArgs,
contextHeight rpc.BlockNumber,
config *evm.TraceConfig,
) (interface{}, error)
}

var _ BackendI = (*Backend)(nil)
Expand Down
18 changes: 18 additions & 0 deletions eth/rpc/backend/evm_query_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ func RegisterTraceTransaction(
Return(&evm.QueryTraceTxResponse{Data: data}, nil)
}

func RegisterTraceCall(
queryClient *mocks.EVMQueryClient, msgEthTx *evm.MsgEthereumTx,
) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
queryClient.On(
"TraceCall",
rpc.NewContextWithHeight(1),
&evm.QueryTraceTxRequest{
Msg: msgEthTx,
BlockNumber: 1,
ChainId: TEST_CHAIN_ID_NUMBER(),
BlockMaxGas: -1,
TraceConfig: &evm.TraceConfig{},
},
).
Return(&evm.QueryTraceTxResponse{Data: data}, nil)
}
Comment on lines +60 to +76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the RegisterTraceCall function.

The RegisterTraceCall function is crucial for setting up the mock environment for testing the TraceCall method. Here are some observations and suggestions:

  1. Hardcoded Data: The JSON data used in the mock response is hardcoded (line 63). While this is acceptable for unit tests, ensure that this data accurately represents what the TraceCall method would return in a real scenario.
  2. Error Scenarios: The function currently does not test how the TraceCall method behaves under error conditions. It would be beneficial to add tests that simulate various error scenarios to ensure robust error handling.
  3. Documentation: Adding comments to explain the purpose of each parameter and the expected behavior of the mock could help other developers understand the test setup more quickly.

Consider adding error scenarios to the tests, and improve documentation within the function to enhance readability and maintainability.


func RegisterTraceTransactionError(
queryClient *mocks.EVMQueryClient, msgEthTx *evm.MsgEthereumTx,
) {
Expand Down
13 changes: 13 additions & 0 deletions eth/rpc/backend/mocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Mocks Generation

To generate mocks, install `mockery` tool:
https://vektra.github.io/mockery/latest/installation/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address Markdownlint warning: Bare URL used.

To improve the markdown quality and comply with best practices, consider using a markdown link instead of a bare URL. For example:

[installation]: https://vektra.github.io/mockery/latest/installation/
Tools
Markdownlint

4-4: null
Bare URL used

(MD034, no-bare-urls)


```bash
cd x/evm
mockery \
--name QueryClient \
--filename evm_query_client.go \
--output ../../eth/rpc/backend/mocks \
--structname EVMQueryClient
```
Loading
Loading