aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool/errors_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-21 01:01:05 +0800
committerobscuren <geffobscura@gmail.com>2015-03-21 01:01:05 +0800
commitf4e9638867f5dab01eeb6db5fdbd85737a11fbd6 (patch)
tree8d8cbfeb2533a2b84e5f0927e9bfdd688cdffbb2 /blockpool/errors_test.go
parent54dac59285ccc6a3af47201479ca556da2899e93 (diff)
parentecd10d2cf765072cd74347b9e0ca2bb85091450f (diff)
downloadgo-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.gz
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.zst
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.zip
Merge branch 'ethersphere-frontier/blockpool' into conversion
Diffstat (limited to 'blockpool/errors_test.go')
-rw-r--r--blockpool/errors_test.go61
1 files changed, 59 insertions, 2 deletions
diff --git a/blockpool/errors_test.go b/blockpool/errors_test.go
index 65a161233..350d6daef 100644
--- a/blockpool/errors_test.go
+++ b/blockpool/errors_test.go
@@ -5,6 +5,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/blockpool/test"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/pow"
)
@@ -45,7 +46,7 @@ func TestVerifyPoW(t *testing.T) {
first := false
blockPoolTester.blockPool.verifyPoW = func(b pow.Block) bool {
bb, _ := b.(*types.Block)
- indexes := blockPoolTester.hashPool.HashesToIndexes([][]byte{bb.Hash()})
+ indexes := blockPoolTester.hashPool.HashesToIndexes([]common.Hash{bb.Hash()})
if indexes[0] == 2 && !first {
first = true
return false
@@ -92,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 {
@@ -122,3 +122,60 @@ func TestErrInsufficientChainInfo(t *testing.T) {
t.Errorf("expected %v error, got %v", ErrInsufficientChainInfo, peer1.peerErrors)
}
}
+
+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)
+ blockPool.Config.PeerSuspensionInterval = 100 * time.Millisecond
+
+ blockPool.Start()
+
+ peer1 := blockPoolTester.newPeer("peer1", 1, 3)
+ peer1.AddPeer()
+ blockPool.peers.peerError("peer1", 0, "")
+ bestpeer, _ := blockPool.peers.getPeer("peer1")
+ if bestpeer != nil {
+ t.Errorf("peer1 not removed on error")
+ }
+ peer1.AddPeer()
+ bestpeer, _ = blockPool.peers.getPeer("peer1")
+ if bestpeer != nil {
+ t.Errorf("peer1 not removed on reconnect")
+ }
+ time.Sleep(100 * time.Millisecond)
+ peer1.AddPeer()
+ bestpeer, _ = blockPool.peers.getPeer("peer1")
+ if bestpeer == nil {
+ t.Errorf("peer1 not connected after PeerSuspensionInterval")
+ }
+ // blockPool.Wait(waitTimeout)
+ blockPool.Stop()
+
+}