aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool/errors_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/errors_test.go
parenta9926a289dd21bcfd8e2def8f4005b43b728cb3d (diff)
downloadgo-tangerine-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar
go-tangerine-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.gz
go-tangerine-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.bz2
go-tangerine-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.lz
go-tangerine-137a9c9365dd9ec76d4a4aab7475d716457d00ae.tar.xz
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/errors_test.go')
-rw-r--r--blockpool/errors_test.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/blockpool/errors_test.go b/blockpool/errors_test.go
index 5188930f0..350d6daef 100644
--- a/blockpool/errors_test.go
+++ b/blockpool/errors_test.go
@@ -93,7 +93,6 @@ func TestUnrequestedBlock(t *testing.T) {
peer1.AddPeer()
peer1.sendBlocks(1, 2)
- // blockPool.Wait(waitTimeout)
blockPool.Stop()
if len(peer1.peerErrors) == 1 {
if peer1.peerErrors[0] != ErrUnrequestedBlock {
@@ -124,6 +123,33 @@ func TestErrInsufficientChainInfo(t *testing.T) {
}
}
+func TestIncorrectTD(t *testing.T) {
+ test.LogInit()
+ _, blockPool, blockPoolTester := newTestBlockPool(t)
+ blockPoolTester.blockChain[0] = nil
+ blockPoolTester.initRefBlockChain(3)
+
+ blockPool.Start()
+
+ peer1 := blockPoolTester.newPeer("peer1", 1, 3)
+ peer1.AddPeer()
+ go peer1.serveBlocks(2, 3)
+ go peer1.serveBlockHashes(3, 2, 1, 0)
+ peer1.serveBlocks(0, 1, 2)
+
+ blockPool.Wait(waitTimeout)
+ blockPool.Stop()
+ blockPoolTester.refBlockChain[3] = []int{}
+ blockPoolTester.checkBlockChain(blockPoolTester.refBlockChain)
+ if len(peer1.peerErrors) == 1 {
+ if peer1.peerErrors[0] != ErrIncorrectTD {
+ t.Errorf("wrong error, got %v, expected %v", peer1.peerErrors[0], ErrIncorrectTD)
+ }
+ } else {
+ t.Errorf("expected %v error, got %v", ErrIncorrectTD, peer1.peerErrors)
+ }
+}
+
func TestPeerSuspension(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t)