Skip to content

Commit e463c68

Browse files
committed
test(evm-e2e): add zero_gas_er20.test.ts; document localnet mnemonic and migrate EVM E2E tests to "bun:test", adding zero-gas ERC20 helpers and coverage.
1 parent b4d2f9a commit e463c68

17 files changed

+239
-47
lines changed

evm-e2e/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ JSON_RPC_ENDPOINT="http://127.0.0.1:8545"
3333
MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host"
3434
```
3535

36+
The `MNEMONIC` above is the same BIP-39 phrase used by
37+
`contrib/scripts/localnet.sh` to create the `validator` key on the
38+
`nibiru-localnet-0` chain. The `account` used in tests
39+
(`test/setup.ts`) is the EVM signer for that validator/dev account,
40+
which is funded in genesis and used to deploy contracts, pay gas, and
41+
fund other test wallets.
42+
3643
### Execute
3744

3845
```bash

evm-e2e/bun.lock

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

evm-e2e/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@typechain/hardhat": "^9.1.0",
2020
"@types/bun": "^1.2.5",
2121
"@types/jest": "^29.5.14",
22+
"@uniquedivine/jiyuu": "^0.0.2",
2223
"bun": "^1.2.5",
2324
"dotenv": "^16.4.5",
2425
"eslint": "^8.0.0",

evm-e2e/test/contract_infinite_loop_gas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "@jest/globals"
1+
import { describe, expect, it } from "bun:test"
22
import { toBigInt } from "ethers"
33

44
import { TEST_TIMEOUT } from "./setup"

evm-e2e/test/contract_send_nibi.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* The methods tested are from the smart contract,
1010
* "evm-e2e/contracts/SendReceiveNibi.sol".
1111
*/
12-
import { describe, expect, it } from "@jest/globals"
12+
import { describe, expect, it } from "bun:test"
1313
import { parseEther, toBigInt, Wallet } from "ethers"
1414

1515
import { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT } from "./setup"

evm-e2e/test/debug_queries.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeAll, describe, expect, it } from "@jest/globals"
1+
import { beforeAll, describe, expect, it } from "bun:test"
22
import { parseEther, TransactionReceipt } from "ethers"
33

44
import { TestERC20__factory } from "../types"
@@ -28,7 +28,7 @@ describe("debug queries", () => {
2828
txIndex = txResponse.index
2929
blockNumber = receipt.blockNumber
3030
blockHash = receipt.blockHash
31-
}, TEST_TIMEOUT)
31+
})
3232

3333
it("debug_traceBlockByNumber", async () => {
3434
const traceResult = await provider.send("debug_traceBlockByNumber", [

evm-e2e/test/erc20.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "@jest/globals"
1+
import { describe, expect, it } from "bun:test"
22
import { parseUnits, toBigInt, Wallet } from "ethers"
33

44
import { account, TEST_TIMEOUT } from "./setup"

evm-e2e/test/eth_queries.test.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it, jest } from "@jest/globals"
1+
import { describe, expect, it } from "bun:test"
22
import { AbiCoder, ethers, keccak256, parseEther } from "ethers"
33

44
import { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT } from "./setup"
@@ -13,12 +13,10 @@ import {
1313
} from "./utils"
1414

1515
describe("eth queries", () => {
16-
jest.setTimeout(TEST_TIMEOUT)
17-
1816
it("eth_accounts", async () => {
1917
const accounts = await provider.listAccounts()
2018
expect(accounts).not.toBeNull()
21-
})
19+
}, TEST_TIMEOUT)
2220

2321
it("eth_estimateGas", async () => {
2422
const tx = {
@@ -29,7 +27,7 @@ describe("eth queries", () => {
2927
const estimatedGas = await provider.estimateGas(tx)
3028
expect(estimatedGas).toBeGreaterThan(BigInt(0))
3129
expect(estimatedGas - INTRINSIC_TX_GAS).toBeLessThan(INTRINSIC_TX_GAS / BigInt(20))
32-
})
30+
}, TEST_TIMEOUT)
3331

3432
it("eth_feeHistory", async () => {
3533
const blockCount = 5 // Number of blocks in the requested history
@@ -46,18 +44,18 @@ describe("eth queries", () => {
4644
expect(feeHistory).toHaveProperty("gasUsedRatio")
4745
expect(feeHistory).toHaveProperty("oldestBlock")
4846
expect(feeHistory).toHaveProperty("reward")
49-
})
47+
}, TEST_TIMEOUT)
5048

5149
it("eth_gasPrice", async () => {
5250
const gasPrice = await provider.send("eth_gasPrice", [])
5351
expect(gasPrice).toBeDefined()
5452
expect(gasPrice).toEqual(hexify(1000000000000)) // 1 micronibi == 10^{12} wei
55-
})
53+
}, TEST_TIMEOUT)
5654

5755
it("eth_getBalance", async () => {
5856
const balance = await provider.getBalance(account.address)
5957
expect(balance).toBeGreaterThan(0)
60-
})
58+
}, TEST_TIMEOUT)
6159

