3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 03:35:52 +00:00

Allow FullBlockTestGenerator to indicate maximum reorg depth.

This commit is contained in:
Matt Corallo 2013-04-22 13:42:35 -04:00
parent 0ada33d2b1
commit 2e5ca9e72b
3 changed files with 29 additions and 18 deletions

View File

@ -68,11 +68,14 @@ public class BitcoindComparisonTool {
params.genesisBlock.setDifficultyTarget(0x207fFFFFL);
// Also set block.nTime = 1296688602; in the same block
FullBlockTestGenerator generator = new FullBlockTestGenerator(params);
BlockAndValidityList blockList = generator.getBlocksToTest(true);
// Only needs to be set in bitcoinj
params.allowEmptyPeerChains = true;
try {
store = new MemoryFullPrunedBlockStore(params, 10);
store = new MemoryFullPrunedBlockStore(params, blockList.maximumReorgBlockCount);
chain = new FullPrunedBlockChain(params, store);
} catch (BlockStoreException e) {
e.printStackTrace();
@ -128,14 +131,10 @@ public class BitcoindComparisonTool {
ArrayList<Sha256Hash> locator = new ArrayList<Sha256Hash>(1);
locator.add(params.genesisBlock.getHash());
Sha256Hash hashTo = new Sha256Hash("0000000000000000000000000000000000000000000000000000000000000000");
// Tests various test cases from FullBlockTestGenerator
FullBlockTestGenerator generator = new FullBlockTestGenerator(params);
List<BlockAndValidity> blockList = generator.getBlocksToTest(true);
int differingBlocks = 0;
int invalidBlocks = 0;
for (BlockAndValidity block : blockList) {
for (BlockAndValidity block : blockList.list) {
boolean threw = false;
try {
if (chain.add(block.block) != block.connects) {

View File

@ -40,6 +40,15 @@ class TransactionOutPointWithValue {
}
}
class BlockAndValidityList {
public List<BlockAndValidity> list;
public int maximumReorgBlockCount;
public BlockAndValidityList(List<BlockAndValidity> list, int maximumReorgBlockCount) {
this.list = list;
this.maximumReorgBlockCount = maximumReorgBlockCount;
}
}
public class FullBlockTestGenerator {
// Used by BitcoindComparisonTool and FullPrunedBlockChainTest to create test cases
private NetworkParameters params;
@ -53,8 +62,9 @@ public class FullBlockTestGenerator {
Utils.rollMockClock(0); // Set a mock clock for timestamp tests
}
public List<BlockAndValidity> getBlocksToTest(boolean addExpensiveBlocks) throws ScriptException, ProtocolException, IOException {
public BlockAndValidityList getBlocksToTest(boolean addExpensiveBlocks) throws ScriptException, ProtocolException, IOException {
List<BlockAndValidity> blocks = new LinkedList<BlockAndValidity>();
BlockAndValidityList ret = new BlockAndValidityList(blocks, 10);
Queue<TransactionOutPointWithValue> spendableOutputs = new LinkedList<TransactionOutPointWithValue>();
@ -1262,7 +1272,7 @@ public class FullBlockTestGenerator {
//TODO: Explicitly address MoneyRange() checks
// (finally) return the created chain
return blocks;
return ret;
}
private Block createNextBlock(Block baseBlock, int nextBlockHeight, TransactionOutPointWithValue prevOut,

View File

@ -42,9 +42,6 @@ import static org.junit.Assert.*;
public class FullPrunedBlockChainTest {
private static final Logger log = LoggerFactory.getLogger(FullPrunedBlockChainTest.class);
// The number of undoable blocks to keep around
private static final int UNDOABLE_BLOCKS_STORED = 10;
private NetworkParameters unitTestParams;
private FullPrunedBlockChain chain;
private FullPrunedBlockStore store;
@ -57,9 +54,6 @@ public class FullPrunedBlockChainTest {
unitTestParams = NetworkParameters.unitTests();
oldInterval = unitTestParams.interval;
unitTestParams.interval = 10000;
store = new MemoryFullPrunedBlockStore(unitTestParams, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(unitTestParams, store);
}
@After
@ -69,10 +63,14 @@ public class FullPrunedBlockChainTest {
@Test
public void testGeneratedChain() throws Exception {
// Tests various test cases from FullBlockTestGenerator
// Tests various test cases from FullBlockTestGenerator
FullBlockTestGenerator generator = new FullBlockTestGenerator(unitTestParams);
List<BlockAndValidity> blockList = generator.getBlocksToTest(false);
for (BlockAndValidity block : blockList) {
BlockAndValidityList blockList = generator.getBlocksToTest(false);
store = new MemoryFullPrunedBlockStore(unitTestParams, blockList.maximumReorgBlockCount);
chain = new FullPrunedBlockChain(unitTestParams, store);
for (BlockAndValidity block : blockList.list) {
boolean threw = false;
try {
if (chain.add(block.block) != block.connects) {
@ -103,6 +101,10 @@ public class FullPrunedBlockChainTest {
@Test
public void testFinalizedBlocks() throws Exception {
final int UNDOABLE_BLOCKS_STORED = 10;
store = new MemoryFullPrunedBlockStore(unitTestParams, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(unitTestParams, store);
// Check that we aren't accidentally leaving any references
// to the full StoredUndoableBlock's lying around (ie memory leaks)