Skip to content

Commit

Permalink
use localised, gitignored optimism-temporary directory for genesis va…
Browse files Browse the repository at this point in the history
…lidation purposes (#507)
  • Loading branch information
geoknee authored Aug 28, 2024
1 parent 6793309 commit 1365e25
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ commands:
validate-genesis:
description: "Runs genesis validation checks"
steps:
- run:
name: Clone monorepo
command: mkdir ../optimism-temporary && git clone https://github.com/ethereum-optimism/optimism.git ../optimism-temporary
- run: just validate-genesis "*"

jobs:
Expand Down
3 changes: 3 additions & 0 deletions validation/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ generate-genesis/output-*

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

# optimism monorepo used for genesis validation
genesis/optimism-temporary
18 changes: 9 additions & 9 deletions validation/genesis/genesis-predeploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ 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 := path.Join(thisDir, "optimism-temporary")
contractsDir := path.Join(monorepoDir, "packages/contracts-bedrock")

// reset to appropriate commit, this is preferred to git checkout because it will
// blow away any leftover files from the previous run
mustExecuteCommandInDir(t, monorepoDir, exec.Command("git", "reset", "--hard", monorepoCommit))
mustExecuteCommandInDir(t, monorepoDir, exec.Command("rm", "-rf", "node_modules"))
mustExecuteCommandInDir(t, contractsDir, exec.Command("rm", "-rf", "node_modules"))
mustExecuteCommandInDir(monorepoDir, exec.Command("git", "reset", "--hard", monorepoCommit))
mustExecuteCommandInDir(monorepoDir, exec.Command("rm", "-rf", "node_modules"))
mustExecuteCommandInDir(contractsDir, exec.Command("rm", "-rf", "node_modules"))

// attempt to apply config.patch
mustExecuteCommandInDir(t, thisDir, exec.Command("cp", "config.patch", monorepoDir))
_ = executeCommandInDir(t, monorepoDir, exec.Command("git", "apply", "config.patch")) // continue on error
mustExecuteCommandInDir(thisDir, exec.Command("cp", "config.patch", monorepoDir))
_ = executeCommandInDir(monorepoDir, exec.Command("git", "apply", "config.patch")) // continue on error

// copy genesis input files to monorepo
mustExecuteCommandInDir(t, validationInputsDir,
mustExecuteCommandInDir(validationInputsDir,
exec.Command("cp", "deploy-config.json", path.Join(contractsDir, "deploy-config", chainIdString+".json")))
err := os.MkdirAll(path.Join(contractsDir, "deployments", chainIdString), os.ModePerm)
if err != nil {
Expand All @@ -86,13 +86,13 @@ func testGenesisPredeploys(t *testing.T, chain *ChainConfig) {
}

// regenerate genesis.json at this monorepo commit.
mustExecuteCommandInDir(t, thisDir, exec.Command("cp", "./monorepo-outputs.sh", monorepoDir))
mustExecuteCommandInDir(thisDir, exec.Command("cp", "./monorepo-outputs.sh", monorepoDir))
buildCommand := BuildCommand[vis.MonorepoBuildCommand]
if vis.NodeVersion == "" {
panic("must set node_version in meta.toml")
}
creationCommand := GenesisCreationCommand[vis.GenesisCreationCommand](chainId, Superchains[chain.Superchain].Config.L1.PublicRPC)
mustExecuteCommandInDir(t, monorepoDir, exec.Command("sh", "./monorepo-outputs.sh", vis.NodeVersion, buildCommand, creationCommand))
mustExecuteCommandInDir(monorepoDir, exec.Command("sh", "./monorepo-outputs.sh", vis.NodeVersion, buildCommand, creationCommand))

expectedData, err := os.ReadFile(path.Join(monorepoDir, "expected-genesis.json"))
require.NoError(t, err)
Expand Down
15 changes: 15 additions & 0 deletions validation/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package genesis
import (
"embed"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"

Expand Down Expand Up @@ -52,6 +56,17 @@ 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
12 changes: 6 additions & 6 deletions validation/genesis/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package genesis
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"testing"
)

func executeCommandInDir(t *testing.T, dir string, cmd *exec.Cmd) error {
t.Logf("executing %s", cmd.String())
func executeCommandInDir(dir string, cmd *exec.Cmd) error {
log.Printf("executing %s", cmd.String())
cmd.Dir = dir
var outErr bytes.Buffer
cmd.Stdout = os.Stdout
Expand All @@ -22,9 +22,9 @@ func executeCommandInDir(t *testing.T, dir string, cmd *exec.Cmd) error {
return err
}

func mustExecuteCommandInDir(t *testing.T, dir string, cmd *exec.Cmd) {
err := executeCommandInDir(t, dir, cmd)
func mustExecuteCommandInDir(dir string, cmd *exec.Cmd) {
err := executeCommandInDir(dir, cmd)
if err != nil {
t.Fatal(err)
panic(err)
}
}

0 comments on commit 1365e25

Please sign in to comment.