Skip to content

Commit

Permalink
chore: Add hardhat and viem based E2E test suite (#2016)
Browse files Browse the repository at this point in the history
* chore: Add hardhat e2e test suite for precompiles

This adds a tests/e2e-evm hardhat based e2e test suite for testing EVM
and EVM<>Cosmos workflows.  This will be used to drive and test the
implementation of precompiles with a focus on e2e workflows.

The hardhat and kvtool networks are configured to run in CI to ensure
continuous support for both networks is not broken.  The hardhat network
is used to ensure compatibility between Kava and other EVM's, as well as
offer better support for unit testing supporting and example contracts.

The kvtool network runs a Kava network for testing the EVM
implementation on Kava and testing stateful precompiles.

* chore: Improve hardhat configuration

We add correct solidity compiler settings for the kava network, add
kvtool funded accounts, and match the accounts & balances on the hardhat
network.

The consistency of accounts across networks will be important for
testing.

* chore: Add hardhat viem extensions

This adds customizations to the hardhat-viem extension to allow
connections with kvtool (or other custom chains) and allow default
values to be set when using viem from the hardhat runtime interface
(hre).

* chore: Add wallet tests for whale and user

This adds two exported addresses matching the hardhat account
configuration for the hardhat and kvtool network.  In addition, we
assert that both these addresses can sign and successfully send
transactions which ensures the private keys and balances are correctly
configured.

* chore: Update npm test commands

This adds a test-hardhat and test-kvtool command that selects the proper
network and runs typechecks.

In addition, npm test is updated to run test-hardhat, then test-kvtool.
The hardhat tests are run first to fail fast, and the test-kvtool tests
are run after as tests that pass hardhat should pass on kvtool.
However, kvtool will target additional tests that will not be run on the
hardhat network.

* chore: Update to latest kvtool submodule

This brings in a docker-compose.yaml update that removes the obsolete
version field.

* chore: Simpify and clean dependencies

This removes the meta and setup toolbox package in favor of specifying
major depdencies explicitly which allows finer grain control of
dependency management in addition to removing dependencies that are not
required for this project.

* chore: Update tsconfig for node 20 support

This updates the lib, target, and module configuration for the most up
to date native support when compiling and running javascript against
node 20.

* chore: Add eslint with type checking support

This adds and configures eslint with typescript and type checking
support in addition to resolving all lint errors.

* chore: Add prettier for ts/js/sol formatting

This adds a prettier config and npm run commands to check and fix
formatting issues.

* chore: Add solhint for linting solidity contracts

This adds solhint for linting future contracts used for testing.

* chore: Ignore pretteier config for linting

* chore: Add solidity plugin for prettier

Prettier requires a plugin with configuration to format sol files.

* chore: Finish e2e-evm continuous integration

This refactors the e2e-evm tests to run in a single job with the hardhat
network running first to fail fast and trigger any type errors.  In
addition, contracts used to test against kvtool may be unit testing only
in the hardhat network, etc.

In addition, a curl check is added to ensure the EVM JSON-RPC is serving
requests.  This endpoint can take ~30 seconds to come online after the
kvtool server starts.  Curl is configured to check every 5 seconds and
retry 12 times over 60 seconds if the first request is not successful.

Linting and formatting checks are also added via eslint,
typescript-eslint with advanced type check rules, and prettier.

Solhint is installed, but errors without any files so is not configured
to run in CI yet.

* chore: Rollback kvtool change to fix e2e tests

The e2e tests have not yet been updated for the latest kvtool oops.

* chore: Ignore unused expressions in test files

Adding this ignore allows expressions like expect(foo).to.be.defined
to pass linting that is common is chai assertions.  We only ignore
**/*.test.ts files since non-test files should not have assertions.
  • Loading branch information
nddeluca authored Sep 6, 2024
1 parent 7b41265 commit b8428be
Show file tree
Hide file tree
Showing 17 changed files with 6,480 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,48 @@ jobs:
run: make test
- name: run e2e tests
run: make docker-build test-e2e
test-e2e-evm:
runs-on: ubuntu-latest
steps:
- name: Checkout current commit
uses: actions/checkout@v4
with:
submodules: true
- name: Setup nodejs
uses: actions/setup-node@v3
with:
cache: npm
node-version-file: .tool-versions
cache-dependency-path: tests/e2e-evm/package-lock.json
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
cache-dependency-path: |
go.sum
tests/e2e/kvtool/go.sum
- name: Install npm dependencies
run: npm install
working-directory: tests/e2e-evm
- name: Run test suite against hardhat network
run: npm run test-hardhat
working-directory: tests/e2e-evm
- name: Build local image
run: make docker-build
- name: Install kvtool
run: make -C tests/e2e/kvtool install
- name: Generate kava config
run: kvtool testnet gen-config kava --kava.configTemplate $(sed -nr "s/E2E_KVTOOL_KAVA_CONFIG_TEMPLATE=\"(.*)\"/\1/p" tests/e2e/.env)
- name: Start kava chain
run: kvtool testnet up -d
- name: Wait for JSON RPC to start
run: "curl --retry-all-errors --retry 12 --retry-delay 5 -X POST -H \"Content-Type: application/json\" http://127.0.0.1:8545"
- name: Run test suite against kvtool network
run: npm run test-kvtool
working-directory: tests/e2e-evm
- name: Shutdown kava
if: always()
run: kvtool testnet down
fuzz:
runs-on: ubuntu-latest
steps:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,25 @@ jobs:
with:
version: ${{ env.GOLANGCI_VERSION }}
args: -v -c .golangci.yml --new-from-rev ${{ env.REV }}
e2e-evm-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout current commit
uses: actions/checkout@v4
with:
submodules: true
- name: Setup nodejs
uses: actions/setup-node@v3
with:
cache: npm
node-version-file: .tool-versions
cache-dependency-path: tests/e2e-evm/package-lock.json
- name: Install npm dependencies
run: npm install
working-directory: tests/e2e-evm
- name: Run linter
run: npm run lint
working-directory: tests/e2e-evm
- name: Run formatter
run: npm run prettier
working-directory: tests/e2e-evm
17 changes: 17 additions & 0 deletions tests/e2e-evm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules
.env

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

# Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337
1 change: 1 addition & 0 deletions tests/e2e-evm/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json
3 changes: 3 additions & 0 deletions tests/e2e-evm/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "solhint:recommended"
}
1 change: 1 addition & 0 deletions tests/e2e-evm/.solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
21 changes: 21 additions & 0 deletions tests/e2e-evm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# E2E EVM

This is a E2E test suite focused on testing EVM and EVM <> Cosmos integrations for the Kava protocol and blockchain.

This test suite uses viem as the main API used for interacting with the EVM and Ethereum JSON RPC endpoints.

## Networks

The test suite runs on multiple networks to test compatibility with other EVM's and offer extended testing capabilities when required.

### Hardhat

```
npx hardhat test --network hardhat
```

### Kvtool

```
npx hardhat test --network kvtool
```
30 changes: 30 additions & 0 deletions tests/e2e-evm/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
//...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
ignores: [
"eslint.config.mjs",
"prettier.config.mjs",
"artifacts/",
],
},
{
files: ["**/*.test.ts"],
rules: {
"@typescript-eslint/no-unused-expressions": "off",
},
},
);
68 changes: 68 additions & 0 deletions tests/e2e-evm/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { HardhatUserConfig, extendEnvironment } from "hardhat/config";
import "@nomicfoundation/hardhat-viem";
import { parseEther } from "viem";
import { extendViem } from "./test/extend";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";

