Skip to content

Commit

Permalink
Merge pull request ethereum-optimism#7874 from ethereum-optimism/tush…
Browse files Browse the repository at this point in the history
…ar/client-pod-issue-131/initializer-ci-check

Issue 131: Verify Initializer Values in Contract & Genesis Match
  • Loading branch information
tynes authored Oct 30, 2023
2 parents 1bc3691 + 72ac254 commit 06e048c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
28 changes: 27 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,28 @@ jobs:
name: check-generated-mocks
command: make generate-mocks-op-service && git diff --exit-code

check-values-match:
parameters:
pattern_file1:
type: string
default: ""
pattern_file2:
type: string
default: ""
file1_path:
type: string
default: ""
file2_path:
type: string
default: ""
docker:
- image: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:latest
steps:
- checkout
- run:
name: Verify Values Match
command: |
./ops/scripts/ci-match-values-between-files.sh "<< parameters.file1_path >>" "<< parameters.pattern_file1 >>" "<< parameters.file2_path >>" "<< parameters.pattern_file2 >>"
workflows:
main:
when:
Expand Down Expand Up @@ -1477,7 +1499,11 @@ workflows:
- check-generated-mocks-op-service
- cannon-go-lint-and-test
- cannon-build-test-vectors

- check-values-match:
pattern_file1: "uint8 internal constant INITIALIZER ="
pattern_file2: "const initializedValue ="
file1_path: "packages/contracts-bedrock/src/libraries/Constants.sol"
file2_path: "op-chain-ops/genesis/config.go"
release:
when:
not:
Expand Down
57 changes: 57 additions & 0 deletions ops/scripts/ci-match-values-between-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

set -euo pipefail

FILE1=$1
PATTERN1=$2
FILE2=$3
PATTERN2=$4

# shellcheck disable=SC2016
SCRIPT='
BEGIN {
in_comment = 0;
matches = 0;
}
/^ *\/\*/ {
in_comment = 1;
}
in_comment && /\*\// {
in_comment = 0;
next;
}
!in_comment && !/^ *\/\// && $0 ~ PATTERN {
matches++;
matched_line = $0;
}
END {
if (matches == 1) {
print matched_line;
} else if (matches > 1) {
print "Multiple matches found. Exiting.";
exit 1;
} else {
print "No matches found. Exiting.";
exit 1;
}
}'

VALUE1_MATCH=$(echo "$SCRIPT" | awk -v PATTERN="$PATTERN1" -f- "$FILE1")
VALUE1=$(echo "$VALUE1_MATCH" | awk -F'=' '{print $2}' | tr -d ' ;')
echo "Value from File 1: $VALUE1"

VALUE2_MATCH=$(echo "$SCRIPT" | awk -v PATTERN="$PATTERN2" -f- "$FILE2")
VALUE2=$(echo "$VALUE2_MATCH" | awk -F'=' '{print $2}' | tr -d ' ;')
echo "Value from File 2: $VALUE2"

if [ "$VALUE1" != "$VALUE2" ]; then
echo "Error: Values from file1 ($VALUE1) and file2 ($VALUE2) don't match."
exit 1
fi

echo "Values match!"

0 comments on commit 06e048c

Please sign in to comment.