use of snowblossom.node.MemPool in project snowblossom by snowblossomcoin.
the class MemPoolTest method testBasicTxNoInput.
@Test
public void testBasicTxNoInput() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = UtxoUpdateBuffer.EMPTY;
TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(100000L).build();
Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
// Pool starts empty
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
try {
mem_pool.addTransaction(tx, false);
Assert.fail();
} catch (ValidationException e) {
Assert.assertTrue(e.getMessage(), e.getMessage().startsWith("Unable to find source tx"));
}
}
use of snowblossom.node.MemPool in project snowblossom by snowblossomcoin.
the class MemPoolTest method testBasicTxNoDoubleInput.
@Test
public void testBasicTxNoDoubleInput() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = utxo_buffer.commit();
TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(200000L).build();
Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in, in), ImmutableList.of(out), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
// Pool starts empty
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
try {
mem_pool.addTransaction(tx, false);
Assert.fail();
} catch (ValidationException e) {
System.out.println(e);
}
}
use of snowblossom.node.MemPool in project snowblossom by snowblossomcoin.
the class MemPoolTest method testBasicTxYes.
@Test
public void testBasicTxYes() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = utxo_buffer.commit();
TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(100000L).build();
Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
// Pool starts empty
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.addTransaction(tx, false);
// Then has our transaction
Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.rebuildPriorityMap(utxo_root);
// Still has our transaction
Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.rebuildPriorityMap(UtxoUpdateBuffer.EMPTY);
// That transaction is impossible now
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.rebuildPriorityMap(utxo_root);
// And does not come back
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
TransactionOutput out_a = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(50000L).build();
Transaction tx2 = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out_a, out_a), keys);
Assert.assertNotEquals(tx.getTxHash(), tx2.getTxHash());
mem_pool.addTransaction(tx2, false);
// And the outputs are freed up
Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
}
use of snowblossom.node.MemPool in project snowblossom by snowblossomcoin.
the class MemPoolTest method testBasicTxDoubleSpend.
@Test
public void testBasicTxDoubleSpend() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = utxo_buffer.commit();
TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(100000L).build();
Transaction tx = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
// Pool starts empty
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.addTransaction(tx, false);
TransactionOutput out_a = TransactionOutput.newBuilder().setRecipientSpecHash(in.getSpecHash()).setValue(50000L).build();
Transaction tx2 = TransactionUtil.createTransaction(ImmutableList.of(in), ImmutableList.of(out_a, out_a), keys);
Assert.assertNotEquals(tx.getTxHash(), tx2.getTxHash());
try {
mem_pool.addTransaction(tx2, false);
Assert.fail();
} catch (ValidationException e) {
System.out.println(e);
}
}
use of snowblossom.node.MemPool in project snowblossom by snowblossomcoin.
the class MemPoolTest method testSimpleChain.
@Test
public void testSimpleChain() throws Exception {
HashedTrie utxo_trie = newMemoryTrie();
KeyPair keys = KeyUtil.generateECCompressedKey();
UtxoUpdateBuffer utxo_buffer = new UtxoUpdateBuffer(utxo_trie, UtxoUpdateBuffer.EMPTY);
TransactionInput in_a = addUtxoToUseAtInput(utxo_buffer, keys, 100000L);
ChainHash utxo_root = utxo_buffer.commit();
TransactionOutput out_a = TransactionOutput.newBuilder().setRecipientSpecHash(in_a.getSpecHash()).setValue(100000L).build();
Transaction tx_a = TransactionUtil.createTransaction(ImmutableList.of(in_a), ImmutableList.of(out_a), keys);
MemPool mem_pool = new MemPool(utxo_trie, new DummyChainState(100));
mem_pool.rebuildPriorityMap(utxo_root);
Assert.assertEquals(0, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
mem_pool.addTransaction(tx_a, false);
Assert.assertEquals(1, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
TransactionInput in_b = TransactionInput.newBuilder().setSpecHash(in_a.getSpecHash()).setSrcTxId(tx_a.getTxHash()).setSrcTxOutIdx(0).build();
TransactionOutput out_b = TransactionOutput.newBuilder().setRecipientSpecHash(in_a.getSpecHash()).setValue(100000L).build();
Transaction tx_b = TransactionUtil.createTransaction(ImmutableList.of(in_b), ImmutableList.of(out_b), keys);
mem_pool.addTransaction(tx_b, false);
Assert.assertEquals(2, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
TransactionInput in_c = TransactionInput.newBuilder().setSpecHash(in_a.getSpecHash()).setSrcTxId(tx_b.getTxHash()).setSrcTxOutIdx(0).build();
TransactionOutput out_c = TransactionOutput.newBuilder().setRecipientSpecHash(in_a.getSpecHash()).setValue(100000L).build();
Transaction tx_c = TransactionUtil.createTransaction(ImmutableList.of(in_c), ImmutableList.of(out_c), keys);
mem_pool.addTransaction(tx_c, false);
Assert.assertEquals(3, mem_pool.getTransactionsForBlock(utxo_root, 1048576).size());
}
Aggregations