mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Add a miner and make light server sync from it first
This commit is contained in:
parent
9f64fb4f7a
commit
d0f848f422
1 changed files with 24 additions and 13 deletions
|
|
@ -44,6 +44,7 @@ type gethrpc struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *gethrpc) killAndWait() {
|
func (g *gethrpc) killAndWait() {
|
||||||
|
g.test.Logf("Killing %v", g.name)
|
||||||
g.geth.Kill()
|
g.geth.Kill()
|
||||||
g.geth.WaitExit()
|
g.geth.WaitExit()
|
||||||
}
|
}
|
||||||
|
|
@ -113,7 +114,7 @@ func startGethWithRpc(t *testing.T, name string, datadir string, args ...string)
|
||||||
ipcpath := filepath.Join(datadir, "geth.ipc")
|
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{"--datadir", datadir, "--networkid=42", "--port=0", "--nousb", "--rpc", "--rpcport=0", "--rpcapi=admin,eth,les"}, args...)
|
||||||
//args = append([]string{"--verbosity=5"}, args...)
|
args = append([]string{"--verbosity=5"}, 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)
|
||||||
|
|
@ -126,20 +127,25 @@ func startGethWithRpc(t *testing.T, name string, datadir string, args ...string)
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func startLightServer(t *testing.T) *gethrpc {
|
func startMiner(t *testing.T) *gethrpc {
|
||||||
// Create a temporary data directory to use
|
|
||||||
datadir := tmpdir(t)
|
datadir := tmpdir(t)
|
||||||
defer os.RemoveAll(datadir)
|
defer os.RemoveAll(datadir)
|
||||||
|
|
||||||
t.Log("server datadir", datadir)
|
|
||||||
runGeth(t, "--datadir", datadir, "init", "./testdata/genesis.json").WaitExit()
|
runGeth(t, "--datadir", datadir, "init", "./testdata/genesis.json").WaitExit()
|
||||||
t.Log("init done")
|
|
||||||
runGeth(t, "--datadir", datadir, "--gcmode=archive", "import", "./testdata/blockchain.blocks").WaitExit()
|
runGeth(t, "--datadir", datadir, "--gcmode=archive", "import", "./testdata/blockchain.blocks").WaitExit()
|
||||||
t.Log("import done")
|
etherbase := "0x8888f1f195afa192cfee860698584c030f4c9db1"
|
||||||
g := startGethWithRpc(t, "server", datadir, "--light.serve=100", "--light.maxpeers=1", "--nodiscover", "--nat=extip:127.0.0.1")
|
g := startGethWithRpc(t, "miner", datadir, "--mine", "--nodiscover", "--light.serve=1", "--miner.etherbase", etherbase, "--nat=extip:127.0.0.1")
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func startLightServer(t *testing.T) *gethrpc {
|
||||||
|
datadir := tmpdir(t)
|
||||||
|
defer os.RemoveAll(datadir)
|
||||||
|
|
||||||
|
runGeth(t, "--datadir", datadir, "init", "./testdata/genesis.json").WaitExit()
|
||||||
|
g := startGethWithRpc(t, "miner", datadir, "--light.serve=100", "--light.maxpeers=1", "--nodiscover", "--nat=extip:127.0.0.1")
|
||||||
|
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
|
// Create a temporary data directory to use
|
||||||
datadir := tmpdir(t)
|
datadir := tmpdir(t)
|
||||||
|
|
@ -152,11 +158,18 @@ func startClient(t *testing.T, name string) *gethrpc {
|
||||||
|
|
||||||
func TestPriorityClient(t *testing.T) {
|
func TestPriorityClient(t *testing.T) {
|
||||||
// Init and start server
|
// Init and start server
|
||||||
|
miner := startMiner(t)
|
||||||
|
defer miner.killAndWait()
|
||||||
|
|
||||||
server := startLightServer(t)
|
server := startLightServer(t)
|
||||||
defer server.killAndWait()
|
defer server.killAndWait()
|
||||||
|
|
||||||
|
// Make the server sync to the miner
|
||||||
|
// This is the only way to make the server synced
|
||||||
nodeInfo := make(map[string]interface{})
|
nodeInfo := make(map[string]interface{})
|
||||||
server.callRPC(&nodeInfo, "admin_nodeInfo")
|
server.callRPC(&nodeInfo, "admin_nodeInfo")
|
||||||
serverEnode := nodeInfo["enode"].(string)
|
serverEnode := nodeInfo["enode"].(string)
|
||||||
|
miner.addPeer(serverEnode)
|
||||||
server.waitSynced()
|
server.waitSynced()
|
||||||
|
|
||||||
// Start client and add server as peer
|
// Start client and add server as peer
|
||||||
|
|
@ -166,8 +179,8 @@ func TestPriorityClient(t *testing.T) {
|
||||||
var peers []interface{}
|
var peers []interface{}
|
||||||
client.callRPC(&peers, "admin_peers")
|
client.callRPC(&peers, "admin_peers")
|
||||||
if len(peers) != 1 {
|
if len(peers) != 1 {
|
||||||
t.Logf("Expected: # of client peers == 1, actual: %v", len(peers))
|
t.Errorf("Expected: # of client peers == 1, actual: %v", len(peers))
|
||||||
t.Fail()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up priority client, get its nodeID, increase its balance on the server
|
// Set up priority client, get its nodeID, increase its balance on the server
|
||||||
|
|
@ -183,12 +196,10 @@ func TestPriorityClient(t *testing.T) {
|
||||||
// Check if priority client is actually syncing and the regular client got kicked out
|
// Check if priority client is actually syncing and the regular client got kicked out
|
||||||
prio.callRPC(&peers, "admin_peers")
|
prio.callRPC(&peers, "admin_peers")
|
||||||
if len(peers) != 1 {
|
if len(peers) != 1 {
|
||||||
t.Logf("Expected: # of prio peers == 1, actual: %v", len(peers))
|
t.Errorf("Expected: # of prio peers == 1, actual: %v", len(peers))
|
||||||
t.Fail()
|
|
||||||
}
|
}
|
||||||
client.callRPC(&peers, "admin_peers")
|
client.callRPC(&peers, "admin_peers")
|
||||||
if len(peers) > 0 {
|
if len(peers) > 0 {
|
||||||
t.Log("Expected: # of client peers == 0")
|
t.Errorf("Expected: # of client peers == 0")
|
||||||
t.Fail()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue