Skip to content

Commit 3c1a8da

Browse files
authored
Add a justfile (#366)
1 parent 547da23 commit 3c1a8da

File tree

11 files changed

+120
-77
lines changed

11 files changed

+120
-77
lines changed

.circleci/config.yml

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ version: 2.1
22

33
orbs:
44
go: circleci/[email protected]
5+
node: circleci/[email protected]
56
slack: circleci/[email protected]
67

78
commands:
@@ -17,32 +18,32 @@ commands:
1718
event: fail
1819
template: basic_fail_1
1920
branch_pattern: main
21+
install-just:
22+
description: "Install just"
23+
steps:
24+
- run: |
25+
wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/null
26+
echo "deb [arch=all,$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr $(lsb_release -cs)" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.list
27+
sudo apt update
28+
sudo apt install just
29+
2030
jobs:
2131
golang-lint:
2232
executor:
2333
name: go/default # is based on cimg/go
2434
tag: '1.21'
2535
steps:
2636
- checkout
27-
- run: golangci-lint run superchain/... validation/... add-chain/...
37+
- install-just
38+
- run: just lint-all
2839
golang-modules-tidy:
2940
executor:
3041
name: go/default # is based on cimg/go
3142
tag: '1.21'
3243
steps:
3344
- checkout
34-
- run:
35-
name: tidy superchain module
36-
command: go mod tidy
37-
working_directory: superchain
38-
- run:
39-
name: tidy validation module
40-
command: go mod tidy
41-
working_directory: validation
42-
- run:
43-
name: tidy add-chain module
44-
command: go mod tidy
45-
working_directory: add-chain
45+
- install-just
46+
- run: just tidy-all
4647
- run:
4748
name: check git tree is clean
4849
command: git diff --exit-code
@@ -53,6 +54,7 @@ jobs:
5354
tag: '1.21'
5455
steps:
5556
- checkout
57+
- install-just
5658
- run:
5759
# need foundry to execute 'cast call' within add-chain script
5860
name: Install foundry
@@ -71,23 +73,13 @@ jobs:
7173
forge --version
7274
- run:
7375
name: run superchain module tests
74-
command: go test ./... -v
75-
working_directory: superchain
76+
command: just test-superchain
7677
- run:
7778
name: run validation module tests
78-
command: go test ./... -v
79-
working_directory: validation
80-
- run:
81-
name: run add-chain module main test
82-
# We force this test to run first because it creates artifacts that must
83-
# be imported by subsequent tests
84-
command: go test -run TestAddChain_Main -v
85-
working_directory: add-chain
79+
command: just test-validation
8680
- run:
87-
name: run add-chain module additional tests
88-
# Now run all other tests (excluding TestAddChain_Main)
89-
command: go test -run '[^TestAddChain_Main]' -v
90-
working_directory: add-chain
81+
name: run add-chain module tests
82+
command: just test-add-chain
9183
- notify-failures-on-main
9284
publish-bot:
9385
environment:
@@ -110,12 +102,13 @@ jobs:
110102
tag: '1.21'
111103
steps:
112104
- checkout
105+
- install-just
106+
- node/install:
107+
install-yarn: false
108+
node-version: '14.16.1'
113109
- run:
114110
name: Run codegen
115-
command: go run superchain/internal/codegen/main.go
116-
- run:
117-
name: Check for changes
118-
command: git diff --exit-code
111+
command: just codegen
119112

120113
workflows:
121114
hourly:

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ SCR_SUPERCHAIN_TARGET=mainnet
1111
SCR_CHAIN_SHORT_NAME=awsm
1212

1313
SCR_CHAIN_TYPE=frontier # chain type (frontier or standard)
14+
15+
# Set to true to run most of the validation checks for standard chains
16+
# CHAIN_TYPE must be frontier
1417
SCR_STANDARD_CHAIN_CANDIDATE=false
18+
1519
SCR_MONOREPO_DIR=../optimism # path to local "ethereum-optimism/optimism" monorepo
1620
SCR_DEPLOYMENTS_DIR=${SCR_MONOREPO_DIR}/packages/contracts-bedrock/deployments/getting-started
1721
SCR_ROLLUP_CONFIG=${SCR_MONOREPO_DIR}/op-node/rollup.json

README.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,29 @@ This is to ensure your chain has a unique chain ID. Our validation suite will ch
3131

3232

3333
### 1. Install dependencies
34-
You will need [`jq`](https://jqlang.github.io/jq/download/) and [`foundry`](https://book.getfoundry.sh/getting-started/installation) installed, as well as Go.
34+
You will need [`jq`](https://jqlang.github.io/jq/download/) and [`foundry`](https://book.getfoundry.sh/getting-started/installation) installed, as well as Go and [`just`](https://just.systems/man/en/).
3535

3636
### 2. Set env vars
3737

3838
To contribute a standard OP-Stack chain configuration, in addition to user-supplied metadata (chain name) the following data is required: contracts deployment, rollup config, L2 genesis. We provide a tool to scrape this information from your local [monorepo](https://github.com/ethereum-optimism/optimism) folder.
3939

4040
First, make a copy of `.env.example` named `.env`, and alter the variables to appropriate values.
41-
42-
### 3. Run script
43-
4441
#### Frontier chains
4542

4643
Frontier chains are chains with customizations beyond the standard OP
4744
Stack configuration. To contribute a frontier OP-Stack chain
48-
configuration, you can run:
49-
45+
configuration, you set the `SCR_CHAIN_TYPE=frontier` in the `.env` file.
5046

51-
```shell
52-
sh scripts/add-chain.sh frontier
53-
```
5447

5548
#### Standard chains
5649
A chain may meet the definition of a **standard** chain. Adding a standard chain is a two-step process.
5750

58-
First, the chain should be added as a frontier chain but with `--standard-chain-candidate` flag set:
51+
First, the chain should be added as a frontier chain as above, but with `SCR_STANDARD_CHAIN_CANDIDATE=true` in the `.env` file.
52+
53+
### 3. Run script
5954

6055
```shell
61-
sh scripts/add-chain.sh frontier --standard-chain-candidate
56+
just add-chain
6257
```
6358

6459
The remaining steps should then be followed to merge the config data into the registry -- a prerequisite for [promoting the chain](#promote-a-chain-to-standard) to a standard chain.
@@ -85,26 +80,25 @@ The format is a gzipped JSON `genesis.json` file, with either:
8580

8681
### 5. Run tests locally
8782

88-
Run the following command from the `validation` folder to run the Go validation checks, for only the chain you added (replace the chain name or ID accordingly):
83+
Run the following command to run the Go validation checks, for only the chain you added (replace the chain name or ID accordingly):
8984
```
90-
go test -run=TestValidation/OP_Sepolia
85+
just validate OP_Sepolia
9186
```
9287
or
9388
```
94-
go test -run=TestValidation/11155420
89+
just validate 11155420
9590
```
96-
Omit the `-run=` flag to run checks for all chains.
9791

9892
> [!NOTE]
99-
> If you set `--standard-chain-candidate`, your chain will be checked against the majority of the standard configuration requirements. These are defined in the [specs](https://specs.optimism.io/protocol/configurability.html). However, these requirements are currently a draft, pending governance approval.
93+
> If you set `SCR_STANDARD_CHAIN_CANDIDATE`, your chain will be checked against the majority of the standard configuration requirements. These are defined in the [specs](https://specs.optimism.io/protocol/configurability.html). However, these requirements are currently a draft, pending governance approval.
10094
>
10195
> The final requirement to qualify as a standard chain concerns the `ProxyAdminOwner` role. The validation check for this role will not be run until the chain is [promoted](#promote-a-chain-to-standard) to standard.
10296
10397
### 6. Run codegen and check output
10498
This is a tool which will rewrite certain summary files of all the chains in the registry, including the one you are adding. The output will be checked in a continuous integration checks (it is required to pass):
10599

106100
```
107-
sh scripts/codegen.sh
101+
just codegen
108102
```
109103

110104
> [!NOTE]
@@ -123,7 +117,7 @@ This process is only possible for chains already in the registry.
123117

124118
Run this command:
125119
```
126-
sh scripts/promote-to-standard.sh <chain-id>
120+
just promote-to-standard <chain-id>
127121
```
128122

129123
This command will:

add-chain/cmd/check-genesis.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
var CheckGenesisCmd = cli.Command{
1717
Name: "check-genesis",
18-
Flags: []cli.Flag{flags.GenesisFlag, flags.ChainIdFlag},
18+
Flags: []cli.Flag{flags.GenesisFlag},
1919
Usage: "Sanity check genesis (genesis.json) is reproducible",
2020
Action: func(ctx *cli.Context) error {
2121
genesisPath := ctx.String(flags.GenesisFlag.Name)
@@ -29,7 +29,8 @@ var CheckGenesisCmd = cli.Command{
2929
return fmt.Errorf("failed to unmarshal local genesis.json into core.Genesis struct: %w", err)
3030
}
3131

32-
chainId := ctx.Uint64(flags.ChainIdFlag.Name)
32+
chainId := localGenesis.Config.ChainID.Uint64()
33+
3334
gethGenesis, err := core.LoadOPStackGenesis(chainId)
3435
if err != nil {
3536
return fmt.Errorf("failed to load genesis via op-geth: ensure chainId has already been added to registry: %w", err)

add-chain/cmd/promote-to-standard.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"path"
65
"path/filepath"
76
"runtime"
87
"time"
@@ -31,14 +30,14 @@ var PromoteToStandardCmd = cli.Command{
3130
now := uint64(time.Now().Unix())
3231
chain.SuperchainTime = &now
3332

34-
_, currentFilePath, _, ok := runtime.Caller(0)
33+
_, thisFile, _, ok := runtime.Caller(0)
3534
if !ok {
3635
panic("Unable to get the current file path")
3736
}
3837

39-
superchainRepoPath := path.Join(currentFilePath, "../..")
38+
superchainRepoPath := filepath.Dir(filepath.Dir(filepath.Dir(thisFile)))
4039
targetDir := filepath.Join(superchainRepoPath, "superchain", "configs", chain.Superchain)
41-
targetFilePath := filepath.Join(targetDir, chain.Name+".yaml")
40+
targetFilePath := filepath.Join(targetDir, chain.Chain+".yaml")
4241
err := config.WriteChainConfig(*chain, targetFilePath)
4342
if err != nil {
4443
panic(err)

add-chain/e2e_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ func TestAddChain_CheckGenesis(t *testing.T) {
149149
"add-chain",
150150
"check-genesis",
151151
"--genesis=" + "./testdata/monorepo/op-node/genesis_zorasep.json",
152-
"--chain-id=" + "4206904",
153152
}
154153
err = runApp(args)
155154
require.NoError(t, err, "add-chain check-genesis failed")

add-chain/testdata/.env.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
SCR_CHAIN_NAME=testchain # L2 chain name
33
SCR_SUPERCHAIN_TARGET=sepolia # L1 chain name
44
SCR_MONOREPO_DIR=./testdata/monorepo
5-
SCR_DEPLOYMENTS_DIR=${MONOREPO_DIR}/deployments
6-
SCR_ROLLUP_CONFIG=${MONOREPO_DIR}/op-node/rollup.json
5+
SCR_DEPLOYMENTS_DIR=${SCR_MONOREPO_DIR}/deployments
6+
SCR_ROLLUP_CONFIG=${SCR_MONOREPO_DIR}/op-node/rollup.json
77
SCR_PUBLIC_RPC="http://awe.some.rpc" # L2 RPC URL
88
SCR_SEQUENCER_RPC="http://awe.some.seq.rpc"
99
SCR_EXPLORER="https://awesomescan.org" # L2 block explorer URL

justfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
set positional-arguments
2+
3+
# Adding a chain
4+
add-chain:
5+
go run ./add-chain
6+
go run ./add-chain check-rollup-config
7+
go run ./add-chain compress-genesis
8+
go run ./add-chain check-genesis
9+
just codegen
10+
11+
# Promote a standard candidate chain to a standard chain, example: just promote-to-standard 10
12+
promote-to-standard CHAIN:
13+
go run ./add-chain promote-to-standard --chain-id={{CHAIN}}
14+
15+
# Generate auto-generated files
16+
codegen:
17+
go run superchain/internal/codegen/main.go
18+
node ./scripts/codegen.js
19+
20+
# Lint all Go code
21+
lint-all:
22+
golangci-lint run superchain/... validation/... add-chain/... --fix
23+
24+
# Test all Go code
25+
test-all: test-add-chain test-superchain test-validation
26+
27+
# Test all Go code in the add-chain module
28+
test-add-chain:
29+
# We separate the first test from the rest because it generates artifacts
30+
# Which need to exist before the remaining tests run.
31+
go test ./add-chain/... -run TestAddChain_Main -v
32+
go test ./add-chain/... -run '[^TestAddChain_Main]' -v
33+
34+
# Test all Go code in the superchain module
35+
test-superchain:
36+
go test ./superchain/... -v
37+
38+
# Test all Go code in the validation module
39+
test-validation:
40+
go test ./validation/... -v
41+
42+
# Run validation checks for chains with a name or chain ID matching the supplied regex, example: just validate 10
43+
validate CHAIN:
44+
go test ./validation/... -v -run=TestValidation/{{CHAIN}}
45+
46+
# Clean test files generated by the add-chain tooling
47+
clean-add-chain:
48+
rm -f superchain/configs/sepolia/testchain_*.yaml
49+
rm -f superchain/extra/addresses/sepolia/testchain_*.json
50+
rm -f superchain/extra/genesis-system-configs/sepolia/testchain_*.json
51+
52+
# Tidying all go.mod files
53+
tidy-all: tidy-add-chain tidy-superchain tidy-validation
54+
55+
# Tidy the add-chain go.mod file
56+
tidy-add-chain:
57+
cd add-chain && go mod tidy
58+
59+
# Tidy the superchain go.mod file
60+
tidy-superchain:
61+
cd superchain && go mod tidy
62+
63+
# Tidy the validation go.mod file
64+
tidy-validation:
65+
cd validation && go mod tidy
66+
67+
# Removing a chain, example: just remove-chain sepolia op
68+
remove-chain SUPERCHAIN_TARGET CHAIN:
69+
rm superchain/configs/{{SUPERCHAIN_TARGET}}/{{CHAIN}}.yaml
70+
rm superchain/extra/addresses/{{SUPERCHAIN_TARGET}}/{{CHAIN}}.json
71+
rm superchain/extra/genesis-system-configs/{{SUPERCHAIN_TARGET}}/{{CHAIN}}.json
72+
rm superchain/extra/genesis/{{SUPERCHAIN_TARGET}}/{{CHAIN}}.json.gz

scripts/add-chain.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

scripts/codegen.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)