Use datadir as already handled by testgeth

This commit is contained in:
Adam Schmideg 2020-02-12 12:11:18 +01:00
parent ea4f93f18e
commit 5a4fe0c945

View file

@ -2,7 +2,6 @@ package main
import ( import (
"context" "context"
"os"
"path/filepath" "path/filepath"
"testing" "testing"
"time" "time"
@ -85,14 +84,14 @@ func (g *gethrpc) waitSynced() {
} }
} }
func startGethWithRpc(t *testing.T, name string, datadir string, args ...string) *gethrpc { func startGethWithRpc(t *testing.T, name string, args ...string) *gethrpc {
ipcpath := filepath.Join(datadir, "geth.ipc")
g := &gethrpc{test: t, name: name} g := &gethrpc{test: t, name: name}
args = append([]string{"--datadir", datadir, "--networkid=42", "--port=0", "--nousb", "--rpc", "--rpcport=0", "--rpcapi=admin,eth,les"}, args...) args = append([]string{"--networkid=42", "--port=0", "--nousb", "--rpc", "--rpcport=0", "--rpcapi=admin,eth,les"}, args...)
g.geth = runGeth(t, args...) g.geth = runGeth(t, args...)
// wait before we can attach to it. TODO: probe for it properly // wait before we can attach to it. TODO: probe for it properly
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
var err error var err error
ipcpath := filepath.Join(g.geth.Datadir, "geth.ipc")
g.rpc, err = rpc.Dial(ipcpath) g.rpc, err = rpc.Dial(ipcpath)
if err != nil { if err != nil {
t.Fatalf("%v rpc connect: %v", name, err) t.Fatalf("%v rpc connect: %v", name, err)
@ -102,33 +101,23 @@ func startGethWithRpc(t *testing.T, name string, datadir string, args ...string)
} }
func startServer(t *testing.T) *gethrpc { func startServer(t *testing.T) *gethrpc {
datadir := tmpdir(t) runGeth(t, "init", "./testdata/genesis.json").WaitExit()
defer os.RemoveAll(datadir) runGeth(t, "--gcmode=archive", "import", "./testdata/blockchain.blocks").WaitExit()
g := startGethWithRpc(t, "server", "--nodiscover", "--light.serve=1", "--nat=extip:127.0.0.1")
runGeth(t, "--datadir", datadir, "init", "./testdata/genesis.json").WaitExit()
runGeth(t, "--datadir", datadir, "--gcmode=archive", "import", "./testdata/blockchain.blocks").WaitExit()
g := startGethWithRpc(t, "server", datadir, "--nodiscover", "--light.serve=1", "--nat=extip:127.0.0.1")
return g return g
} }
func startLightServer(t *testing.T) *gethrpc { func startLightServer(t *testing.T) *gethrpc {
datadir := tmpdir(t) runGeth(t, "init", "./testdata/genesis.json").WaitExit()
defer os.RemoveAll(datadir)
runGeth(t, "--datadir", datadir, "init", "./testdata/genesis.json").WaitExit()
// Start it as a miner, otherwise it won't consider itself synced // Start it as a miner, otherwise it won't consider itself synced
// Use the coinbase from testdata/genesis.json // Use the coinbase from testdata/genesis.json
etherbase := "0x8888f1f195afa192cfee860698584c030f4c9db1" etherbase := "0x8888f1f195afa192cfee860698584c030f4c9db1"
g := startGethWithRpc(t, "lightserver", datadir, "--mine", "--miner.etherbase", etherbase, "--syncmode=fast", "--light.serve=100", "--light.maxpeers=1", "--nodiscover", "--nat=extip:127.0.0.1") g := startGethWithRpc(t, "lightserver", "--mine", "--miner.etherbase", etherbase, "--syncmode=fast", "--light.serve=100", "--light.maxpeers=1", "--nodiscover", "--nat=extip:127.0.0.1")
return g return g
} }
func startClient(t *testing.T, name string) *gethrpc { func startClient(t *testing.T, name string) *gethrpc {
// Create a temporary data directory to use runGeth(t, "init", "./testdata/genesis.json").WaitExit()
datadir := tmpdir(t) g := startGethWithRpc(t, name, "--nodiscover", "--syncmode=light")
defer os.RemoveAll(datadir)
runGeth(t, "--datadir", datadir, "init", "./testdata/genesis.json").WaitExit()
g := startGethWithRpc(t, name, datadir, "--nodiscover", "--syncmode=light")
return g return g
} }