From ed814b3dc4afbada6dd93a65950b663aff22c18f Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Wed, 4 Dec 2024 15:53:58 +1100 Subject: [PATCH 01/30] add poc husky lint script --- .husky/pre-commit | 31 +++++++++++++++++++++++++++++++ package.json | 4 +++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000..7b94b3fba --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,31 @@ +# For this to run on pre-commit hook, should run `npx husky` in root after `git clone` repo onto dev machine +echo "RUNNING HUSKY PRE-COMMIT HOOK" + +# Path filters +CONTRACTS_PATH_FILTER="contracts/" + +# Filter booleans +CONTRACTS_CHANGE_DETECTED=0 + +# Get list of all `git add` files to be committed +GIT_ADDED_FILE_LIST=($(git diff --name-only --cached)) + +# Iterate through staged files to update filters +for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do + if echo $FILE | grep -q "^$CONTRACTS_PATH_FILTER"; then + CONTRACTS_CHANGE_DETECTED=1 + fi +done + +# Selective linting based on filters +if [ $CONTRACTS_CHANGE_DETECTED -eq 1 ]; then + echo "$CONTRACTS_PATH_FILTER files are changed, linting..." + cd contracts + if [ ! -d "node_modules" ]; then + echo "Missing dev dependencies in $CONTRACTS_PATH_FILTER, installing..." + pnpm i -D + fi + pnpm run lint + cd .. + git update-index --again +fi \ No newline at end of file diff --git a/package.json b/package.json index 77b4852bf..18f8e6971 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "lint:fix": "pnpm run -r --if-present lint:fix", "clean": "pnpm run -r --if-present clean && rm -rf node_modules", "test": "pnpm run -r --if-present test", - "build": "pnpm run -r --if-present build" + "build": "pnpm run -r --if-present build", + "prepare": "husky" }, "devDependencies": { "@types/node": "20.12.7", @@ -23,6 +24,7 @@ "eslint": "8.57.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-prettier": "5.1.3", + "husky": "9.1.7", "prettier": "3.2.5", "rimraf": "5.0.5", "ts-node": "10.9.2", From 4d926b61fbd029ab41344e305ca7e622e43d0313 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Wed, 4 Dec 2024 18:02:34 +1100 Subject: [PATCH 02/30] test commit change --- contracts/README.md | 2 +- pnpm-lock.yaml | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/contracts/README.md b/contracts/README.md index efa4eed77..231530850 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -16,7 +16,7 @@ The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. -- Claiming of messages sent from L1 to L2. +- Claiming of messages sent from L1 to L2. ## Linea Canonical Token Bridge diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0d0ef6247..a866f1f46 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: eslint-plugin-prettier: specifier: 5.1.3 version: 5.1.3(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.2.5) + husky: + specifier: 9.1.7 + version: 9.1.7 prettier: specifier: 3.2.5 version: 3.2.5 @@ -260,6 +263,8 @@ importers: specifier: 17.7.2 version: 17.7.2 + contracts/lib/forge-std: {} + e2e: devDependencies: '@jest/globals': @@ -5827,6 +5832,11 @@ packages: resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==} engines: {node: '>=16.17.0'} + husky@9.1.7: + resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==} + engines: {node: '>=18'} + hasBin: true + i18next-browser-languagedetector@7.1.0: resolution: {integrity: sha512-cr2k7u1XJJ4HTOjM9GyOMtbOA47RtUoWRAtt52z43r3AoMs2StYKyjS3URPhzHaf+mn10hY9dZWamga5WPQjhA==} @@ -17177,6 +17187,8 @@ snapshots: human-signals@5.0.0: {} + husky@9.1.7: {} + i18next-browser-languagedetector@7.1.0: dependencies: '@babel/runtime': 7.25.7 From 5be0d986a09895fffb01b4b3fa9d85a862dbd569 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Wed, 4 Dec 2024 18:03:49 +1100 Subject: [PATCH 03/30] undo test change --- contracts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/README.md b/contracts/README.md index 231530850..efa4eed77 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -16,7 +16,7 @@ The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. -- Claiming of messages sent from L1 to L2. +- Claiming of messages sent from L1 to L2. ## Linea Canonical Token Bridge From 5aa932b417fb8bc567d1bed4b1f2e564f0e50056 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Wed, 4 Dec 2024 18:04:15 +1100 Subject: [PATCH 04/30] test change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 01d533938..35db99a01 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ It serves developers by making the Linea tech stack open source under the [Apach [Linea](https://linea.build) is a developer-ready layer 2 network scaling Ethereum. It's secured with a zero-knowledge rollup, built on lattice-based cryptography, and powered by [Consensys](https://consensys.io). -## Get started +## Get started If you already have an understanding of the tech stack, use our [Get Started](docs/get-started.md) guide. From e7be1df42edc540a865031f4fb78f97d764b6b31 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Wed, 4 Dec 2024 18:04:26 +1100 Subject: [PATCH 05/30] undo test change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35db99a01..01d533938 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ It serves developers by making the Linea tech stack open source under the [Apach [Linea](https://linea.build) is a developer-ready layer 2 network scaling Ethereum. It's secured with a zero-knowledge rollup, built on lattice-based cryptography, and powered by [Consensys](https://consensys.io). -## Get started +## Get started If you already have an understanding of the tech stack, use our [Get Started](docs/get-started.md) guide. From 9446cebc92a9f9a2136ea864160798de95cfa842 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 00:52:57 +1100 Subject: [PATCH 06/30] test --- .husky/pre-commit | 47 ++++++++++++++++++++++++++++++++------------- contracts/README.md | 2 +- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 7b94b3fba..4859c9093 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,31 +1,52 @@ # For this to run on pre-commit hook, should run `npx husky` in root after `git clone` repo onto dev machine echo "RUNNING HUSKY PRE-COMMIT HOOK" +# File extension filters + + # Path filters CONTRACTS_PATH_FILTER="contracts/" +SDK_PATH_FILTER="sdk/" # Filter booleans CONTRACTS_CHANGE_DETECTED=0 +SDK_CHANGE_DETECTED=0 # Get list of all `git add` files to be committed GIT_ADDED_FILE_LIST=($(git diff --name-only --cached)) # Iterate through staged files to update filters for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do - if echo $FILE | grep -q "^$CONTRACTS_PATH_FILTER"; then - CONTRACTS_CHANGE_DETECTED=1 + if [[ $FILE =~ ^$CONTRACTS_PATH_FILTER ]]; then + echo "HI" + # if echo $FILE | grep -q "^$CONTRACTS_PATH_FILTER"; then + # CONTRACTS_CHANGE_DETECTED=1 + # elif echo $FILE | grep -q "^$SDK_PATH_FILTER"; then + # SDK_CHANGE_DETECTED=1 fi done # Selective linting based on filters -if [ $CONTRACTS_CHANGE_DETECTED -eq 1 ]; then - echo "$CONTRACTS_PATH_FILTER files are changed, linting..." - cd contracts - if [ ! -d "node_modules" ]; then - echo "Missing dev dependencies in $CONTRACTS_PATH_FILTER, installing..." - pnpm i -D - fi - pnpm run lint - cd .. - git update-index --again -fi \ No newline at end of file +# if [ $CONTRACTS_CHANGE_DETECTED -eq 1 ]; then +# echo "$CONTRACTS_PATH_FILTER files are changed, linting..." +# cd contracts +# if [ ! -d "node_modules" ]; then +# echo "Error: missing dependencies in $CONTRACTS_PATH_FILTER" +# exit 1 +# fi +# pnpm run lint +# cd .. +# git update-index --again +# fi + +# if [ $SDK_CHANGE_DETECTED -eq 1 ]; then +# echo "$SDK_PATH_FILTER files are changed, linting..." +# cd contracts +# if [ ! -d "node_modules" ]; then +# echo "Error: missing dependencies in $CONTRACTS_PATH_FILTER" +# exit 1 +# fi +# pnpm run lint +# cd .. +# git update-index --again +# fi \ No newline at end of file diff --git a/contracts/README.md b/contracts/README.md index efa4eed77..2d22f6bbb 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From a513e13629b73ea84fdeb3c629569443dd970feb Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 00:53:18 +1100 Subject: [PATCH 07/30] test --- .husky/pre-commit | 2 +- contracts/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 4859c9093..698495747 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -17,7 +17,7 @@ GIT_ADDED_FILE_LIST=($(git diff --name-only --cached)) # Iterate through staged files to update filters for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do - if [[ $FILE =~ ^$CONTRACTS_PATH_FILTER ]]; then + if [[ $FILE =~ "^$CONTRACTS_PATH_FILTER" ]]; then echo "HI" # if echo $FILE | grep -q "^$CONTRACTS_PATH_FILTER"; then # CONTRACTS_CHANGE_DETECTED=1 diff --git a/contracts/README.md b/contracts/README.md index 2d22f6bbb..efa4eed77 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 91d45cbd4aa4489b0416ef6b5caa2a9dcb368062 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 00:53:49 +1100 Subject: [PATCH 08/30] test --- .husky/pre-commit | 4 +++- contracts/README.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 698495747..d142c3666 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -19,7 +19,9 @@ GIT_ADDED_FILE_LIST=($(git diff --name-only --cached)) for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do if [[ $FILE =~ "^$CONTRACTS_PATH_FILTER" ]]; then echo "HI" - # if echo $FILE | grep -q "^$CONTRACTS_PATH_FILTER"; then + elif echo $FILE | grep -q "^$CONTRACTS_PATH_FILTER"; then + echo "HI2" + # CONTRACTS_CHANGE_DETECTED=1 # elif echo $FILE | grep -q "^$SDK_PATH_FILTER"; then # SDK_CHANGE_DETECTED=1 diff --git a/contracts/README.md b/contracts/README.md index efa4eed77..2d22f6bbb 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 7223d5dd59a837e7522dbbd3bda2c2a397f7005d Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 00:54:38 +1100 Subject: [PATCH 09/30] test --- contracts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/README.md b/contracts/README.md index 2d22f6bbb..efa4eed77 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From e0c87d44c6f5cc2137e1e93234dd854c3df8582d Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 00:56:00 +1100 Subject: [PATCH 10/30] do --- .husky/pre-commit | 2 +- contracts/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index d142c3666..fc10831ae 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -17,7 +17,7 @@ GIT_ADDED_FILE_LIST=($(git diff --name-only --cached)) # Iterate through staged files to update filters for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do - if [[ $FILE =~ "^$CONTRACTS_PATH_FILTER" ]]; then + if [[ $FILE =~ ^"$CONTRACTS_PATH_FILTER" ]]; then echo "HI" elif echo $FILE | grep -q "^$CONTRACTS_PATH_FILTER"; then echo "HI2" diff --git a/contracts/README.md b/contracts/README.md index efa4eed77..2d22f6bbb 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 208a27ff6b631aa09901a99f0b6956e0df997fdd Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 00:56:10 +1100 Subject: [PATCH 11/30] test --- contracts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/README.md b/contracts/README.md index 2d22f6bbb..efa4eed77 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 24ec15cb46c1de1b1f410643f828f4c875ee97ca Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 01:10:13 +1100 Subject: [PATCH 12/30] test --- .husky/pre-commit | 26 +++++++++++++++----------- contracts/README.md | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index fc10831ae..95127f0c2 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,15 +2,18 @@ echo "RUNNING HUSKY PRE-COMMIT HOOK" # File extension filters - +TYPESCRIPT_FILTER="\.ts$" +SOLIDITY_FILTER="\.sol$" # Path filters CONTRACTS_PATH_FILTER="contracts/" SDK_PATH_FILTER="sdk/" -# Filter booleans -CONTRACTS_CHANGE_DETECTED=0 -SDK_CHANGE_DETECTED=0 +# List of changed files +CONTRACTS_PATH_CHANGES=() +SDK_PATH_CHANGES=() +# CONTRACTS_CHANGE_DETECTED=0 +# SDK_CHANGE_DETECTED=0 # Get list of all `git add` files to be committed GIT_ADDED_FILE_LIST=($(git diff --name-only --cached)) @@ -18,16 +21,17 @@ GIT_ADDED_FILE_LIST=($(git diff --name-only --cached)) # Iterate through staged files to update filters for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do if [[ $FILE =~ ^"$CONTRACTS_PATH_FILTER" ]]; then - echo "HI" - elif echo $FILE | grep -q "^$CONTRACTS_PATH_FILTER"; then - echo "HI2" - - # CONTRACTS_CHANGE_DETECTED=1 - # elif echo $FILE | grep -q "^$SDK_PATH_FILTER"; then - # SDK_CHANGE_DETECTED=1 + CONTRACTS_PATH_CHANGES+=($FILE) + # CONTRACTS_CHANGE_DETECTED=1 + elif [[ $FILE =~ ^"$SDK_PATH_FILTER" ]]; then + SDK_CHANGE_DETECTED+=($FILE) + # SDK_CHANGE_DETECTED=1 fi done +echo $CONTRACTS_PATH_CHANGES +echo $SDK_PATH_CHANGES + # Selective linting based on filters # if [ $CONTRACTS_CHANGE_DETECTED -eq 1 ]; then # echo "$CONTRACTS_PATH_FILTER files are changed, linting..." diff --git a/contracts/README.md b/contracts/README.md index efa4eed77..2d22f6bbb 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 9a8ad8b889845da8a4f4070358fae131deca324b Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 01:10:25 +1100 Subject: [PATCH 13/30] test --- contracts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/README.md b/contracts/README.md index 2d22f6bbb..efa4eed77 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 5dbd778f30f59c2f4a2dbaee642cad03ea932071 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 01:15:36 +1100 Subject: [PATCH 14/30] test --- .husky/pre-commit | 2 +- contracts/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 95127f0c2..91366b9ce 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -16,7 +16,7 @@ SDK_PATH_CHANGES=() # SDK_CHANGE_DETECTED=0 # Get list of all `git add` files to be committed -GIT_ADDED_FILE_LIST=($(git diff --name-only --cached)) +GIT_ADDED_FILE_LIST=($(git diff --name-only HEAD)) # Iterate through staged files to update filters for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do diff --git a/contracts/README.md b/contracts/README.md index efa4eed77..2d22f6bbb 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 8fbfb895211b955ecb2cb006b9423de42232b844 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 01:24:40 +1100 Subject: [PATCH 15/30] test --- .husky/pre-commit | 49 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 91366b9ce..143bc3215 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -12,20 +12,16 @@ SDK_PATH_FILTER="sdk/" # List of changed files CONTRACTS_PATH_CHANGES=() SDK_PATH_CHANGES=() -# CONTRACTS_CHANGE_DETECTED=0 -# SDK_CHANGE_DETECTED=0 -# Get list of all `git add` files to be committed +# Get list of all changes since last commit GIT_ADDED_FILE_LIST=($(git diff --name-only HEAD)) # Iterate through staged files to update filters for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do if [[ $FILE =~ ^"$CONTRACTS_PATH_FILTER" ]]; then CONTRACTS_PATH_CHANGES+=($FILE) - # CONTRACTS_CHANGE_DETECTED=1 elif [[ $FILE =~ ^"$SDK_PATH_FILTER" ]]; then SDK_CHANGE_DETECTED+=($FILE) - # SDK_CHANGE_DETECTED=1 fi done @@ -33,17 +29,38 @@ echo $CONTRACTS_PATH_CHANGES echo $SDK_PATH_CHANGES # Selective linting based on filters -# if [ $CONTRACTS_CHANGE_DETECTED -eq 1 ]; then -# echo "$CONTRACTS_PATH_FILTER files are changed, linting..." -# cd contracts -# if [ ! -d "node_modules" ]; then -# echo "Error: missing dependencies in $CONTRACTS_PATH_FILTER" -# exit 1 -# fi -# pnpm run lint -# cd .. -# git update-index --again -# fi +if [[ ${#CONTRACTS_PATH_CHANGES[@]} -gt 0 ]]; then + cd $CONTRACTS_PATH_FILTER + if [ ! -d "node_modules" ]; then + echo "Error: missing dependencies in $CONTRACTS_PATH_FILTER" + exit 1 + fi + + TYPESCRIPT_FILE_FOUND=0 + SOLIDITY_FILE_FOUND=0 + + for FILE in "${CONTRACTS_PATH_CHANGES[@]}"; do + if [[ $FILE =~ $TYPESCRIPT_FILTER ]]; then + TYPESCRIPT_FILE_FOUND=1 + elif [[ $FILE =~ $SOLIDITY_FILTER ]]; then + SOLIDITY_FILE_FOUND=1 + fi + done + + if [ $TYPESCRIPT_FILE_FOUND -eq 1 ]; then + echo "*.ts files changed in $CONTRACTS_PATH_FILTER, linting..." + pnpm run lint:ts + fi + + if [ $SOLIDITY_FILE_FOUND -eq 1 ]; then + echo "*.sol files changed in $CONTRACTS_PATH_FILTER, linting..." + pnpm run lint:sol + fi + + + cd .. + git update-index --again +fi # if [ $SDK_CHANGE_DETECTED -eq 1 ]; then # echo "$SDK_PATH_FILTER files are changed, linting..." From 59c1d7d594a6bc70f505f076e2b27973218b041d Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 01:26:09 +1100 Subject: [PATCH 16/30] test --- .husky/pre-commit | 3 +-- contracts/README.md | 2 +- contracts/contracts/token/ITokenMinter.sol | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 143bc3215..e24bca791 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -9,14 +9,13 @@ SOLIDITY_FILTER="\.sol$" CONTRACTS_PATH_FILTER="contracts/" SDK_PATH_FILTER="sdk/" -# List of changed files +# Lists of changed files for each filter CONTRACTS_PATH_CHANGES=() SDK_PATH_CHANGES=() # Get list of all changes since last commit GIT_ADDED_FILE_LIST=($(git diff --name-only HEAD)) -# Iterate through staged files to update filters for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do if [[ $FILE =~ ^"$CONTRACTS_PATH_FILTER" ]]; then CONTRACTS_PATH_CHANGES+=($FILE) diff --git a/contracts/README.md b/contracts/README.md index 2d22f6bbb..efa4eed77 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. diff --git a/contracts/contracts/token/ITokenMinter.sol b/contracts/contracts/token/ITokenMinter.sol index 117ec646d..a0b0ed905 100644 --- a/contracts/contracts/token/ITokenMinter.sol +++ b/contracts/contracts/token/ITokenMinter.sol @@ -13,7 +13,7 @@ interface ITokenMinter { * @param _amount The amount of token to receive. * @dev Only the MINTER_ROLE can mint these tokens */ - function mint(address _to, uint256 _amount) external; + function mint(address _to, uint256 _amount) external; /** * @notice Mints a single token amount for a multiple recipients. From 5f7c8bf5651cffda0e91034ac71ec614e36d64d0 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 01:28:22 +1100 Subject: [PATCH 17/30] test --- contracts/contracts/token/ITokenMinter.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/contracts/token/ITokenMinter.sol b/contracts/contracts/token/ITokenMinter.sol index a0b0ed905..117ec646d 100644 --- a/contracts/contracts/token/ITokenMinter.sol +++ b/contracts/contracts/token/ITokenMinter.sol @@ -13,7 +13,7 @@ interface ITokenMinter { * @param _amount The amount of token to receive. * @dev Only the MINTER_ROLE can mint these tokens */ - function mint(address _to, uint256 _amount) external; + function mint(address _to, uint256 _amount) external; /** * @notice Mints a single token amount for a multiple recipients. From 7f18ac941e7d48ef49bda425e27a12c7b75d1f53 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 01:28:41 +1100 Subject: [PATCH 18/30] test --- contracts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/README.md b/contracts/README.md index efa4eed77..2d22f6bbb 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 619435c710fee597b9ad5a60fef808a983fa846b Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 11:55:12 +1100 Subject: [PATCH 19/30] test --- .husky/pre-commit | 84 +++++++++++++++++++++++++++------------------ contracts/README.md | 2 +- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index e24bca791..07857441c 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -16,50 +16,68 @@ SDK_PATH_CHANGES=() # Get list of all changes since last commit GIT_ADDED_FILE_LIST=($(git diff --name-only HEAD)) +# for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do +# if [[ $FILE =~ ^"$CONTRACTS_PATH_FILTER" ]]; then +# CONTRACTS_PATH_CHANGES+=($FILE) +# elif [[ $FILE =~ ^"$SDK_PATH_FILTER" ]]; then +# SDK_CHANGE_DETECTED+=($FILE) +# fi +# done + +## Experiment + +declare -A PATH_FILTER_LISTS=( + ["CONTRACTS_PATH_FILTER"]="CONTRACTS_PATH_CHANGES" + ["SDK_PATH_FILTER"]="SDK_CHANGE_DETECTED" +) + for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do - if [[ $FILE =~ ^"$CONTRACTS_PATH_FILTER" ]]; then - CONTRACTS_PATH_CHANGES+=($FILE) - elif [[ $FILE =~ ^"$SDK_PATH_FILTER" ]]; then - SDK_CHANGE_DETECTED+=($FILE) - fi + for FILTER in "${!PATH_FILTERS[@]}"; do + if [[ $FILE =~ ^"${!FILTER}" ]]; then + eval "${PATH_FILTERS[$FILTER]}+=(\"$FILE\")" + break + fi + done done echo $CONTRACTS_PATH_CHANGES echo $SDK_PATH_CHANGES +# For demo purposes, to demonstrate that above steps don't take long +echo "FILTERING GIT CHANGES DONE" + # Selective linting based on filters -if [[ ${#CONTRACTS_PATH_CHANGES[@]} -gt 0 ]]; then - cd $CONTRACTS_PATH_FILTER - if [ ! -d "node_modules" ]; then - echo "Error: missing dependencies in $CONTRACTS_PATH_FILTER" - exit 1 - fi - - TYPESCRIPT_FILE_FOUND=0 - SOLIDITY_FILE_FOUND=0 - - for FILE in "${CONTRACTS_PATH_CHANGES[@]}"; do - if [[ $FILE =~ $TYPESCRIPT_FILTER ]]; then - TYPESCRIPT_FILE_FOUND=1 - elif [[ $FILE =~ $SOLIDITY_FILTER ]]; then - SOLIDITY_FILE_FOUND=1 - fi - done +# if [[ ${#CONTRACTS_PATH_CHANGES[@]} -gt 0 ]]; then +# cd $CONTRACTS_PATH_FILTER +# if [ ! -d "node_modules" ]; then +# echo "Error: missing dependencies in $CONTRACTS_PATH_FILTER" +# exit 1 +# fi - if [ $TYPESCRIPT_FILE_FOUND -eq 1 ]; then - echo "*.ts files changed in $CONTRACTS_PATH_FILTER, linting..." - pnpm run lint:ts - fi +# TYPESCRIPT_FILE_FOUND=0 +# SOLIDITY_FILE_FOUND=0 - if [ $SOLIDITY_FILE_FOUND -eq 1 ]; then - echo "*.sol files changed in $CONTRACTS_PATH_FILTER, linting..." - pnpm run lint:sol - fi +# for FILE in "${CONTRACTS_PATH_CHANGES[@]}"; do +# if [[ $FILE =~ $TYPESCRIPT_FILTER ]]; then +# TYPESCRIPT_FILE_FOUND=1 +# elif [[ $FILE =~ $SOLIDITY_FILTER ]]; then +# SOLIDITY_FILE_FOUND=1 +# fi +# done +# if [ $TYPESCRIPT_FILE_FOUND -eq 1 ]; then +# echo "*.ts files changed in $CONTRACTS_PATH_FILTER, linting..." +# pnpm run lint:ts +# fi - cd .. - git update-index --again -fi +# if [ $SOLIDITY_FILE_FOUND -eq 1 ]; then +# echo "*.sol files changed in $CONTRACTS_PATH_FILTER, linting..." +# pnpm run lint:sol +# fi + +# cd .. +# git update-index --again +# fi # if [ $SDK_CHANGE_DETECTED -eq 1 ]; then # echo "$SDK_PATH_FILTER files are changed, linting..." diff --git a/contracts/README.md b/contracts/README.md index 2d22f6bbb..4cb6d323b 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -9,7 +9,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Anchoring of L2 message Merkle roots to allow later claiming. - Claiming of messages sent from L2 to Ethereum mainnet (L1). - Submission of L2 compressed data using EIP-4844 blobs or via calldata. -- Finalization of L2 state on L1 using a Zero Knowledge Proof. +- Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService The L2MessageService is the L2 smart contract that is responsible for: From 521aa8ccbab8aa1834a1dde8a6235bb640dd2028 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 15:21:27 +1100 Subject: [PATCH 20/30] test --- .husky/pre-commit | 37 ++++++++++++++++++++++++------------- contracts/README.md | 2 +- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 07857441c..795a7ebce 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,6 +1,15 @@ +#!/bin/bash + # For this to run on pre-commit hook, should run `npx husky` in root after `git clone` repo onto dev machine echo "RUNNING HUSKY PRE-COMMIT HOOK" +# Execute NodeJS script because +# i.) Husky requires NodeJS -> fair assumption that machine will have NodeJS +# ii.) Shell scripting syntax more convoluted + sh shell lack hashmap (associative array) support +node .husky/pre-commit.js + +exit 0 + # File extension filters TYPESCRIPT_FILTER="\.ts$" SOLIDITY_FILTER="\.sol$" @@ -25,27 +34,29 @@ GIT_ADDED_FILE_LIST=($(git diff --name-only HEAD)) # done ## Experiment +# typeset -A +# PATH_FILTER_LISTS["CONTRACTS_PATH_FILTER"]="CONTRACTS_PATH_CHANGES" +# PATH_FILTER_LISTS["SDK_PATH_FILTER"]="SDK_CHANGE_DETECTED" -declare -A PATH_FILTER_LISTS=( - ["CONTRACTS_PATH_FILTER"]="CONTRACTS_PATH_CHANGES" - ["SDK_PATH_FILTER"]="SDK_CHANGE_DETECTED" -) - -for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do - for FILTER in "${!PATH_FILTERS[@]}"; do - if [[ $FILE =~ ^"${!FILTER}" ]]; then - eval "${PATH_FILTERS[$FILTER]}+=(\"$FILE\")" - break - fi - done -done +# for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do +# for FILTER in "${!PATH_FILTERS[@]}"; do +# if [[ $FILE =~ ^"${!FILTER}" ]]; then +# eval "${PATH_FILTERS[$FILTER]}+=(\"$FILE\")" +# break +# fi +# done +# done echo $CONTRACTS_PATH_CHANGES echo $SDK_PATH_CHANGES +echo $SHELL + # For demo purposes, to demonstrate that above steps don't take long echo "FILTERING GIT CHANGES DONE" +exit 2 + # Selective linting based on filters # if [[ ${#CONTRACTS_PATH_CHANGES[@]} -gt 0 ]]; then # cd $CONTRACTS_PATH_FILTER diff --git a/contracts/README.md b/contracts/README.md index 4cb6d323b..2d22f6bbb 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -9,7 +9,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Anchoring of L2 message Merkle roots to allow later claiming. - Claiming of messages sent from L2 to Ethereum mainnet (L1). - Submission of L2 compressed data using EIP-4844 blobs or via calldata. -- Finalization of L2 state on L1 using a Zero Knowledge Proof. +- Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService The L2MessageService is the L2 smart contract that is responsible for: From 6b19c2e2d94c86d4d3ee4705d3f4403dfa1bbd8c Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 16:40:49 +1100 Subject: [PATCH 21/30] refactor to pre-commit to NodeJS script --- .husky/pre-commit | 96 +------------ .husky/pre-commit.js | 150 +++++++++++++++++++++ contracts/contracts/proxies/ProxyAdmin.sol | 2 +- 3 files changed, 153 insertions(+), 95 deletions(-) create mode 100644 .husky/pre-commit.js diff --git a/.husky/pre-commit b/.husky/pre-commit index 795a7ebce..6bd65572b 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -5,99 +5,7 @@ echo "RUNNING HUSKY PRE-COMMIT HOOK" # Execute NodeJS script because # i.) Husky requires NodeJS -> fair assumption that machine will have NodeJS -# ii.) Shell scripting syntax more convoluted + sh shell lack hashmap (associative array) support +# ii.) Cleaner syntax and abstractions than shell scripting node .husky/pre-commit.js -exit 0 - -# File extension filters -TYPESCRIPT_FILTER="\.ts$" -SOLIDITY_FILTER="\.sol$" - -# Path filters -CONTRACTS_PATH_FILTER="contracts/" -SDK_PATH_FILTER="sdk/" - -# Lists of changed files for each filter -CONTRACTS_PATH_CHANGES=() -SDK_PATH_CHANGES=() - -# Get list of all changes since last commit -GIT_ADDED_FILE_LIST=($(git diff --name-only HEAD)) - -# for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do -# if [[ $FILE =~ ^"$CONTRACTS_PATH_FILTER" ]]; then -# CONTRACTS_PATH_CHANGES+=($FILE) -# elif [[ $FILE =~ ^"$SDK_PATH_FILTER" ]]; then -# SDK_CHANGE_DETECTED+=($FILE) -# fi -# done - -## Experiment -# typeset -A -# PATH_FILTER_LISTS["CONTRACTS_PATH_FILTER"]="CONTRACTS_PATH_CHANGES" -# PATH_FILTER_LISTS["SDK_PATH_FILTER"]="SDK_CHANGE_DETECTED" - -# for FILE in "${GIT_ADDED_FILE_LIST[@]}"; do -# for FILTER in "${!PATH_FILTERS[@]}"; do -# if [[ $FILE =~ ^"${!FILTER}" ]]; then -# eval "${PATH_FILTERS[$FILTER]}+=(\"$FILE\")" -# break -# fi -# done -# done - -echo $CONTRACTS_PATH_CHANGES -echo $SDK_PATH_CHANGES -echo $SHELL - - -# For demo purposes, to demonstrate that above steps don't take long -echo "FILTERING GIT CHANGES DONE" - -exit 2 - -# Selective linting based on filters -# if [[ ${#CONTRACTS_PATH_CHANGES[@]} -gt 0 ]]; then -# cd $CONTRACTS_PATH_FILTER -# if [ ! -d "node_modules" ]; then -# echo "Error: missing dependencies in $CONTRACTS_PATH_FILTER" -# exit 1 -# fi - -# TYPESCRIPT_FILE_FOUND=0 -# SOLIDITY_FILE_FOUND=0 - -# for FILE in "${CONTRACTS_PATH_CHANGES[@]}"; do -# if [[ $FILE =~ $TYPESCRIPT_FILTER ]]; then -# TYPESCRIPT_FILE_FOUND=1 -# elif [[ $FILE =~ $SOLIDITY_FILTER ]]; then -# SOLIDITY_FILE_FOUND=1 -# fi -# done - -# if [ $TYPESCRIPT_FILE_FOUND -eq 1 ]; then -# echo "*.ts files changed in $CONTRACTS_PATH_FILTER, linting..." -# pnpm run lint:ts -# fi - -# if [ $SOLIDITY_FILE_FOUND -eq 1 ]; then -# echo "*.sol files changed in $CONTRACTS_PATH_FILTER, linting..." -# pnpm run lint:sol -# fi - -# cd .. -# git update-index --again -# fi - -# if [ $SDK_CHANGE_DETECTED -eq 1 ]; then -# echo "$SDK_PATH_FILTER files are changed, linting..." -# cd contracts -# if [ ! -d "node_modules" ]; then -# echo "Error: missing dependencies in $CONTRACTS_PATH_FILTER" -# exit 1 -# fi -# pnpm run lint -# cd .. -# git update-index --again -# fi \ No newline at end of file +exit 0 \ No newline at end of file diff --git a/.husky/pre-commit.js b/.husky/pre-commit.js new file mode 100644 index 000000000..2153fe169 --- /dev/null +++ b/.husky/pre-commit.js @@ -0,0 +1,150 @@ +const fs = require('fs'); +const { execSync } = require('child_process'); + +// Enums + +const FILE_EXTENSION = { + TYPESCRIPT: "TYPESCRIPT", + SOLIDITY: "SOLIDITY", +} + +const FOLDER = { + CONTRACTS: "CONTRACTS", + SDK: "SDK", +} + +const RUNTIME = { + NODEJS: "NODEJS" +} + +// Maps + +const FILE_EXTENSION_FILTERS = { + [FILE_EXTENSION.TYPESCRIPT]: "\.ts$", + [FILE_EXTENSION.SOLIDITY]: "\.sol$", +}; + +const FILE_EXTENSION_LINTING_COMMAND = { + [FILE_EXTENSION.TYPESCRIPT]: "pnpm run lint:ts", + [FILE_EXTENSION.SOLIDITY]: "pnpm run lint:sol", +}; + +const FOLDER_PATH = { + [FOLDER.CONTRACTS]: "contracts/", + [FOLDER.SDK]: "sdk/", +}; + +const FOLDER_CHANGED_FILES = { + [FOLDER.CONTRACTS]: new Array(), + [FOLDER.SDK]: new Array(), +}; + +const FOLDER_RUNTIME = { + [FOLDER.CONTRACTS]: RUNTIME.NODEJS, + [FOLDER.SDK]: RUNTIME.NODEJS, +}; + +// Main function + +main(); + +function main() { + const changedFileList = getChangedFileList(); + partitionChangedFileList(changedFileList); + + // Iterate through each folder + for (const folder in FOLDER) { + if (!isDependenciesInstalled(folder)) process.exit(1); + const changedFileExtensions = getChangedFileExtensions(folder); + executeLinting(folder, changedFileExtensions); + } + + updateGitIndex(); +} + +// Utility functions +function getChangedFileList() { + try { + const cmd = 'git diff --name-only HEAD' + const stdout = execSync(cmd, { encoding: 'utf8' }); + return stdout.split('\n').filter(file => file.trim() !== ''); + } catch (error) { + console.error($`Error running ${cmd}:`, error.message); + process.exit(1) + } +} + +function partitionChangedFileList(_changedFileList) { + // Populate lists of filter matches + for (const file of _changedFileList) { + // ? Should we do better than O(N) iterating through each path. + for (const path in FOLDER) { + if (file.match(new RegExp(`^${FOLDER_PATH[path]}`))) { + FOLDER_CHANGED_FILES[path].push(file); + } + } + } +} + +function isDependenciesInstalled(_folder) { + const runtime = FOLDER_RUNTIME[_folder]; + const path = FOLDER_PATH[_folder]; + + switch(runtime) { + case RUNTIME.NODEJS: + const dependencyFolder = `${path}node_modules` + return fs.existsSync(dependencyFolder) + default: + return false + } +} + +function getChangedFileExtensions(_folder) { + // Use sets to stop iterating through changed files, once we have found all file extensions of interest. + const remainingFileExtensionsSet = new Set(Object.values(FILE_EXTENSION)); + const foundFileExtensionsSet = new Set(); + + // Iterate through each changed file, look for file extension matches + for (const file of FOLDER_CHANGED_FILES[_folder]) { + for (const fileExtension of remainingFileExtensionsSet) { + if (file.match(new RegExp(FILE_EXTENSION_FILTERS[fileExtension]))) { + foundFileExtensionsSet.add(fileExtension); + remainingFileExtensionsSet.delete(fileExtension); + } + } + + // No more remaining file extensions to look for + if (remainingFileExtensionsSet.size == 0) break; + } + + return Array.from(foundFileExtensionsSet); +} + +function executeLinting(_folder, _changedFileExtensions) { + for (const fileExtension of _changedFileExtensions) { + const path = FOLDER_PATH[_folder]; + const cmd = FILE_EXTENSION_LINTING_COMMAND[fileExtension]; + console.log(`${fileExtension} change found in ${path}, linting...`); + try { + // Execute command synchronously and route output directly to the current stdout + execSync(` + cd ${path}; + ${cmd}; + `, { stdio: 'inherit' }); + } catch (error) { + console.error(`Error:`, error.message); + console.error(`Exiting...`); + process.exit(1); + } + } +} + +function updateGitIndex() { + try { + const cmd = 'git update-index --again' + execSync(cmd, { stdio: 'inherit' }); + } catch (error) { + console.error($`Error running ${cmd}:`, error.message); + process.exit(1); + } +} \ No newline at end of file diff --git a/contracts/contracts/proxies/ProxyAdmin.sol b/contracts/contracts/proxies/ProxyAdmin.sol index 702efa302..b503248c5 100644 --- a/contracts/contracts/proxies/ProxyAdmin.sol +++ b/contracts/contracts/proxies/ProxyAdmin.sol @@ -15,7 +15,7 @@ pragma solidity ^0.8.0; * paying for execution may not be the actual sender (as far as an application * is concerned). * - * This contract is only required for intermediate, library-like contracts. + * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { From 4277ef74f3339e9290d995574d63ba1b25d1ee81 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 16:43:48 +1100 Subject: [PATCH 22/30] add logs for demo --- .husky/pre-commit | 2 -- .husky/pre-commit.js | 2 ++ contracts/contracts/proxies/ProxyAdmin.sol | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 6bd65572b..9455de62e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,3 @@ -#!/bin/bash - # For this to run on pre-commit hook, should run `npx husky` in root after `git clone` repo onto dev machine echo "RUNNING HUSKY PRE-COMMIT HOOK" diff --git a/.husky/pre-commit.js b/.husky/pre-commit.js index 2153fe169..4c8ab9b84 100644 --- a/.husky/pre-commit.js +++ b/.husky/pre-commit.js @@ -49,8 +49,10 @@ const FOLDER_RUNTIME = { main(); function main() { + console.time('GET_CHANGED_FILE_LIST_TIMER'); const changedFileList = getChangedFileList(); partitionChangedFileList(changedFileList); + console.timeEnd('GET_CHANGED_FILE_LIST_TIMER'); // Iterate through each folder for (const folder in FOLDER) { diff --git a/contracts/contracts/proxies/ProxyAdmin.sol b/contracts/contracts/proxies/ProxyAdmin.sol index b503248c5..702efa302 100644 --- a/contracts/contracts/proxies/ProxyAdmin.sol +++ b/contracts/contracts/proxies/ProxyAdmin.sol @@ -15,7 +15,7 @@ pragma solidity ^0.8.0; * paying for execution may not be the actual sender (as far as an application * is concerned). * - * This contract is only required for intermediate, library-like contracts. + * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { From 6a6d404f14f51e65e3fcc78d93011ab333d112a9 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 5 Dec 2024 23:17:51 +1100 Subject: [PATCH 23/30] small refactor of pre-commit.js --- .husky/pre-commit.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.husky/pre-commit.js b/.husky/pre-commit.js index 4c8ab9b84..9602ced69 100644 --- a/.husky/pre-commit.js +++ b/.husky/pre-commit.js @@ -1,7 +1,7 @@ const fs = require('fs'); const { execSync } = require('child_process'); -// Enums +// ENUMS const FILE_EXTENSION = { TYPESCRIPT: "TYPESCRIPT", @@ -17,7 +17,7 @@ const RUNTIME = { NODEJS: "NODEJS" } -// Maps +// MAPS const FILE_EXTENSION_FILTERS = { [FILE_EXTENSION.TYPESCRIPT]: "\.ts$", @@ -44,7 +44,7 @@ const FOLDER_RUNTIME = { [FOLDER.SDK]: RUNTIME.NODEJS, }; -// Main function +// MAIN FUNCTION main(); @@ -54,9 +54,11 @@ function main() { partitionChangedFileList(changedFileList); console.timeEnd('GET_CHANGED_FILE_LIST_TIMER'); - // Iterate through each folder for (const folder in FOLDER) { - if (!isDependenciesInstalled(folder)) process.exit(1); + if (!isDependenciesInstalled(folder)) { + console.error(`Dependencies not installed in ${FOLDER_PATH[folder]}, exiting...`) + process.exit(1); + } const changedFileExtensions = getChangedFileExtensions(folder); executeLinting(folder, changedFileExtensions); } @@ -64,7 +66,8 @@ function main() { updateGitIndex(); } -// Utility functions +// HELPER FUNCTIONS + function getChangedFileList() { try { const cmd = 'git diff --name-only HEAD' @@ -79,7 +82,6 @@ function getChangedFileList() { function partitionChangedFileList(_changedFileList) { // Populate lists of filter matches for (const file of _changedFileList) { - // ? Should we do better than O(N) iterating through each path. for (const path in FOLDER) { if (file.match(new RegExp(`^${FOLDER_PATH[path]}`))) { FOLDER_CHANGED_FILES[path].push(file); @@ -97,16 +99,16 @@ function isDependenciesInstalled(_folder) { const dependencyFolder = `${path}node_modules` return fs.existsSync(dependencyFolder) default: + console.error(`${runtime} runtime not supported.`); return false } } function getChangedFileExtensions(_folder) { - // Use sets to stop iterating through changed files, once we have found all file extensions of interest. + // Use sets to implement early exit from iteration of all changed files, once we have matched all file extensions of interest. const remainingFileExtensionsSet = new Set(Object.values(FILE_EXTENSION)); const foundFileExtensionsSet = new Set(); - // Iterate through each changed file, look for file extension matches for (const file of FOLDER_CHANGED_FILES[_folder]) { for (const fileExtension of remainingFileExtensionsSet) { if (file.match(new RegExp(FILE_EXTENSION_FILTERS[fileExtension]))) { From d9ad23aa58579af0e23f1e6b408193d60d97ba0e Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Fri, 6 Dec 2024 00:44:00 +1100 Subject: [PATCH 24/30] add shebang to pre-commit --- .husky/pre-commit | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.husky/pre-commit b/.husky/pre-commit index 9455de62e..6bd65572b 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,5 @@ +#!/bin/bash + # For this to run on pre-commit hook, should run `npx husky` in root after `git clone` repo onto dev machine echo "RUNNING HUSKY PRE-COMMIT HOOK" From c9875d15f39a91cb009b28058b111eed5fed9c5e Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 12 Dec 2024 00:22:28 +1100 Subject: [PATCH 25/30] add other folders to husky script --- .husky/pre-commit | 1 - .husky/pre-commit.js | 21 ++++++++++++++++++--- bridge-ui/package.json | 1 + operations/package.json | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 6bd65572b..f9f0dc8c6 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,7 +1,6 @@ #!/bin/bash # For this to run on pre-commit hook, should run `npx husky` in root after `git clone` repo onto dev machine -echo "RUNNING HUSKY PRE-COMMIT HOOK" # Execute NodeJS script because # i.) Husky requires NodeJS -> fair assumption that machine will have NodeJS diff --git a/.husky/pre-commit.js b/.husky/pre-commit.js index 9602ced69..d3dd9da39 100644 --- a/.husky/pre-commit.js +++ b/.husky/pre-commit.js @@ -9,7 +9,11 @@ const FILE_EXTENSION = { } const FOLDER = { + BRIDGEUI: "BRIDGEUI", CONTRACTS: "CONTRACTS", + E2E: "E2E", + OPERATIONS: "OPERATIONS", + // POSTMAN: "POSTMAN", SDK: "SDK", } @@ -25,22 +29,35 @@ const FILE_EXTENSION_FILTERS = { }; const FILE_EXTENSION_LINTING_COMMAND = { - [FILE_EXTENSION.TYPESCRIPT]: "pnpm run lint:ts", + [FILE_EXTENSION.TYPESCRIPT]: "pnpm run lint:ts:fix", [FILE_EXTENSION.SOLIDITY]: "pnpm run lint:sol", }; const FOLDER_PATH = { + + [FOLDER.BRIDGEUI]: "bridge-ui/", [FOLDER.CONTRACTS]: "contracts/", + [FOLDER.E2E]: "e2e/", + [FOLDER.OPERATIONS]: "operations/", + // [FOLDER.POSTMAN]: "postman/", [FOLDER.SDK]: "sdk/", }; const FOLDER_CHANGED_FILES = { + [FOLDER.BRIDGEUI]: new Array(), [FOLDER.CONTRACTS]: new Array(), + [FOLDER.E2E]: new Array(), + [FOLDER.OPERATIONS]: new Array(), + // [FOLDER.POSTMAN]: new Array(), [FOLDER.SDK]: new Array(), }; const FOLDER_RUNTIME = { + [FOLDER.BRIDGEUI]: RUNTIME.NODEJS, [FOLDER.CONTRACTS]: RUNTIME.NODEJS, + [FOLDER.E2E]: RUNTIME.NODEJS, + [FOLDER.OPERATIONS]: RUNTIME.NODEJS, + // [FOLDER.POSTMAN]: RUNTIME.NODEJS, [FOLDER.SDK]: RUNTIME.NODEJS, }; @@ -49,10 +66,8 @@ const FOLDER_RUNTIME = { main(); function main() { - console.time('GET_CHANGED_FILE_LIST_TIMER'); const changedFileList = getChangedFileList(); partitionChangedFileList(changedFileList); - console.timeEnd('GET_CHANGED_FILE_LIST_TIMER'); for (const folder in FOLDER) { if (!isDependenciesInstalled(folder)) { diff --git a/bridge-ui/package.json b/bridge-ui/package.json index f92a83960..b3d5ede76 100644 --- a/bridge-ui/package.json +++ b/bridge-ui/package.json @@ -9,6 +9,7 @@ "start": "next start", "lint": "next lint", "lint:fix": "next lint --fix", + "lint:ts:fix": "next lint --fix", "clean": "rimraf node_modules .next .next-env.d.ts", "install:playwright": "playwright install --with-deps", "build:cache": "synpress", diff --git a/operations/package.json b/operations/package.json index a3d436369..374780f27 100644 --- a/operations/package.json +++ b/operations/package.json @@ -10,6 +10,7 @@ "prettier:fix": "prettier -w '**/*.{js,ts}'", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", + "lint:ts:fix": "eslint . --ext .ts --fix", "test": "node --experimental-vm-modules node_modules/jest/bin/jest --bail --detectOpenHandles --forceExit", "clean": "rimraf node_modules dist coverage", "postpack": "shx rm -f oclif.manifest.json", From 0fd9ec5654c448a1e0c2904d55a9b4e011bff3b1 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 12 Dec 2024 00:26:01 +1100 Subject: [PATCH 26/30] added postman to pre-commit --- .husky/pre-commit.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.husky/pre-commit.js b/.husky/pre-commit.js index d3dd9da39..91e1ebbae 100644 --- a/.husky/pre-commit.js +++ b/.husky/pre-commit.js @@ -13,7 +13,7 @@ const FOLDER = { CONTRACTS: "CONTRACTS", E2E: "E2E", OPERATIONS: "OPERATIONS", - // POSTMAN: "POSTMAN", + POSTMAN: "POSTMAN", SDK: "SDK", } @@ -39,7 +39,7 @@ const FOLDER_PATH = { [FOLDER.CONTRACTS]: "contracts/", [FOLDER.E2E]: "e2e/", [FOLDER.OPERATIONS]: "operations/", - // [FOLDER.POSTMAN]: "postman/", + [FOLDER.POSTMAN]: "postman/", [FOLDER.SDK]: "sdk/", }; @@ -48,7 +48,7 @@ const FOLDER_CHANGED_FILES = { [FOLDER.CONTRACTS]: new Array(), [FOLDER.E2E]: new Array(), [FOLDER.OPERATIONS]: new Array(), - // [FOLDER.POSTMAN]: new Array(), + [FOLDER.POSTMAN]: new Array(), [FOLDER.SDK]: new Array(), }; @@ -57,7 +57,7 @@ const FOLDER_RUNTIME = { [FOLDER.CONTRACTS]: RUNTIME.NODEJS, [FOLDER.E2E]: RUNTIME.NODEJS, [FOLDER.OPERATIONS]: RUNTIME.NODEJS, - // [FOLDER.POSTMAN]: RUNTIME.NODEJS, + [FOLDER.POSTMAN]: RUNTIME.NODEJS, [FOLDER.SDK]: RUNTIME.NODEJS, }; From 9c0d551c83ebef8928f073202cd48007a41ecc41 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 12 Dec 2024 00:40:08 +1100 Subject: [PATCH 27/30] remove test md change --- contracts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/README.md b/contracts/README.md index 2d22f6bbb..efa4eed77 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -12,7 +12,7 @@ The Linea Rollup, which contains the L1MessageService, is the smart contract tha - Finalization of L2 state on L1 using a Zero Knowledge Proof. ## L2MessageService -The L2MessageService is the L2 smart contract that is responsible for: +The L2MessageService is the L2 smart contract that is responsible for: - Submitting messages to be sent to L1 for later claiming. - Anchoring of L1 to L2 Message hashes for later claiming. From 4b935115342bb7be5ca4d61e2d82e28aee5190a4 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Wed, 18 Dec 2024 21:06:45 +1100 Subject: [PATCH 28/30] add comments for pre-commit.js --- .husky/pre-commit | 2 +- .husky/pre-commit.js | 64 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index f9f0dc8c6..93acec6f4 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,6 +1,6 @@ #!/bin/bash -# For this to run on pre-commit hook, should run `npx husky` in root after `git clone` repo onto dev machine +# Run `npx husky` in root directory to initialize this pre-commit hook for local machine # Execute NodeJS script because # i.) Husky requires NodeJS -> fair assumption that machine will have NodeJS diff --git a/.husky/pre-commit.js b/.husky/pre-commit.js index 91e1ebbae..44af785ce 100644 --- a/.husky/pre-commit.js +++ b/.husky/pre-commit.js @@ -1,13 +1,24 @@ +/** + * Runs as git pre-commit hook + * Filters the list of changed files on 'git commit' + * If *.ts files in specified projects are detected, runs the 'lint:ts:fix' package.json script for that project + * E.g. if a *.ts file is changed in /sdk, then this script will run 'pnpm run lint:ts:fix' in the /sdk project + */ + const fs = require('fs'); const { execSync } = require('child_process'); -// ENUMS +/** + * ENUMS + */ +// File extensions to filter for const FILE_EXTENSION = { TYPESCRIPT: "TYPESCRIPT", SOLIDITY: "SOLIDITY", } +// Projects to filter for const FOLDER = { BRIDGEUI: "BRIDGEUI", CONTRACTS: "CONTRACTS", @@ -17,24 +28,29 @@ const FOLDER = { SDK: "SDK", } +// Project runtimes const RUNTIME = { NODEJS: "NODEJS" } -// MAPS +/** + * MAPPINGS + */ +// File extension => regex const FILE_EXTENSION_FILTERS = { [FILE_EXTENSION.TYPESCRIPT]: "\.ts$", [FILE_EXTENSION.SOLIDITY]: "\.sol$", }; +// File extension => script in package.json to run const FILE_EXTENSION_LINTING_COMMAND = { [FILE_EXTENSION.TYPESCRIPT]: "pnpm run lint:ts:fix", [FILE_EXTENSION.SOLIDITY]: "pnpm run lint:sol", }; +// Project => Path in monorepo const FOLDER_PATH = { - [FOLDER.BRIDGEUI]: "bridge-ui/", [FOLDER.CONTRACTS]: "contracts/", [FOLDER.E2E]: "e2e/", @@ -43,6 +59,7 @@ const FOLDER_PATH = { [FOLDER.SDK]: "sdk/", }; +// Project => List of changed files const FOLDER_CHANGED_FILES = { [FOLDER.BRIDGEUI]: new Array(), [FOLDER.CONTRACTS]: new Array(), @@ -52,6 +69,7 @@ const FOLDER_CHANGED_FILES = { [FOLDER.SDK]: new Array(), }; +// Project => Runtime const FOLDER_RUNTIME = { [FOLDER.BRIDGEUI]: RUNTIME.NODEJS, [FOLDER.CONTRACTS]: RUNTIME.NODEJS, @@ -61,7 +79,9 @@ const FOLDER_RUNTIME = { [FOLDER.SDK]: RUNTIME.NODEJS, }; -// MAIN FUNCTION +/** + * MAIN FUNCTION + */ main(); @@ -81,8 +101,14 @@ function main() { updateGitIndex(); } -// HELPER FUNCTIONS +/** + * HELPER FUNCTIONS + */ +/** + * Gets a list of changed files in the git commit + * @returns {string[]} + */ function getChangedFileList() { try { const cmd = 'git diff --name-only HEAD' @@ -94,8 +120,12 @@ function getChangedFileList() { } } +/** + * Partitions list of changed files from getChangedFileList() by project + * Stores results in FOLDER_CHANGED_FILES + * @param {string[]} + */ function partitionChangedFileList(_changedFileList) { - // Populate lists of filter matches for (const file of _changedFileList) { for (const path in FOLDER) { if (file.match(new RegExp(`^${FOLDER_PATH[path]}`))) { @@ -105,6 +135,11 @@ function partitionChangedFileList(_changedFileList) { } } +/** + * Checks if runtime dependencies are installed for a project + * @param {FOLDER} + * @returns {boolean} + */ function isDependenciesInstalled(_folder) { const runtime = FOLDER_RUNTIME[_folder]; const path = FOLDER_PATH[_folder]; @@ -119,8 +154,13 @@ function isDependenciesInstalled(_folder) { } } +/** + * Resolve list of changed file extensions for a project + * @param {FOLDER} + * @returns {FILE_EXTENSION[]} + */ function getChangedFileExtensions(_folder) { - // Use sets to implement early exit from iteration of all changed files, once we have matched all file extensions of interest. + // Use sets to implement early exit from loop, once we have matched all configured file extensions const remainingFileExtensionsSet = new Set(Object.values(FILE_EXTENSION)); const foundFileExtensionsSet = new Set(); @@ -139,13 +179,17 @@ function getChangedFileExtensions(_folder) { return Array.from(foundFileExtensionsSet); } +/** + * Execute linting command + * @param {FOLDER, FILE_EXTENSION[]} + */ function executeLinting(_folder, _changedFileExtensions) { for (const fileExtension of _changedFileExtensions) { const path = FOLDER_PATH[_folder]; const cmd = FILE_EXTENSION_LINTING_COMMAND[fileExtension]; console.log(`${fileExtension} change found in ${path}, linting...`); try { - // Execute command synchronously and route output directly to the current stdout + // Execute command synchronously and stream output directly to the current stdout execSync(` cd ${path}; ${cmd}; @@ -158,6 +202,10 @@ function executeLinting(_folder, _changedFileExtensions) { } } +/** + * Redo `git add` for files updated during executeLinting(), so that they are not left out of the commit + * The difference between 'git add .' and 'git update-index --again', is that the latter will not include untracked files + */ function updateGitIndex() { try { const cmd = 'git update-index --again' From 3b3dd33f254e7c83c4ccf98bdc82d638e23596c6 Mon Sep 17 00:00:00 2001 From: kyzooghost Date: Thu, 19 Dec 2024 00:17:41 +1100 Subject: [PATCH 29/30] adjust lint:fix scripts --- bridge-ui/package.json | 2 +- operations/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge-ui/package.json b/bridge-ui/package.json index b3d5ede76..06af155cc 100644 --- a/bridge-ui/package.json +++ b/bridge-ui/package.json @@ -8,7 +8,7 @@ "build": "next build", "start": "next start", "lint": "next lint", - "lint:fix": "next lint --fix", + "lint:fix": "pnpm run lint:ts:fix", "lint:ts:fix": "next lint --fix", "clean": "rimraf node_modules .next .next-env.d.ts", "install:playwright": "playwright install --with-deps", diff --git a/operations/package.json b/operations/package.json index 374780f27..d8762b068 100644 --- a/operations/package.json +++ b/operations/package.json @@ -9,7 +9,7 @@ "prettier": "prettier -c '**/*.{js,ts}'", "prettier:fix": "prettier -w '**/*.{js,ts}'", "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", + "lint:fix": "pnpm run lint:ts:fix", "lint:ts:fix": "eslint . --ext .ts --fix", "test": "node --experimental-vm-modules node_modules/jest/bin/jest --bail --detectOpenHandles --forceExit", "clean": "rimraf node_modules dist coverage", From 1426dbf1f5137db4587d110ee34a6e4e3908bd8c Mon Sep 17 00:00:00 2001 From: kyzooghost <73516204+kyzooghost@users.noreply.github.com> Date: Fri, 20 Dec 2024 23:03:49 +1100 Subject: [PATCH 30/30] Update .husky/pre-commit.js Co-authored-by: The Dark Jester Signed-off-by: kyzooghost <73516204+kyzooghost@users.noreply.github.com> --- .husky/pre-commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-commit.js b/.husky/pre-commit.js index 44af785ce..86d60c090 100644 --- a/.husky/pre-commit.js +++ b/.husky/pre-commit.js @@ -46,7 +46,7 @@ const FILE_EXTENSION_FILTERS = { // File extension => script in package.json to run const FILE_EXTENSION_LINTING_COMMAND = { [FILE_EXTENSION.TYPESCRIPT]: "pnpm run lint:ts:fix", - [FILE_EXTENSION.SOLIDITY]: "pnpm run lint:sol", + [FILE_EXTENSION.SOLIDITY]: "pnpm run lint:sol:fix", }; // Project => Path in monorepo