aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool/errors_test.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-02-25 20:34:12 +0800
committerzelig <viktor.tron@gmail.com>2015-02-25 20:34:12 +0800
commit422490d75cf9a2406430f2d7c0d7dd77ede18f7c (patch)
tree63860f0914370bec71cac6f1708476da4f7533cc /blockpool/errors_test.go
parentd46c7bcaf9268a191f0156d36abf394df5374795 (diff)
downloadgo-tangerine-422490d75cf9a2406430f2d7c0d7dd77ede18f7c.tar.gz
go-tangerine-422490d75cf9a2406430f2d7c0d7dd77ede18f7c.tar.zst
go-tangerine-422490d75cf9a2406430f2d7c0d7dd77ede18f7c.zip
major rewrite, reorg of blockpool + new features
- blockpool moves to its own package - uses errs pkg for its own coded errors - publicly settable config of params (time intervals and batchsizes) - test helpers in subpackage - optional TD in blocks used now to update peers chain info - major improvement in algorithm - fix fragility and sync/parallelisation bugs - implement status for reporting on sync status (peers/hashes/blocks etc) - several tests added and further corner cases covered
Diffstat (limited to 'blockpool/errors_test.go')
-rw-r--r--blockpool/errors_test.go124
1 files changed, 124 insertions, 0 deletions
diff --git a/blockpool/errors_test.go b/blockpool/errors_test.go
new file mode 100644
index 000000000..65a161233
--- /dev/null
+++ b/blockpool/errors_test.go
@@ -0,0 +1,124 @@
+package blockpool
+
+import (
+ "testing"
+ "time"
+
+ "github.com/ethereum/go-ethereum/blockpool/test"
+ "github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/pow"
+)
+
+func TestInvalidBlock(t *testing.T) {
+ test.LogInit()
+ _, blockPool, blockPoolTester := newTestBlockPool(t)
+ blockPoolTester.blockChain[0] = nil
+ blockPoolTester.initRefBlockChain(2)
+ blockPoolTester.refBlockChain[2] = []int{}
+
+ 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[2] = []int{}
+ blockPoolTester.checkBlockChain(blockPoolTester.refBlockChain)
+ if len(peer1.peerErrors) == 1 {
+ if peer1.peerErrors[0] != ErrInvalidBlock {
+ t.Errorf("wrong error, got %v, expected %v", peer1.peerErrors[0], ErrInvalidBlock)
+ }
+ } else {
+ t.Errorf("expected %v error, got %v", ErrInvalidBlock, peer1.peerErrors)
+ }
+}
+
+func TestVerifyPoW(t *testing.T) {
+ test.LogInit()
+ _, blockPool, blockPoolTester := newTestBlockPool(t)
+ blockPoolTester.blockChain[0] = nil
+ blockPoolTester.initRefBlockChain(3)
+ first := false
+ blockPoolTester.blockPool.verifyPoW = func(b pow.Block) bool {
+ bb, _ := b.(*types.Block)
+ indexes := blockPoolTester.hashPool.HashesToIndexes([][]byte{bb.Hash()})
+ if indexes[0] == 2 && !first {
+ first = true
+ return false
+ } else {
+ return true
+ }
+
+ }
+
+ blockPool.Start()
+
+ peer1 := blockPoolTester.newPeer("peer1", 1, 3)
+ peer2 := blockPoolTester.newPeer("peer2", 1, 3)
+ peer1.AddPeer()
+ peer2.AddPeer()
+ go peer1.serveBlocks(2, 3)
+ go peer1.serveBlockHashes(3, 2, 1, 0)
+ peer1.serveBlocks(0, 1, 2, 3)
+ blockPoolTester.blockPool.verifyPoW = func(b pow.Block) bool {
+ return true
+ }
+ peer2.serveBlocks(1, 2)
+
+ blockPool.Wait(waitTimeout)
+ blockPool.Stop()
+ blockPoolTester.refBlockChain[3] = []int{}
+ blockPoolTester.checkBlockChain(blockPoolTester.refBlockChain)
+ if len(peer1.peerErrors) == 1 {
+ if peer1.peerErrors[0] != ErrInvalidPoW {
+ t.Errorf("wrong error, expected %v, got %v", ErrInvalidPoW, peer1.peerErrors[0])
+ }
+ } else {
+ t.Errorf("expected %v error, got %v", ErrInvalidPoW, peer1.peerErrors)
+ }
+}
+
+func TestUnrequestedBlock(t *testing.T) {
+ test.LogInit()
+ _, blockPool, blockPoolTester := newTestBlockPool(t)
+ blockPoolTester.blockChain[0] = nil
+ blockPool.Start()
+
+ peer1 := blockPoolTester.newPeer("peer1", 1, 3)
+ peer1.AddPeer()
+ peer1.sendBlocks(1, 2)
+
+ // blockPool.Wait(waitTimeout)
+ blockPool.Stop()
+ if len(peer1.peerErrors) == 1 {
+ if peer1.peerErrors[0] != ErrUnrequestedBlock {
+ t.Errorf("wrong error, got %v, expected %v", peer1.peerErrors[0], ErrUnrequestedBlock)
+ }
+ } else {
+ t.Errorf("expected %v error, got %v", ErrUnrequestedBlock, peer1.peerErrors)
+ }
+}
+
+func TestErrInsufficientChainInfo(t *testing.T) {
+ test.LogInit()
+ _, blockPool, blockPoolTester := newTestBlockPool(t)
+ blockPool.Config.BlockHashesTimeout = 100 * time.Millisecond
+ blockPool.Start()
+
+ peer1 := blockPoolTester.newPeer("peer1", 1, 3)
+ peer1.AddPeer()
+
+ blockPool.Wait(waitTimeout)
+ blockPool.Stop()
+ if len(peer1.peerErrors) == 1 {
+ if peer1.peerErrors[0] != ErrInsufficientChainInfo {
+ t.Errorf("wrong error, got %v, expected %v", peer1.peerErrors[0], ErrInsufficientChainInfo)
+ }
+ } else {
+ t.Errorf("expected %v error, got %v", ErrInsufficientChainInfo, peer1.peerErrors)
+ }
+}