-
Notifications
You must be signed in to change notification settings - Fork 70
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
Get genesis validation checks to run on CI #529
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d3afe53
switch to cimg/go:1.22.6-node docker image for genesis validation
geoknee e041b41
remove set -e
geoknee 578f64f
use bash instead of sh
geoknee 95409a1
use . instead of source
geoknee c5b9754
install pnpm
geoknee 8ac836c
move optimism-temporary out from under superchain-registry
geoknee 585e25a
do not allow validate-genesis to timeout
geoknee 25649b6
improve pipefail behaviour
geoknee 1bfb9a2
just lint-all
geoknee 6e6d9a9
remove all set -e behaviour
geoknee 703267d
stream output from test
geoknee 34afc3e
try running as a matrix
geoknee f0021f9
add base and base sepolia to genesis validation list (#530)
geoknee 25831cb
add comment
geoknee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package genesis | ||
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
"os/exec" | ||
|
@@ -26,7 +28,23 @@ func perChainTestName(chain *superchain.ChainConfig) string { | |
return chain.Name + fmt.Sprintf(" (%d)", chain.ChainID) | ||
} | ||
|
||
var temporaryOptimismDir string | ||
|
||
func TestGenesisPredeploys(t *testing.T) { | ||
// | ||
// Clone optimism into gitignored temporary directory (if that directory does not yet exist) | ||
geoknee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_, filename, _, ok := runtime.Caller(0) | ||
if !ok { | ||
panic("No caller information") | ||
} | ||
thisDir := filepath.Dir(filename) | ||
temporaryOptimismDir = path.Join(thisDir, "../../../optimism-temporary") | ||
|
||
if _, err := os.Stat(temporaryOptimismDir); os.IsNotExist(err) { | ||
mustExecuteCommandInDir(thisDir, | ||
exec.Command("git", "clone", "https://github.com/ethereum-optimism/optimism.git", temporaryOptimismDir)) | ||
} | ||
|
||
for _, chain := range OPChains { | ||
if chain.SuperchainLevel == Standard || chain.StandardChainCandidate { | ||
t.Run(perChainTestName(chain), func(t *testing.T) { | ||
|
@@ -35,6 +53,8 @@ func TestGenesisPredeploys(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
// TODO cleanup temporaryOptimismDir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a github issue I think (if you are not planning to address in this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will address that on the feature branch PR before merging that one. |
||
} | ||
|
||
// Invoke this with go test -timeout 0 ./validation/genesis -run=TestGenesisPredeploys -v | ||
|
@@ -55,7 +75,7 @@ func testGenesisPredeploys(t *testing.T, chain *ChainConfig) { | |
thisDir := getDirOfThisFile() | ||
chainIdString := strconv.Itoa(int(chainId)) | ||
validationInputsDir := path.Join(thisDir, "validation-inputs", chainIdString) | ||
monorepoDir := path.Join(thisDir, "optimism-temporary") | ||
monorepoDir := temporaryOptimismDir | ||
contractsDir := path.Join(monorepoDir, "packages/contracts-bedrock") | ||
|
||
// reset to appropriate commit, this is preferred to git checkout because it will | ||
|
@@ -92,7 +112,22 @@ func testGenesisPredeploys(t *testing.T, chain *ChainConfig) { | |
panic("must set node_version in meta.toml") | ||
} | ||
creationCommand := GenesisCreationCommand[vis.GenesisCreationCommand](chainId, Superchains[chain.Superchain].Config.L1.PublicRPC) | ||
mustExecuteCommandInDir(monorepoDir, exec.Command("sh", "./monorepo-outputs.sh", vis.NodeVersion, buildCommand, creationCommand)) | ||
cmd := exec.Command("bash", "./monorepo-outputs.sh", vis.NodeVersion, buildCommand, creationCommand) | ||
// Create a pipe to read the command's output | ||
stdoutPipe, err := cmd.StdoutPipe() | ||
if err != nil { | ||
t.Fatalf("Failed to get stdout pipe: %v", err) | ||
} | ||
|
||
stderrPipe, err := cmd.StderrPipe() | ||
if err != nil { | ||
t.Fatalf("Failed to get stderr pipe: %v", err) | ||
} | ||
// Stream the command's stdout and stderr to the test logger | ||
go streamOutputToLogger(stdoutPipe, t) | ||
go streamOutputToLogger(stderrPipe, t) | ||
|
||
mustExecuteCommandInDir(monorepoDir, cmd) | ||
|
||
expectedData, err := os.ReadFile(path.Join(monorepoDir, "expected-genesis.json")) | ||
require.NoError(t, err) | ||
|
@@ -142,6 +177,16 @@ func writeDeployments(chainId uint64, directory string) error { | |
return nil | ||
} | ||
|
||
func streamOutputToLogger(reader io.Reader, t *testing.T) { | ||
scanner := bufio.NewScanner(reader) | ||
for scanner.Scan() { | ||
t.Log(scanner.Text()) | ||
} | ||
if err := scanner.Err(); err != nil { | ||
t.Errorf("Error reading command output: %v", err) | ||
} | ||
} | ||
|
||
func writeDeploymentsLegacy(chainId uint64, directory string) error { | ||
// Prepare a HardHat Deployment type, we need this whole structure to make things | ||
// work, although it is only the Address field which ends up getting used. | ||
|
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
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 |
---|---|---|
@@ -1,25 +1,20 @@ | ||
set -e | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | ||
|
||
echo "Inferring and selecting correct Node version" | ||
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | ||
echo "Installing and selecting correct Node version" | ||
nvm install $1 | ||
nvm use $1 | ||
|
||
echo "Running install command" | ||
eval $2 | ||
|
||
echo "Inferring and selecting correct go version" | ||
|
||
echo "Installing and selecting correct go version" | ||
go_version=$(grep -m 1 '^go ' go.mod | awk '{print $2}') | ||
|
||
# Source the gvm script to load gvm functions into the shell | ||
set +e | ||
source ~/.gvm/scripts/gvm || exit 1 | ||
gvm install go${go_version} || exit 1 | ||
gvm use go${go_version} || exit 1 | ||
set -e | ||
|
||
. ~/.gvm/scripts/gvm | ||
gvm install go${go_version} | ||
gvm use go${go_version} | ||
|
||
echo "Running op-node genesis l2 command" | ||
|
||
eval "$3" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be helpful to add a comment above the chain IDs with the names of the chains as well.