diff --git a/core/src/test/java/com/google/bitcoin/core/BitcoindComparisonTool.java b/core/src/test/java/com/google/bitcoin/core/BitcoindComparisonTool.java index f800d2dd..a44a663e 100644 --- a/core/src/test/java/com/google/bitcoin/core/BitcoindComparisonTool.java +++ b/core/src/test/java/com/google/bitcoin/core/BitcoindComparisonTool.java @@ -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 locator = new ArrayList(1); locator.add(params.genesisBlock.getHash()); Sha256Hash hashTo = new Sha256Hash("0000000000000000000000000000000000000000000000000000000000000000"); - - // Tests various test cases from FullBlockTestGenerator - FullBlockTestGenerator generator = new FullBlockTestGenerator(params); - List 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) { diff --git a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java index d4575dff..f1de774b 100644 --- a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java +++ b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java @@ -40,6 +40,15 @@ class TransactionOutPointWithValue { } } +class BlockAndValidityList { + public List list; + public int maximumReorgBlockCount; + public BlockAndValidityList(List 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 getBlocksToTest(boolean addExpensiveBlocks) throws ScriptException, ProtocolException, IOException { + public BlockAndValidityList getBlocksToTest(boolean addExpensiveBlocks) throws ScriptException, ProtocolException, IOException { List blocks = new LinkedList(); + BlockAndValidityList ret = new BlockAndValidityList(blocks, 10); Queue spendableOutputs = new LinkedList(); @@ -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, diff --git a/core/src/test/java/com/google/bitcoin/core/FullPrunedBlockChainTest.java b/core/src/test/java/com/google/bitcoin/core/FullPrunedBlockChainTest.java index 8d1961f1..afdd9817 100644 --- a/core/src/test/java/com/google/bitcoin/core/FullPrunedBlockChainTest.java +++ b/core/src/test/java/com/google/bitcoin/core/FullPrunedBlockChainTest.java @@ -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 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)