Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add auto-generating basic abi tests for solidity interfaces #2018

Merged
merged 18 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
run: make docker-build test-e2e
test-e2e-evm:
runs-on: ubuntu-latest
env:
KAVA_TAG: local
steps:
- name: Checkout current commit
uses: actions/checkout@v4
Expand All @@ -58,6 +60,9 @@ jobs:
- name: Install npm dependencies
run: npm install
working-directory: tests/e2e-evm
- name: Run test suite against hardhat network
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Run test suite against hardhat network
- name: Compile contracts and create artifcats

Copy link
Member Author

@nddeluca nddeluca Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📠 🍝

run: npm run compile
working-directory: tests/e2e-evm
- name: Run test suite against hardhat network
run: npm run test-hardhat
working-directory: tests/e2e-evm
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ jobs:
- name: Install npm dependencies
run: npm install
working-directory: tests/e2e-evm
- name: Run solhint
run: npm run solhint
working-directory: tests/e2e-evm
- name: Compile contracts and create artifcats
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artif🐱🐱🐱🐱

Suggested change
- name: Compile contracts and create artifcats
- name: Compile contracts and create artifacts

run: npm run compile
working-directory: tests/e2e-evm
- name: Run linter
run: npm run lint
working-directory: tests/e2e-evm
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e-evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ npx hardhat test --network hardhat
```
npx hardhat test --network kvtool
```

## Running CI Locally

With act installed, the following commands will run the lint and e2e CI jobs locally.

```
act -W '.github/workflows/ci-lint.yml' -j e2e-evm-lint
act -W '.github/workflows/ci-default.yml' -j test-e2e-evm --bind
```

The `--bind` flag is required for volume mounts of docker containers correctly mount. Without this flag, volumes are mounted as an empty directory.
78 changes: 78 additions & 0 deletions tests/e2e-evm/contracts/ABI_BasicTests.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// solhint-disable one-contract-per-file
// solhint-disable no-empty-blocks
// solhint-disable payable-fallback

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

//
// Normal noop functions only with nonpayable, payable, view, and pure modifiers
//
interface NoopNoReceiveNoFallback {
function noopNonpayable() external;
function noopPayable() external payable;
function noopView() external view;
function noopPure() external pure;
}
contract NoopNoReceiveNoFallbackMock is NoopNoReceiveNoFallback {
function noopNonpayable() external {}
function noopPayable() external payable {}
function noopView() external view {}
function noopPure() external pure {}
}

//
// Added receive function (always payable)
//
interface NoopReceiveNoFallback is NoopNoReceiveNoFallback {
receive() external payable;
}
contract NoopReceiveNoFallbackMock is NoopReceiveNoFallback, NoopNoReceiveNoFallbackMock {
receive() external payable {}
}

//
// Added receive function and payable fallback
//
interface NoopReceivePayableFallback is NoopNoReceiveNoFallback {
receive() external payable;
fallback() external payable;
}
contract NoopReceivePayableFallbackMock is NoopReceivePayableFallback, NoopNoReceiveNoFallbackMock {
receive() external payable {}
fallback() external payable {}
}

//
// Added receive function and non-payable fallback
//
interface NoopReceiveNonpayableFallback is NoopNoReceiveNoFallback {
receive() external payable;
fallback() external;
}
contract NoopReceiveNonpayableFallbackMock is NoopReceiveNonpayableFallback, NoopNoReceiveNoFallbackMock {
receive() external payable {}
fallback() external {}
}

//
// Added payable fallback and no receive function
//
// solc-ignore-next-line missing-receive
interface NoopNoReceivePayableFallback is NoopNoReceiveNoFallback {
fallback() external payable;
}
// solc-ignore-next-line missing-receive
contract NoopNoReceivePayableFallbackMock is NoopNoReceivePayableFallback, NoopNoReceiveNoFallbackMock {
fallback() external payable {}
}

//
// Added non-payable fallback and no receive function
//
interface NoopNoReceiveNonpayableFallback is NoopNoReceiveNoFallback {
fallback() external;
}
contract NoopNoReceiveNonpayableFallbackMock is NoopNoReceiveNonpayableFallback, NoopNoReceiveNoFallbackMock {
fallback() external {}
}
6 changes: 5 additions & 1 deletion tests/e2e-evm/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
//...tseslint.configs.recommendedTypeChecked,
{
rules: {
eqeqeq: ["error", "smart"],
},
},
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e-evm/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { HardhatUserConfig, extendEnvironment } from "hardhat/config";
import "@nomicfoundation/hardhat-viem";
import { parseEther } from "viem";
import { extendViem } from "./test/extend";
import { extendViem } from "./test/extensions/viem";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import "hardhat-ignore-warnings";

//
// Chai setup
Expand Down Expand Up @@ -56,6 +57,11 @@ const config: HardhatUserConfig = {
chainId: 31337, // The default hardhat network chain id
hardfork: "berlin", // The current hardfork of kava mainnet
accounts: accounts,
//
// This is required for hardhat-viem to have the same behavior
// for reverted transactions as on Kava.
//
throwOnTransactionFailures: false,
},
kvtool: {
chainId: 8888, // The evm chain id of the kvtool network
Expand Down
Loading
Loading