Search in sources :

Example 11 with TransactionPoolImpl

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

the class MainNetMinerTest method submitBitcoinBlockProofOfWorkNotGoodEnough.

/*
     * This test is probabilistic, but it has a really high chance to pass. We will generate
     * a random block that it is unlikely to pass the Long.MAX_VALUE difficulty, though
     * it may happen once. Twice would be suspicious.
     */
@Test
public void submitBitcoinBlockProofOfWorkNotGoodEnough() {
    /* We need a low target */
    BlockChainImpl bc = new BlockChainBuilder().build();
    Genesis gen = (Genesis) BlockChainImplTest.getGenesisBlock(bc);
    gen.getHeader().setDifficulty(new BlockDifficulty(BigInteger.valueOf(Long.MAX_VALUE)));
    bc.setStatus(gen, gen.getCumulativeDifficulty());
    World world = new World(bc, gen);
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), world.getBlockChain().getBlockStore(), null, null, null, 10, 100);
    blockchain = world.getBlockChain();
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), blockToMineBuilder(), ConfigUtils.getDefaultMiningConfig());
    try {
        minerServer.start();
        MinerWork work = minerServer.getWork();
        co.rsk.bitcoinj.core.BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlock(work);
        bitcoinMergedMiningBlock.setNonce(2);
        SubmitBlockResult result = minerServer.submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock);
        Assert.assertEquals("ERROR", result.getStatus());
        Assert.assertNull(result.getBlockInfo());
        Mockito.verify(ethereumImpl, Mockito.times(0)).addNewMinedBlock(Mockito.any());
    } finally {
        minerServer.stop();
    }
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) EthereumImpl(org.ethereum.facade.EthereumImpl) World(co.rsk.test.World) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) BlockDifficulty(co.rsk.core.BlockDifficulty) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) Genesis(org.ethereum.core.Genesis) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 12 with TransactionPoolImpl

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

the class Web3ImplLogsTest method createMainContractWithoutEvents.

@Test
public void createMainContractWithoutEvents() throws Exception {
    World world = new World();
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    BlockChainImpl blockChain = world.getBlockChain();
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
    SimpleEthereum eth = new SimpleEthereum();
    eth.repository = world.getBlockChain().getRepository();
    eth.blockchain = world.getBlockChain();
    Web3Impl web3 = createWeb3(eth, world.getBlockChain(), transactionPool, WalletFactory.createWallet());
    // TODO tricky link to listener
    blockChain.setListener(web3.setupListener());
    web3.personal_newAccountWithSeed("notDefault");
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.fromBlock = "earliest";
    String id = web3.eth_newFilter(fr);
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getMainContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    blockChain.tryToConnect(block1);
    Object[] logs = web3.eth_getFilterChanges(id);
    Assert.assertNotNull(id);
    Assert.assertNotNull(logs);
    Assert.assertEquals(0, logs.length);
}
Also used : BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ArrayList(java.util.ArrayList) World(co.rsk.test.World) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 13 with TransactionPoolImpl

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

the class Web3ImplLogsTest method createCallerContractWithEventsOnInvoke.

