Commit 64fd0f09 authored by Daniel Connolly's avatar Daniel Connolly Committed by Daniel Connolly

test that the chain downloads

parent 2b983907
package org.bitcoinj.core;
import org.bitcoinj.core.listeners.DownloadProgressTracker;
import org.bitcoinj.net.BlockingClientManager;
import org.bitcoinj.net.ClientConnectionManager;
import org.bitcoinj.net.discovery.DnsDiscovery;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.store.MemoryBlockStore;
public class ChainDownloadParent {
protected NetworkParameters parameters;
protected Context context;
protected BlockStore blockStore;
protected BlockChain blockChain;
protected ClientConnectionManager connectionManager;
protected PeerGroup peerGroup;
public ChainDownloadParent(NetworkParameters parameters) throws BlockStoreException {
this.parameters = parameters;
this.context = new Context(parameters);
this.blockStore = new MemoryBlockStore(parameters);
this.blockChain = new BlockChain(context, blockStore);
this.connectionManager = new BlockingClientManager();
this.peerGroup = new PeerGroup(context, blockChain, connectionManager);
peerGroup.addPeerDiscovery(new DnsDiscovery(parameters));
}
public void sync() throws InterruptedException {
DownloadProgressTracker listener = new DownloadProgressTracker();
peerGroup.start();
peerGroup.startBlockChainDownload(listener);
listener.await();
}
}
package org.bitcoinj.core;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.store.BlockStoreException;
import org.junit.Test;
public class MainnetDownloadIT extends ChainDownloadParent {
public MainnetDownloadIT() throws BlockStoreException {
super(new MainNetParams());
}
@Test
public void testDownloadedChain() throws InterruptedException, BlockStoreException {
sync();
assert(blockChain.getBestChainHeight() > 538009);
assert(blockStore.get(new Sha256Hash("000000000000000000079fc7ce821f88f4864358decd958b676235447e34619b")).getHeight() == 538007);
}
}
package org.bitcoinj.core;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.store.BlockStoreException;
import org.junit.Test;
public class TestnetDownloadIT extends ChainDownloadParent {
public TestnetDownloadIT() throws BlockStoreException {
super(new MainNetParams());
}
@Test
public void testDownloadedChain() throws InterruptedException, BlockStoreException {
sync();
assert (blockChain.getBestChainHeight() > 1245531);
assert (blockStore.get(new Sha256Hash("000000000000f8d83b0341531b39685b1cc2963d0086a9a64cf2de684b804be5")).getHeight() == 1245530);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment