Search in sources :

Example 76 with BlockBuilder

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

the class BlockValidatorTest method validateBlockWithTransaction.

@Test
public void validateBlockWithTransaction() {
    BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
    Block genesis = BlockChainImplTest.getGenesisBlock(blockChain);
    genesis.seal();
    Block parent = new BlockBuilder().parent(genesis).build();
    parent.seal();
    List<Transaction> txs = new ArrayList<>();
    txs.add(BlockExecutorTest.generateBlockWithOneTransaction().getTransaction());
    Block block = new BlockBuilder().parent(parent).transactions(txs).build();
    ;
    block.seal();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(parent));
    BlockValidator validator = createValidator(blockChain.getBlockStore());
    Assert.assertTrue(validator.isValid(block));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockValidator(co.rsk.validators.BlockValidator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 77 with BlockBuilder

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

the class BlockValidatorTest method parentInvalidNumber.

@Test
public void parentInvalidNumber() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block = new BlockBuilder().parent(genesis).build();
    block.getHeader().setNumber(25L);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addParentNumberRule().blockStore(store).build();
    Assert.assertFalse(validator.isValid(block));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 78 with BlockBuilder

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

the class Web3ImplLogsTest method getWorld3WithBlockWithEventInContractCreation.

public static World getWorld3WithBlockWithEventInContractCreation(RskSystemProperties config, ReceiptStore receiptStore) {
    World world = new World(receiptStore);
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    BlockChainImpl blockChain = world.getBlockChain();
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    blockChain.tryToConnect(block1);
    return world;
}
Also used : ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Example 79 with BlockBuilder

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

the class Web3ImplLogsTest method getWeb3WithContractCreationWithoutEvents.

private Web3Impl getWeb3WithContractCreationWithoutEvents() {
    World world = new World();
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    Block genesis = world.getBlockByName("g00");
    /* contract compiled in data attribute of tx
        contract greeter {

            address owner;
            modifier onlyOwner { if (msg.sender != owner) throw; _ ; }

            function greeter() public {
                owner = msg.sender;
            }
            function greet(string param) onlyOwner constant returns (string) {
                return param;
            }
        } */
    Transaction tx = new TransactionBuilder().sender(acc1).gasLimit(BigInteger.valueOf(100000)).gasPrice(BigInteger.ONE).data(compiledGreeter).build();
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    BlockChainImpl blockChain = world.getBlockChain();
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    blockChain.tryToConnect(block1);
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
    Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool);
    web3.personal_newAccountWithSeed("notDefault");
    return web3;
}
Also used : ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) World(co.rsk.test.World) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) AccountBuilder(co.rsk.test.builders.AccountBuilder) 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