diff --git a/.forge-snapshots/Increment counter number.snap b/.forge-snapshots/Increment counter number.snap index 64cea38..5f8239b 100644 --- a/.forge-snapshots/Increment counter number.snap +++ b/.forge-snapshots/Increment counter number.snap @@ -1 +1 @@ -26304 \ No newline at end of file +26263 \ No newline at end of file diff --git a/.forge-snapshots/Set counter number.snap b/.forge-snapshots/Set counter number.snap index 44d33ec..1a947f3 100644 --- a/.forge-snapshots/Set counter number.snap +++ b/.forge-snapshots/Set counter number.snap @@ -1 +1 @@ -26394 \ No newline at end of file +26337 \ No newline at end of file diff --git a/docs/autogen/book.toml b/docs/autogen/book.toml index 5677d7a..9ef6709 100644 --- a/docs/autogen/book.toml +++ b/docs/autogen/book.toml @@ -6,7 +6,7 @@ title = "" no-section-label = true additional-js = ["solidity.min.js"] additional-css = ["book.css"] -git-repository-url = "https://github.com/gretzke/foundry-template" +git-repository-url = "https://github.com/Uniswap/foundry-template" [output.html.fold] enable = true diff --git a/docs/autogen/src/SUMMARY.md b/docs/autogen/src/SUMMARY.md index 332e1a1..5890735 100644 --- a/docs/autogen/src/SUMMARY.md +++ b/docs/autogen/src/SUMMARY.md @@ -1,6 +1,6 @@ # Summary - [Home](README.md) # src - - [❱ interface](src/interface/README.md) - - [ICounter](src/interface/ICounter.sol/interface.ICounter.md) + - [❱ interfaces](src/interfaces/README.md) + - [ICounter](src/interfaces/ICounter.sol/interface.ICounter.md) - [Counter](src/Counter.sol/contract.Counter.md) diff --git a/docs/autogen/src/src/Counter.sol/contract.Counter.md b/docs/autogen/src/src/Counter.sol/contract.Counter.md index 0366122..150384a 100644 --- a/docs/autogen/src/src/Counter.sol/contract.Counter.md +++ b/docs/autogen/src/src/Counter.sol/contract.Counter.md @@ -1,8 +1,8 @@ # Counter -[Git Source](https://github.com/Uniswap/foundry-template/blob/6ed2d53f10b4739f84426a12bef01482d7a2e669/src/Counter.sol) +[Git Source](https://github.com/Uniswap/foundry-template/blob/0864bd3fda3ae2b97362ae80691cd59ca9cf5090/src/Counter.sol) **Inherits:** -[ICounter](/src/interface/ICounter.sol/interface.ICounter.md) +[ICounter](/src/interfaces/ICounter.sol/interface.ICounter.md) ## State Variables diff --git a/docs/autogen/src/src/README.md b/docs/autogen/src/src/README.md index 1b1cc23..c0bac33 100644 --- a/docs/autogen/src/src/README.md +++ b/docs/autogen/src/src/README.md @@ -1,5 +1,5 @@ # Contents -- [interface](/src/interface) +- [interfaces](/src/interfaces) - [Counter](Counter.sol/contract.Counter.md) diff --git a/docs/autogen/src/src/interface/IVersioned.sol/interface.IVersioned.md b/docs/autogen/src/src/interface/IVersioned.sol/interface.IVersioned.md deleted file mode 100644 index edc2c3e..0000000 --- a/docs/autogen/src/src/interface/IVersioned.sol/interface.IVersioned.md +++ /dev/null @@ -1,18 +0,0 @@ -# IVersioned -[Git Source](https://github.com/gretzke/foundry-template/blob/952489c408f511dc764c05d3a2a21ded78da224f/src/interface/IVersioned.sol) - - -## Functions -### version - - -```solidity -function version() external pure returns (string memory); -``` -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|``|`string`|The version of the contract| - - diff --git a/docs/autogen/src/src/interface/ICounter.sol/interface.ICounter.md b/docs/autogen/src/src/interfaces/ICounter.sol/interface.ICounter.md similarity index 79% rename from docs/autogen/src/src/interface/ICounter.sol/interface.ICounter.md rename to docs/autogen/src/src/interfaces/ICounter.sol/interface.ICounter.md index 98a74ba..a5347fb 100644 --- a/docs/autogen/src/src/interface/ICounter.sol/interface.ICounter.md +++ b/docs/autogen/src/src/interfaces/ICounter.sol/interface.ICounter.md @@ -1,5 +1,5 @@ # ICounter -[Git Source](https://github.com/Uniswap/foundry-template/blob/6ed2d53f10b4739f84426a12bef01482d7a2e669/src/interface/ICounter.sol) +[Git Source](https://github.com/Uniswap/foundry-template/blob/0864bd3fda3ae2b97362ae80691cd59ca9cf5090/src/interfaces/ICounter.sol) ## Functions diff --git a/docs/autogen/src/src/interface/README.md b/docs/autogen/src/src/interfaces/README.md similarity index 100% rename from docs/autogen/src/src/interface/README.md rename to docs/autogen/src/src/interfaces/README.md diff --git a/foundry.toml b/foundry.toml index 3b27b64..b1b13cb 100644 --- a/foundry.toml +++ b/foundry.toml @@ -4,7 +4,7 @@ out = "out" libs = ["lib"] optimizer = true optimizer_runs = 999999 -via_ir = false +via_ir = true solc = "0.8.26" verbosity = 2 ffi = true @@ -19,6 +19,14 @@ remappings = [ "@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts" ] +additional_compiler_profiles = [ + { name = "test", via_ir = false } +] + +compilation_restrictions = [ + { paths = "test/**", via_ir = false } +] + [profile.default.fuzz] runs = 1000 diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index 216f766..30a7288 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -3,13 +3,16 @@ pragma solidity 0.8.26; import 'forge-std/Script.sol'; -import {Counter} from 'src/Counter.sol'; +import {ICounter} from '../src/interfaces/ICounter.sol'; contract Deploy is Script { using stdJson for string; - function run() public returns (Counter) { + function run() public returns (ICounter counter) { uint256 initialNumber = 5; - return new Counter(initialNumber); + bytes memory bytecode = abi.encodePacked(vm.getCode('Counter.sol:Counter'), abi.encode(initialNumber)); + assembly { + counter := create(0, add(bytecode, 0x20), mload(bytecode)) + } } } diff --git a/script/util/doc_gen.sh b/script/util/doc_gen.sh index 15f35c5..c6f4eae 100755 --- a/script/util/doc_gen.sh +++ b/script/util/doc_gen.sh @@ -1,5 +1,7 @@ #!/bin/bash - +set -e +forge build +rm -rf docs/autogen # generate docs forge doc -b -o docs/autogen @@ -9,12 +11,19 @@ files=$(git diff --name-only -- 'docs/autogen/*') # Loop over each file for file in $files; do - # Get the diff for the file, only lines that start with - or + - diff=$(git diff $file | grep '^[+-][^+-]') - # Check if there are any other changes in the diff besides the commit hash (in that case the file has more than 1 line that changed, one minus one plus) - if [[ $(echo "$diff" | wc -l) -eq 2 ]]; then - # If there are no other changes, discard the changes for the file - git reset HEAD $file - git checkout -- $file + # Check if the file exists + if [[ -f $file ]]; then + # Get the diff for the file, strip metadata and only keep lines that start with - or + + diff=$(git diff $file | sed '/^diff --git/d; /^index /d; /^--- /d; /^\+\+\+ /d; /^@@ /d' | grep '^[+-]') + + # Filter lines that start with -[Git Source] or +[Git Source] + filtered_diff=$(echo "$diff" | grep '^\-\[Git Source\]\|^\+\[Git Source\]' || true) + + # Compare the original diff with the filtered diff + if [[ "$diff" == "$filtered_diff" ]]; then + # If they are equal, discard the changes for the file + git reset HEAD $file + git checkout -- $file + fi fi done \ No newline at end of file diff --git a/src/Counter.sol b/src/Counter.sol index 3362e98..c04f600 100644 --- a/src/Counter.sol +++ b/src/Counter.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.26; -import {ICounter} from './interface/ICounter.sol'; +import {ICounter} from './interfaces/ICounter.sol'; contract Counter is ICounter { uint256 public number; diff --git a/src/interface/ICounter.sol b/src/interfaces/ICounter.sol similarity index 100% rename from src/interface/ICounter.sol rename to src/interfaces/ICounter.sol diff --git a/test/Counter.t.sol b/test/Counter.t.sol index 084b23d..e23ed0d 100644 --- a/test/Counter.t.sol +++ b/test/Counter.t.sol @@ -4,15 +4,15 @@ pragma solidity 0.8.26; import {GasSnapshot} from 'forge-gas-snapshot/GasSnapshot.sol'; import 'forge-std/Test.sol'; +import {CounterDeployer, ICounter} from './deployers/CounterDeployer.sol'; import {Deploy} from 'script/Deploy.s.sol'; -import {Counter} from 'src/Counter.sol'; -abstract contract Deployed is Test { - Counter counter; +abstract contract Deployed is CounterDeployer { + ICounter counter; function setUp() public virtual { uint256 initialNumber = 10; - counter = new Counter(initialNumber); + counter = deploy(initialNumber); } } @@ -40,7 +40,7 @@ contract CounterTest_Deployed is Deployed, GasSnapshot { } contract DeploymentTest is Test { - Counter counter; + ICounter counter; function setUp() public virtual { counter = new Deploy().run(); diff --git a/test/deployers/CounterDeployer.sol b/test/deployers/CounterDeployer.sol new file mode 100644 index 0000000..e00065e --- /dev/null +++ b/test/deployers/CounterDeployer.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.23; + +import {ICounter} from '../../src/interfaces/ICounter.sol'; +import {Test} from 'forge-std/Test.sol'; + +contract CounterDeployer is Test { + function deploy(uint256 initialNumber) internal returns (ICounter counter) { + bytes memory bytecode = abi.encodePacked(vm.getCode('Counter.sol:Counter'), abi.encode(initialNumber)); + assembly { + counter := create(0, add(bytecode, 0x20), mload(bytecode)) + } + } +}