Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ci scripts #11

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/template/create-pull-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Description
PR to merge from [{{ .fromBranch }}](/axieinfinity/foundry-contract-template/tree/{{ .fromBranch }}) to [{{ .toBranch }}](/axieinfinity/foundry-contract-template/tree/{{ .toBranch }}).
50 changes: 50 additions & 0 deletions .github/workflows/create-PR-implement-to-feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create Pull Request From Implement To Feature
on:
push:
branches:
- 'implement-feature/**'
- 'implement-feature/**/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

env:
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}

jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- name: Set env
run: |
echo "FEATURE_NAME=$(echo ${HEAD_BRANCH} | cut -d'/' -f2)" >> $GITHUB_ENV
echo "FEATURE_BRANCH=feature/$(echo ${HEAD_BRANCH} | cut -d'/' -f2)" >> $GITHUB_ENV
echo "IMPLEMENT_NAME=$(echo ${HEAD_BRANCH} | cut -d'/' -f3)" >> $GITHUB_ENV

- uses: actions/checkout@v3
with:
ref: ${{env.FEATURE_BRANCH}}

- name: Reset promotion branch
run: |
git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH}
git reset --hard ${HEAD_BRANCH}

- name: Render template
id: template
uses: chuhlomin/[email protected]
with:
template: .github/template/create-pull-request.md
vars: |
fromBranch: ${{env.HEAD_BRANCH}}
toBranch: ${{ env.FEATURE_BRANCH }}

- name: Create Pull Request
uses: peter-evans/[email protected]
with:
branch: ${{ env.HEAD_BRANCH }}
base: ${{env.FEATURE_BRANCH}}
labels: automated PR
title: 'feat(${{env.FEATURE_NAME}}): implement `${{env.IMPLEMENT_NAME}}`'
body: ${{ steps.template.outputs.result }}
54 changes: 54 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: test

on:
push:
branches:
- mainnet
- testnet
- 'feature/*'
- 'features/*'
pull_request:
branches:
- mainnet
- testnet
- 'feature/*'
- 'features/*'

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: [self-hosted, dockerize]
steps:
- id: 'gh-app'
name: 'Get Token'
uses: 'tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a' #v1.7.0
with:
app_id: ${{ secrets.GH_APP_ID }}
private_key: ${{ secrets.GH_PRIVATE_KEY }}

- uses: actions/[email protected]
with:
submodules: recursive
token: ${{ steps.gh-app.outputs.token }}

- 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
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
16 changes: 16 additions & 0 deletions .husky/generate-layout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

