Search in sources :

Example 71 with BlockBuilder

use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.

the class BlockValidatorTest method processValidMGPBlock.

@Test
public void processValidMGPBlock() {
    BlockStore blockStore = mock(org.ethereum.db.BlockStore.class);
    Repository repository = mock(Repository.class);
    when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
    Block parent = new BlockBuilder(null, null, null).minGasPrice(BigInteger.TEN).parent(new BlockGenerator().getGenesisBlock()).build();
    List<Transaction> txs = new ArrayList<>();
    byte chainId = config.getNetworkConstants().getChainId();
    Transaction tx = Transaction.builder().nonce(BigInteger.ZERO).gasPrice(BigInteger.valueOf(12L)).gasLimit(BigInteger.TEN).destination(Hex.decode("0000000000000000000000000000000000000006")).chainId(chainId).value(BigInteger.ZERO).build();
    tx.sign(new byte[] { 22, 11, 00 });
    txs.add(tx);
    Block block = new BlockBuilder(null, null, null).transactions(txs).minGasPrice(BigInteger.valueOf(11L)).parent(parent).build();
    when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addPrevMinGasPriceRule().addTxsMinGasPriceRule().blockStore(blockStore).build();
    Assert.assertTrue(validator.isValid(block));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) RemascTransaction(co.rsk.remasc.RemascTransaction) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 72 with BlockBuilder

use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.

the class BlockValidatorTest method noRemascTx.

@Test
public void noRemascTx() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    List<Transaction> txs = new ArrayList<>();
    byte chainId = config.getNetworkConstants().getChainId();
    Transaction tx = Transaction.builder().nonce(BigInteger.ZERO).gasPrice(BigInteger.valueOf(12L)).gasLimit(BigInteger.TEN).destination(Hex.decode("0000000000000000000000000000000000000006")).chainId(chainId).value(BigInteger.ZERO).build();
    tx.sign(new byte[] {});
    txs.add(tx);
    Block block = new BlockBuilder(null, null, null).parent(genesis).transactions(txs).build();
    BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
    Assert.assertFalse(validator.isValid(block));
    block = new BlockBuilder(null, null, null).parent(genesis).transactions(null).build();
    Assert.assertFalse(validator.isValid(block));
    block = new BlockBuilder(null, null, null).parent(genesis).transactions(new ArrayList<>()).build();
    Assert.assertFalse(validator.isValid(block));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 73 with BlockBuilder

use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.

the class BlockValidatorTest method remascTx.

@Test
public void remascTx() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    List<Transaction> txs = new ArrayList<>();
    byte chainId = config.getNetworkConstants().getChainId();
    Transaction tx = Transaction.builder().nonce(BigInteger.ZERO).gasPrice(BigInteger.valueOf(12L)).gasLimit(BigInteger.TEN).destination(Hex.decode("0000000000000000000000000000000000000006")).chainId(chainId).value(BigInteger.ZERO).build();
    tx.sign(new byte[] {});
    txs.add(tx);
    txs.add(new RemascTransaction(BigInteger.ONE.longValue()));
    Block block = new BlockBuilder(null, null, null).parent(genesis).transactions(txs).build();
    BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
    Assert.assertTrue(validator.isValid(block));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 74 with BlockBuilder

use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.

the class BlockBuilderTest method buildBlockWithGenesisAsParent.

@Test
public void buildBlockWithGenesisAsParent() {
    Block genesis = new BlockGenerator().getGenesisBlock();
    BlockBuilder builder = new BlockBuilder(null, null, null);
    Block block = builder.parent(genesis).build();
    Assert.assertNotNull(block);
    Assert.assertEquals(1, block.getNumber());
    // Assert.assertTrue(genesis.getCumulativeDifficulty().compareTo(block.getDifficultyBI()) < 0);
    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 75 with BlockBuilder

use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.

the class RskForksBridgeTest method buildBlock.

private Block buildBlock(Block parent, long difficulty) {
    World world = new World(blockChain, genesis);
    BlockBuilder blockBuilder = new BlockBuilder(world).difficulty(difficulty).parent(parent);
    return blockBuilder.build();
}
Also used : World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Aggregations

BlockBuilder (co.rsk.test.builders.BlockBuilder)79 Test (org.junit.Test)63 World (co.rsk.test.World)31 AccountBuilder (co.rsk.test.builders.AccountBuilder)30 ArrayList (java.util.ArrayList)30 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)13 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)12 BlockResultDTO (org.ethereum.rpc.dto.BlockResultDTO)12 RemascTransaction (co.rsk.remasc.RemascTransaction)11 Block (org.ethereum.core.Block)10 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)9 HashMapDB (org.ethereum.datasource.HashMapDB)8 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)7 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)7 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)6 SimplePeer (co.rsk.net.simples.SimplePeer)6 BlockHeader (org.ethereum.core.BlockHeader)6 Keccak256 (co.rsk.crypto.Keccak256)5 SimpleBlock (co.rsk.peg.simples.SimpleBlock)5