Skip to content

Commit

Permalink
Add foundry integrated with hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
gnpar committed Mar 20, 2024
1 parent d67d546 commit 126b16e
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
with:
node-version: "20"
cache: "npm"
- uses: foundry-rs/foundry-toolchain@v1
- run: npm ci
- run: npx hardhat compile
- run: npx hardhat size-contracts
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ cache
artifacts
build

# foundry files
cache_forge
out

.openzeppelin
.DS_Store
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
6 changes: 6 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = 'contracts'
out = 'out'
libs = ['node_modules', 'lib']
test = 'test'
cache_path = 'cache_forge'
14 changes: 14 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ require("@openzeppelin/hardhat-upgrades");
require("hardhat-dependency-compiler");
require("hardhat-contract-sizer");
require("solidity-coverage");
require("@nomicfoundation/hardhat-foundry");

// const exec = require("util").promisify(require("child_process").exec);
const { execSync } = require("child_process");
const { task } = require("hardhat/config");
const { TASK_TEST } = require("hardhat/builtin-tasks/task-names");

task(TASK_TEST, async function (args, hre, runSuper) {
// Run forge tests
await execSync("forge test", { stdio: "inherit" });

// Run tests as usual
await runSuper();
});

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
Expand Down
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at bb4cee
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@openzeppelin/hardhat-upgrades": "^3.0.2",
Expand All @@ -19,13 +20,13 @@
"eslint-config-prettier": "^9.1.0",
"hardhat": "^2.19.5",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-dependency-compiler": "^1.1.3",
"prettier": "^3.2.5",
"prettier-plugin-solidity": "^1.3.1",
"solhint": "^4.1.1",
"solhint-plugin-prettier": "0.1.0",
"ts-node": "^10.9.2",
"typescript": "^4.8.2",
"hardhat-dependency-compiler": "^1.1.3"
"typescript": "^4.8.2"
},
"dependencies": {
"@chainlink/contracts": "^0.6.1",
Expand Down
22 changes: 22 additions & 0 deletions test/StableSwapPayoutHandler.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.16;

import "forge-std/Test.sol";

import {StableSwapPayoutHandler} from "contracts/StableSwapPayoutHandler.sol";
import {IPolicyHolder} from "@ensuro/core/contracts/interfaces/IPolicyHolder.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";

contract TestStableSwapPayoutHandler is Test {
StableSwapPayoutHandler payoutHandler;

function setUp() public {
payoutHandler = new StableSwapPayoutHandler(IERC20Metadata(address(20)));
}

function test_SupportsInterface() public {
assertTrue(payoutHandler.supportsInterface(type(IPolicyHolder).interfaceId));
assertTrue(payoutHandler.supportsInterface(type(IERC721).interfaceId));
}
}

0 comments on commit 126b16e

Please sign in to comment.