rm -rf logs/storage/*
dirOutputs=$(ls out | grep '^[^.]*\.sol$') # assuming the out dir is at 'out'
while IFS= read -r contractDir; do
innerdirOutputs=$(ls out/"$contractDir")

while IFS= read -r jsonFile; do
fileIn=out/"$contractDir"/$jsonFile
fileOut=logs/storage/"$contractDir":${jsonFile%.json}.log
node .husky/storage-logger.js "$fileIn" "$fileOut" &
done <<< "$innerdirOutputs"
done <<< "$dirOutputs"

# Wait for all background jobs to finish
wait
10 changes: 4 additions & 6 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

set -ex

yarn lint-staged
yarn compile
forge build
npx lint-staged
26 changes: 26 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

set -ex

# Workaround: git stash no changes doesn't cause failure but git stash pop cause
output=$(git stash)
stashed=true
if [[ $output == *"No local changes to save"* ]]; then
stashed=false
fi

forge build --sizes 2>&1 | sed -n '/Contract/,$p' > logs/contract-code-sizes.log
.husky/generate-layout.sh

git add logs

output=$(git status -s)
line_count=$(echo "$output" | wc -l)
if [ "$line_count" -gt 1 ]; then
git commit -m "chore: storage layout"
fi

if $stashed; then
git stash pop
fi
60 changes: 60 additions & 0 deletions .husky/storage-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const fs = require('fs');
const fileIn = process.argv[2];
const fileOut = process.argv[3];

if (!fileIn) {
console.error('Invalid input');
}

fs.readFile(fileIn, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}

try {
const jsonData = JSON.parse(data);

if (typeof jsonData.storageLayout == 'undefined') return;
if (jsonData.storageLayout.storage.length == 0) return;

const hasAst = typeof jsonData.ast != 'undefined';

let storageLayout;
if (hasAst) {
const absolutePath = jsonData.ast.absolutePath;
if (typeof absolutePath == 'undefined') return;
if (!absolutePath.startsWith('src')) return;
storageLayout = jsonData.storageLayout.storage;
} else {
// filter only contracts in src/*
storageLayout = jsonData.storageLayout.storage.filter(({ contract }) =>
contract.startsWith('src')
);
}

const outputData = storageLayout
.map(({ contract, label, offset, slot, type: typeId }) => {
const typeObj = jsonData.storageLayout.types[typeId];
const typeLabel = typeObj.label;
const numberOfBytes = typeObj.numberOfBytes;
return `${contract}:${label} (storage_slot: ${slot}) (offset: ${offset}) (type: ${typeLabel}) (numberOfBytes: ${numberOfBytes})`;
})
.join('\n');

if (outputData == '') return;

if (!fileOut) {
console.log(outputData);
} else {
fs.writeFile(fileOut, outputData, 'utf-8', (err) => {
if (err) {
console.error('Error writing file:', err);
return;
}
});
}
} catch (err) {
console.error('Error parsing JSON:', err);
}
});
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ solc = '0.8.17'
evm_version = 'istanbul'
cache_path = 'cache/foundry'

extra_output = ["devdoc", "userdoc", "storagelayout"]
fs_permissions = [{ access = "read-write", path = "./" }]

[fmt]
line_length = 120
tab_width = 2
32 changes: 32 additions & 0 deletions logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
| Contract | Size (kB) | Margin (kB) |
|-----------------------------------------------------|-----------|-------------|
| Address | 0.086 | 24.49 |
| AddressUpgradeable | 0.086 | 24.49 |
| Counters | 0.086 | 24.49 |
| CountersUpgradeable | 0.086 | 24.49 |
| ERC1967Proxy | 0.699 | 23.877 |
| ERC721 | 4.339 | 20.237 |
| ERC721PresetMinterPauserAutoIdCustomized | 9.984 | 14.592 |
| ERC721PresetMinterPauserAutoIdCustomizedUpgradeable | 10.727 | 13.849 |
| ERC721Upgradeable | 4.339 | 20.237 |
| EnumerableSet | 0.086 | 24.49 |
| EnumerableSetUpgradeable | 0.086 | 24.49 |
| Math | 0.086 | 24.49 |
| MathUpgradeable | 0.086 | 24.49 |
| SampleERC721 | 11.012 | 13.564 |
| SampleERC721Upgradeable | 11.734 | 12.842 |
| SignedMathUpgradeable | 0.086 | 24.49 |
| StdInvariant | 2.038 | 22.538 |
| StdStyle | 0.086 | 24.49 |
| StorageSlot | 0.086 | 24.49 |
| Strings | 0.086 | 24.49 |
| StringsUpgradeable | 0.086 | 24.49 |
| TransparentUpgradeableProxy | 2.096 | 22.48 |
| console | 0.086 | 24.49 |
| console2 | 0.086 | 24.49 |
| stdError | 0.591 | 23.985 |
| stdJson | 0.086 | 24.49 |
| stdMath | 0.086 | 24.49 |
| stdStorage | 0.086 | 24.49 |
| stdStorageSafe | 0.086 | 24.49 |

17 changes: 17 additions & 0 deletions logs/storage/ERC721Common.sol:ERC721Common.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
src/ERC721Common.sol:ERC721Common:_roles (storage_slot: 0) (offset: 0) (type: mapping(bytes32 => struct AccessControl.RoleData)) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_roleMembers (storage_slot: 1) (offset: 0) (type: mapping(bytes32 => struct EnumerableSet.AddressSet)) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_name (storage_slot: 2) (offset: 0) (type: string) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_symbol (storage_slot: 3) (offset: 0) (type: string) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_owners (storage_slot: 4) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_balances (storage_slot: 5) (offset: 0) (type: mapping(address => uint256)) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_tokenApprovals (storage_slot: 6) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_operatorApprovals (storage_slot: 7) (offset: 0) (type: mapping(address => mapping(address => bool))) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:nonces (storage_slot: 8) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:______gap (storage_slot: 9) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
src/ERC721Common.sol:ERC721Common:_ownedTokens (storage_slot: 59) (offset: 0) (type: mapping(address => mapping(uint256 => uint256))) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_ownedTokensIndex (storage_slot: 60) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_allTokens (storage_slot: 61) (offset: 0) (type: uint256[]) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_allTokensIndex (storage_slot: 62) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_paused (storage_slot: 63) (offset: 0) (type: bool) (numberOfBytes: 1)
src/ERC721Common.sol:ERC721Common:_tokenIdTracker (storage_slot: 64) (offset: 0) (type: struct Counters.Counter) (numberOfBytes: 32)
src/ERC721Common.sol:ERC721Common:_baseTokenURI (storage_slot: 65) (offset: 0) (type: string) (numberOfBytes: 32)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_initialized (storage_slot: 0) (offset: 0) (type: uint8) (numberOfBytes: 1)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_initializing (storage_slot: 0) (offset: 1) (type: bool) (numberOfBytes: 1)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 1) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 51) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_roles (storage_slot: 101) (offset: 0) (type: mapping(bytes32 => struct AccessControlUpgradeable.RoleData)) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 102) (offset: 0) (type: uint256[49]) (numberOfBytes: 1568)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_roleMembers (storage_slot: 151) (offset: 0) (type: mapping(bytes32 => struct EnumerableSetUpgradeable.AddressSet)) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 152) (offset: 0) (type: uint256[49]) (numberOfBytes: 1568)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_name (storage_slot: 201) (offset: 0) (type: string) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_symbol (storage_slot: 202) (offset: 0) (type: string) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_owners (storage_slot: 203) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_balances (storage_slot: 204) (offset: 0) (type: mapping(address => uint256)) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_tokenApprovals (storage_slot: 205) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_operatorApprovals (storage_slot: 206) (offset: 0) (type: mapping(address => mapping(address => bool))) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 207) (offset: 0) (type: uint256[44]) (numberOfBytes: 1408)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:nonces (storage_slot: 251) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:______gap (storage_slot: 252) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_ownedTokens (storage_slot: 302) (offset: 0) (type: mapping(address => mapping(uint256 => uint256))) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_ownedTokensIndex (storage_slot: 303) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_allTokens (storage_slot: 304) (offset: 0) (type: uint256[]) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_allTokensIndex (storage_slot: 305) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 306) (offset: 0) (type: uint256[46]) (numberOfBytes: 1472)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 352) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_paused (storage_slot: 402) (offset: 0) (type: bool) (numberOfBytes: 1)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 403) (offset: 0) (type: uint256[49]) (numberOfBytes: 1568)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 452) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_tokenIdTracker (storage_slot: 502) (offset: 0) (type: struct CountersUpgradeable.Counter) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:_baseTokenURI (storage_slot: 503) (offset: 0) (type: string) (numberOfBytes: 32)
src/upgradeable/ERC721CommonUpgradeable.sol:ERC721CommonUpgradeable:__gap (storage_slot: 504) (offset: 0) (type: uint256[48]) (numberOfBytes: 1536)
8 changes: 8 additions & 0 deletions logs/storage/ERC721Nonce.sol:ERC721Nonce.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
src/refs/ERC721Nonce.sol:ERC721Nonce:_name (storage_slot: 0) (offset: 0) (type: string) (numberOfBytes: 32)
src/refs/ERC721Nonce.sol:ERC721Nonce:_symbol (storage_slot: 1) (offset: 0) (type: string) (numberOfBytes: 32)
src/refs/ERC721Nonce.sol:ERC721Nonce:_owners (storage_slot: 2) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/refs/ERC721Nonce.sol:ERC721Nonce:_balances (storage_slot: 3) (offset: 0) (type: mapping(address => uint256)) (numberOfBytes: 32)
src/refs/ERC721Nonce.sol:ERC721Nonce:_tokenApprovals (storage_slot: 4) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/refs/ERC721Nonce.sol:ERC721Nonce:_operatorApprovals (storage_slot: 5) (offset: 0) (type: mapping(address => mapping(address => bool))) (numberOfBytes: 32)
src/refs/ERC721Nonce.sol:ERC721Nonce:nonces (storage_slot: 6) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/refs/ERC721Nonce.sol:ERC721Nonce:______gap (storage_slot: 7) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
13 changes: 13 additions & 0 deletions logs/storage/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:_initialized (storage_slot: 0) (offset: 0) (type: uint8) (numberOfBytes: 1)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:_initializing (storage_slot: 0) (offset: 1) (type: bool) (numberOfBytes: 1)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:__gap (storage_slot: 1) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:__gap (storage_slot: 51) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:_name (storage_slot: 101) (offset: 0) (type: string) (numberOfBytes: 32)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:_symbol (storage_slot: 102) (offset: 0) (type: string) (numberOfBytes: 32)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:_owners (storage_slot: 103) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:_balances (storage_slot: 104) (offset: 0) (type: mapping(address => uint256)) (numberOfBytes: 32)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:_tokenApprovals (storage_slot: 105) (offset: 0) (type: mapping(uint256 => address)) (numberOfBytes: 32)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:_operatorApprovals (storage_slot: 106) (offset: 0) (type: mapping(address => mapping(address => bool))) (numberOfBytes: 32)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:__gap (storage_slot: 107) (offset: 0) (type: uint256[44]) (numberOfBytes: 1408)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:nonces (storage_slot: 151) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/upgradeable/refs/ERC721NonceUpgradeable.sol:ERC721NonceUpgradeable:______gap (storage_slot: 152) (offset: 0) (type: uint256[50]) (numberOfBytes: 1600)
Loading
Loading