Skip to content

Commit

Permalink
Add back unit tests to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mslipper committed Dec 31, 2024
1 parent d004f23 commit dbee18d
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 26 deletions.
88 changes: 88 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
version: 2.1

orbs:
codecov: codecov/[email protected]

jobs:
go-lint-test:
parameters:
package:
type: string
docker:
- image: cimg/go:1.23.1
steps:
- checkout
- run:
name: Tidy mod
command: |
go mod tidy
git diff --exit-code
working_directory: << parameters.package >>
- run:
name: Lint
command: golangci-lint run ./...
working_directory: << parameters.package >>
- run:
name: Run tests
command: gotestsum --format testname --junitfile test-results.xml --packages=./... -- --coverprofile coverage.out
working_directory: << parameters.package >>
- store_test_results:
path: << parameters.package >>/test-results.xml
- codecov/upload:
disable_search: true
files: ./<<parameters.package>>/coverage.out

run-tool:
parameters:
tool:
type: string
args:
type: string
default: ""
check_diff:
type: boolean
default: false
docker:
- image: cimg/go:1.23.1
steps:
- checkout
- run:
name: Build tool
command: go build -o ./bin/<<parameters.tool>> ./cmd/<< parameters.tool >>/main.go
working_directory: ./ops
- run:
name: Run tool
command: ./ops/bin/<< parameters.tool >> << parameters.args >>
- when:
condition: << parameters.check_diff >>
steps:
- run:
name: Check diff
command: git diff --exit-code


workflows:
main:
jobs:
- go-lint-test:
name: go-lint-test-ops
package: ops
- go-lint-test:
name: go-lint-test-validation
package: validation
- run-tool:
name: check-genesis-integrity
tool: check_genesis_integrity
- run-tool:
name: check-codegen
tool: codegen
check_diff: true
- run-tool:
name: check-staging
tool: sync_staging
check_diff: true
- run-tool:
name: check-apply-hardforks
tool: apply_hardforks
check_diff: true

6 changes: 4 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ set dotenv-load := true
alias t := test-all
alias l := lint-all

_lint DIRECTORY FLAGS='':
cd {{ DIRECTORY }} && golangci-lint run {{FLAGS}}

# Lint all Go code
lint-all:
golangci-lint run validation/... ops/... --fix
lint-all: (_lint 'ops' '--fix') (_lint 'validation' '--fix')

_go-test DIRECTORY:
cd {{ DIRECTORY }} && go run gotest.tools/gotestsum@v1.12.0 --format testname ./...
Expand Down
12 changes: 7 additions & 5 deletions ops/cmd/sync_staging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ func action(cliCtx *cli.Context) error {
}

stagingDir := path.Join(wd, ".staging")
exists, err := fs.DirExists(stagingDir)

