Search in sources :

Example 81 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class WorldTest method saveAndGetBlock.

@Test
public void saveAndGetBlock() {
    World world = new World();
    Block block = new BlockGenerator().getBlock(1);
    world.saveBlock("b01", block);
    Assert.assertSame(block, world.getBlockByName("b01"));
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 82 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockBuilderTest method buildBlockWithDifficulty.

@Test
public void buildBlockWithDifficulty() {
    Block genesis = new BlockGenerator().getGenesisBlock();
    BlockBuilder builder = new BlockBuilder();
    Block block = builder.parent(genesis).difficulty(1).build();
    Assert.assertNotNull(block);
    Assert.assertEquals(1, block.getNumber());
    Assert.assertEquals(BigInteger.ONE, block.getDifficulty().asBigInteger());
    Assert.assertEquals(genesis.getHash(), block.getParentHash());
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 83 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockchainTest method tryToConnectWithCompetingChain.

@Test
public void tryToConnectWithCompetingChain() {
    // Two competing blockchains of the same size (2)
    Blockchain blockchain = createBlockchain();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
    Block block2 = blockGenerator.createChildBlock(block1, 0, 5);
    Block block1b = blockGenerator.createChildBlock(blockchain.getBestBlock());
    Block block2b = blockGenerator.createChildBlock(block1b, 0, 4);
    // genesis <- block1 <- block2
    // genesis <- block1b <- block2b
    Assert.assertEquals(ImportResult.NO_PARENT, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block1b));
    Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1b));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block2b));
    Assert.assertEquals(blockchain.getBestBlock(), block2);
    Assert.assertEquals(2, block2.getNumber());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 84 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockchainTest method checkItDoesntAddAnInvalidBlock.

@Test
public void checkItDoesntAddAnInvalidBlock() {
    Blockchain blockchain = createBlockchain();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
    ImportResult importResult1 = blockchain.tryToConnect(block1);
    assertTrue(importResult1.isSuccessful());
    Block block2 = blockGenerator.createChildBlock(blockchain.getBestBlock());
    Block block2b = blockGenerator.createBlock(10, 5);
    Block block3 = Block.fromValidData(block2.getHeader(), block2b.getTransactionsList(), block2b.getUncleList());
    ImportResult importResult2 = blockchain.tryToConnect(block3);
    Assert.assertFalse(importResult2.isSuccessful());
}
Also used : ImportResult(org.ethereum.core.ImportResult) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 85 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockchainTest method addFirstBlock.

@Test
public void addFirstBlock() {
    Blockchain blockchain = createBlockchain();
    Block block = new BlockGenerator().createChildBlock(blockchain.getBestBlock());
    blockchain.tryToConnect(block);
    Assert.assertEquals(blockchain.getBestBlock(), block);
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) 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