Search in sources :

Example 16 with TransactionPoolImpl

use of co.rsk.core.bc.TransactionPoolImpl 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)

Example 17 with TransactionPoolImpl

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

the class Web3ImplLogsTest method getWeb3WithEventInContractCreation.

private Web3Impl getWeb3WithEventInContractCreation() {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = getWorld3WithBlockWithEventInContractCreation(config, receiptStore);
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), world.getBlockChain().getBlockStore(), receiptStore, null, null, 10, 100);
    Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool, receiptStore);
    web3.personal_newAccountWithSeed("notDefault");
    return web3;
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore)

Example 18 with TransactionPoolImpl

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

the class Web3ImplTest method getBalanceWithAccountAndBlockWithTransaction.

@Test
public void getBalanceWithAccountAndBlockWithTransaction() throws Exception {
    World world = new World();
    BlockChainImpl blockChain = world.getBlockChain();
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
    Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(10000000)).build();
    Account acc2 = new AccountBuilder(world).name("acc2").build();
    Block genesis = world.getBlockByName("g00");
    Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(10000)).build();
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block1));
    Web3Impl web3 = createWeb3(world, transactionPool, null);
    web3.repository = world.getBlockChain().getRepository();
    String accountAddress = Hex.toHexString(acc2.getAddress().getBytes());
    String balanceString = "0x" + Hex.toHexString(BigInteger.valueOf(10000).toByteArray());
    org.junit.Assert.assertEquals("0x0", web3.eth_getBalance(accountAddress, "0x0"));
    org.junit.Assert.assertEquals(balanceString, web3.eth_getBalance(accountAddress, "0x1"));
    org.junit.Assert.assertEquals(balanceString, web3.eth_getBalance(accountAddress, "pending"));
}
Also used : 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) Test(org.junit.Test)

Example 19 with TransactionPoolImpl

use of co.rsk.core.bc.TransactionPoolImpl 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)

Aggregations

TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)19 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)14 World (co.rsk.test.World)14 AccountBuilder (co.rsk.test.builders.AccountBuilder)13 BlockBuilder (co.rsk.test.builders.BlockBuilder)12 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 SimpleEthereum (org.ethereum.rpc.Simples.SimpleEthereum)8 HashMapDB (org.ethereum.datasource.HashMapDB)4 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)3 ReceiptStore (org.ethereum.db.ReceiptStore)3 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)3 BlockDifficulty (co.rsk.core.BlockDifficulty)2 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)2 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 RskAddress (co.rsk.core.RskAddress)1 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)1