From 21b557fe1f7fcfdee35374577249b0e9fa7dd8b4 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Thu, 25 Aug 2022 16:43:35 +0300 Subject: [PATCH 1/5] cmd/geth: fix on darwin, where long test names fail Error is "The ipc endpoint is longer than %d characters." --- cmd/geth/consolecmd_cg_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/geth/consolecmd_cg_test.go b/cmd/geth/consolecmd_cg_test.go index f9226f414a..154d0af333 100644 --- a/cmd/geth/consolecmd_cg_test.go +++ b/cmd/geth/consolecmd_cg_test.go @@ -1,11 +1,13 @@ package main import ( + "crypto/sha1" "fmt" "os" "path/filepath" "regexp" "strconv" + "strings" "testing" "time" @@ -165,7 +167,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) { + // fix for darwin, where long test names fail with "The ipc endpoint is longer than %d characters." + hashedFlags := fmt.Sprintf("%x", sha1.Sum([]byte(strings.Join(c.flags, " ")))) + + t.Run(fmt.Sprintf("%d:%v", i, hashedFlags[:8]), func(t *testing.T) { geth := runGeth(t, append(c.flags, "--exec", "admin.nodeInfo.name", "console")...) geth.KillTimeout = 10 * time.Second geth.ExpectRegexp("(?ism).*CoreGeth.*") From b62c2b97cdc8424c25b902ec16121e9b5a42253f Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Thu, 25 Aug 2022 16:53:39 +0300 Subject: [PATCH 2/5] go.mod,go.sum: update dependency for etclabscore/go-openrpc-reflect@fix-m1-nil-pointer for fixing test issue --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 718014a12e..24002156ef 100644 --- a/go.mod +++ b/go.mod @@ -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-0.20220823201110-a9dbe3af9006 github.com/ethereum/evmc/v7 v7.5.0 github.com/fatih/color v1.7.0 github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c diff --git a/go.sum b/go.sum index 9e89c3db4b..73fcf98ff2 100644 --- a/go.sum +++ b/go.sum @@ -132,6 +132,8 @@ github.com/etclabscore/go-jsonschema-walk v0.0.6 h1:DrNzoKWKd8f8XB5nFGBY00IcjakR 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-0.20220823201110-a9dbe3af9006 h1:c871GQvxjXH8BIW1GSjuqtGMEDSqSnkob/7X9U+EaOU= +github.com/etclabscore/go-openrpc-reflect v0.0.37-0.20220823201110-a9dbe3af9006/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= From f67dd6300a38e756a9e4c8cad19ac21e8148a5e5 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Thu, 25 Aug 2022 17:24:13 +0300 Subject: [PATCH 3/5] cmd/geth: fix lint issue (G401: Use of weak cryptographic primitive (gosec)) --- cmd/geth/consolecmd_cg_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/geth/consolecmd_cg_test.go b/cmd/geth/consolecmd_cg_test.go index 154d0af333..5e7f52b939 100644 --- a/cmd/geth/consolecmd_cg_test.go +++ b/cmd/geth/consolecmd_cg_test.go @@ -1,7 +1,7 @@ package main import ( - "crypto/sha1" + "crypto/sha256" "fmt" "os" "path/filepath" @@ -168,7 +168,7 @@ func TestGethStartupLogs(t *testing.T) { } for i, c := range cases { // fix for darwin, where long test names fail with "The ipc endpoint is longer than %d characters." - hashedFlags := fmt.Sprintf("%x", sha1.Sum([]byte(strings.Join(c.flags, " ")))) + hashedFlags := fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(c.flags, " ")))) t.Run(fmt.Sprintf("%d:%v", i, hashedFlags[:8]), func(t *testing.T) { geth := runGeth(t, append(c.flags, "--exec", "admin.nodeInfo.name", "console")...) From 3d7538059e6f93349abd0f3881ab876ce6bf93c4 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 29 Aug 2022 09:21:05 -0500 Subject: [PATCH 4/5] cmd/geth: fixup subtest names, logging, and datadir paths If IPC paths are too long, Unix systems will complain because there are limits, albeit inconsistent ones. So we try to keep IPC path names short (ie <100 chars). I removed all instances where flags were used in test names because - they cause issues with apple silicon M1, - and they are pointless I also removed the redundant subtest naming scheme which included the test name. Go includes the test name by default anyway. Date: 2022-08-29 09:21:05-05:00 Signed-off-by: meows --- cmd/geth/consolecmd_cg_test.go | 38 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/cmd/geth/consolecmd_cg_test.go b/cmd/geth/consolecmd_cg_test.go index 5e7f52b939..b203f4ddca 100644 --- a/cmd/geth/consolecmd_cg_test.go +++ b/cmd/geth/consolecmd_cg_test.go @@ -1,13 +1,12 @@ package main import ( - "crypto/sha256" "fmt" + "math/rand" "os" "path/filepath" "regexp" "strconv" - "strings" "testing" "time" @@ -51,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))) } } @@ -67,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)) @@ -88,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() @@ -100,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 { @@ -167,11 +180,10 @@ func TestGethStartupLogs(t *testing.T) { }, } for i, c := range cases { - // fix for darwin, where long test names fail with "The ipc endpoint is longer than %d characters." - hashedFlags := fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(c.flags, " ")))) - - t.Run(fmt.Sprintf("%d:%v", i, hashedFlags[:8]), 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() From 9002f71b5a4b1f97b0fc5b099b37296ecf492e25 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 29 Aug 2022 09:22:26 -0500 Subject: [PATCH 5/5] go.mod,go.sum: bump etclabscore/go-openrpc-reflect to v0.0.37 Bumps dep to a tag version equivalent to the previously referenced, untagged version. Date: 2022-08-29 09:22:26-05:00 Signed-off-by: meows --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 24002156ef..96823835ec 100644 --- a/go.mod +++ b/go.mod @@ -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.37-0.20220823201110-a9dbe3af9006 + 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 diff --git a/go.sum b/go.sum index 73fcf98ff2..89f737ffa6 100644 --- a/go.sum +++ b/go.sum @@ -130,10 +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-0.20220823201110-a9dbe3af9006 h1:c871GQvxjXH8BIW1GSjuqtGMEDSqSnkob/7X9U+EaOU= -github.com/etclabscore/go-openrpc-reflect v0.0.37-0.20220823201110-a9dbe3af9006/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=