Skip to content

Commit

Permalink
chore: fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tzdybal committed Nov 20, 2024
1 parent 1403e27 commit da70ddd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 244 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ run:

linters:
enable:
- deadcode
- errcheck
- gofmt
- goimports
Expand All @@ -15,10 +14,8 @@ linters:
- misspell
- revive
- staticcheck
- structcheck
- typecheck
- unused
- varcheck

issues:
exclude-use-default: false
Expand Down
25 changes: 12 additions & 13 deletions execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ import (
"net/http"
"time"

"github.com/golang-jwt/jwt/v5"

"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"

"github.com/golang-jwt/jwt/v5"
execution "github.com/rollkit/go-execution"
"github.com/rollkit/go-execution"
proxy_json_rpc "github.com/rollkit/go-execution/proxy/jsonrpc"
execution_types "github.com/rollkit/go-execution/types"
)

var (
ErrNilPayloadStatus = errors.New("nil payload status")
// ErrNilPayloadStatus indicates that PayloadID returned by EVM was nil
ErrNilPayloadStatus = errors.New("nil payload status")
// ErrInvalidPayloadStatus indicates that EVM returned status != VALID
ErrInvalidPayloadStatus = errors.New("invalid payload status")
)

Expand All @@ -32,7 +35,6 @@ var _ execution.Executor = (*EngineAPIExecutionClient)(nil)

// EngineAPIExecutionClient implements the execution.Execute interface
type EngineAPIExecutionClient struct {
proxyClient *proxy_json_rpc.Client
engineClient *rpc.Client // engine api
ethClient *ethclient.Client
genesisHash common.Hash
Expand Down Expand Up @@ -88,7 +90,6 @@ func NewEngineAPIExecutionClient(
}

return &EngineAPIExecutionClient{
proxyClient: proxyClient,
engineClient: engineClient,
ethClient: ethClient,
genesisHash: genesisHash,
Expand All @@ -97,14 +98,12 @@ func NewEngineAPIExecutionClient(
}

// Start starts the execution client
func (c *EngineAPIExecutionClient) Start(url string) error {
return c.proxyClient.Start(url)
func (c *EngineAPIExecutionClient) Start() error {
return nil
}

// Stop stops the execution client and closes all connections
func (c *EngineAPIExecutionClient) Stop() {
c.proxyClient.Stop()

if c.engineClient != nil {
c.engineClient.Close()
}
Expand All @@ -124,7 +123,7 @@ func (c *EngineAPIExecutionClient) InitChain(ctx context.Context, genesisTime ti
FinalizedBlockHash: c.genesisHash,
},
engine.PayloadAttributes{
Timestamp: uint64(genesisTime.Unix()),
Timestamp: uint64(genesisTime.Unix()), //nolint:gosec // disable G115
Random: common.Hash{},
SuggestedFeeRecipient: c.feeRecipient,
BeaconRoot: &c.genesisHash,
Expand Down Expand Up @@ -222,7 +221,7 @@ func (c *EngineAPIExecutionClient) ExecuteTxs(ctx context.Context, txs []executi
FinalizedBlockHash: c.genesisHash,
},
&engine.PayloadAttributes{
Timestamp: uint64(timestamp.Unix()),
Timestamp: uint64(timestamp.Unix()), //nolint:gosec // disable G115
Random: c.derivePrevRandao(height),
SuggestedFeeRecipient: c.feeRecipient,
Withdrawals: []*types.Withdrawal{},
Expand Down Expand Up @@ -264,7 +263,7 @@ func (c *EngineAPIExecutionClient) ExecuteTxs(ctx context.Context, txs []executi

// SetFinal marks a block at the given height as final
func (c *EngineAPIExecutionClient) SetFinal(ctx context.Context, height uint64) error {
block, err := c.ethClient.BlockByNumber(ctx, big.NewInt(int64(height)))
block, err := c.ethClient.BlockByNumber(ctx, big.NewInt(int64(height))) //nolint:gosec // disable G115
if err != nil {
return fmt.Errorf("failed to get block at height %d: %w", height, err)
}
Expand Down Expand Up @@ -293,5 +292,5 @@ func (c *EngineAPIExecutionClient) SetFinal(ctx context.Context, height uint64)

// derivePrevRandao generates a deterministic prevRandao value based on block height
func (c *EngineAPIExecutionClient) derivePrevRandao(blockHeight uint64) common.Hash {
return common.BigToHash(big.NewInt(int64(blockHeight)))
return common.BigToHash(big.NewInt(int64(blockHeight))) //nolint:gosec // disable G115
}
36 changes: 19 additions & 17 deletions execution_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package execution
package execution_test

Check failure on line 1 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

: # github.com/rollkit/go-execution-evm_test [github.com/rollkit/go-execution-evm.test]

import (
"context"
"encoding/hex"
"encoding/json"
"io"
"math/big"
Expand All @@ -10,14 +11,14 @@ import (
"testing"
"time"

"encoding/hex"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/rollkit/go-execution-evm/mocks"

"github.com/rollkit/go-execution-evm"
proxy_json_rpc "github.com/rollkit/go-execution/proxy/jsonrpc"
execution_types "github.com/rollkit/go-execution/types"
"github.com/stretchr/testify/require"
)

// Helper function to generate a test JWT secret
Expand All @@ -31,14 +32,14 @@ func generateTestJWTSecret() string {
}

func TestEngineAPIExecutionClient_InitChain(t *testing.T) {
mockEngine := mocks.NewMockEngineAPI(t)
mockEngine := NewMockEngineAPI(t)

Check failure on line 35 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

undefined: NewMockEngineAPI
defer mockEngine.Close()

mockEth := mocks.NewMockEthAPI(t)
mockEth := NewMockEthAPI(t)

Check failure on line 38 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

undefined: NewMockEthAPI
defer mockEth.Close()

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
client, err := execution.NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
Expand Down Expand Up @@ -70,14 +71,14 @@ func TestEngineAPIExecutionClient_InitChain(t *testing.T) {
}

func TestEngineAPIExecutionClient_ExecuteTxs(t *testing.T) {
mockEngine := mocks.NewMockEngineAPI(t)
mockEngine := NewMockEngineAPI(t)

Check failure on line 74 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

undefined: NewMockEngineAPI
defer mockEngine.Close()

mockEth := mocks.NewMockEthAPI(t)
mockEth := NewMockEthAPI(t)

Check failure on line 77 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

undefined: NewMockEthAPI
defer mockEth.Close()

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
client, err := execution.NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
Expand Down Expand Up @@ -121,14 +122,14 @@ func TestEngineAPIExecutionClient_ExecuteTxs(t *testing.T) {
}

func TestEngineAPIExecutionClient_GetTxs(t *testing.T) {
mockEngine := mocks.NewMockEngineAPI(t)
mockEngine := NewMockEngineAPI(t)

Check failure on line 125 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

undefined: NewMockEngineAPI
defer mockEngine.Close()

mockEth := mocks.NewMockEthAPI(t)
mockEth := NewMockEthAPI(t)

Check failure on line 128 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

undefined: NewMockEthAPI
defer mockEth.Close()

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
client, err := execution.NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
Expand Down Expand Up @@ -174,11 +175,12 @@ func TestEngineAPIExecutionClient_GetTxs(t *testing.T) {
}
}

json.NewEncoder(w).Encode(map[string]interface{}{
err = json.NewEncoder(w).Encode(map[string]interface{}{
"jsonrpc": "2.0",
"id": req["id"],
"result": resp,
})
require.NoError(t, err)
}))

ctx := context.Background()
Expand All @@ -189,14 +191,14 @@ func TestEngineAPIExecutionClient_GetTxs(t *testing.T) {
}

func TestEngineAPIExecutionClient_SetFinal(t *testing.T) {
mockEngine := mocks.NewMockEngineAPI(t)
mockEngine := NewMockEngineAPI(t)

Check failure on line 194 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

undefined: NewMockEngineAPI
defer mockEngine.Close()

mockEth := mocks.NewMockEthAPI(t)
mockEth := NewMockEthAPI(t)

Check failure on line 197 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

undefined: NewMockEthAPI (typecheck)
defer mockEth.Close()

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
client, err := execution.NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
Expand Down
11 changes: 6 additions & 5 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

proxy_json_rpc "github.com/rollkit/go-execution/proxy/jsonrpc"
rollkit_types "github.com/rollkit/go-execution/types"
Expand All @@ -25,7 +26,7 @@ import (
const (
TEST_ETH_URL = "http://localhost:8545"
TEST_ENGINE_URL = "http://localhost:8551"
JWT_SECRET = "09a23c010d96caaebb21c193b85d30bbb62a9bac5bd0a684e9e91c77c811ca65"
JWT_SECRET = "09a23c010d96caaebb21c193b85d30bbb62a9bac5bd0a684e9e91c77c811ca65" //nolint:gosec

CHAIN_ID = "1234"
GENESIS_HASH = "0x8bf225d50da44f60dee1c4ee6f810fe5b44723c76ac765654b6692d50459f216"
Expand All @@ -34,7 +35,7 @@ const (
TEST_TO_ADDRESS = "0x944fDcD1c868E3cC566C78023CcB38A32cDA836E"

DOCKER_CHAIN_PATH = "./docker/chain" // path relative to the test file
DOCKER_JWTSECRET_PATH = "./docker/jwttoken/" // path relative to the test file
DOCKER_JWTSECRET_PATH = "./docker/jwttoken/" //nolint:gosec // path relative to the test file
DOCKER_JWT_SECRET_FILE = "testsecret.hex"
)

Expand All @@ -47,7 +48,7 @@ func setupTestRethEngine(t *testing.T) {
jwtSecretPath, err := filepath.Abs(DOCKER_JWTSECRET_PATH)
require.NoError(t, err)

err = os.WriteFile(DOCKER_JWTSECRET_PATH+DOCKER_JWT_SECRET_FILE, []byte(JWT_SECRET), 0644)
err = os.WriteFile(DOCKER_JWTSECRET_PATH+DOCKER_JWT_SECRET_FILE, []byte(JWT_SECRET), 0600)
require.NoError(t, err)

cli, err := client.NewClientWithOpts()
Expand Down
Loading

0 comments on commit da70ddd

Please sign in to comment.