Skip to content

Commit

Permalink
evm: forge init
Browse files Browse the repository at this point in the history
  • Loading branch information
nhynes committed Mar 7, 2024
1 parent 3272f5e commit af44b05
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: test

on:
pull_request:
push:
branches:
- main

env:
FOUNDRY_PROFILE: ci

jobs:
evm:
defaults:
run:
working-directory: ./evm
strategy:
fail-fast: true
name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "evm/lib/forge-std"]
path = evm/lib/forge-std
url = https://github.com/foundry-rs/forge-std
14 changes: 14 additions & 0 deletions evm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
11 changes: 11 additions & 0 deletions evm/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[profile.default]
solc_version = "0.8.23"
optimizer = false
via_ir = true

[fmt]
line_length = 100

[profile.release]
optimizer = true
optimizer_runs = 1_000_000_000
1 change: 1 addition & 0 deletions evm/lib/forge-std
Submodule forge-std added at ae570f
12 changes: 12 additions & 0 deletions evm/script/Counter.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";

contract CounterScript is Script {
function setUp() public {}

function run() public {
vm.broadcast();
}
}
14 changes: 14 additions & 0 deletions evm/src/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract Counter {
uint256 public number;

function setNumber(uint256 newNumber) public {
number = newNumber;
}

function increment() public {
number++;
}
}
24 changes: 24 additions & 0 deletions evm/test/Counter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";

contract CounterTest is Test {
Counter public counter;

function setUp() public {
counter = new Counter();
counter.setNumber(0);
}

function test_Increment() public {
counter.increment();
assertEq(counter.number(), 1);
}

function testFuzz_SetNumber(uint256 x) public {
counter.setNumber(x);
assertEq(counter.number(), x);
}
}

0 comments on commit af44b05

Please sign in to comment.