diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..967424d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Test CI + +on: + push: + branches: [main] + tags: ["*"] + pull_request: + types: [opened, reopened, synchronize] + +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true + +jobs: + forge: + name: Run Forge Tests + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Install forge dependencies + run: forge install + + - name: Run tests + run: FOUNDRY_PROFILE=test forge test -vvv diff --git a/.gitignore b/.gitignore index f0e124c..4e0257d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,11 @@ cache/ out/ +#foundry test compilation files +cache +out +test-cache + # Ignores development broadcast logs !/broadcast /broadcast/*/31337/ @@ -13,4 +18,4 @@ docs/ # Dotenv file .env -.DS_Store \ No newline at end of file +.DS_Store diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..888d42d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/forge-std"] + path = lib/forge-std + url = https://github.com/foundry-rs/forge-std diff --git a/foundry.toml b/foundry.toml index 19d478a..b0c11be 100644 --- a/foundry.toml +++ b/foundry.toml @@ -3,5 +3,13 @@ src = "src" out = "out" libs = ["lib"] evm_version = "cancun" +test = 'test/foundry' +remappings = [ + 'forge-std/=lib/forge-std/src/', + ] + +[profile.test] +src = 'test/foundry' +cache_path='test-cache' # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/lib/forge-std b/lib/forge-std new file mode 160000 index 0000000..bb4ceea --- /dev/null +++ b/lib/forge-std @@ -0,0 +1 @@ +Subproject commit bb4ceea94d6f10eeb5b41dc2391c6c8bf8e734ef diff --git a/test/foundry/TestTstorish.t.sol b/test/foundry/TestTstorish.t.sol new file mode 100644 index 0000000..7771cb2 --- /dev/null +++ b/test/foundry/TestTstorish.t.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import {Test} from "forge-std/Test.sol"; + +import {Tstorish} from "../../src/Tstorish.sol"; + +contract TestTstorish is Test { + Tstorish tstorish; + + function setUp() public { + _deployTstorish(); + } + + function _deployTstorish() private { + tstorish = new Tstorish(); + } + + function testActivateTstore() public { + vm.expectRevert(abi.encodeWithSignature("TStoreAlreadyActivated()")); + tstorish.__activateTstore(); + } +}