-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(evm): e2e tests for debug namespace (#2020)
* test(evm): e2e tests for debug namespace * chore: changelog update
- Loading branch information
1 parent
7ae2443
commit 3e9bda9
Showing
5 changed files
with
123 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { describe, expect, it, beforeAll } from "@jest/globals" | ||
import { parseEther } from "ethers" | ||
import { provider } from "./setup" | ||
import { alice, deployERC20 } from "./utils" | ||
|
||
describe("debug queries", () => { | ||
let contractAddress | ||
let txHash | ||
let txIndex | ||
let blockNumber | ||
let blockHash | ||
|
||
beforeAll(async () => { | ||
// Deploy ERC-20 contract | ||
const contract = await deployERC20() | ||
contractAddress = await contract.getAddress() | ||
|
||
// Execute some contract TX | ||
const txResponse = await contract.transfer(alice, parseEther("0.01")) | ||
await txResponse.wait(1, 5e3) | ||
|
||
const receipt = await provider.getTransactionReceipt(txResponse.hash) | ||
txHash = txResponse.hash | ||
txIndex = txResponse.index | ||
blockNumber = receipt.blockNumber | ||
blockHash = receipt.blockHash | ||
}, 20e3) | ||
|
||
it("debug_traceBlockByNumber", async () => { | ||
const traceResult = await provider.send("debug_traceBlockByNumber", [ | ||
blockNumber, | ||
]) | ||
expectTrace(traceResult) | ||
}) | ||
|
||
it("debug_traceBlockByHash", async () => { | ||
const traceResult = await provider.send("debug_traceBlockByHash", [ | ||
blockHash, | ||
]) | ||
expectTrace(traceResult) | ||
}) | ||
|
||
it("debug_traceTransaction", async () => { | ||
const traceResult = await provider.send("debug_traceTransaction", [txHash]) | ||
expectTrace([{ result: traceResult }]) | ||
}) | ||
|
||
// TODO: implement that in EVM | ||
it.skip("debug_getBadBlocks", async () => { | ||
const traceResult = await provider.send("debug_getBadBlocks", [txHash]) | ||
expect(traceResult).toBeDefined() | ||
}) | ||
|
||
// TODO: implement that in EVM | ||
it.skip("debug_storageRangeAt", async () => { | ||
const traceResult = await provider.send("debug_storageRangeAt", [ | ||
blockNumber, | ||
txIndex, | ||
contractAddress, | ||
"0x0", | ||
100, | ||
]) | ||
expect(traceResult).toBeDefined() | ||
}) | ||
}) | ||
|
||
const expectTrace = (traceResult: any[]) => { | ||
expect(traceResult).toBeDefined() | ||
expect(traceResult.length).toBeGreaterThan(0) | ||
|
||
const trace = traceResult[0]["result"] | ||
expect(trace).toHaveProperty("failed", false) | ||
expect(trace).toHaveProperty("gas") | ||
expect(trace).toHaveProperty("returnValue") | ||
expect(trace).toHaveProperty("structLogs") | ||
} |
52 changes: 3 additions & 49 deletions
52
e2e/evm/test/basic_queries.test.ts → e2e/evm/test/eth_queries.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, expect, it } from "@jest/globals" | ||
import { toBigInt } from "ethers" | ||
import { account, provider } from "./setup" | ||
import { alice } from "./utils" | ||
|
||
describe("native transfer", () => { | ||
it("simple transfer, balance check", async () => { | ||
const amountToSend = toBigInt(5e12) * toBigInt(1e6) // unibi | ||
const senderBalanceBefore = await provider.getBalance(account) | ||
const recipientBalanceBefore = await provider.getBalance(alice) | ||
expect(senderBalanceBefore).toBeGreaterThan(0) | ||
expect(recipientBalanceBefore).toEqual(BigInt(0)) | ||
|
||
// Execute EVM transfer | ||
const transaction = { | ||
gasLimit: toBigInt(100e3), | ||
to: alice, | ||
value: amountToSend, | ||
} | ||
const txResponse = await account.sendTransaction(transaction) | ||
await txResponse.wait(1, 10e3) | ||
expect(txResponse).toHaveProperty("blockHash") | ||
|
||
const senderBalanceAfter = await provider.getBalance(account) | ||
const recipientBalanceAfter = await provider.getBalance(alice) | ||
|
||
// Assert balances with logging | ||
const tenPow12 = toBigInt(1e12) | ||
const gasUsed = 50000n // 50k gas for the transaction | ||
const txCostMicronibi = amountToSend / tenPow12 + gasUsed | ||
const txCostWei = txCostMicronibi * tenPow12 | ||
const expectedSenderWei = senderBalanceBefore - txCostWei | ||
console.debug("DEBUG should send via transfer method %o:", { | ||
senderBalanceBefore, | ||
amountToSend, | ||
expectedSenderWei, | ||
senderBalanceAfter, | ||
}) | ||
expect(senderBalanceAfter).toEqual(expectedSenderWei) | ||
expect(recipientBalanceAfter).toEqual(amountToSend) | ||
}, 20e3) | ||
}) |