6260
it("eth_getBlockByNumber, eth_getBlockByHash", async () => {
6361
const blockNumber = "latest"
@@ -75,7 +73,7 @@ describe("eth queries", () => {
7573
expect(blockByHash).toBeDefined()
7674
expect(blockByHash.hash).toEqual(blockByNumber.hash)
7775
expect(blockByHash.number).toEqual(blockByNumber.number)
78-
})
76+
}, TEST_TIMEOUT)
7977

8078
it("eth_getBlockTransactionCountByHash", async () => {
8179
const blockNumber = "latest"
@@ -87,7 +85,7 @@ describe("eth queries", () => {
8785
block.hash,
8886
])
8987
expect(parseInt(txCount)).toBeGreaterThanOrEqual(0)
90-
})
88+
}, TEST_TIMEOUT)
9189

9290
it("eth_getBlockTransactionCountByNumber", async () => {
9391
const blockNumber = "latest"
@@ -96,14 +94,14 @@ describe("eth queries", () => {
9694
[blockNumber],
9795
)
9896
expect(parseInt(txCount)).toBeGreaterThanOrEqual(0)
99-
})
97+
}, TEST_TIMEOUT)
10098

10199
it("eth_getCode", async () => {
102100
const contract = await deployContractSendNibi()
103101
const contractAddr = await contract.getAddress()
104102
const code = await provider.send("eth_getCode", [contractAddr, "latest"])
105103
expect(code).toBeDefined()
106-
})
104+
}, TEST_TIMEOUT)
107105

108106
it("eth_getFilterChanges", async () => {
109107
const currentBlock = await provider.getBlockNumber()
@@ -132,7 +130,7 @@ describe("eth queries", () => {
132130

133131
const success = await provider.send("eth_uninstallFilter", [filterId])
134132
expect(success).toBeTruthy()
135-
})
133+
}, TEST_TIMEOUT)
136134

137135
it("eth_getFilterLogs", async () => {
138136
const currentBlock = await provider.getBlockNumber()
@@ -158,7 +156,7 @@ describe("eth queries", () => {
158156
expect(changes[0]).toHaveProperty("address")
159157
expect(changes[0]).toHaveProperty("data")
160158
expect(changes[0]).toHaveProperty("topics")
161-
})
159+
}, TEST_TIMEOUT)
162160

163161
it("eth_getLogs", async () => {
164162
const currentBlock = await provider.getBlockNumber()
@@ -180,7 +178,7 @@ describe("eth queries", () => {
180178
expect(changes[0]).toHaveProperty("address")
181179
expect(changes[0]).toHaveProperty("data")
182180
expect(changes[0]).toHaveProperty("topics")
183-
})
181+
}, TEST_TIMEOUT)
184182

185183
it("eth_getProof", async () => {
186184
// Deploy ERC-20 contract
@@ -211,15 +209,15 @@ describe("eth queries", () => {
211209
expect(proof.storageProof[0]).toHaveProperty("value")
212210
expect(proof.storageProof[0]).toHaveProperty("proof")
213211
}
214-
})
212+
}, TEST_TIMEOUT)
215213

