From 1fa9cb97a1769522a9cbfb98111f74fea69f2c94 Mon Sep 17 00:00:00 2001 From: "italiano@oplabs.co" Date: Fri, 28 Jun 2024 16:25:00 -0400 Subject: [PATCH] Adds lint command and fixes lint issues --- Justfile | 3 +++ anvil/anvil.go | 6 +++--- supersim_test.go | 10 ++++++++-- utils/rpc.go | 3 ++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Justfile b/Justfile index e3b3d3f2..4d5317e4 100644 --- a/Justfile +++ b/Justfile @@ -7,6 +7,9 @@ build-contracts: build-go: go build ./... +lint-go: + golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./... + test-contracts: forge test -vvv --root ./contracts diff --git a/anvil/anvil.go b/anvil/anvil.go index 84ffb5ad..dc357612 100644 --- a/anvil/anvil.go +++ b/anvil/anvil.go @@ -58,13 +58,13 @@ func (a *Anvil) Start(ctx context.Context) error { tempFile, err := os.CreateTemp("", "genesis-*.json") if err != nil { - return fmt.Errorf("Error creating temporary genesis file: %v", err) + return fmt.Errorf("Error creating temporary genesis file: %w", err) } defer os.Remove(tempFile.Name()) _, err = tempFile.Write(a.cfg.Genesis) if err != nil { - return fmt.Errorf("Error writing to genesis file: %v", err) + return fmt.Errorf("Error writing to genesis file: %w", err) } // Prep args @@ -72,7 +72,7 @@ func (a *Anvil) Start(ctx context.Context) error { "--host", host, "--chain-id", fmt.Sprintf("%d", a.cfg.ChainId), "--port", fmt.Sprintf("%d", a.cfg.Port), - "--init", fmt.Sprintf("%s", tempFile.Name()), + "--init", tempFile.Name(), } a.cmd = exec.CommandContext(a.resourceCtx, "anvil", args...) diff --git a/supersim_test.go b/supersim_test.go index cb23c123..b6d8172e 100644 --- a/supersim_test.go +++ b/supersim_test.go @@ -23,8 +23,14 @@ const ( func TestGenesisState(t *testing.T) { logger := oplog.NewLogger(os.Stderr, oplog.DefaultCLIConfig()) supersim := NewSupersim(logger, &DefaultConfig) - supersim.Start(context.Background()) - defer supersim.Stop(context.Background()) + _ = supersim.Start(context.Background()) + + defer func() { + err := supersim.Stop(context.Background()) + if err != nil { + t.Fatalf("Failed to stop supersim: %v", err) + } + }() for _, l2ChainConfig := range DefaultConfig.l2Chains { client, err := utils.WaitForAnvilClientToBeReady(fmt.Sprintf("http://127.0.0.1:%d", l2ChainConfig.Port), anvilClientTimeout) diff --git a/utils/rpc.go b/utils/rpc.go index de7e3cf9..30440ac2 100644 --- a/utils/rpc.go +++ b/utils/rpc.go @@ -21,12 +21,13 @@ func WaitForAnvilClientToBeReady(rpcUrl string, timeout time.Duration) (*rpc.Cli case <-ctx.Done(): return nil, fmt.Errorf("timed out waiting for response from %s", rpcUrl) case <-ticker.C: - _, err := http.Get(rpcUrl) + res, err := http.Get(rpcUrl) if err != nil { fmt.Printf("Error making request: %v\n", err) continue } + defer res.Body.Close() client, err := rpc.Dial(rpcUrl) if err != nil {