Search in sources :

Example 26 with BlockChainImpl

use of co.rsk.core.bc.BlockChainImpl in project rskj by rsksmart.

the class Web3ImplTest method getPendingTransactionByHash.

@Test
public void getPendingTransactionByHash() throws Exception {
    World world = new World();
    BlockChainImpl blockChain = world.getBlockChain();
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
    transactionPool.processBest(blockChain.getBestBlock());
    Web3Impl web3 = createWeb3(world, transactionPool, null);
    Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(2000000)).build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    transactionPool.addTransaction(tx);
    String hashString = tx.getHash().toHexString();
    TransactionResultDTO tr = web3.eth_getTransactionByHash(hashString);
    Assert.assertNotNull(tr);
    org.junit.Assert.assertEquals("0x" + hashString, tr.hash);
    org.junit.Assert.assertEquals("0", tr.nonce);
    org.junit.Assert.assertEquals(null, tr.blockHash);
    org.junit.Assert.assertEquals(null, tr.transactionIndex);
    org.junit.Assert.assertEquals("0x00", tr.input);
    org.junit.Assert.assertEquals("0x" + Hex.toHexString(tx.getReceiveAddress().getBytes()), tr.to);
}
Also used : TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) Test(org.junit.Test)

Example 27 with BlockChainImpl

use of co.rsk.core.bc.BlockChainImpl in project rskj by rsksmart.

the class RskTestFactory method getBlockchain.

public BlockChainImpl getBlockchain() {
    if (blockchain == null) {
        blockchain = new BlockChainImpl(config, getRepository(), getBlockStore(), getReceiptStore(), // circular dependency
        null, null, null, new DummyBlockValidator());
        TransactionPool transactionPool = getTransactionPool();
        blockchain.setTransactionPool(transactionPool);
    }
    return blockchain;
}
Also used : DummyBlockValidator(co.rsk.validators.DummyBlockValidator) BlockChainImpl(co.rsk.core.bc.BlockChainImpl)

Example 28 with BlockChainImpl

use of co.rsk.core.bc.BlockChainImpl in project rskj by rsksmart.

the class WorldDslProcessor method processBlockConnectCommand.

private void processBlockConnectCommand(DslCommand cmd) {
    BlockChainImpl blockChain = world.getBlockChain();
    int nblocks = cmd.getArity();
    for (int k = 0; k < nblocks; k++) {
        String name = cmd.getArgument(k);
        Block block = world.getBlockByName(name);
        BlockExecutor executor = world.getBlockExecutor();
        executor.executeAndFill(block, blockChain.getBestBlock());
        block.seal();
        latestImportResult = blockChain.tryToConnect(block);
    }
}
Also used : BlockExecutor(co.rsk.core.bc.BlockExecutor) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) Block(org.ethereum.core.Block)

Aggregations

BlockChainImpl (co.rsk.core.bc.BlockChainImpl)28 Test (org.junit.Test)15 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)14 ArrayList (java.util.ArrayList)14 World (co.rsk.test.World)11 BlockBuilder (co.rsk.test.builders.BlockBuilder)11 AccountBuilder (co.rsk.test.builders.AccountBuilder)10 BlockDifficulty (co.rsk.core.BlockDifficulty)7 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)6 Block (org.ethereum.core.Block)6 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)4 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)4 BigInteger (java.math.BigInteger)4 BlockHeader (org.ethereum.core.BlockHeader)4 HashMapDB (org.ethereum.datasource.HashMapDB)4 RskAddress (co.rsk.core.RskAddress)3 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)3 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)3 BlockStore (org.ethereum.db.BlockStore)3 SimpleEthereum (org.ethereum.rpc.Simples.SimpleEthereum)3