216214
it("eth_getStorageAt", async () => {
217215
const contract = await deployContractTestERC20()
218216
const contractAddr = await contract.getAddress()
219217

220218
const value = await provider.getStorage(contractAddr, 1)
221219
expect(value).toBeDefined()
222-
})
220+
}, TEST_TIMEOUT)
223221

224222
it("eth_getTransactionByBlockHashAndIndex, eth_getTransactionByBlockNumberAndIndex", async () => {
225223
// Execute EVM transfer
@@ -246,26 +244,26 @@ describe("eth queries", () => {
246244
expect(txByBlockNumber["from"]).toEqual(txByBlockHash["from"])
247245
expect(txByBlockNumber["to"]).toEqual(txByBlockHash["to"])
248246
expect(txByBlockNumber["value"]).toEqual(txByBlockHash["value"])
249-
})
247+
}, TEST_TIMEOUT)
250248

251249
it("eth_getTransactionByHash", async () => {
252250
const txResponse = await sendTestNibi()
253251
const txByHash = await provider.getTransaction(txResponse.hash)
254252
expect(txByHash).toBeDefined()
255253
expect(txByHash.hash).toEqual(txResponse.hash)
256-
})
254+
}, TEST_TIMEOUT)
257255

258256
it("eth_getTransactionCount", async () => {
259257
const txCount = await provider.getTransactionCount(account.address)
260258
expect(txCount).toBeGreaterThanOrEqual(0)
261-
})
259+
}, TEST_TIMEOUT)
262260

263261
it("eth_getTransactionReceipt", async () => {
264262
const txResponse = await sendTestNibi()
265263
const txReceipt = await provider.getTransactionReceipt(txResponse.hash)
266264
expect(txReceipt).toBeDefined()
267265
expect(txReceipt.hash).toEqual(txResponse.hash)
268-
})
266+
}, TEST_TIMEOUT)
269267

270268
it("eth_getUncleCountByBlockHash", async () => {
271269
const latestBlock = await provider.getBlockNumber()
@@ -274,33 +272,33 @@ describe("eth queries", () => {
274272
block.hash,
275273
])
276274
expect(parseInt(uncleCount)).toBeGreaterThanOrEqual(0)
277-
})
275+
}, TEST_TIMEOUT)
278276

279277
it("eth_getUncleCountByBlockNumber", async () => {
280278
const latestBlock = await provider.getBlockNumber()
281279
const uncleCount = await provider.send("eth_getUncleCountByBlockNumber", [
282280
latestBlock,
283281
])
284282
expect(parseInt(uncleCount)).toBeGreaterThanOrEqual(0)
285-
})
283+
}, TEST_TIMEOUT)
286284

287285
it("eth_maxPriorityFeePerGas", async () => {
288286
const maxPriorityGas = await provider.send("eth_maxPriorityFeePerGas", [])
289287
expect(parseInt(maxPriorityGas)).toBeGreaterThanOrEqual(0)
290-
})
288+
}, TEST_TIMEOUT)
291289

292290
it("eth_newBlockFilter", async () => {
293291
const filterId = await provider.send("eth_newBlockFilter", [])
294292
expect(filterId).toBeDefined()
295-
})
293+
}, TEST_TIMEOUT)
296294

297295
it("eth_newPendingTransactionFilter", async () => {
298296
const filterId = await provider.send("eth_newPendingTransactionFilter", [])
299297
expect(filterId).toBeDefined()
300-
})
298+
}, TEST_TIMEOUT)
301299

302300
it("eth_syncing", async () => {
303301
const syncing = await provider.send("eth_syncing", [])
304302
expect(syncing).toBeFalsy()
305-
})
303+
}, TEST_TIMEOUT)
306304
})

evm-e2e/test/native_transfer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "@jest/globals"
1+
import { describe, expect, it } from "bun:test"
22
import { parseEther, toBigInt } from "ethers"
33

44
import { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT } from "./setup"

evm-e2e/test/nibiru_oracle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from "@jest/globals"
1+
import { expect, test } from "bun:test"
22
import { toBigInt } from "ethers"
33

44
import { TEST_TIMEOUT } from "./setup"

0 commit comments

Comments
 (0)