Search in sources :

Example 56 with BlockGenerator

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));
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 57 with BlockGenerator

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()));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 58 with BlockGenerator

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));
}
Also used : Coin(co.rsk.core.Coin) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 59 with BlockGenerator

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;
}
Also used : BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) Blockchain(org.ethereum.core.Blockchain) Genesis(org.ethereum.core.Genesis) IOException(java.io.IOException) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BridgeSupport(co.rsk.peg.BridgeSupport) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 60 with BlockGenerator

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());
}
Also used : ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)250 Test (org.junit.Test)237 Block (org.ethereum.core.Block)104 ArrayList (java.util.ArrayList)39 Blockchain (org.ethereum.core.Blockchain)38 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)36 RskSystemProperties (co.rsk.config.RskSystemProperties)35 SimpleBlock (co.rsk.peg.simples.SimpleBlock)34 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)33 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)31 HashMapDB (org.ethereum.datasource.HashMapDB)22 BlockBuilder (co.rsk.test.builders.BlockBuilder)17 Keccak256 (co.rsk.crypto.Keccak256)15 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)15 BlockStore (org.ethereum.db.BlockStore)15 World (co.rsk.test.World)14 RepositoryImpl (co.rsk.db.RepositoryImpl)13 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)13 Ignore (org.junit.Ignore)12 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)10