Ugly code works with clique

This commit is contained in:
Adam Schmideg 2020-02-26 14:05:31 +01:00
parent c8b998acaa
commit 841103c5bd
5 changed files with 82 additions and 73 deletions

View file

@ -115,62 +115,44 @@ func startGethWithRpc(t *testing.T, name string, args ...string) *gethrpc {
return g
}
func startServer(t *testing.T) *gethrpc {
runGeth(t, "init", "./testdata/genesis.json").WaitExit()
runGeth(t, "--gcmode=archive", "import", "./testdata/blockchain.blocks").WaitExit()
g := startGethWithRpc(t, "server", "--nodiscover", "--light.serve=1", "--nat=extip:127.0.0.1")
return g
func initGeth(t *testing.T) string {
g := runGeth(t, "--networkid=42", "init", "./testdata/clique.json")
datadir := g.Datadir
g.WaitExit()
return datadir
}
func startLightServer(t *testing.T) *gethrpc {
runGeth(t, "init", "./testdata/genesis.json").WaitExit()
// Start it as a miner, otherwise it won't consider itself synced
// Use the coinbase from testdata/genesis.json
etherbase := "0x8888f1f195afa192cfee860698584c030f4c9db1"
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
// Create an account, we'll need the private key and password to unlock it later.
// We add the account to the genesis json
datadir := initGeth(t)
// key := "48aa455c373ec5ce7fefb0e54f44a215decdc85b9047bc4d09801e038909bdbe"
// password := "foobar"
runGeth(t, "--datadir", datadir, "--password", "./testdata/password.txt", "account", "import", "./testdata/key.prv").WaitExit()
account := "0x02f0d131f1f97aef08aec6e3291b957d9efe7105"
server := startGethWithRpc(t, "lightserver", "--allow-insecure-unlock", "--datadir", datadir, "--password", "./testdata/password.txt", "--unlock", account, "--mine", "--light.serve=100", "--light.maxpeers=1", "--nodiscover", "--nat=extip:127.0.0.1")
// server.geth.InputLine(password)
return server
}
func startClient(t *testing.T, name string) *gethrpc {
runGeth(t, "init", "./testdata/genesis.json").WaitExit()
g := startGethWithRpc(t, name, "--nodiscover", "--syncmode=light", "--nat=extip:127.0.0.1")
return g
}
func TestDev(t *testing.T) {
password := "foobar"
args := []string{"account", "new"}
g := runGeth(t, args...)
g.InputLine(password)
g.InputLine(password)
// Extract account from the returned string
_, output := g.ExpectRegexp(`(?ms)Public address of the key: (0x[0-9a-fA-F]{40}).*`)
account := output[1]
t.Log("account", account)
g.WaitExit()
t.Log("finished 1")
args = []string{"--unlock", account, "--mine", "--datadir", g.Datadir}
g2 := runGeth(t, args...)
g2.InputLine(password)
datadir := initGeth(t)
return startGethWithRpc(t, name, "--datadir", datadir, "--nodiscover", "--syncmode=light", "--nat=extip:127.0.0.1")
}
func TestPriorityClient(t *testing.T) {
// Init and start server
server := startServer(t)
defer server.killAndWait()
lightServer := startLightServer(t)
defer lightServer.killAndWait()
// Make the lightServer sync to the server
// This is the only way to make the lightServer synced
lightServer.addPeer(server)
lightServer.waitSynced()
// Start client and add lightServer as peer
freeCli := startClient(t, "freeCli")
defer freeCli.killAndWait()
freeCli.addPeer(lightServer)
if true {
return
}
var peers []*p2p.PeerInfo
freeCli.callRPC(&peers, "admin_peers")
if len(peers) != 1 {
@ -193,7 +175,6 @@ func TestPriorityClient(t *testing.T) {
}
nodes := map[string]*gethrpc{
server.getNodeInfo().ID: server,
lightServer.getNodeInfo().ID: lightServer,
freeCli.getNodeInfo().ID: freeCli,
prioCli.getNodeInfo().ID: prioCli,

24
cmd/geth/testdata/clique.json vendored Normal file
View file

@ -0,0 +1,24 @@
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"clique": {
"period": 5,
"epoch": 30000
}
},
"difficulty": "1",
"gasLimit": "8000000",
"extradata": "0x000000000000000000000000000000000000000000000000000000000000000002f0d131f1f97aef08aec6e3291b957d9efe71050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"alloc": {
"02f0d131f1f97aef08aec6e3291b957d9efe7105": {
"balance": "300000"
}
}
}

View file

@ -1,34 +1,36 @@
{
"version": "1",
"params":{
"petersburgForkBlock":"0x0",
"chainId":"0xdeadbeef",
"miningMethod":"ethash"
},
"genesis":{
"author":"0x0000000000000000000000000000000000000000",
"difficulty":"0x1",
"extraData":"0xdeadbeef",
"gasLimit":"0x900000",
"nonce":"0x00000000deadbeef",
"timestamp":"0x0"
},
"config": {
"chainId": 42,
"ethash": {
}
},
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty" : "0x020000",
"gasLimit" : "0x2fefd8",
"timestamp" : "0x54c98c81",
"extraData" : "0x42",
"mixHash" : "0x2c85bcbce56429100b2108254bb56906257582aeafcbd682bc9af67a9f5aee46",
"nonce" : "0x78cc16f7b4f65485",
"alloc" : {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance" : "0x09184e72a000"
}
"version": "1",
"params": {
"petersburgForkBlock": "0x0",
"chainId": "0xdeadbeef",
"miningMethod": "ethash"
},
"genesis": {
"author": "0x0000000000000000000000000000000000000000",
"difficulty": "0x1",
"extraData": "0xdeadbeef",
"gasLimit": "0x900000",
"nonce": "0x00000000deadbeef",
"timestamp": "0x0"
},
"config": {
"chainId": 42,
"clique": {
"period": 5,
"epoch": 3000
}
},
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty": "0x020000",
"gasLimit": "0x2fefd8",
"timestamp": "0x54c98c81",
"extraData": "0x42",
"mixHash": "0x2c85bcbce56429100b2108254bb56906257582aeafcbd682bc9af67a9f5aee46",
"nonce": "0x78cc16f7b4f65485",
"alloc": {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x09184e72a000"
}
}
}

1
cmd/geth/testdata/key.prv vendored Normal file
View file

@ -0,0 +1 @@
48aa455c373ec5ce7fefb0e54f44a215decdc85b9047bc4d09801e038909bdbe

1
cmd/geth/testdata/password.txt vendored Normal file
View file

@ -0,0 +1 @@
foobar