From a1c1a1117a1d40fd665423e83b4b6a3cf1d35c75 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 18 May 2013 23:19:16 +0200 Subject: [PATCH] Rename blocks in FullBlockTestGenerator to make new tests easier --- .../bitcoin/core/FullBlockTestGenerator.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) 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 70da5a0a..ed1fdca0 100644 --- a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java +++ b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java @@ -1289,7 +1289,7 @@ public class FullBlockTestGenerator { // Test accepting an invalid block which has the same hash as a valid one (via merkle tree tricks) // -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) -> b64 (18) -> b65 (19) -> b69 (20) -> b71 (21) - // \-> b71 (21) + // \-> b72 (21) // Block b72 = createNextBlock(b69, chainHeadHeight + 22, out21, null); { @@ -1317,30 +1317,30 @@ public class FullBlockTestGenerator { // Add new tests here. // Test massive reorgs (in terms of tx count) - // -> b60 (17) -> b64 (18) -> b65 (19) -> b69 (20) -> b72 (21) -> b73 (22) -> lots of outputs -> lots of spends + // -> b60 (17) -> b64 (18) -> b65 (19) -> b69 (20) -> b72 (21) -> b1001 (22) -> lots of outputs -> lots of spends // Reorg back to: - // -> b60 (17) -> b64 (18) -> b65 (19) -> b69 (20) -> b72 (21) -> b73 (22) -> empty blocks + // -> b60 (17) -> b64 (18) -> b65 (19) -> b69 (20) -> b72 (21) -> b1001 (22) -> empty blocks // TransactionOutPointWithValue out22 = spendableOutputs.poll(); Preconditions.checkState(out22 != null); - Block b73 = createNextBlock(b72, chainHeadHeight + 23, out22, null); - blocks.add(new BlockAndValidity(blockToHeightMap, b73, true, false, b73.getHash(), chainHeadHeight + 23, "b73")); + Block b1001 = createNextBlock(b72, chainHeadHeight + 23, out22, null); + blocks.add(new BlockAndValidity(blockToHeightMap, b1001, true, false, b1001.getHash(), chainHeadHeight + 23, "b1001")); spendableOutputs.offer(new TransactionOutPointWithValue( - new TransactionOutPoint(params, 0, b73.getTransactions().get(0).getHash()), - b73.getTransactions().get(0).getOutputs().get(0).getValue(), - b73.getTransactions().get(0).getOutputs().get(0).getScriptPubKey())); + new TransactionOutPoint(params, 0, b1001.getTransactions().get(0).getHash()), + b1001.getTransactions().get(0).getOutputs().get(0).getValue(), + b1001.getTransactions().get(0).getOutputs().get(0).getScriptPubKey())); if (runLargeReorgs) { // No way you can fit this test in memory Preconditions.checkArgument(blockStorageFile != null); - Block lastBlock = b73; + Block lastBlock = b1001; int nextHeight = chainHeadHeight + 24; - TransactionOutPoint lastOutput = new TransactionOutPoint(params, 2, b73.getTransactions().get(1).getHash()); - int blockCountAfter73; + TransactionOutPoint lastOutput = new TransactionOutPoint(params, 2, b1001.getTransactions().get(1).getHash()); + int blockCountAfter1001; List hashesToSpend = new LinkedList(); // all index 0 final int TRANSACTION_CREATION_BLOCKS = 100; - for (blockCountAfter73 = 0; blockCountAfter73 < TRANSACTION_CREATION_BLOCKS; blockCountAfter73++) { + for (blockCountAfter1001 = 0; blockCountAfter1001 < TRANSACTION_CREATION_BLOCKS; blockCountAfter1001++) { Block block = createNextBlock(lastBlock, nextHeight++, null, null); while (block.getMessageSize() < Block.MAX_BLOCK_SIZE - 500) { Transaction tx = new Transaction(params); @@ -1353,7 +1353,7 @@ public class FullBlockTestGenerator { } block.solve(); blocks.add(new BlockAndValidity(blockToHeightMap, block, true, false, block.getHash(), nextHeight-1, - "post-b73 repeated transaction generator " + blockCountAfter73 + "/" + TRANSACTION_CREATION_BLOCKS)); + "post-b1001 repeated transaction generator " + blockCountAfter1001 + "/" + TRANSACTION_CREATION_BLOCKS)); lastBlock = block; } @@ -1368,51 +1368,51 @@ public class FullBlockTestGenerator { block.addTransaction(tx); } block.solve(); - blocks.add(new BlockAndValidity(blockToHeightMap, block, true, false, block.getHash(), nextHeight-1, "post-b73 repeated transaction spender " + i)); + blocks.add(new BlockAndValidity(blockToHeightMap, block, true, false, block.getHash(), nextHeight-1, "post-b1001 repeated transaction spender " + i)); lastBlock = block; - blockCountAfter73++; + blockCountAfter1001++; } - // Reorg back to b73 + empty blocks + // Reorg back to b1001 + empty blocks Sha256Hash firstHash = lastBlock.getHash(); int height = nextHeight-1; nextHeight = chainHeadHeight + 24; - lastBlock = b73; - for (int i = 0; i < blockCountAfter73; i++) { + lastBlock = b1001; + for (int i = 0; i < blockCountAfter1001; i++) { Block block = createNextBlock(lastBlock, nextHeight++, null, null); - blocks.add(new BlockAndValidity(blockToHeightMap, block, true, false, firstHash, height, "post-b73 empty reorg block " + i + "/" + blockCountAfter73)); + blocks.add(new BlockAndValidity(blockToHeightMap, block, true, false, firstHash, height, "post-b1001 empty reorg block " + i + "/" + blockCountAfter1001)); lastBlock = block; } // Try to spend from the other chain - Block b74 = createNextBlock(lastBlock, nextHeight, null, null); + Block b1002 = createNextBlock(lastBlock, nextHeight, null, null); { Transaction tx = new Transaction(params); tx.addInput(new TransactionInput(params, tx, new byte[] {OP_TRUE}, new TransactionOutPoint(params, 0, hashesToSpend.get(0)))); tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] { OP_TRUE })); - b74.addTransaction(tx); + b1002.addTransaction(tx); } - b74.solve(); - blocks.add(new BlockAndValidity(blockToHeightMap, b74, false, true, firstHash, height, "b74")); + b1002.solve(); + blocks.add(new BlockAndValidity(blockToHeightMap, b1002, false, true, firstHash, height, "b1002")); // Now actually reorg - Block b75 = createNextBlock(lastBlock, nextHeight, null, null); - blocks.add(new BlockAndValidity(blockToHeightMap, b75, true, false, b75.getHash(), nextHeight, "b75")); + Block b1003 = createNextBlock(lastBlock, nextHeight, null, null); + blocks.add(new BlockAndValidity(blockToHeightMap, b1003, true, false, b1003.getHash(), nextHeight, "b1003")); // Now try to spend again - Block b76 = createNextBlock(b75, nextHeight+1, null, null); + Block b1004 = createNextBlock(b1003, nextHeight+1, null, null); { Transaction tx = new Transaction(params); tx.addInput(new TransactionInput(params, tx, new byte[] {OP_TRUE}, new TransactionOutPoint(params, 0, hashesToSpend.get(0)))); tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] { OP_TRUE })); - b76.addTransaction(tx); + b1004.addTransaction(tx); } - b76.solve(); - blocks.add(new BlockAndValidity(blockToHeightMap, b76, false, true, b75.getHash(), nextHeight, "b74")); + b1004.solve(); + blocks.add(new BlockAndValidity(blockToHeightMap, b1004, false, true, b1003.getHash(), nextHeight, "b1004")); - ret.maximumReorgBlockCount = Math.max(ret.maximumReorgBlockCount, blockCountAfter73); + ret.maximumReorgBlockCount = Math.max(ret.maximumReorgBlockCount, blockCountAfter1001); } //TODO: Explicitly address MoneyRange() checks