intentExists, err := fs.FileExists(path.Join(stagingDir, "intent.toml"))
if err != nil {
return fmt.Errorf("failed to check if staging dir exists: %w", err)
return fmt.Errorf("failed to check for intent file: %w", err)
}
if !exists {
return fmt.Errorf("staging dir does not exist - check working directory")
if !intentExists {
output.WriteOK("no staged intent file found, exiting")
return nil
}

stagedChain, err := manage.NewStagedChain(stagingDir)
Expand Down Expand Up @@ -83,7 +85,7 @@ func action(cliCtx *cli.Context) error {
return fmt.Errorf("failed to fetch global chain IDs: %w", err)
}
if globalChainData.ChainIDs[chainCfg.ChainID] {
return fmt.Errorf("chain ID %s is already in use", chainCfg.ChainID)
return fmt.Errorf("chain ID %d is already in use", chainCfg.ChainID)
}
if globalChainData.ShortNames[stagedChain.Meta.ShortName] {
return fmt.Errorf("short name %s is already in use", stagedChain.Meta.ShortName)
Expand Down
10 changes: 6 additions & 4 deletions ops/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ require (
github.com/urfave/cli/v2 v2.27.5
)

require github.com/ethereum-optimism/superchain-registry/validation v0.0.0-20241225221610-a64f6a26aa8e
require (
github.com/ethereum-optimism/superchain-registry/validation v0.0.0-20241225221610-a64f6a26aa8e
github.com/google/go-github/v68 v68.0.0
github.com/klauspost/compress v1.17.11
)

require (
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e // indirect
Expand Down Expand Up @@ -49,7 +53,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-github/v68 v68.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand All @@ -60,7 +64,6 @@ require (
github.com/holiman/uint256 v1.3.2 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -82,7 +85,6 @@ require (
github.com/rs/cors v1.11.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/supranational/blst v0.3.13 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
Expand Down
3 changes: 3 additions & 0 deletions ops/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,14 @@ github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v68 v68.0.0 h1:ZW57zeNZiXTdQ16qrDiZ0k6XucrxZ2CGmoTvcCyQG6s=
github.com/google/go-github/v68 v68.0.0/go.mod h1:K9HAUBovM2sLwM408A18h+wd9vqdLOEqTUCbnRIcx68=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8 h1:Ep/joEub9YwcjRY6ND3+Y/w0ncE540RtGatVhtZL0/Q=
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
Expand Down
4 changes: 2 additions & 2 deletions ops/internal/fs/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestDirExists(t *testing.T) {
require.NoError(t, err)
require.False(t, exists)

exists, err = DirExists("testdata/file.txt")
_, err = DirExists("testdata/file.txt")
require.Error(t, err)
require.ErrorContains(t, err, "is not a directory")
}
Expand All @@ -25,7 +25,7 @@ func TestFileExists(t *testing.T) {
require.NoError(t, err)
require.True(t, exists)

exists, err = FileExists("testdata")
_, err = FileExists("testdata")
require.Error(t, err)
require.ErrorContains(t, err, "is a directory")

Expand Down
1 change: 1 addition & 0 deletions ops/internal/manage/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func FetchGlobalChainIDs() (*GlobalChainIDs, error) {
if err != nil {
return nil, err
}
defer res.Body.Close()

type chainEntry struct {
ChainId uint64 `json:"chainId"`
Expand Down
3 changes: 1 addition & 2 deletions ops/internal/report/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"bytes"
_ "embed"
"fmt"
"math/big"
"text/template"
"time"

"math/big"

"github.com/ethereum-optimism/superchain-registry/validation"
"github.com/ethereum/go-ethereum/common"
)
Expand Down
20 changes: 19 additions & 1 deletion ops/internal/testutil/mockrpc/mockrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"testing"
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -112,9 +113,26 @@ func NewMockRPC(t *testing.T, lgr log.Logger, opts ...Option) *MockRPC {
srv := &http.Server{
Handler: m,
}
go srv.Serve(m.lis)

errCh := make(chan error, 1)
go func() {
err := srv.Serve(m.lis)
if errors.Is(err, http.ErrServerClosed) {
err = nil
}
errCh <- err
}()

timer := time.NewTimer(100 * time.Millisecond)
select {
case err := <-errCh:
require.NoError(t, err)
case <-timer.C:
}

t.Cleanup(func() {
require.NoError(t, srv.Shutdown(context.Background()))
require.NoError(t, <-errCh)
})

return m
Expand Down
1 change: 0 additions & 1 deletion superchain/extra/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
This is a collection of extra configuration data because not all address and system-config information is available through L1 for some chains.

- [addresses.json](./addresses/addresses.json): L1 Smart Contract addresses for each network.
- [bytecodes](./bytecodes/): The full bytecode that is factored out of the compressed genesis system configuration file. Not designed for human consumption.
- [genesis](./genesis/): Compressed genesis system configuration data. Not designed for human consumption.
6 changes: 4 additions & 2 deletions validation/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module github.com/ethereum-optimism/superchain-registry/validation

go 1.23.1

require github.com/BurntSushi/toml v1.4.0
require (
github.com/BurntSushi/toml v1.4.0
github.com/stretchr/testify v1.10.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
1 change: 1 addition & 0 deletions validation/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 4 additions & 2 deletions validation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ var standardConfigParamsMainnetToml []byte
//go:embed standard/standard-config-params-sepolia.toml
var standardConfigParamsSepoliaToml []byte

var StandardConfigParamsMainnet ConfigParams
var StandardConfigParamsSepolia ConfigParams
var (
StandardConfigParamsMainnet ConfigParams
StandardConfigParamsSepolia ConfigParams
)

func init() {
if err := toml.Unmarshal(standardConfigParamsMainnetToml, &StandardConfigParamsMainnet); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions validation/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ var standardConfigRolesMainnetToml []byte
//go:embed standard/standard-config-roles-sepolia.toml
var standardConfigRolesSepoliaToml []byte

var StandardConfigRolesMainnet RolesConfig
var StandardConfigRolesSepolia RolesConfig
var (
StandardConfigRolesMainnet RolesConfig
StandardConfigRolesSepolia RolesConfig
)

func init() {
if err := toml.Unmarshal(standardConfigRolesMainnetToml, &StandardConfigRolesMainnet); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion validation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (h *Hash) UnmarshalText(text []byte) error {

b, err := hex.DecodeString(string(text[2:]))
if err != nil {
return fmt.Errorf("invalid hex string: %v", err)
return fmt.Errorf("invalid hex string: %w", err)
}

if len(b) != len(h) {
Expand Down
6 changes: 4 additions & 2 deletions validation/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ var standardVersionsMainnetToml []byte
//go:embed standard/standard-versions-sepolia.toml
var standardVersionsSepoliaToml []byte

var StandardVersionsMainnet Versions
var StandardVersionsSepolia Versions
var (
StandardVersionsMainnet Versions
StandardVersionsSepolia Versions
)

func init() {
if err := toml.Unmarshal(standardVersionsMainnetToml, &StandardVersionsMainnet); err != nil {
Expand Down

0 comments on commit dbee18d

Please sign in to comment.