aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/downloader_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-13 22:38:32 +0800
committerobscuren <geffobscura@gmail.com>2015-04-13 22:38:32 +0800
commita8a2b2a488f7433abc09c51b751556875c9107a9 (patch)
tree86536fc432ddf85ca2f9de0a4b1895c3bee8715b /eth/downloader/downloader_test.go
parent7dcb9825c3a3afe1a287ad544a5ad0500c0027a7 (diff)
downloaddexon-a8a2b2a488f7433abc09c51b751556875c9107a9.tar.gz
dexon-a8a2b2a488f7433abc09c51b751556875c9107a9.tar.zst
dexon-a8a2b2a488f7433abc09c51b751556875c9107a9.zip
downloader: added missing blocks catchup functionality
When a parent is missing in the block list an attempt should be made to fetch the missing parent and grandparents.
Diffstat (limited to 'eth/downloader/downloader_test.go')
-rw-r--r--eth/downloader/downloader_test.go37
1 files changed, 32 insertions, 5 deletions
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go
index 64bf9b096..6cf99b678 100644
--- a/eth/downloader/downloader_test.go
+++ b/eth/downloader/downloader_test.go
@@ -14,7 +14,7 @@ import (
var knownHash = common.Hash{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-func createHashes(amount int) (hashes []common.Hash) {
+func createHashes(start, amount int) (hashes []common.Hash) {
hashes = make([]common.Hash, amount+1)
hashes[len(hashes)-1] = knownHash
@@ -49,7 +49,7 @@ type downloadTester struct {
func newTester(t *testing.T, hashes []common.Hash, blocks map[common.Hash]*types.Block) *downloadTester {
tester := &downloadTester{t: t, hashes: hashes, blocks: blocks, done: make(chan bool)}
- downloader := New(tester.hasBlock, tester.insertChain)
+ downloader := New(tester.hasBlock, tester.insertChain, func() *big.Int { return new(big.Int) })
tester.downloader = downloader
return tester
@@ -84,7 +84,7 @@ func (dl *downloadTester) getBlocks(id string) func([]common.Hash) error {
blocks[i] = dl.blocks[hash]
}
- go dl.downloader.DeliverBlocks(id, blocks)
+ go dl.downloader.DeliverChunk(id, blocks)
return nil
}
@@ -109,11 +109,11 @@ func TestDownload(t *testing.T) {
glog.SetV(logger.Detail)
glog.SetToStderr(true)
- hashes := createHashes(1000)
+ hashes := createHashes(0, 1000)
blocks := createBlocksFromHashes(hashes)
tester := newTester(t, hashes, blocks)
- tester.newPeer("peer1", big.NewInt(10000), hashes[len(hashes)-1])
+ tester.newPeer("peer1", big.NewInt(10000), hashes[0])
tester.newPeer("peer2", big.NewInt(0), common.Hash{})
tester.badBlocksPeer("peer3", big.NewInt(0), common.Hash{})
tester.badBlocksPeer("peer4", big.NewInt(0), common.Hash{})
@@ -126,3 +126,30 @@ success:
t.Error("timout")
}
}
+
+func TestMissing(t *testing.T) {
+ t.Skip()
+
+ glog.SetV(logger.Detail)
+ glog.SetToStderr(true)
+
+ hashes := createHashes(0, 1000)
+ extraHashes := createHashes(1001, 1003)
+ blocks := createBlocksFromHashes(append(extraHashes, hashes...))
+ tester := newTester(t, hashes, blocks)
+
+ tester.newPeer("peer1", big.NewInt(10000), hashes[len(hashes)-1])
+
+ hashes = append(extraHashes, hashes[:len(hashes)-1]...)
+ tester.newPeer("peer2", big.NewInt(0), common.Hash{})
+
+success1:
+ select {
+ case <-tester.done:
+ break success1
+ case <-time.After(10 * time.Second): // XXX this could actually fail on a slow computer
+ t.Error("timout")
+ }
+
+ tester.downloader.AddBlock("peer2", blocks[hashes[len(hashes)-1]], big.NewInt(10001))
+}