Skip to content

Commit

Permalink
⚡ Initialize testing suite
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Sep 10, 2023
1 parent 2f51729 commit a9af998
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "My Codespace",
"postCreateCommand": "curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundryup"
}
2 changes: 2 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tester:test(string) (runs: 256, μ: 63252, ~: 69216)
TesterTest:testTest() (gas: 27690)
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: ci

on: [push]

jobs:
tests:
name: Forge Testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: dependencies
run: forge install
- name: tests
run: forge test

snapshot:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: dependencies
run: forge install
- name: check contract sizes
run: forge build --sizes
- name: check gas snapshots
run: forge snapshot --check

scripts:
strategy:
fail-fast: true
name: Run Unix Scripts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: dependencies
run: forge build --sizes
continue-on-error: true
- name: Run scripts
run: |
ls -lsa
ls script/
for file in script/*; do
forge script $file
done
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
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# zenplate
The simplest foundry template for contract testing.
# zenplate [![tests](https://github.com/z0r0z/zenplate/actions/workflows/ci.yml/badge.svg?label=tests)](https://github.com/z0r0z/zenplate/actions/workflows/ci.yml) [![Foundry][foundry-badge]][foundry] [![License: AGPL-3.0-only][license-badge]][license]![solidity](https://img.shields.io/badge/solidity-%5E0.8.19-black)

[foundry]: https://getfoundry.sh/
[foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg
[license]: https://opensource.org/license/agpl-v3/
[license-badge]: https://img.shields.io/badge/License-AGPL-black.svg

A very simple foundry template for contract testing.

### Usage

**Building & Testing**

Build the foundry project with `forge build`. Run tests with `forge test`. Measure gas with `forge snapshot`. Format with `forge fmt`.

### GitHub Actions

This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull
request made to the `main` branch.

You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).

### Blueprint

```txt
lib
├─ forge-std — https://github.com/foundry-rs/forge-std
scripts
├─ Deploy.s.sol — Example Contract Deployment Script
src
├─ Tester — Test Contract
test
└─ Tester.t - Testing Contract
### Notable Mentions
- [femplate](https://github.com/refcell/femplate)
- [foundry-template](https://github.dev/PaulRBerg/foundry-template)
### Disclaimer
_These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. The creators are not liable for any of the foregoing. Users should proceed with caution and use at their own risk._
See [LICENSE](./LICENSE) for more details.
10 changes: 10 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[profile.default]
solc = "0.8.19"
optimizer_runs = 9_999_999

remappings = [
"@forge=lib/forge-std/src/"
]

[rpc_endpoints]
mainnet = "https://rpc.ankr.com/eth"
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 705263
13 changes: 13 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;

import {Script} from "@forge/Script.sol";
import {Tester} from "src/Tester.sol";

contract Deploy is Script {
function run() public payable returns (Tester tester) {
vm.startBroadcast();
tester = new Tester();
vm.stopBroadcast();
}
}
14 changes: 0 additions & 14 deletions src/Test.sol

This file was deleted.

14 changes: 14 additions & 0 deletions src/Tester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;

contract Tester {
event Tested(string _data);

string public data;

function test(string calldata _data) public payable {
data = _data;

emit Tested(_data);
}
}
15 changes: 15 additions & 0 deletions test/Tester.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;

import "../src/Tester.sol";
import "@forge/Test.sol";

contract TesterTest is Test {
Tester immutable tester = new Tester();

function setup() public {}

function testTest() public {
tester.test("ommm");
}
}

0 comments on commit a9af998

Please sign in to comment.