Skip to content

Commit

Permalink
refactor(evm): clean up e2e tests (#1980)
Browse files Browse the repository at this point in the history
* fix: package json dependencies

* refactor: update ERC20 contract name

* chore: regenerate types

* Update README.md

* Update setup.ts

* refactor: clean up tests

---------

Co-authored-by: Unique Divine <[email protected]>
  • Loading branch information
k-yang and Unique-Divine authored Jul 31, 2024
1 parent ed12018 commit 3c73f03
Show file tree
Hide file tree
Showing 14 changed files with 4,328 additions and 197 deletions.
56 changes: 24 additions & 32 deletions e2e/evm/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# EVM Tests

Folder contains ethers.js test bundle which executes main
Nibiru EVM methods via JSON RPC.
Nibiru EVM methods via JSON RPC.

Contract [FunToken.sol](./contracts/FunToken.sol) represents
Contract [TestERC20.sol](./contracts/TestERC20.sol) represents
simple ERC20 token with initial supply `1000,000 * 10e18` tokens.

Contract is compiled via HardHat into [json file](./contracts/FunTokenCompiled.json)
Contract is compiled via HardHat into [json file](./contracts/TestERC20Compiled.json)
with ABI and bytecode.


## Setup and Run

### Run Nibiru node
Expand All @@ -36,33 +35,26 @@ MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit lia
### Execute

```bash
npm test

> [email protected] test
> jest

PASS test/contract_infinite_loop_gas.test.js (8.617 s)
Infinite loop gas contract
✓ should fail due to out of gas error (4152 ms)

PASS test/contract_send_nibi.test.js (16.977 s)
Send NIBI from smart contract
✓ send nibi via "sendViaTransfer" method (4244 ms)
✓ send nibi via "sendViaSend" method (4239 ms)
✓ send nibi via "sendViaCall" method (4259 ms)

PASS test/erc20.test.js (8.845 s)
ERC-20 contract tests
✓ send, balanceOf (8765 ms)

PASS test/basic_queries.test.js
Basic Queries
✓ Simple transfer, balance check (4224 ms)

Test Suites: 4 passed, 4 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: 38.783 s, estimated 50 s
Ran all test suites.
❯ bun test
bun test v1.1.12 (43f0913c)

test/erc20.test.ts:
✓ ERC-20 contract tests > should send properly [8410.41ms]

test/basic_queries.test.ts:
✓ Basic Queries > Simple transfer, balance check [4251.02ms]

test/contract_infinite_loop_gas.test.ts:
✓ Infinite loop gas contract > should fail due to out of gas error [8281.13ms]

test/contract_send_nibi.test.ts:
✓ Send NIBI via smart contract > should send via transfer method [4228.80ms]
✓ Send NIBI via smart contract > should send via send method [4231.87ms]
✓ Send NIBI via smart contract > should send via transfer method [4213.43ms]

6 pass
0 fail
22 expect() calls
Ran 6 tests across 4 files. [38.08s]

```
Binary file modified e2e/evm/bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions e2e/evm/contracts/TestERC20.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// contracts/FunToken.sol
// contracts/TestERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract FunToken is ERC20 {
contract TestERC20 is ERC20 {

// Define the supply of FunToken: 1,000,000
// Define the supply of TestERC20: 1,000,000
uint256 constant initialSupply = 1000000 * (10**18);

// Constructor will be called on contract creation
constructor() ERC20("FunToken", "FUN") {
constructor() ERC20("TestERC20", "FOO") {
_mint(msg.sender, initialSupply);
}
}
Loading

0 comments on commit 3c73f03

Please sign in to comment.