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

Get genesis validation checks to run on CI #529

Merged
merged 14 commits into from
Aug 29, 2024
30 changes: 22 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ commands:
steps:
- run:
command: |
apt-get update
apt-get -yq install curl git mercurial make binutils bison gcc build-essential bsdmainutils
sudo apt-get update
sudo apt-get -yq install curl git mercurial make binutils bison gcc build-essential bsdmainutils
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
validate-genesis:
description: "Runs genesis validation checks"
install-pnpm:
description: "Installs pnpm"
steps:
- run: just validate-genesis "*"
- run:
command: |
sudo npm install -g pnpm

jobs:
golang-lint:
Expand Down Expand Up @@ -118,18 +120,27 @@ jobs:
channel: C03N11M0BBN # to slack channel `notify-ci-failures`
golang-validate-genesis:
docker:
- image: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:v0.49.0
- image: cimg/go:1.22.6-node
resource_class: medium
parameters:
chainid:
type: string
steps:
- checkout
- install-pnpm
- install-just
- install-foundry
- install-gvm
- run:
name: Install NVM
command: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
source ~/.bashrc
nvm --version
- validate-genesis # TODO this should also be filtered on modified chains
- run: just validate-genesis <<parameters.chainid>>
# TODO this should also be filtered on modified chains
golang-validate-modified:
shell: /bin/bash -eo pipefail
executor:
Expand Down Expand Up @@ -267,7 +278,10 @@ workflows:
- golang-lint
- golang-modules-tidy
- golang-test
- golang-validate-genesis
- golang-validate-genesis:
matrix:
parameters:
chainid: ["7777777", "4801", "1750", "480","34443", "6806"]
Copy link
Contributor

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.

- golang-validate-modified
- check-codegen
- cargo-tests
Expand Down
3 changes: 1 addition & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ test-validation: clean-add-chain
validate-modified-chains REF:
# Running validation checks only for chains whose config has changed:
git diff --merge-base {{REF}} --name-only 'superchain/configs/*.toml' ':(exclude)superchain/**/superchain.toml' | xargs -r awk '/chain_id/ {print $3}' | xargs -I {} just validate {}

# Run validation checks for chains with a name or chain ID matching the supplied regex, example: just validate 10
validate CHAIN_ID:
TEST_DIRECTORY=./validation go run gotest.tools/gotestsum@latest --format testname -- -run='TestValidation/.+\({{CHAIN_ID}}\)$' -count=1

# Run genesis validation (this is separated from other validation checks, because it is not a part of drift detection)
validate-genesis CHAIN_ID:
TEST_DIRECTORY=./validation/genesis go run gotest.tools/gotestsum@latest --format testname -- -run='TestGenesisPredeploys/.+\({{CHAIN_ID}}\)$' -v
TEST_DIRECTORY=./validation/genesis go run gotest.tools/gotestsum@latest --format standard-verbose -- -run='TestGenesisPredeploys/.+\({{CHAIN_ID}}\)$' -timeout 0

promotion-test:
TEST_DIRECTORY=./validation go run gotest.tools/gotestsum@latest --format dots -- -run Promotion
Expand Down
3 changes: 0 additions & 3 deletions validation/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ generate-genesis/output-*

# test output artifacts
genesis/validation-inputs/*-test

# optimism monorepo used for genesis validation
genesis/optimism-temporary
49 changes: 47 additions & 2 deletions validation/genesis/genesis-predeploy_test.go
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"
Expand All @@ -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) {
Expand All @@ -35,6 +53,8 @@ func TestGenesisPredeploys(t *testing.T) {
})
}
}

// TODO cleanup temporaryOptimismDir
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 0 additions & 15 deletions validation/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package genesis
import (
"embed"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"

Expand Down Expand Up @@ -56,17 +52,6 @@ func init() {

ValidationInputs[uint64(chainID)] = *m

// Clone optimism into gitignored temporary directory (if that directory does not yet exist)
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("No caller information")
}
thisDir := filepath.Dir(filename)

if _, err := os.Stat(path.Join(thisDir, "optimism-temporary")); os.IsNotExist(err) {
mustExecuteCommandInDir(filepath.Dir(filename),
exec.Command("git", "clone", "https://github.com/ethereum-optimism/optimism.git", path.Join(thisDir, "optimism-temporary")))
}
}
}

Expand Down
21 changes: 8 additions & 13 deletions validation/genesis/monorepo-outputs.sh
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"
Loading