mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 10:15:52 +00:00
Rename blocks in FullBlockTestGenerator to make new tests easier
This commit is contained in:
parent
f9ebf56047
commit
a1c1a1117a
@ -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)
|
// 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)
|
// -> 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);
|
Block b72 = createNextBlock(b69, chainHeadHeight + 22, out21, null);
|
||||||
{
|
{
|
||||||
@ -1317,30 +1317,30 @@ public class FullBlockTestGenerator {
|
|||||||
// Add new tests here.
|
// Add new tests here.
|
||||||
|
|
||||||
// Test massive reorgs (in terms of tx count)
|
// 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:
|
// 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);
|
TransactionOutPointWithValue out22 = spendableOutputs.poll(); Preconditions.checkState(out22 != null);
|
||||||
Block b73 = createNextBlock(b72, chainHeadHeight + 23, out22, null);
|
Block b1001 = createNextBlock(b72, chainHeadHeight + 23, out22, null);
|
||||||
blocks.add(new BlockAndValidity(blockToHeightMap, b73, true, false, b73.getHash(), chainHeadHeight + 23, "b73"));
|
blocks.add(new BlockAndValidity(blockToHeightMap, b1001, true, false, b1001.getHash(), chainHeadHeight + 23, "b1001"));
|
||||||
spendableOutputs.offer(new TransactionOutPointWithValue(
|
spendableOutputs.offer(new TransactionOutPointWithValue(
|
||||||
new TransactionOutPoint(params, 0, b73.getTransactions().get(0).getHash()),
|
new TransactionOutPoint(params, 0, b1001.getTransactions().get(0).getHash()),
|
||||||
b73.getTransactions().get(0).getOutputs().get(0).getValue(),
|
b1001.getTransactions().get(0).getOutputs().get(0).getValue(),
|
||||||
b73.getTransactions().get(0).getOutputs().get(0).getScriptPubKey()));
|
b1001.getTransactions().get(0).getOutputs().get(0).getScriptPubKey()));
|
||||||
|
|
||||||
if (runLargeReorgs) {
|
if (runLargeReorgs) {
|
||||||
// No way you can fit this test in memory
|
// No way you can fit this test in memory
|
||||||
Preconditions.checkArgument(blockStorageFile != null);
|
Preconditions.checkArgument(blockStorageFile != null);
|
||||||
|
|
||||||
Block lastBlock = b73;
|
Block lastBlock = b1001;
|
||||||
int nextHeight = chainHeadHeight + 24;
|
int nextHeight = chainHeadHeight + 24;
|
||||||
TransactionOutPoint lastOutput = new TransactionOutPoint(params, 2, b73.getTransactions().get(1).getHash());
|
TransactionOutPoint lastOutput = new TransactionOutPoint(params, 2, b1001.getTransactions().get(1).getHash());
|
||||||
int blockCountAfter73;
|
int blockCountAfter1001;
|
||||||
|
|
||||||
List<Sha256Hash> hashesToSpend = new LinkedList<Sha256Hash>(); // all index 0
|
List<Sha256Hash> hashesToSpend = new LinkedList<Sha256Hash>(); // all index 0
|
||||||
final int TRANSACTION_CREATION_BLOCKS = 100;
|
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);
|
Block block = createNextBlock(lastBlock, nextHeight++, null, null);
|
||||||
while (block.getMessageSize() < Block.MAX_BLOCK_SIZE - 500) {
|
while (block.getMessageSize() < Block.MAX_BLOCK_SIZE - 500) {
|
||||||
Transaction tx = new Transaction(params);
|
Transaction tx = new Transaction(params);
|
||||||
@ -1353,7 +1353,7 @@ public class FullBlockTestGenerator {
|
|||||||
}
|
}
|
||||||
block.solve();
|
block.solve();
|
||||||
blocks.add(new BlockAndValidity(blockToHeightMap, block, true, false, block.getHash(), nextHeight-1,
|
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;
|
lastBlock = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1368,51 +1368,51 @@ public class FullBlockTestGenerator {
|
|||||||
block.addTransaction(tx);
|
block.addTransaction(tx);
|
||||||
}
|
}
|
||||||
block.solve();
|
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;
|
lastBlock = block;
|
||||||
blockCountAfter73++;
|
blockCountAfter1001++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reorg back to b73 + empty blocks
|
// Reorg back to b1001 + empty blocks
|
||||||
Sha256Hash firstHash = lastBlock.getHash();
|
Sha256Hash firstHash = lastBlock.getHash();
|
||||||
int height = nextHeight-1;
|
int height = nextHeight-1;
|
||||||
nextHeight = chainHeadHeight + 24;
|
nextHeight = chainHeadHeight + 24;
|
||||||
lastBlock = b73;
|
lastBlock = b1001;
|
||||||
for (int i = 0; i < blockCountAfter73; i++) {
|
for (int i = 0; i < blockCountAfter1001; i++) {
|
||||||
Block block = createNextBlock(lastBlock, nextHeight++, null, null);
|
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;
|
lastBlock = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to spend from the other chain
|
// 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);
|
Transaction tx = new Transaction(params);
|
||||||
tx.addInput(new TransactionInput(params, tx, new byte[] {OP_TRUE},
|
tx.addInput(new TransactionInput(params, tx, new byte[] {OP_TRUE},
|
||||||
new TransactionOutPoint(params, 0, hashesToSpend.get(0))));
|
new TransactionOutPoint(params, 0, hashesToSpend.get(0))));
|
||||||
tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] { OP_TRUE }));
|
tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] { OP_TRUE }));
|
||||||
b74.addTransaction(tx);
|
b1002.addTransaction(tx);
|
||||||
}
|
}
|
||||||
b74.solve();
|
b1002.solve();
|
||||||
blocks.add(new BlockAndValidity(blockToHeightMap, b74, false, true, firstHash, height, "b74"));
|
blocks.add(new BlockAndValidity(blockToHeightMap, b1002, false, true, firstHash, height, "b1002"));
|
||||||
|
|
||||||
// Now actually reorg
|
// Now actually reorg
|
||||||
Block b75 = createNextBlock(lastBlock, nextHeight, null, null);
|
Block b1003 = createNextBlock(lastBlock, nextHeight, null, null);
|
||||||
blocks.add(new BlockAndValidity(blockToHeightMap, b75, true, false, b75.getHash(), nextHeight, "b75"));
|
blocks.add(new BlockAndValidity(blockToHeightMap, b1003, true, false, b1003.getHash(), nextHeight, "b1003"));
|
||||||
|
|
||||||
// Now try to spend again
|
// 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);
|
Transaction tx = new Transaction(params);
|
||||||
tx.addInput(new TransactionInput(params, tx, new byte[] {OP_TRUE},
|
tx.addInput(new TransactionInput(params, tx, new byte[] {OP_TRUE},
|
||||||
new TransactionOutPoint(params, 0, hashesToSpend.get(0))));
|
new TransactionOutPoint(params, 0, hashesToSpend.get(0))));
|
||||||
tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] { OP_TRUE }));
|
tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] { OP_TRUE }));
|
||||||
b76.addTransaction(tx);
|
b1004.addTransaction(tx);
|
||||||
}
|
}
|
||||||
b76.solve();
|
b1004.solve();
|
||||||
blocks.add(new BlockAndValidity(blockToHeightMap, b76, false, true, b75.getHash(), nextHeight, "b74"));
|
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
|
//TODO: Explicitly address MoneyRange() checks
|
||||||
|
Loading…
x
Reference in New Issue
Block a user