//
// Chai setup
//
chai.use(chaiAsPromised);

//
// Load HRE extensions
//
extendEnvironment(extendViem);

// These accounts are defined in the kvtool/config/common/addresses.json.
//
// The balances match the set balances in kvtool and these accounts are used for both the hardhat and kvtool networks.
// This ensures test consistency when running against either network.
const accounts = [
// 0x03db6b11f47d074a532b9eb8a98ab7ada5845087
// kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a
//
// jq -r '.kava.users.whale2.mnemonic' < tests/e2e/kvtool/config/common/addresses.json | kava keys add whale2 --eth --recover
// kava keys unsafe-export-eth-key whale2
{
privateKey: "AA50F4C6C15190D9E18BF8B14FC09BFBA0E7306331A4F232D10A77C2879E7966",
balance: parseEther("1000000").toString(),
},

// 0x7bbf300890857b8c241b219c6a489431669b3afa
// kava10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t
//
// jq -r '.kava.users.user.mnemonic' < tests/e2e/kvtool/config/common/addresses.json | kava keys add user --eth --recover
// kava keys unsafe-export-eth-key user
{
privateKey: "9549F115B0A21E5071A8AEC1B74AC093190E18DD83D019AC6497B0ADFBEFF26D",
balance: parseEther("1000").toString(),
},
];

const config: HardhatUserConfig = {
solidity: {
version: "0.8.24",
settings: {
evmVersion: "berlin", // The current hardfork of kava mainnet
optimizer: {
enabled: false, // The contracts here are only for testing and not deployment to mainnet.
},
},
},
networks: {
hardhat: {
chainId: 31337, // The default hardhat network chain id
hardfork: "berlin", // The current hardfork of kava mainnet
accounts: accounts,
},
kvtool: {
chainId: 8888, // The evm chain id of the kvtool network
url: "http://127.0.0.1:8545",
accounts: accounts.map((account) => account.privateKey),
},
},
};

export default config;
Loading

0 comments on commit b8428be

Please sign in to comment.