Skip to content

Commit

Permalink
feat(evm): debug_traceCall method implemented (#2022)
Browse files Browse the repository at this point in the history
* feat(evm): debug_traceCall method implemented

* chore: cleanup

* chore: changelog update

* test(evm): added api backend test for debug_traceCall
  • Loading branch information
onikonychev authored Sep 5, 2024
1 parent e2bc002 commit b1aac01
Show file tree
Hide file tree
Showing 14 changed files with 769 additions and 174 deletions.
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)
}

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/

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

0 comments on commit b1aac01

Please sign in to comment.