mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
whisper: test added - pow exchange protocol
This commit is contained in:
parent
8b96630df6
commit
1501a11750
1 changed files with 33 additions and 1 deletions
|
|
@ -93,7 +93,8 @@ var expectedMessage []byte = []byte("per rectum ad astra")
|
||||||
// 2. installs the filters with shared (predefined) parameters,
|
// 2. installs the filters with shared (predefined) parameters,
|
||||||
// 3. each node sends a number of random (undecryptable) messages,
|
// 3. each node sends a number of random (undecryptable) messages,
|
||||||
// 4. first node sends one expected (decryptable) message,
|
// 4. first node sends one expected (decryptable) message,
|
||||||
// 5. checks if each node have received and decrypted exactly one message.
|
// 5. checks if each node have received and decrypted exactly one message,
|
||||||
|
// 6. sends protocol-level messages (powRequirementCode) and checks the new PoW requirement values.
|
||||||
func TestSimulation(t *testing.T) {
|
func TestSimulation(t *testing.T) {
|
||||||
initialize(t)
|
initialize(t)
|
||||||
|
|
||||||
|
|
@ -103,6 +104,7 @@ func TestSimulation(t *testing.T) {
|
||||||
|
|
||||||
sendMsg(t, true, 0)
|
sendMsg(t, true, 0)
|
||||||
checkPropagation(t)
|
checkPropagation(t)
|
||||||
|
powReqExchange(t)
|
||||||
stopServers()
|
stopServers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -304,3 +306,33 @@ func TestPeerBasic(t *testing.T) {
|
||||||
t.Fatalf("failed mark with seed %d.", seed)
|
t.Fatalf("failed mark with seed %d.", seed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func powReqExchange(t *testing.T) {
|
||||||
|
for i, node := range nodes {
|
||||||
|
for peer, _ := range node.shh.peers {
|
||||||
|
if peer.powRequirement > 1000.0 {
|
||||||
|
t.Fatalf("node %d: one of the peers' pow requirement is too big (%f).", i, peer.powRequirement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const pow float64 = 7777777.0
|
||||||
|
nodes[0].shh.SetMinimumPoW(pow, true)
|
||||||
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
|
||||||
|
cnt := 0
|
||||||
|
for i, node := range nodes {
|
||||||
|
for peer, _ := range node.shh.peers {
|
||||||
|
if peer.peer.ID() == discover.PubkeyID(&nodes[0].id.PublicKey) {
|
||||||
|
cnt++
|
||||||
|
if peer.powRequirement != pow {
|
||||||
|
t.Fatalf("node %d: failed to set the new pow requirement.", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cnt == 0 {
|
||||||
|
t.Fatalf("no matching peers found.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue