Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 25 additions & 8 deletions cmd/geth/consolecmd_cg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"math/rand"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -49,14 +50,14 @@ func TestConsoleCmdNetworkIdentities(t *testing.T) {
// or collisions with an existing geth service.
p.flags = append(p.flags, "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none")

t.Run(fmt.Sprintf("%d/%v/networkid", i, p.flags),
t.Run(fmt.Sprintf("%d/networkid", i),
consoleCmdStdoutTest(p.flags, "admin.nodeInfo.protocols.eth.network", p.networkId))
t.Run(fmt.Sprintf("%d/%v/chainid", i, p.flags),
t.Run(fmt.Sprintf("%d/chainid", i),
consoleCmdStdoutTest(p.flags, "admin.nodeInfo.protocols.eth.config.chainId", p.chainId))

// The developer mode block has a dynamic genesis, depending on a parameterized address (coinbase) value.
if p.genesisHash != "0x0" {
t.Run(fmt.Sprintf("%d/%v/genesis_hash", i, p.flags),
t.Run(fmt.Sprintf("%d/genesis_hash", i),
consoleCmdStdoutTest(p.flags, "eth.getBlock(0, false).hash", strconv.Quote(p.genesisHash)))
}
}
Expand All @@ -65,6 +66,7 @@ func TestConsoleCmdNetworkIdentities(t *testing.T) {
func consoleCmdStdoutTest(flags []string, execCmd string, want interface{}) func(t *testing.T) {
return func(t *testing.T) {
flags = append(flags, "--ipcpath", filepath.Join(os.TempDir(), "geth.ipc"), "--exec", execCmd, "console")
t.Log("flags:", flags)
geth := runGeth(t, flags...)
geth.Expect(fmt.Sprintf(`%v
`, want))
Expand All @@ -86,8 +88,9 @@ func TestGethFailureToLaunch(t *testing.T) {
expectErrorReStr: "(?ism)incorrect usage.*",
},
}
for _, c := range cases {
t.Run(fmt.Sprintf("TestIncorrectUsage: %v", c.flags), func(t *testing.T) {
for i, c := range cases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
t.Log("flags:", c.flags)
geth := runGeth(t, c.flags...)
geth.ExpectRegexp(c.expectErrorReStr)
geth.ExpectExit()
Expand All @@ -98,11 +101,23 @@ func TestGethFailureToLaunch(t *testing.T) {
}
}

// randomStr is used in naming the geth tests' temporary datadir.
func randomStr(n int) string {
letterBytes := "abcdefghijklmnopqrstuvwxyz"
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Int63()%int64(len(letterBytes))]
}
return string(b)
}

// TestGethStartupLogs tests that geth logs certain things (given some set of flags).
// In these cases, geth is run with a console command to print its name (and tests that it does).
func TestGethStartupLogs(t *testing.T) {
// semiPersistentDatadir is used to house an adhoc datadir for co-dependent geth test cases.
semiPersistentDatadir := filepath.Join(os.TempDir(), fmt.Sprintf("geth-startup-logs-test-%d", time.Now().Unix()))
// WATCHOUT: For Unix-based operating systems, you're going to have problems if the IPC endpoint is
// longer than ___ characters.
semiPersistentDatadir := filepath.Join(os.TempDir(), fmt.Sprintf("geth-test-%x", randomStr(4)))
defer os.RemoveAll(semiPersistentDatadir)

type matching struct {
Expand Down Expand Up @@ -165,8 +180,10 @@ func TestGethStartupLogs(t *testing.T) {
},
}
for i, c := range cases {
t.Run(fmt.Sprintf("TestGethStartupLogs/%d: %v", i, c.flags), func(t *testing.T) {
geth := runGeth(t, append(c.flags, "--exec", "admin.nodeInfo.name", "console")...)
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
caseFlags := append(c.flags, "--exec", "admin.nodeInfo.name", "console")
t.Log("flags:", caseFlags)
geth := runGeth(t, caseFlags...)
geth.KillTimeout = 10 * time.Second
geth.ExpectRegexp("(?ism).*CoreGeth.*")
geth.ExpectExit()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/docker/docker v1.6.2
github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf
github.com/edsrzf/mmap-go v1.0.0
github.com/etclabscore/go-openrpc-reflect v0.0.36
github.com/etclabscore/go-openrpc-reflect v0.0.37
github.com/ethereum/evmc/v7 v7.5.0
github.com/fatih/color v1.7.0
github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/etclabscore/go-jsonschema-walk v0.0.6 h1:DrNzoKWKd8f8XB5nFGBY00IcjakRE22OTI12k+2LkyY=
github.com/etclabscore/go-jsonschema-walk v0.0.6/go.mod h1:VdfDY72AFAiUhy0ZXEaWSpveGjMT5JcDIm903NGqFwQ=
github.com/etclabscore/go-openrpc-reflect v0.0.36 h1:kSqNB2U8RVoW4si+4fsv13NGNkRAQ5j78zTUx1qiehk=
github.com/etclabscore/go-openrpc-reflect v0.0.36/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E=
github.com/etclabscore/go-openrpc-reflect v0.0.37 h1:IH0e7JqIvR9OhbbFWi/BHIkXrqbR3Zyia3RJ733eT6c=
github.com/etclabscore/go-openrpc-reflect v0.0.37/go.mod h1:0404Ky3igAasAOpyj1eESjstTyneBAIk5PgJFbK4s5E=
github.com/ethereum/evmc/v7 v7.5.0 h1:vwKcs1DINXqvaymranmlpO64fysJJkirCCJ+kkaPaCs=
github.com/ethereum/evmc/v7 v7.5.0/go.mod h1:q2Q0rCSUlIkngd+mZwfCzEUbvB0IIopH1+7hcs9QuDg=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
Expand Down