@Test
public void createCallerContractWithEventsOnInvoke() throws Exception {
    World world = new World();
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    BlockChainImpl blockChain = world.getBlockChain();
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
    SimpleEthereum eth = new SimpleEthereum();
    eth.repository = world.getBlockChain().getRepository();
    eth.blockchain = world.getBlockChain();
    Web3Impl web3 = createWeb3(eth, world.getBlockChain(), transactionPool, WalletFactory.createWallet());
    // TODO tricky link to listener
    blockChain.setListener(web3.setupListener());
    web3.personal_newAccountWithSeed("notDefault");
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.fromBlock = "earliest";
    String id = web3.eth_newFilter(fr);
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getMainContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    blockChain.tryToConnect(block1);
    String mainAddress = tx.getContractAddress().toString();
    Transaction tx2;
    tx2 = getCallerContractTransaction(acc1, mainAddress);
    String callerAddress = Hex.toHexString(tx2.getContractAddress().getBytes());
    List<Transaction> txs2 = new ArrayList<>();
    txs2.add(tx2);
    Block block2 = new BlockBuilder(world).parent(block1).transactions(txs2).build();
    blockChain.tryToConnect(block2);
    Transaction tx3;
    tx3 = getCallerContractTransactionWithInvoke(acc1, tx2.getContractAddress().getBytes(), mainAddress);
    List<Transaction> txs3 = new ArrayList<>();
    txs3.add(tx3);
    Block block3 = new BlockBuilder(world).parent(block2).transactions(txs3).build();
    blockChain.tryToConnect(block3);
    Object[] logs = web3.eth_getFilterChanges(id);
    Assert.assertNotNull(id);
    Assert.assertNotNull(logs);
    Assert.assertEquals(3, logs.length);
    Assert.assertEquals("0x" + mainAddress, ((LogFilterElement) logs[0]).address);
    Assert.assertEquals("0x" + callerAddress, ((LogFilterElement) logs[1]).address);
    Assert.assertEquals("0x" + mainAddress, ((LogFilterElement) logs[2]).address);
}
Also used : BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ArrayList(java.util.ArrayList) World(co.rsk.test.World) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 14 with TransactionPoolImpl

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

the class Web3ImplLogsTest method newFilterGetLogsTwiceAfterBlock.

@Test
public void newFilterGetLogsTwiceAfterBlock() throws Exception {
    World world = new World();
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), world.getBlockChain().getBlockStore(), null, null, null, 10, 100);
    SimpleEthereum eth = new SimpleEthereum();
    eth.repository = world.getBlockChain().getRepository();
    eth.blockchain = world.getBlockChain();
    Web3Impl web3 = createWeb3(eth, world.getBlockChain(), transactionPool, WalletFactory.createWallet());
    // TODO tricky link to listener
    world.getBlockChain().setListener(web3.setupListener());
    web3.personal_newAccountWithSeed("notDefault");
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.fromBlock = "earliest";
    String id = web3.eth_newFilter(fr);
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    world.getBlockChain().tryToConnect(block1);
    web3.eth_getFilterLogs(id);
    Object[] logs = web3.eth_getFilterLogs(id);
    Assert.assertNotNull(id);
    Assert.assertNotNull(logs);
    Assert.assertEquals(1, logs.length);
    Assert.assertEquals("0x" + tx.getContractAddress().toString(), ((LogFilterElement) logs[0]).address);
}
Also used : ArrayList(java.util.ArrayList) World(co.rsk.test.World) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 15 with TransactionPoolImpl

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

the class Web3ImplLogsTest method createCallerContractWithEvents.

@Test
public void createCallerContractWithEvents() throws Exception {
    World world = new World();
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    BlockChainImpl blockChain = world.getBlockChain();
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
    SimpleEthereum eth = new SimpleEthereum();
    eth.repository = world.getBlockChain().getRepository();
    eth.blockchain = world.getBlockChain();
    Web3Impl web3 = createWeb3(eth, world.getBlockChain(), transactionPool, WalletFactory.createWallet());
    // TODO tricky link to listener
    blockChain.setListener(web3.setupListener());
    web3.personal_newAccountWithSeed("notDefault");
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.fromBlock = "earliest";
    String id = web3.eth_newFilter(fr);
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getMainContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    blockChain.tryToConnect(block1);
    String mainAddress = tx.getContractAddress().toString();
    Transaction tx2;
    tx2 = getCallerContractTransaction(acc1, mainAddress);
    String callerAddress = Hex.toHexString(tx2.getContractAddress().getBytes());
    List<Transaction> txs2 = new ArrayList<>();
    txs2.add(tx2);
    Block block2 = new BlockBuilder(world).parent(block1).transactions(txs2).build();
    blockChain.tryToConnect(block2);
    Object[] logs = web3.eth_getFilterChanges(id);
    Assert.assertNotNull(id);
    Assert.assertNotNull(logs);
    Assert.assertEquals(2, logs.length);
    Assert.assertEquals("0x" + mainAddress, ((LogFilterElement) logs[0]).address);
    Assert.assertEquals("0x" + callerAddress, ((LogFilterElement) logs[1]).address);
}
Also used : BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ArrayList(java.util.ArrayList) World(co.rsk.test.World) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder) 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