ethtest suite_test.go¶
| Source (upstream v1.17.3) | Current | |
|---|---|---|
| File | cmd/devp2p/internal/ethtest/suite_test.go |
suite_test.go |
| Symbol | (entire file) |
(entire file) |
| Ref | v1.17.3 |
etc/v1.17.3-full-node |
Test node reconfigured from PoS to PoW vs upstream v1.17.3: drops the JWT/engine-API/catalyst wiring and runs ethash in ModeFake (skips seal verification), with TTD cleared so the node stays on PoW instead of beacon sync. NewSuite is called with an empty engineURL.
Diff — vs upstream v1.17.3 (modified in-place)¶
--- a/cmd/devp2p/internal/ethtest/suite_test.go
+++ b/cmd/devp2p/internal/ethtest/suite_test.go
@@ -17,47 +17,27 @@
package ethtest
import (
- crand "crypto/rand"
- "fmt"
"os"
- "path/filepath"
"testing"
"time"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/hexutil"
+ "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/eth"
- "github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/utesting"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
+ "github.com/ethereum/go-ethereum/params"
)
-func makeJWTSecret(t *testing.T) (string, [32]byte, error) {
- var secret [32]byte
- if _, err := crand.Read(secret[:]); err != nil {
- return "", secret, fmt.Errorf("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)
- }
- return jwtPath, secret, nil
-}
-
func TestEthSuite(t *testing.T) {
- jwtPath, secret, err := makeJWTSecret(t)
- if err != nil {
- t.Fatalf("could not make jwt secret: %v", err)
- }
- geth, err := runGeth("./testdata", jwtPath)
+ geth, err := runGeth("./testdata")
if err != nil {
t.Fatalf("could not run geth: %v", err)
}
defer geth.Close()
- suite, err := NewSuite(geth.Server().Self(), "./testdata", geth.HTTPAuthEndpoint(), common.Bytes2Hex(secret[:]))
+ suite, err := NewSuite(geth.Server().Self(), "./testdata", "", "")
if err != nil {
t.Fatalf("could not create new test suite: %v", err)
}
@@ -75,17 +55,13 @@
}
func TestSnapSuite(t *testing.T) {
- jwtPath, secret, err := makeJWTSecret(t)
- if err != nil {
- t.Fatalf("could not make jwt secret: %v", err)
- }
- geth, err := runGeth("./testdata", jwtPath)
+ geth, err := runGeth("./testdata")
if err != nil {
t.Fatalf("could not run geth: %v", err)
}
defer geth.Close()
- suite, err := NewSuite(geth.Server().Self(), "./testdata", geth.HTTPAuthEndpoint(), common.Bytes2Hex(secret[:]))
+ suite, err := NewSuite(geth.Server().Self(), "./testdata", "", "")
if err != nil {
t.Fatalf("could not create new test suite: %v", err)
}
@@ -99,18 +75,15 @@
}
}
-// runGeth creates and starts a geth node
-func runGeth(dir string, jwtPath string) (*node.Node, error) {
+// runGeth creates and starts a geth node configured as PoW (ETH/68).
+func runGeth(dir string) (*node.Node, error) {
stack, err := node.New(&node.Config{
- AuthAddr: "127.0.0.1",
- AuthPort: 0,
P2P: p2p.Config{
ListenAddr: "127.0.0.1:0",
NoDiscovery: true,
MaxPeers: 10, // in case a test requires multiple connections, can be changed in the future
NoDial: true,
},
- JWTSecret: jwtPath,
})
if err != nil {
return nil, err
@@ -133,9 +106,16 @@
if err != nil {
return err
}
+ // Configure as PoW with ModeFake (cf. core-geth setupGeth):
+ // - Ethash config present so engine uses PoW path (ETH/68 with TD)
+ // - ModeFake skips seal verification (testdata blocks have zero mixhash)
+ // - TTD cleared so node runs perpetual PoW, not beacon sync
+ chain.genesis.Config.Ethash = new(params.EthashConfig)
+
backend, err := eth.New(stack, ðconfig.Config{
Genesis: &chain.genesis,
- NetworkId: chain.genesis.Config.ChainID.Uint64(), // 19763
+ Ethash: ethash.Config{PowMode: ethash.ModeFake},
+ NetworkId: chain.genesis.Config.ChainID.Uint64(),
DatabaseCache: 10,
TrieCleanCache: 10,
TrieDirtyCache: 16,
@@ -145,9 +125,6 @@
if err != nil {
return err
}
- if err := catalyst.Register(stack, backend); err != nil {
- return fmt.Errorf("failed to register catalyst service: %v", err)
- }
_, err = backend.BlockChain().InsertChain(chain.blocks[1:])
return err
}
core-geth validation — +16 -62
| | | |---|---| | File | [`suite_test.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/cmd/devp2p/internal/ethtest/suite_test.go) | | Symbol | `` | | Ref | `v1.12.20` |--- a/core-geth/cmd/devp2p/internal/ethtest/suite_test.go
+++ b/etc/cmd/devp2p/internal/ethtest/suite_test.go
@@ -17,50 +17,27 @@
package ethtest
import (
- crand "crypto/rand"
- "fmt"
"os"
- "path"
"testing"
"time"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/eth"
- "github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/utesting"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
- "github.com/ethereum/go-ethereum/params/types/ctypes"
- "github.com/ethereum/go-ethereum/params/vars"
+ "github.com/ethereum/go-ethereum/params"
)
-func makeJWTSecret() (string, [32]byte, error) {
- var secret [32]byte
- if _, err := crand.Read(secret[:]); err != nil {
- return "", secret, fmt.Errorf("failed to create jwt secret: %v", err)
- }
- jwtPath := path.Join(os.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)
- }
- return jwtPath, secret, nil
-}
-
func TestEthSuite(t *testing.T) {
- jwtPath, secret, err := makeJWTSecret()
- if err != nil {
- t.Fatalf("could not make jwt secret: %v", err)
- }
- geth, err := runGeth("./testdata", jwtPath)
+ geth, err := runGeth("./testdata")
if err != nil {
t.Fatalf("could not run geth: %v", err)
}
defer geth.Close()
- suite, err := NewSuite(geth.Server().Self(), "./testdata", geth.HTTPAuthEndpoint(), common.Bytes2Hex(secret[:]))
+ suite, err := NewSuite(geth.Server().Self(), "./testdata", "", "")
if err != nil {
t.Fatalf("could not create new test suite: %v", err)
}
@@ -78,17 +55,13 @@
}
func TestSnapSuite(t *testing.T) {
- jwtPath, secret, err := makeJWTSecret()
- if err != nil {
- t.Fatalf("could not make jwt secret: %v", err)
- }
- geth, err := runGeth("./testdata", jwtPath)
+ geth, err := runGeth("./testdata")
if err != nil {
t.Fatalf("could not run geth: %v", err)
}
defer geth.Close()
- suite, err := NewSuite(geth.Server().Self(), "./testdata", geth.HTTPAuthEndpoint(), common.Bytes2Hex(secret[:]))
+ suite, err := NewSuite(geth.Server().Self(), "./testdata", "", "")
if err != nil {
t.Fatalf("could not create new test suite: %v", err)
}
@@ -102,18 +75,15 @@
}
}
-// runGeth creates and starts a geth node
-func runGeth(dir string, jwtPath string) (*node.Node, error) {
+// runGeth creates and starts a geth node configured as PoW (ETH/68).
+func runGeth(dir string) (*node.Node, error) {
stack, err := node.New(&node.Config{
- AuthAddr: "127.0.0.1",
- AuthPort: 0,
P2P: p2p.Config{
ListenAddr: "127.0.0.1:0",
NoDiscovery: true,
MaxPeers: 10, // in case a test requires multiple connections, can be changed in the future
NoDial: true,
},
- JWTSecret: jwtPath,
})
if err != nil {
return nil, err
@@ -128,7 +98,6 @@
stack.Close()
return nil, err
}
-
return stack, nil
}
@@ -137,40 +106,25 @@
if err != nil {
return err
}
+ // Configure as PoW with ModeFake (cf. core-geth setupGeth):
+ // - Ethash config present so engine uses PoW path (ETH/68 with TD)
+ // - ModeFake skips seal verification (testdata blocks have zero mixhash)
+ // - TTD cleared so node runs perpetual PoW, not beacon sync
+ chain.genesis.Config.Ethash = new(params.EthashConfig)
- ethConfig := ðconfig.Config{
+ backend, err := eth.New(stack, ðconfig.Config{
Genesis: &chain.genesis,
- NetworkId: chain.genesis.Config.GetChainID().Uint64(), // 19763
- ProtocolVersions: vars.DefaultProtocolVersions,
+ Ethash: ethash.Config{PowMode: ethash.ModeFake},
+ NetworkId: chain.genesis.Config.ChainID.Uint64(),
DatabaseCache: 10,
TrieCleanCache: 10,
TrieDirtyCache: 16,
TrieTimeout: 60 * time.Minute,
SnapshotCache: 10,
- }
-
- // Ensure that if we're running an ethash config (which we are, per the testdata setup),
- // that we're using an ethash config which does not validate the PoW seals because
- // the mixhashes for all testdata are 0x00...00.
- // TODO(meowsbits)/maybe: Create ./testdata-etc or ./testdata-cg which defines valid mixhashes for ethash/PoW engines
- // and which would be validated by the ethash engine.
- // These testdata could be generated by this test, for example, if we walk the NewChain and generate seals for all the blocks,
- // then write the testdata to disk under the new directory.
- switch chain.config.GetConsensusEngineType() {
- case ctypes.ConsensusEngineT_Ethash:
- ethConfig.Ethash = ethash.Config{
- PowMode: ethash.ModeFake,
- }
- }
-
- backend, err := eth.New(stack, ethConfig)
-
+ })
if err != nil {
return err
}
- if err := catalyst.Register(stack, backend); err != nil {
- return fmt.Errorf("failed to register catalyst service: %v", err)
- }
_, err = backend.BlockChain().InsertChain(chain.blocks[1:])
return err
}