diff --git a/.circleci/config.yml b/.circleci/config.yml index 7700560ac..049731493 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/validation/.gitignore b/validation/.gitignore index 8a5e1f691..0c444819b 100644 --- a/validation/.gitignore +++ b/validation/.gitignore @@ -4,3 +4,6 @@ generate-genesis/output-* # test output artifacts genesis/validation-inputs/*-test + +# optimism monorepo used for genesis validation +genesis/optimism-temporary diff --git a/validation/genesis/genesis-predeploy_test.go b/validation/genesis/genesis-predeploy_test.go index 981599dec..44078343e 100644 --- a/validation/genesis/genesis-predeploy_test.go +++ b/validation/genesis/genesis-predeploy_test.go @@ -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 { @@ -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) diff --git a/validation/genesis/genesis.go b/validation/genesis/genesis.go index 04f8f859a..2591dd2b4 100644 --- a/validation/genesis/genesis.go +++ b/validation/genesis/genesis.go @@ -3,7 +3,11 @@ package genesis import ( "embed" "fmt" + "os" + "os/exec" "path" + "path/filepath" + "runtime" "strconv" "strings" @@ -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"))) + } } } diff --git a/validation/genesis/utils.go b/validation/genesis/utils.go index ebdce95a2..66aa41e04 100644 --- a/validation/genesis/utils.go +++ b/validation/genesis/utils.go @@ -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 @@ -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) } }