forked from alchemyplatform/light-account
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 56c0a52
Showing
16 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
DEPLOYER_PRIVATE_KEY= | ||
|
||
RPC_URL_MAINNET= | ||
RPC_URL_GOERLI= | ||
|
||
ETHERSCAN_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Gas Estimates | ||
Generated via `bash utils/inspect.sh`. | ||
|
||
--- | ||
|
||
`forge test --gas-report --no-match-path "test/script/**/*"` | ||
| src/Counter.sol:Counter contract | | | | | | | ||
|----------------------------------|-----------------|-------|--------|-------|---------| | ||
| Deployment Cost | Deployment Size | | | | | | ||
| 77935 | 417 | | | | | | ||
| Function Name | min | avg | median | max | # calls | | ||
| increment | 22334 | 22334 | 22334 | 22334 | 1 | | ||
| number | 269 | 269 | 269 | 269 | 2 | | ||
| setNumber | 2338 | 8971 | 2338 | 22238 | 3 | | ||
|
||
|
||
|
||
`forge inspect src/Counter.sol:Counter gasestimates` | ||
```json | ||
{ | ||
"creation": { | ||
"codeDepositCost": "77800", | ||
"executionCost": "135", | ||
"totalCost": "77935" | ||
}, | ||
"external": { | ||
"increment()": "24434", | ||
"number()": "2269", | ||
"setNumber(uint256)": "22238" | ||
}, | ||
"internal": {} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- | ||
Borrowed from foundry. | ||
Thank you for your Pull Request. Please provide a description above and review | ||
the requirements below. | ||
Bug fixes and new features should include tests. | ||
--> | ||
|
||
## Motivation | ||
|
||
<!-- | ||
Explain the context and why you're making that change. What is the problem | ||
you're trying to solve? In some cases there is not a problem and this can be | ||
thought of as being the motivation for your change. | ||
If your PR solves a particular issue, tag that issue. | ||
--> | ||
|
||
## Solution | ||
|
||
<!-- | ||
Summarize the solution and provide any necessary context needed to understand | ||
the code change. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: sc-template Test CI | ||
|
||
on: [pull_request, workflow_dispatch] | ||
|
||
concurrency: | ||
group: ${{github.workflow}}-${{github.ref}} | ||
cancel-in-progress: true | ||
|
||
# Runs linter, tests, and inspection checker in parallel | ||
jobs: | ||
lint: | ||
name: Run Linter | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
- run: forge install | ||
|
||
- run: forge fmt --check | ||
|
||
check-inspect: | ||
name: Verify Inspections | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- run: forge install | ||
- run: bash ./utils/inspect.sh | ||
|
||
- run: git status --untracked-files=no --porcelain | ||
- run: git --no-pager diff | ||
|
||
- name: Check Inspections | ||
run: if [[ -n "$(git status --untracked-files=no --porcelain)" ]]; then echo "Inspection difference detected, verify tests are passing and run \`bash ./utils/inspect.sh\` to fix." && exit 1; fi | ||
|
||
test: | ||
name: Run Forge Tests | ||
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: Install forge dependencies | ||
run: forge install | ||
|
||
- name: Build project | ||
run: forge build | ||
|
||
- name: Run tests | ||
run: forge test -vvv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Foundry build and cache directories | ||
out/ | ||
cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
branch = v1.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Storage Layouts | ||
Generated via `bash utils/inspect.sh`. | ||
|
||
--- | ||
|
||
`forge inspect --pretty src/Counter.sol:Counter storage-layout` | ||
| Name | Type | Slot | Offset | Bytes | Contract | | ||
|--------|---------|------|--------|-------|-------------------------| | ||
| number | uint256 | 0 | 0 | 32 | src/Counter.sol:Counter | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"solidity.packageDefaultDependenciesContractsDirectory": "src", | ||
"solidity.packageDefaultDependenciesDirectory": "lib", | ||
"solidity.compileUsingRemoteVersion": "v0.8.14", | ||
"editor.formatOnSave": true, | ||
"[solidity]": { | ||
"editor.defaultFormatter": "JuanBlanco.solidity" | ||
}, | ||
"solidity.formatter": "forge", | ||
"search.exclude": { "lib": true } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[profile.default] | ||
solc = '0.8.14' | ||
via_ir = true | ||
src = 'src' | ||
out = 'out' | ||
test = 'test' | ||
libs = ['lib'] | ||
optimizer = true | ||
optimizer_runs = 10_000 | ||
|
||
[fuzz] | ||
runs = 5000 | ||
|
||
[rpc_endpoints] | ||
mainnet = "${RPC_URL_MAINNET}" | ||
goerli = "${RPC_URL_GOERLI}" | ||
|
||
[etherscan] | ||
mainnet = { key = "${ETHERSCAN_API_KEY}" } | ||
goerli = { key = "${ETHERSCAN_API_KEY}" } | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/tree/master/config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.14; | ||
|
||
import "forge-std/Script.sol"; | ||
|
||
contract CounterScript is Script { | ||
function setUp() public {} | ||
|
||
function run() public { | ||
vm.broadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"filter_paths": "lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.14; | ||
|
||
/// @title A public counter for anyone to use. | ||
contract Counter { | ||
uint256 public number; | ||
|
||
/// @notice Set the counter's number to a new value. | ||
/// @param newNumber The new number for the counter. | ||
function setNumber(uint256 newNumber) public { | ||
number = newNumber; | ||
} | ||
|
||
/// @notice Increase the counter's value by one. | ||
/// @dev The number is not in an unchecked block, so overflows will revert. | ||
function increment() public { | ||
number++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.14; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../src/Counter.sol"; | ||
|
||
contract CounterTest is Test { | ||
Counter public counter; | ||
|
||
function setUp() public { | ||
counter = new Counter(); | ||
counter.setNumber(0); | ||
} | ||
|
||
function testIncrement() public { | ||
counter.increment(); | ||
assertEq(counter.number(), 1); | ||
} | ||
|
||
function testSetNumber(uint256 x) public { | ||
counter.setNumber(x); | ||
assertEq(counter.number(), x); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
# Generate inspection files in MD format for all primary contracts in src. | ||
|
||
CONTRACT_FILES=($(find src -iname '*.sol' | sort)) | ||
|
||
rm .storagelayout.md | ||
rm .gasestimates.md | ||
|
||
echo "# Storage Layouts" >> .storagelayout.md | ||
echo "Generated via \`bash utils/inspect.sh\`." >> .storagelayout.md | ||
echo "" >> .storagelayout.md | ||
echo "---" >> .storagelayout.md | ||
echo "" >> .storagelayout.md | ||
|
||
echo "# Gas Estimates" >> .gasestimates.md | ||
echo "Generated via \`bash utils/inspect.sh\`." >> .gasestimates.md | ||
echo "" >> .gasestimates.md | ||
echo "---" >> .gasestimates.md | ||
echo "" >> .gasestimates.md | ||
echo "\`forge test --gas-report --no-match-path \"test/script/**/*\"\`" >> .gasestimates.md | ||
# Sed strings to strip color data and only start printing after the first '|' character, to exclude previous contents (compilation, test results, etc) | ||
forge test --gas-report --no-match-path "test/script/**/*" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" | sed -nr '/\|/,$p' >> .gasestimates.md | ||
|
||
for index in ${!CONTRACT_FILES[*]}; do | ||
# echo "${CONTRACT_NAMES[$index]} is in ${CONTRACT_FILES[$index]}" | ||
CONTRACT_NAME=$(basename -s ".sol" ${CONTRACT_FILES[${index}]}) | ||
# echo ${CONTRACT_NAME} | ||
# If file does not contain a contract named the same as the filename, discard from inspection (e.g. libraries). | ||
if ! grep -q "contract ${CONTRACT_NAME}" ${CONTRACT_FILES[$index]}; then | ||
# echo "Skipping ${CONTRACT_NAME}" | ||
continue | ||
fi | ||
|
||
# Show command names in files | ||
echo "\`forge inspect --pretty ${CONTRACT_FILES[$index]}:${CONTRACT_NAME} storage-layout\`" >> .storagelayout.md | ||
forge inspect --pretty ${CONTRACT_FILES[$index]}:${CONTRACT_NAME} storage-layout >> .storagelayout.md | ||
echo "" >> .storagelayout.md | ||
|
||
echo "\`forge inspect ${CONTRACT_FILES[$index]}:${CONTRACT_NAME} gasestimates\`" >> .gasestimates.md | ||
echo "\`\`\`json" >> .gasestimates.md | ||
forge inspect ${CONTRACT_FILES[$index]}:${CONTRACT_NAME} gasestimates >> .gasestimates.md | ||
echo "\`\`\`" >> .gasestimates.md | ||
echo "" >> .gasestimates.md | ||
|
||
done |