aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool/peers_test.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-20 07:14:08 +0800
committerzelig <viktor.tron@gmail.com>2015-03-20 18:41:41 +0800
commita578db5dae0ae82ac8e06be8a29c48a7db22ebe0 (patch)
tree535e469b9511ec193b00591e3c3051d78c0801f3 /blockpool/peers_test.go
parent8767179d7439d8a28086ae6162e2234ed9e16d64 (diff)
downloaddexon-a578db5dae0ae82ac8e06be8a29c48a7db22ebe0.tar.gz
dexon-a578db5dae0ae82ac8e06be8a29c48a7db22ebe0.tar.zst
dexon-a578db5dae0ae82ac8e06be8a29c48a7db22ebe0.zip
improve documentation and move one test
Diffstat (limited to 'blockpool/peers_test.go')
-rw-r--r--blockpool/peers_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/blockpool/peers_test.go b/blockpool/peers_test.go
index db83de43a..0e4c40e87 100644
--- a/blockpool/peers_test.go
+++ b/blockpool/peers_test.go
@@ -142,3 +142,47 @@ func TestAddPeer(t *testing.T) {
blockPool.Stop()
}
+
+func TestPeerPromotionByOptionalTdOnBlock(t *testing.T) {
+ test.LogInit()
+ _, blockPool, blockPoolTester := newTestBlockPool(t)
+ blockPoolTester.blockChain[0] = nil
+ blockPoolTester.initRefBlockChain(4)
+ peer0 := blockPoolTester.newPeer("peer0", 2, 2)
+ peer1 := blockPoolTester.newPeer("peer1", 1, 1)
+ peer2 := blockPoolTester.newPeer("peer2", 4, 4)
+
+ blockPool.Start()
+ blockPoolTester.tds = make(map[int]int)
+ blockPoolTester.tds[3] = 3
+
+ // pool
+ peer0.AddPeer()
+ peer0.serveBlocks(1, 2)
+ best := peer1.AddPeer()
+ // this tests that peer1 is not promoted over peer0 yet
+ if best {
+ t.Errorf("peer1 (TD=1) should not be set as best")
+ }
+ best = peer2.AddPeer()
+ peer2.serveBlocks(3, 4)
+ peer2.serveBlockHashes(4, 3, 2, 1)
+ hashes := blockPoolTester.hashPool.IndexesToHashes([]int{2, 3})
+ peer1.waitBlocksRequests(3)
+ blockPool.AddBlock(&types.Block{
+ HeaderHash: common.Bytes(hashes[1]),
+ ParentHeaderHash: common.Bytes(hashes[0]),
+ Td: common.Big3,
+ }, "peer1")
+
+ blockPool.RemovePeer("peer2")
+ if blockPool.peers.best.id != "peer1" {
+ t.Errorf("peer1 (TD=3) should be set as best")
+ }
+ peer1.serveBlocks(0, 1, 2)
+
+ blockPool.Wait(waitTimeout)
+ blockPool.Stop()
+ blockPoolTester.refBlockChain[4] = []int{}
+ blockPoolTester.checkBlockChain(blockPoolTester.refBlockChain)
+}