Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "packages/contracts/lib/forge-std"]
path = packages/contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
3 changes: 3 additions & 0 deletions packages/contracts/.env.example
Comment thread
0xnonso marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PRIVATE_KEY=


34 changes: 34 additions & 0 deletions packages/contracts/.github/workflows/test.yml
Comment thread
0xnonso marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
19 changes: 18 additions & 1 deletion packages/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# Hardhat
# Foundry
cache/
out/
.env
broadcast/

# JS
node_modules/

#Hardhat files
cache_hardhat/
artifacts/
build/

#Hardhat plugin files
typechain-types/

#yarn
*.log
6 changes: 6 additions & 0 deletions packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = "src"
out = "out"
libs = ["node_modules", "lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
29 changes: 27 additions & 2 deletions packages/contracts/hardhat.config.ts
Comment thread
0xnonso marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import fs from "fs";
import { HardhatUserConfig } from 'hardhat/config'
import '@nomicfoundation/hardhat-toolbox'
import "hardhat-preprocessor"

function getRemappings() {
return fs
.readFileSync("remappings.txt", "utf8")
.split("\n")
.filter(Boolean)
.map((line) => line.trim().split("="));
}

const config: HardhatUserConfig = {
solidity: '0.8.18',
Expand All @@ -12,6 +22,21 @@ const config: HardhatUserConfig = {
typechain: {
outDir: 'build/typechain',
},
}
// This fully resolves paths for imports in the ./lib directory for Hardhat
preprocess: {
eachLine: (hre) => ({
transform: (line: string) => {
if (line.match(/^\s*import /i)) {
getRemappings().forEach(([find, replace]) => {
if (line.match(find)) {
line = line.replace(find, replace);
}
});
}
return line;
},
}),
},
};

export default config
export default config;
1 change: 1 addition & 0 deletions packages/contracts/lib/forge-std
Submodule forge-std added at f73c73
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"chai": "^4.3.7",
"ethers": "^5.0.0",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-preprocessor": "^0.1.5",
Comment thread
0xnonso marked this conversation as resolved.
Outdated
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typechain": "^8.1.1"
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
16 changes: 16 additions & 0 deletions packages/contracts/scripts/deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";
import {Inputs} from "../src/Inputs.sol";
contract DeployScript is Script {

function run() public {
vm.startBroadcast();

Inputs inputs = new Inputs();

vm.stopBroadcast();
console2.log(address(inputs));
}
}
35 changes: 35 additions & 0 deletions packages/contracts/test/Inputs.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console2} from "forge-std/Test.sol";
import {Inputs} from "../src/Inputs.sol";
import {Caller} from "../src/Caller.sol";

contract InputsTest is Test {
bytes constant randomBytes = '0x12345678907654321234567890987654321234567890987654';
address constant bob = address(0xb0b);
Inputs private inputs;
Caller private caller;

event BatchAppended(address sender);

function setUp() public {
inputs = new Inputs();
caller = new Caller(address(inputs));
}

function testEvent_BatchAppended() public {
// expect address `bob` to be emitted
vm.prank(bob, bob);
vm.expectEmit();
emit BatchAppended(bob);
inputs.appendBatch(randomBytes);
}

function testRevert_Caller() public {
// expect call to be reverted
vm.expectRevert();
caller.appendBatch(randomBytes);

}
}