Skip to content

Commit 6126724

Browse files
Separate debugTrace related tests to separate files
1 parent 30f75be commit 6126724

File tree

4 files changed

+275
-169
lines changed

4 files changed

+275
-169
lines changed

utils/e2e-tests/ts/tests/evm-tracing/debugTrace.ts

Lines changed: 0 additions & 169 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { beforeEach, describe, expect, it } from "vitest";
2+
import { RunNodeState, runNode } from "../../lib/node";
3+
import * as eth from "../../lib/ethViem";
4+
import { beforeEachWithCleanup } from "../../lib/lifecycle";
5+
import callee from "../../lib/abis/evmTracing/callee";
6+
import caller from "../../lib/abis/evmTracing/caller";
7+
import { encodeFunctionData } from "viem";
8+
import { customRpcRequest } from "../../lib/rpcUtils";
9+
10+
describe("test debug trace block by number or hash logic", () => {
11+
let node: RunNodeState;
12+
let publicClient: eth.PublicClientWebSocket;
13+
let devClients: eth.DevClientsWebSocket;
14+
beforeEachWithCleanup(async (cleanup) => {
15+
node = runNode(
16+
{
17+
args: ["--tracing-mode=debug", "--dev", "--tmp"],
18+
},
19+
cleanup.push,
20+
);
21+
22+
await node.waitForBoot;
23+
24+
publicClient = eth.publicClientFromNodeWebSocket(node, cleanup.push);
25+
devClients = eth.devClientsFromNodeWebSocket(node, cleanup.push);
26+
}, 60 * 1000);
27+
28+
let calleeAddress: `0x${string}`;
29+
let callerAddress: `0x${string}`;
30+
31+
beforeEach(async () => {
32+
const [alice, _] = devClients;
33+
34+
const deployCalleeContractTxHash = await alice.deployContract({
35+
abi: callee.abi,
36+
bytecode: callee.bytecode,
37+
});
38+
const deployCalleeContractTxReceipt =
39+
await publicClient.waitForTransactionReceipt({
40+
hash: deployCalleeContractTxHash,
41+
timeout: 18_000,
42+
});
43+
calleeAddress = deployCalleeContractTxReceipt.contractAddress!;
44+
45+
const deployCallerContractTxHash = await alice.deployContract({
46+
abi: caller.abi,
47+
bytecode: caller.bytecode,
48+
});
49+
const deployCallerContractTxReceipt =
50+
await publicClient.waitForTransactionReceipt({
51+
hash: deployCallerContractTxHash,
52+
timeout: 18_000,
53+
});
54+
callerAddress = deployCallerContractTxReceipt.contractAddress!;
55+
});
56+
57+
it("should trace block by number and hash", async () => {
58+
const [alice, _] = devClients;
59+
60+
const txHash = await alice.sendTransaction({
61+
to: callerAddress,
62+
data: encodeFunctionData({
63+
abi: caller.abi,
64+
functionName: "someAction",
65+
args: [calleeAddress, 7n],
66+
}),
67+
});
68+
const txReceipt = await publicClient.waitForTransactionReceipt({
69+
hash: txHash,
70+
});
71+
const blockNumberHex = txReceipt.blockNumber.toString(16);
72+
const blockHash = txReceipt.blockHash;
73+
74+
const responseByNumber = await customRpcRequest(
75+
node.meta.rpcUrlHttp,
76+
"debug_traceBlockByNumber",
77+
[blockNumberHex, { tracer: "callTracer" }],
78+
);
79+
80+
expect(responseByNumber.length).to.equal(1);
81+
expect(txHash).to.equal(responseByNumber[0].txHash);
82+
83+
const responseByHash = await customRpcRequest(
84+
node.meta.rpcUrlHttp,
85+
"debug_traceBlockByHash",
86+
[blockHash, { tracer: "callTracer" }],
87+
);
88+
89+
expect(responseByHash.length).to.equal(1);
90+
expect(txHash).to.equal(responseByHash[0].txHash);
91+
});
92+
});
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { beforeEach, describe, expect, it } from "vitest";
2+
import { RunNodeState, runNode } from "../../lib/node";
3+
import * as eth from "../../lib/ethViem";
4+
import { beforeEachWithCleanup } from "../../lib/lifecycle";
5+
import callee from "../../lib/abis/evmTracing/callee";
6+
import caller from "../../lib/abis/evmTracing/caller";
7+
import { encodeFunctionData } from "viem";
8+
import { customRpcRequest } from "../../lib/rpcUtils";
9+
10+
describe("test debug trace call logic", () => {
11+
let node: RunNodeState;
12+
let publicClient: eth.PublicClientWebSocket;
13+
let devClients: eth.DevClientsWebSocket;
14+
beforeEachWithCleanup(async (cleanup) => {
15+
node = runNode(
16+
{
17+
args: ["--tracing-mode=debug", "--dev", "--tmp"],
18+
},
19+
cleanup.push,
20+
);
21+
22+
await node.waitForBoot;
23+
24+
publicClient = eth.publicClientFromNodeWebSocket(node, cleanup.push);
25+
devClients = eth.devClientsFromNodeWebSocket(node, cleanup.push);
26+
}, 60 * 1000);
27+
28+
let calleeAddress: `0x${string}`;
29+
let callerAddress: `0x${string}`;
30+
31+
beforeEach(async () => {
32+
const [alice, _] = devClients;
33+
34+
const deployCalleeContractTxHash = await alice.deployContract({
35+
abi: callee.abi,
36+
bytecode: callee.bytecode,
37+
});
38+
const deployCalleeContractTxReceipt =
39+
await publicClient.waitForTransactionReceipt({
40+
hash: deployCalleeContractTxHash,
41+
timeout: 18_000,
42+
});
43+
calleeAddress = deployCalleeContractTxReceipt.contractAddress!;
44+
45+
const deployCallerContractTxHash = await alice.deployContract({
46+
abi: caller.abi,
47+
bytecode: caller.bytecode,
48+
});
49+
const deployCallerContractTxReceipt =
50+
await publicClient.waitForTransactionReceipt({
51+
hash: deployCallerContractTxHash,
52+
timeout: 18_000,
53+
});
54+
callerAddress = deployCallerContractTxReceipt.contractAddress!;
55+
});
56+
57+
it("should trace nested contract calls", async () => {
58+
const [alice, bob] = devClients;
59+
60+
const dummyTx = await alice.sendTransaction({
61+
to: bob.account.address,
62+
value: 1000n,
63+
});
64+
await publicClient.waitForTransactionReceipt({ hash: dummyTx });
65+
66+
const callParams = {
67+
to: callerAddress,
68+
data: encodeFunctionData({
69+
abi: caller.abi,
70+
functionName: "someAction",
71+
args: [calleeAddress, 7n],
72+
}),
73+
};
74+
75+
const response = await customRpcRequest(
76+
node.meta.rpcUrlHttp,
77+
"debug_traceCall",
78+
[callParams, "latest"],
79+
);
80+
81+
const logs: any[] = [];
82+
for (const log of response.structLogs) {
83+
if (logs.length === 1) {
84+
logs.push(log);
85+
}
86+
if (log.op === "RETURN") {
87+
logs.push(log);
88+
}
89+
}
90+
expect(logs).to.be.lengthOf(2);
91+
expect(logs[0].depth).to.be.equal(2);
92+
expect(logs[1].depth).to.be.equal(1);
93+
});
94+
});

0 commit comments

Comments
 (0)