The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyperlane-monorepo/pre-commit.sh

187 lines
4.3 KiB

#!/bin/bash
# Specifying minimum versions
MIN_GIT=2.25.0
MIN_CARGO=1.51.0
# prevent envy from borking
export ETHERSCAN_API_KEY=""
echo_abort ()
{
echo >&2 '
***************
*** ABORTED ***
***************
'
}
ensure()
{
if ! command -v "$1" &> /dev/null
then
echo_abort
echo "command '$1' could not be found."
echo "please ensure it is installed."
exit 1
fi
}
echo "Making pre-run checks"
ensure npm
ensure cargo
ensure jq
ensure npx
# TODO: DRY these
if (echo min version $MIN_GIT; git --version) | sort -Vk3 | tail -1 | grep -q git
then
echo "git version 👌"
else
echo_abort
echo "Upgrade to git $MIN_GIT or later."
exit 1
fi
if (echo min $MIN_CARGO; cargo --version) | sort -Vk2 | tail -1 | grep -q cargo
then
echo "cargo version 👌"
else
echo_abort
echo "Upgrade to cargo $MIN_CARGO or later."
exit 1
fi
echo "Pre-run checks complete"
# Stash uncommitted changes
echo "Stashing changes not staged for commit"
git stash push --keep-index
abort()
{
echo_abort
echo "An error occurred. Please review your code and try again" >&2
git stash pop
exit 1
}
trap 'abort' 0
set -e
git update-index -q --refresh
# Lint and compile optics-core
if ! git diff-index --quiet HEAD -- ./solidity/optics-core; then
echo "+Updating core ABIs, generating typechain, linting"
cd ./solidity/optics-core
npm run lint
npm run compile
# add abis, typechain
cd ../..
git add rust/chains/optics-ethereum/abis
test: migrate tests and deploy process to ts (#400) * refactor: migrate js lib to ts * refactor: rewrite extendEnvironment in ts * add: sample tests * add: extend hre * refactor: ts deploy and signer type * refactor: devDeploy for tests * document: isTestDeploy param, add common.test.ts * add: common tests * fix: common tests * clean: remove sample script * refactor: remove Signer type and use ethers.Signer * refactor: typescript directory * build: generate typechain * refactor: typescript code (#399) * refactor: optics-tests/optics-deploy * fix: install typechain * fix * fix: ts errors * add: merkle tests (#417) * add: merkle tests * clean: remove commented code * fix: merkle tests * test: add queue tests (#422) * Add queue tests * fix: add await to fix nonce bug * test: home ts (#401) * add: home tests * add: home tests * add: deploy home (broken) * refactor: add num confirmations to config * refactor: clean up around ts tests (#424) - add testChain.ts with utility functions for making test Chain and Deploy - refactor the Optics hardhat extension - improve typing of enums in Optics lib - remove most references to waffle (prefer ethers) - remove isTestDeploy from deployment args in favor of a test? on Deploys * refactor: clean test deploy, home tests passing * refactor: deployOptics * fix: white space * lint: fix white space * refactor: testCase vectors and imports * fix: rust test vector generation * fix: missing await Co-authored-by: James Prestwich <10149425+prestwich@users.noreply.github.com> * test: add message test (#423) * test: add message test * fix: replace require with import * fix: import for queue.test.ts * enhance: add type check * fix: import conflicts * test: add upgrade tests (#443) * test: add upgrade tests * fix: missing arg * refactor: clean up code * remove: unused code * refactor: deploy proxy * fix: unsaved code * fix: ts conflicts * add: utils ts (#453) * draft * refactor: remove waffle from home tests * fix: types, remove waffle Co-authored-by: yoduyodu <wang7ong@gmail.com> * test: add XAppConnectionManager tests (#456) * test: add XAppConnectionManager tests * test: initial setup for XAppConnectionManager tests * test: most XAppConnectionManager tests passing * fix: failing test * test: SimpleMessage ts (#468) * test: add cross-chain test utils * test: simpleMessage, mostly passing * fix: prove and process test * test: add initial state test, clean up * test: recoverymanager ts (#473) * test: add recoveryManager initial tests * fix: set recoveryManager in ts deploy * fix: set governor * test: replica ts (#483) * test: add replica tests * debug: fix failing tests * WIP: test: governance router/upgrade ts (#470) * test: add governance router tests * debug: some tests * debug: Gov Router tests * refactor: upgradeUtils * fix: missing await * test: clean up ts tests (#484) * clean: imports * refactor: utils * refactor: remove logs during testing * fix: weird bug, ethers.getSigners messes up describe blocks * delete: solidity/optics-core/js * update: pre-commit script for ts * update: pre-commit and scripts * fix: test, update with main * clean: types * fix: bad recipient handle * add: todo for gov router test * add: add back verify deploy stuff in js for now * bug: fix the governance upgrade test (#490) * fix: gov router upgrade test * feature: use TS in both solidity packages * bug: install deps in typescript dir in tests * feature: enhanced github action install * chore: disable automerge, and move lint before test Co-authored-by: Tong Wang <wang7ong@gmail.com> Co-authored-by: James Prestwich <10149425+prestwich@users.noreply.github.com> Co-authored-by: James Prestwich <james@prestwi.ch>
3 years ago
git add typescript/typechain
# add linter modified files
git add solidity/optics-core/contracts
git add solidity/optics-core/libs
git add solidity/optics-core/interfaces
else
echo "+Skipping core ABI updates, typechain generation and lint"
fi
# Lint and compile optics-xapps
if ! git diff-index --quiet HEAD -- ./solidity/optics-xapps; then
echo "+Updating xapps ABIs, generating typechain, linting"
cd ./solidity/optics-xapps
npm run lint
npm run compile
# add typechain
cd ../..
test: migrate tests and deploy process to ts (#400) * refactor: migrate js lib to ts * refactor: rewrite extendEnvironment in ts * add: sample tests * add: extend hre * refactor: ts deploy and signer type * refactor: devDeploy for tests * document: isTestDeploy param, add common.test.ts * add: common tests * fix: common tests * clean: remove sample script * refactor: remove Signer type and use ethers.Signer * refactor: typescript directory * build: generate typechain * refactor: typescript code (#399) * refactor: optics-tests/optics-deploy * fix: install typechain * fix * fix: ts errors * add: merkle tests (#417) * add: merkle tests * clean: remove commented code * fix: merkle tests * test: add queue tests (#422) * Add queue tests * fix: add await to fix nonce bug * test: home ts (#401) * add: home tests * add: home tests * add: deploy home (broken) * refactor: add num confirmations to config * refactor: clean up around ts tests (#424) - add testChain.ts with utility functions for making test Chain and Deploy - refactor the Optics hardhat extension - improve typing of enums in Optics lib - remove most references to waffle (prefer ethers) - remove isTestDeploy from deployment args in favor of a test? on Deploys * refactor: clean test deploy, home tests passing * refactor: deployOptics * fix: white space * lint: fix white space * refactor: testCase vectors and imports * fix: rust test vector generation * fix: missing await Co-authored-by: James Prestwich <10149425+prestwich@users.noreply.github.com> * test: add message test (#423) * test: add message test * fix: replace require with import * fix: import for queue.test.ts * enhance: add type check * fix: import conflicts * test: add upgrade tests (#443) * test: add upgrade tests * fix: missing arg * refactor: clean up code * remove: unused code * refactor: deploy proxy * fix: unsaved code * fix: ts conflicts * add: utils ts (#453) * draft * refactor: remove waffle from home tests * fix: types, remove waffle Co-authored-by: yoduyodu <wang7ong@gmail.com> * test: add XAppConnectionManager tests (#456) * test: add XAppConnectionManager tests * test: initial setup for XAppConnectionManager tests * test: most XAppConnectionManager tests passing * fix: failing test * test: SimpleMessage ts (#468) * test: add cross-chain test utils * test: simpleMessage, mostly passing * fix: prove and process test * test: add initial state test, clean up * test: recoverymanager ts (#473) * test: add recoveryManager initial tests * fix: set recoveryManager in ts deploy * fix: set governor * test: replica ts (#483) * test: add replica tests * debug: fix failing tests * WIP: test: governance router/upgrade ts (#470) * test: add governance router tests * debug: some tests * debug: Gov Router tests * refactor: upgradeUtils * fix: missing await * test: clean up ts tests (#484) * clean: imports * refactor: utils * refactor: remove logs during testing * fix: weird bug, ethers.getSigners messes up describe blocks * delete: solidity/optics-core/js * update: pre-commit script for ts * update: pre-commit and scripts * fix: test, update with main * clean: types * fix: bad recipient handle * add: todo for gov router test * add: add back verify deploy stuff in js for now * bug: fix the governance upgrade test (#490) * fix: gov router upgrade test * feature: use TS in both solidity packages * bug: install deps in typescript dir in tests * feature: enhanced github action install * chore: disable automerge, and move lint before test Co-authored-by: Tong Wang <wang7ong@gmail.com> Co-authored-by: James Prestwich <10149425+prestwich@users.noreply.github.com> Co-authored-by: James Prestwich <james@prestwi.ch>
3 years ago
git add typescript/typechain
# add linter modified files
git add solidity/optics-xapps/contracts
git add solidity/optics-xapps/interfaces
else
echo "+Skipping xapps ABI updates, typechain generation and lint"
fi
# Conditionally run Rust bins to output into vector JSON files
if ! git diff-index --quiet HEAD -- ./rust/optics-core/src/lib.rs; then
echo "+Running lib vector generation"
cd ./rust/optics-core
echo '+cargo run --bin lib_test_output --features output'
cargo run --bin lib_test_output --features output
cd ../..
else
echo "+Skipping lib vector generation"
fi
# Conditionally run Rust bins to output into vector JSON files
if ! git diff-index --quiet HEAD -- ./rust/optics-core/src/utils.rs; then
echo "+Running utils vector generation"
cd ./rust/optics-core
echo '+cargo run --bin utils_test_output --features output'
cargo run --bin utils_test_output --features output
cd ../..
else
echo "+Skipping utils vector generation"
fi
# Run rust tests, clippy, and formatting
if ! git diff-index --quiet HEAD -- ./rust; then
echo "+Running rust tests"
cd ./rust
echo '+cargo fmt -- --check'
cargo fmt -- --check
echo '+cargo clippy -- -D warnings'
cargo clippy -- -D warnings
echo '+cargo test -- -q'
cargo test -- -q
cd ..
else
echo "+Skipping rust tests"
fi
# Test solidity contracts
if ! git diff-index --quiet HEAD -- ./solidity/optics-core ./solidity/optics-xapps ./typescript/abacus-tests ./typescript/abacus-deploy; then
echo "+Running solidity tests"
cd ./typescript/abacus-tests
npm run testNoCompile
cd ../..
else
echo "+Skipping solidity tests"
fi
# Git add abis if updated
abis_dir=./rust/chains/optics-ethereum/abis/
if ! git diff-index --quiet HEAD -- $abis_dir; then
echo "+git add $abis_dir\*"
git add $abis_dir/*
else
echo "+Skipping git add ABIs"
fi
# Format and git add JSON files if updated
if ! git diff-index --quiet HEAD -- ./vectors; then
for file in vectors/*.json; do
temp=$(mktemp)
jq . "$file" > "$temp"
mv -f "$temp" "$file"
done
echo '+git add ./vectors/*'
git add ./vectors/*
else
echo "+Skipping git add vectors"
fi
trap : 0
echo >&2 '
************
*** DONE ***
************
'
git stash pop -q