use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockValidatorTest method validateGenesisBlock.
@Test
public void validateGenesisBlock() {
BlockValidatorImpl validator = new BlockValidatorBuilder().build();
Block genesis = new BlockGenerator().getGenesisBlock();
Assert.assertTrue(validator.isValid(genesis));
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class FamilyUtilsTest method getFamilyGetAncestorsWithUncles.
@Test
public void getFamilyGetAncestorsWithUncles() {
BlockStore store = createBlockStore();
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block1 = blockGenerator.createChildBlock(genesis);
Block uncle11 = blockGenerator.createChildBlock(genesis);
Block uncle12 = blockGenerator.createChildBlock(genesis);
Block block2 = blockGenerator.createChildBlock(block1);
Block uncle21 = blockGenerator.createChildBlock(block1);
Block uncle22 = blockGenerator.createChildBlock(block1);
Block block3 = blockGenerator.createChildBlock(block2);
Block uncle31 = blockGenerator.createChildBlock(block2);
Block uncle32 = blockGenerator.createChildBlock(block2);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(block1, TEST_DIFFICULTY, true);
store.saveBlock(uncle11, TEST_DIFFICULTY, false);
store.saveBlock(uncle12, TEST_DIFFICULTY, false);
store.saveBlock(block2, TEST_DIFFICULTY, true);
store.saveBlock(uncle21, TEST_DIFFICULTY, false);
store.saveBlock(uncle22, TEST_DIFFICULTY, false);
store.saveBlock(block3, TEST_DIFFICULTY, true);
store.saveBlock(uncle31, TEST_DIFFICULTY, false);
store.saveBlock(uncle32, TEST_DIFFICULTY, false);
Set<Keccak256> family = FamilyUtils.getFamily(store, block3, 2);
Assert.assertNotNull(family);
Assert.assertFalse(family.isEmpty());
Assert.assertEquals(4, family.size());
Assert.assertFalse(family.contains(genesis.getHash()));
Assert.assertTrue(family.contains(block1.getHash()));
Assert.assertFalse(family.contains(uncle11.getHash()));
Assert.assertFalse(family.contains(uncle12.getHash()));
Assert.assertTrue(family.contains(block2.getHash()));
Assert.assertTrue(family.contains(uncle21.getHash()));
Assert.assertTrue(family.contains(uncle22.getHash()));
Assert.assertFalse(family.contains(block3.getHash()));
Assert.assertFalse(family.contains(uncle31.getHash()));
Assert.assertFalse(family.contains(uncle32.getHash()));
family = FamilyUtils.getFamily(store, block3, 3);
Assert.assertNotNull(family);
Assert.assertFalse(family.isEmpty());
Assert.assertEquals(7, family.size());
Assert.assertTrue(family.contains(genesis.getHash()));
Assert.assertTrue(family.contains(block1.getHash()));
Assert.assertTrue(family.contains(uncle11.getHash()));
Assert.assertTrue(family.contains(uncle12.getHash()));
Assert.assertTrue(family.contains(block2.getHash()));
Assert.assertTrue(family.contains(uncle21.getHash()));
Assert.assertTrue(family.contains(uncle22.getHash()));
Assert.assertFalse(family.contains(block3.getHash()));
Assert.assertFalse(family.contains(uncle31.getHash()));
Assert.assertFalse(family.contains(uncle32.getHash()));
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class TransactionPoolImplTest method retractBlockAddsTransactionsAsPending.
@Test
public void retractBlockAddsTransactionsAsPending() {
BlockChainImpl blockchain = createBlockchain();
Coin balance = Coin.valueOf(1000000);
TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(3, balance, blockchain);
transactionPool.processBest(blockchain.getBestBlock());
Transaction tx1 = createSampleTransaction(1, 2, 1000, 0);
Transaction tx2 = createSampleTransaction(1, 2, 3000, 1);
Transaction tx3 = createSampleTransaction(2, 3, 1000, 0);
Transaction tx4 = createSampleTransaction(2, 3, 3000, 1);
transactionPool.addTransaction(tx1);
transactionPool.addTransaction(tx2);
List<Transaction> txs = new ArrayList<>();
txs.add(tx3);
txs.add(tx4);
Block block = new BlockBuilder().parent(new BlockGenerator().getGenesisBlock()).transactions(txs).build();
transactionPool.retractBlock(block);
List<Transaction> alltxs = transactionPool.getPendingTransactions();
Assert.assertNotNull(alltxs);
Assert.assertFalse(alltxs.isEmpty());
Assert.assertEquals(4, alltxs.size());
Assert.assertTrue(alltxs.contains(tx1));
Assert.assertTrue(alltxs.contains(tx2));
Assert.assertTrue(alltxs.contains(tx3));
Assert.assertTrue(alltxs.contains(tx4));
List<Transaction> ptxs = transactionPool.getPendingTransactions();
Assert.assertNotNull(ptxs);
Assert.assertFalse(ptxs.isEmpty());
Assert.assertEquals(4, ptxs.size());
Assert.assertTrue(ptxs.contains(tx1));
Assert.assertTrue(ptxs.contains(tx2));
Assert.assertTrue(ptxs.contains(tx3));
Assert.assertTrue(ptxs.contains(tx4));
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class RemascFederationProviderTest method getRemascFederationProvider.
private static RemascFederationProvider getRemascFederationProvider() throws IOException, BlockStoreException {
Genesis genesisBlock = new BlockGenerator().getGenesisBlock();
BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock);
Blockchain blockchain = builder.build();
BridgeSupport bridgeSupport = new BridgeSupport(new RskSystemProperties(), blockchain.getRepository(), null, PrecompiledContracts.BRIDGE_ADDR, null);
RemascFederationProvider provider = null;
try {
provider = new RemascFederationProvider(bridgeSupport);
} catch (BlockStoreException | IOException e) {
e.printStackTrace();
}
return provider;
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class RemascStateTest method serializeAndDeserializeWithSomeValues.
@Test
public void serializeAndDeserializeWithSomeValues() {
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block1 = blockGenerator.createChildBlock(genesis);
Block block2 = blockGenerator.createChildBlock(block1);
Block block3 = blockGenerator.createChildBlock(block2);
Block block4 = blockGenerator.createChildBlock(block3);
Block block5 = blockGenerator.createChildBlock(block4);
Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1);
Sibling sibling2 = new Sibling(block1.getHeader(), block1.getCoinbase(), 2);
Sibling sibling3 = new Sibling(block2.getHeader(), block2.getCoinbase(), 3);
Sibling sibling4 = new Sibling(block3.getHeader(), block3.getCoinbase(), 4);
Sibling sibling5 = new Sibling(block4.getHeader(), block4.getCoinbase(), 5);
Sibling sibling6 = new Sibling(block5.getHeader(), block5.getCoinbase(), 6);
List<Sibling> siblings0 = new ArrayList<>();
List<Sibling> siblings1 = new ArrayList<>();
List<Sibling> siblings2 = new ArrayList<>();
siblings0.add(sibling1);
siblings0.add(sibling2);
siblings1.add(sibling3);
siblings1.add(sibling4);
siblings2.add(sibling5);
siblings2.add(sibling6);
SortedMap<Long, List<Sibling>> siblings = new TreeMap<>();
siblings.put(Long.valueOf(0), siblings0);
siblings.put(Long.valueOf(1), siblings1);
siblings.put(Long.valueOf(2), siblings2);
RemascState state = new RemascState(Coin.valueOf(1), Coin.valueOf(10), siblings, true);
byte[] bytes = state.getEncoded();
RemascState result = RemascState.create(bytes);
Assert.assertNotNull(result);
Assert.assertEquals(Coin.valueOf(1), result.getRewardBalance());
Assert.assertEquals(Coin.valueOf(10), result.getBurnedBalance());
Assert.assertNotNull(result.getSiblings());
Assert.assertFalse(result.getSiblings().isEmpty());
Assert.assertTrue(result.getBrokenSelectionRule());
}
Aggregations