aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/queue_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-03 20:09:33 +0800
committerobscuren <geffobscura@gmail.com>2015-05-03 20:09:33 +0800
commit25bc88113f8d78a265e03be670a4c9ae4ee0bdbe (patch)
tree8731344ce55649970dc8ced1c839b5178b5a742d /eth/downloader/queue_test.go
parentc6ad3aec05e1c42c3e4a222d1e8306598d5254f3 (diff)
downloadgo-tangerine-25bc88113f8d78a265e03be670a4c9ae4ee0bdbe.tar
go-tangerine-25bc88113f8d78a265e03be670a4c9ae4ee0bdbe.tar.gz
go-tangerine-25bc88113f8d78a265e03be670a4c9ae4ee0bdbe.tar.bz2
go-tangerine-25bc88113f8d78a265e03be670a4c9ae4ee0bdbe.tar.lz
go-tangerine-25bc88113f8d78a265e03be670a4c9ae4ee0bdbe.tar.xz
go-tangerine-25bc88113f8d78a265e03be670a4c9ae4ee0bdbe.tar.zst
go-tangerine-25bc88113f8d78a265e03be670a4c9ae4ee0bdbe.zip
eth/downloader: added additional tests
Diffstat (limited to 'eth/downloader/queue_test.go')
-rw-r--r--eth/downloader/queue_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/eth/downloader/queue_test.go b/eth/downloader/queue_test.go
new file mode 100644
index 000000000..b163bd9c7
--- /dev/null
+++ b/eth/downloader/queue_test.go
@@ -0,0 +1,62 @@
+package downloader
+
+import (
+ "testing"
+
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/types"
+ "gopkg.in/fatih/set.v0"
+)
+
+func createHashSet(hashes []common.Hash) *set.Set {
+ hset := set.New()
+
+ for _, hash := range hashes {
+ hset.Add(hash)
+ }
+
+ return hset
+}
+
+func createBlocksFromHashSet(hashes *set.Set) []*types.Block {
+ blocks := make([]*types.Block, hashes.Size())
+
+ var i int
+ hashes.Each(func(v interface{}) bool {
+ blocks[i] = createBlock(i, common.Hash{}, v.(common.Hash))
+ i++
+ return true
+ })
+
+ return blocks
+}
+
+func TestChunking(t *testing.T) {
+ queue := newqueue()
+ peer1 := newPeer("peer1", common.Hash{}, nil, nil)
+ peer2 := newPeer("peer2", common.Hash{}, nil, nil)
+
+ // 99 + 1 (1 == known genesis hash)
+ hashes := createHashes(0, 99)
+ hashSet := createHashSet(hashes)
+ queue.put(hashSet)
+
+ chunk1 := queue.get(peer1, 99)
+ if chunk1 == nil {
+ t.Errorf("chunk1 is nil")
+ t.FailNow()
+ }
+ chunk2 := queue.get(peer2, 99)
+ if chunk2 == nil {
+ t.Errorf("chunk2 is nil")
+ t.FailNow()
+ }
+
+ if chunk1.hashes.Size() != 99 {
+ t.Error("expected chunk1 hashes to be 99, got", chunk1.hashes.Size())
+ }
+
+ if chunk2.hashes.Size() != 1 {
+ t.Error("expected chunk1 hashes to be 1, got", chunk2.hashes.Size())
+ }
+}