Skip to content

Commit

Permalink
Improve docs and justfile formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianBland committed Sep 10, 2024
1 parent f9da409 commit 9004b40
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 74 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ $ just build
```

### Start a local devnet

#### Create a local devnet with the default config file (devnet/standard.yaml)

```shell
$ just create-devnet
```

#### Create a local devnet with a custom config file

Config files must follow the format described in the [optimism-package](https://github.com/ethpandaops/optimism-package) repository.
```shell
$ just devnet-config-file=devnet/minimal.yaml create-devnet
```

### Cleanup a local devnet

```shell
$ just cleanup-devnet
```
Expand All @@ -52,16 +63,36 @@ $ just name=Reader script-args="2000000" generate-fixture

### Test Fixtures in op-program

#### Using fixtures defined by the script name and arguments

```shell
$ just name=<script name> script-args="<script args>" run-fixture
# Example
$ just name=Reader script-args="2000000" run-fixture
```

#### Using a fixture file

```shell
$ just fixture-file=<fixture file> run-fixture
# Example
$ just fixture-file=fixtures/Reader-2000000.json run-fixture
```

### Test Fixtures in Cannon

#### Using fixtures defined by the script name and arguments

```shell
$ just name=<script name> script-args="<script args>" cannon-fixture
# Example
$ just name=Reader script-args="2000000" cannon-fixture
```

#### Using a fixture file

```shell
$ just fixture-file=<fixture file> run-fixture
# Example
$ just fixture-file=fixtures/Reader-2000000.json cannon-fixture
```
121 changes: 47 additions & 74 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,111 +1,84 @@
set dotenv-load

opfp := if `which opfp || true` != "" {
`which opfp`
} else {
"target/debug/opfp"
}
op-program := if `which op-program || true` != "" {
`which op-program`
} else {
join(env("OPTIMISM_DIR"), "op-program/bin/op-program")
}
cannon-dir := if `which cannon || true` != "" {
parent_directory(parent_directory(`which cannon`))
} else {
join(env("OPTIMISM_DIR"), "cannon")
}
set dotenv-load := true

opfp := if `which opfp || true` != "" { `which opfp` } else { "target/debug/opfp" }
op-program := if `which op-program || true` != "" { `which op-program` } else { join(env("OPTIMISM_DIR"), "op-program/bin/op-program") }
cannon-dir := if `which cannon || true` != "" { parent_directory(parent_directory(`which cannon`)) } else { join(env("OPTIMISM_DIR"), "cannon") }
cannon-bin := join(cannon-dir, "bin/cannon")
cannon-state := join(cannon-dir, "state.json")
cannon-meta := join(cannon-dir, "meta.json")

enclave := "devnet"
devnet-config-file := "devnet/minimal.yaml"

devnet-config-file := "devnet/standard.yaml"
account := "TEST"

name := "Writer"
script-file := name + ".s.sol"

# Space-separated list of script arguments
script-args := "1000000"
script-signature := "run(" + \
replace_regex(
replace_regex(
replace_regex(
replace_regex(script-args, "0x[0-9a-fA-F]{40}", "address"),
"\\d+", "uint256",
), "(true|false)", "bool"
), " ", ","
) + ")"

script-args := "1000000"
script-signature := "run(" + replace_regex(replace_regex(replace_regex(replace_regex(script-args, "0x[0-9a-fA-F]{40}", "address"), "\\d+", "uint256"), "(true|false)", "bool"), " ", ",") + ")"
expanded-name := replace_regex(trim(name + " " + script-args), " ", "-")
fixture-file := join("fixtures", expanded-name + ".json")

op-program-output := join("output", "op-program", file_name(fixture-file))
cannon-output := join("output", "cannon", file_name(fixture-file))

verbosity := "-vv"

genesis-path := "op-genesis-configs/genesis.json"
rollup-path := "op-genesis-configs/rollup.json"

# default recipe to display help information
default:
@just --list
@just --list

# Fixes and checks all workspace formatting
fmt: fmt-fix fmt-check

# Fixes the formatting of the workspace
fmt-fix:
cargo +nightly fmt --all
cargo +nightly fmt --all

# Check the formatting of the workspace
fmt-check:
cargo +nightly fmt --all -- --check
cargo +nightly fmt --all -- --check

# Run clippy lints on the workspace
clippy:
cargo +nightly clippy --workspace --all --all-features --all-targets -- -D warnings

# Build for the native target
build *args='':
cargo build --workspace --all $@
cargo build --workspace --all $@

# Shuts down and removes the local devnet
cleanup-devnet:
kurtosis enclave rm {{enclave}} -f
kurtosis enclave rm {{ enclave }} -f

# Creates a new local devnet
create-devnet:
kurtosis run github.com/ethpandaops/optimism-package \
--args-file {{devnet-config-file}} \
--enclave {{enclave}}
--args-file {{ devnet-config-file }} \
--enclave {{ enclave }}

# Generates a fixture for the given script (name) and arguments (script-args)
generate-fixture:
#!/bin/bash
set -e

L2_RPC_URL={{shell("kurtosis service inspect " + enclave + " op-el-1-op-geth-op-node | grep -- ' rpc: ' | sed 's/.*-> //'")}}
ROLLUP_URL={{shell("kurtosis service inspect " + enclave + " op-cl-1-op-node-op-geth | grep -- ' http: ' | sed 's/.*-> //'")}}
L2_RPC_URL={{ shell("kurtosis service inspect " + enclave + " op-el-1-op-geth-op-node | grep -- ' rpc: ' | sed 's/.*-> //'") }}
ROLLUP_URL={{ shell("kurtosis service inspect " + enclave + " op-cl-1-op-node-op-geth | grep -- ' http: ' | sed 's/.*-> //'") }}

forge script \
--non-interactive \
--password="" \
--rpc-url $L2_RPC_URL \
--account {{account}} \
--account {{ account }} \
--broadcast \
--sig "{{script-signature}}" \
script/{{script-file}} \
{{script-args}}
--sig "{{ script-signature }}" \
script/{{ script-file }} \
{{ script-args }}

rm -rf op-genesis-configs
kurtosis files download {{enclave}} op-genesis-configs
kurtosis files download {{ enclave }} op-genesis-configs

L2_BLOCK_NUM=$(($(jq < broadcast/{{script-file}}/2151908/run-latest.json '.receipts[0].blockNumber' -r)))
L2_BLOCK_NUM=$(($(jq < broadcast/{{ script-file }}/2151908/run-latest.json '.receipts[0].blockNumber' -r)))

while true; do
SYNC_STATUS=$(cast rpc optimism_syncStatus --rpc-url $ROLLUP_URL)
Expand All @@ -118,40 +91,40 @@ generate-fixture:
sleep 10
done

mkdir -p {{parent_directory(fixture-file)}}
mkdir -p {{ parent_directory(fixture-file) }}

{{opfp}} from-op-program \
--op-program {{op-program}} \
{{ opfp }} from-op-program \
--op-program {{ op-program }} \
--l2-block $L2_BLOCK_NUM \
--l1-block $L1_BLOCK_NUM \
--l1-rpc-url {{"http://" + shell("kurtosis service inspect " + enclave + " el-1-geth-lighthouse | grep -- ' rpc: ' | sed 's/.*-> //'")}} \
--l1-rpc-url {{ "http://" + shell("kurtosis service inspect " + enclave + " el-1-geth-lighthouse | grep -- ' rpc: ' | sed 's/.*-> //'") }} \
--l2-rpc-url $L2_RPC_URL \
--beacon-url {{shell("kurtosis service inspect " + enclave + " cl-1-lighthouse-geth | grep -- ' http: ' | sed 's/.*-> //'")}} \
--beacon-url {{ shell("kurtosis service inspect " + enclave + " cl-1-lighthouse-geth | grep -- ' http: ' | sed 's/.*-> //'") }} \
--rollup-url $ROLLUP_URL \
--rollup-path {{rollup-path}} \
--genesis-path {{genesis-path}} \
--output {{fixture-file}} \
{{verbosity}}
--rollup-path {{ rollup-path }} \
--genesis-path {{ genesis-path }} \
--output {{ fixture-file }} \
{{ verbosity }}

# Runs the given fixture through the op-program
run-fixture:
mkdir -p {{parent_directory(op-program-output)}}
mkdir -p {{ parent_directory(op-program-output) }}

{{opfp}} run-op-program \
--op-program {{op-program}} \
--fixture {{fixture-file}} \
--output {{op-program-output}} \
{{verbosity}}
{{ opfp }} run-op-program \
--op-program {{ op-program }} \
--fixture {{ fixture-file }} \
--output {{ op-program-output }} \
{{ verbosity }}

# Runs the given fixture through Cannon and op-program
cannon-fixture:
mkdir -p {{parent_directory(cannon-output)}}

{{opfp}} run-op-program \
--op-program {{op-program}} \
--fixture {{fixture-file}} \
--cannon {{cannon-bin}} \
--cannon-state {{cannon-state}} \
--cannon-meta {{cannon-meta}} \
--output {{cannon-output}} \
{{verbosity}}
mkdir -p {{ parent_directory(cannon-output) }}

{{ opfp }} run-op-program \
--op-program {{ op-program }} \
--fixture {{ fixture-file }} \
--cannon {{ cannon-bin }} \
--cannon-state {{ cannon-state }} \
--cannon-meta {{ cannon-meta }} \
--output {{ cannon-output }} \
{{ verbosity }}

0 comments on commit 9004b40

Please sign in to comment.