Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cmd/devp2p): mark makeJWTSecret to be a test helper #30169

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions cmd/devp2p/internal/ethtest/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,21 @@ import (
"github.com/ethereum/go-ethereum/p2p"
)

func makeJWTSecret(t *testing.T) (string, [32]byte, error) {
func makeJWTSecret(t *testing.T) (string, [32]byte) {
t.Helper()
var secret [32]byte
if _, err := crand.Read(secret[:]); err != nil {
return "", secret, fmt.Errorf("failed to create jwt secret: %v", err)
t.Fatalf("failed to create jwt secret: %v", err)
}
jwtPath := filepath.Join(t.TempDir(), "jwt_secret")
if err := os.WriteFile(jwtPath, []byte(hexutil.Encode(secret[:])), 0600); err != nil {
return "", secret, fmt.Errorf("failed to prepare jwt secret file: %v", err)
t.Fatalf("failed to prepare jwt secret file: %v", err)
}
return jwtPath, secret, nil
return jwtPath, secret
}

func TestEthSuite(t *testing.T) {
jwtPath, secret, err := makeJWTSecret(t)
if err != nil {
t.Fatalf("could not make jwt secret: %v", err)
}
jwtPath, secret := makeJWTSecret(t)
geth, err := runGeth("./testdata", jwtPath)
if err != nil {
t.Fatalf("could not run geth: %v", err)
Expand All @@ -75,10 +73,7 @@ func TestEthSuite(t *testing.T) {
}

func TestSnapSuite(t *testing.T) {
jwtPath, secret, err := makeJWTSecret(t)
if err != nil {
t.Fatalf("could not make jwt secret: %v", err)
}
jwtPath, secret := makeJWTSecret(t)
geth, err := runGeth("./testdata", jwtPath)
if err != nil {
t.Fatalf("could not run geth: %v", err)
Expand Down