mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
fixes config tests and add client key test
This commit is contained in:
parent
bd268e0e73
commit
c587eaa7ea
1 changed files with 34 additions and 2 deletions
|
|
@ -2,8 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
|
@ -13,7 +16,8 @@ func TestGenConfig(t *testing.T) {
|
|||
flagSet := flag.NewFlagSet("test", 0)
|
||||
flagSet.String("rpc.addr", "127.0.0.11", "test")
|
||||
flagSet.String("rpc.port", "8888", "test")
|
||||
flagSet.String("data.dir", "./test", "test")
|
||||
tmpDir := t.TempDir()
|
||||
flagSet.String("data.dir", tmpDir, "test")
|
||||
flagSet.Uint64("data.capacity", size, "test")
|
||||
// flagSet.String("udp.addr", "172.23.50.11", "test")
|
||||
flagSet.Int("udp.port", 9999, "test")
|
||||
|
|
@ -30,9 +34,37 @@ func TestGenConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, config.DataCapacity, size)
|
||||
require.Equal(t, config.DataDir, "./test")
|
||||
require.Equal(t, config.DataDir, tmpDir)
|
||||
require.Equal(t, config.LogLevel, 3)
|
||||
// require.Equal(t, config.RpcAddr, "127.0.0.11:8888")
|
||||
require.Equal(t, config.Protocol.ListenAddr, ":9999")
|
||||
require.Equal(t, config.Networks, []string{"history"})
|
||||
}
|
||||
|
||||
func TestKeyConfig(t *testing.T) {
|
||||
flagSet := flag.NewFlagSet("test", 0)
|
||||
tmpDir := t.TempDir()
|
||||
flagSet.String("data.dir", tmpDir, "test")
|
||||
pk := "a19d7a264e68004832327fca0ac46636332e0ec4b2a20a7ac942020754fcb666"
|
||||
flagSet.String("private.key", "0x"+pk, "test")
|
||||
|
||||
command := &cli.Command{Name: "mycommand"}
|
||||
|
||||
ctx := cli.NewContext(nil, flagSet, nil)
|
||||
ctx.Command = command
|
||||
|
||||
config, err := getPortalConfig(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, config.DataDir, tmpDir)
|
||||
|
||||
keyPk, err := crypto.HexToECDSA(pk)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, config.PrivateKey, keyPk)
|
||||
|
||||
fullPath := filepath.Join(config.DataDir, privateKeyFileName)
|
||||
keyStored, err := os.ReadFile(fullPath)
|
||||
require.Nil(t, err)
|
||||
keyEnc := string(keyStored)
|
||||
require.Equal(t, keyEnc, pk)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue