aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool/peers_test.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-20 07:00:19 +0800
committerzelig <viktor.tron@gmail.com>2015-03-20 18:41:41 +0800
commit137a9c9365dd9ec76d4a4aab7475d716457d00ae (patch)
treebbd282f06b0559c53f9fe3ae7c7beb74e0cfe592 /blockpool/peers_test.go
parenta9926a289dd21bcfd8e2def8f4005b43b728cb3d (diff)
downloadgo-tangerine-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.gz
go-tangerine-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.zst
go-tangerine-137a9c9365dd9ec76d4a4aab7475d716457d00ae.zip
check and penalise td misreporting
- add ErrIncorrectTD - checkTD called after insertChain successful - fix tests, use blockPoolTester.tds to map block index to TD
Diffstat (limited to 'blockpool/peers_test.go')
-rw-r--r--blockpool/peers_test.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/blockpool/peers_test.go b/blockpool/peers_test.go
index 99dd16ba1..db83de43a 100644
--- a/blockpool/peers_test.go
+++ b/blockpool/peers_test.go
@@ -15,9 +15,9 @@ import (
func TestAddPeer(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t)
- peer0 := blockPoolTester.newPeer("peer0", 1, 0)
- peer1 := blockPoolTester.newPeer("peer1", 2, 1)
- peer2 := blockPoolTester.newPeer("peer2", 3, 2)
+ peer0 := blockPoolTester.newPeer("peer0", 1, 1)
+ peer1 := blockPoolTester.newPeer("peer1", 2, 2)
+ peer2 := blockPoolTester.newPeer("peer2", 3, 3)
var bestpeer *peer
blockPool.Start()
@@ -38,7 +38,7 @@ func TestAddPeer(t *testing.T) {
if blockPool.peers.best.id != "peer2" {
t.Errorf("peer2 (TD=3) not set as best")
}
- peer2.waitBlocksRequests(2)
+ peer2.waitBlocksRequests(3)
best = peer1.AddPeer()
if best {
@@ -52,7 +52,7 @@ func TestAddPeer(t *testing.T) {
}
peer2.td = 4
- peer2.currentBlock = 3
+ peer2.currentBlock = 4
best = peer2.AddPeer()
if !best {
t.Errorf("peer2 (TD=4) not accepted as best")
@@ -63,10 +63,10 @@ func TestAddPeer(t *testing.T) {
if blockPool.peers.best.td.Cmp(big.NewInt(int64(4))) != 0 {
t.Errorf("peer2 TD not updated")
}
- peer2.waitBlocksRequests(3)
+ peer2.waitBlocksRequests(4)
peer1.td = 3
- peer1.currentBlock = 2
+ peer1.currentBlock = 3
best = peer1.AddPeer()
if best {
t.Errorf("peer1 (TD=3) should not be set as best")
@@ -88,7 +88,7 @@ func TestAddPeer(t *testing.T) {
if blockPool.peers.best.id != "peer1" {
t.Errorf("existing peer1 (TD=3) should be set as best peer")
}
- peer1.waitBlocksRequests(2)
+ peer1.waitBlocksRequests(3)
blockPool.RemovePeer("peer1")
bestpeer, best = blockPool.peers.getPeer("peer1")
@@ -99,7 +99,7 @@ func TestAddPeer(t *testing.T) {
if blockPool.peers.best.id != "peer0" {
t.Errorf("existing peer0 (TD=1) should be set as best peer")
}
- peer0.waitBlocksRequests(0)
+ peer0.waitBlocksRequests(1)
blockPool.RemovePeer("peer0")
bestpeer, best = blockPool.peers.getPeer("peer0")