Search in sources :

Example 1 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class TestRunner method runTestCase.

public List<String> runTestCase(BlockTestCase testCase) {
    /* 1 */
    // Create genesis + init pre state
    ValidationStats vStats = new ValidationStats();
    Block genesis = build(testCase.getGenesisBlockHeader(), null, null);
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Repository repository = RepositoryBuilder.build(trieStore, testCase.getPre());
    IndexedBlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    CompositeEthereumListener listener = new TestCompositeEthereumListener();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, blockStore, receiptStore, blockFactory, new ProgramInvokeFactoryImpl(), null, blockTxSignatureCache);
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    RepositoryLocator repositoryLocator = new RepositoryLocator(trieStore, stateRootHandler);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repositoryLocator, null, blockFactory, listener, transactionExecutorFactory, new ReceivedTxSignatureCache(), 10, 100);
    BlockChainImpl blockchain = new BlockChainImpl(blockStore, receiptStore, transactionPool, null, new DummyBlockValidator(), new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), transactionExecutorFactory), stateRootHandler);
    blockchain.setNoValidation(true);
    blockchain.setStatus(genesis, genesis.getCumulativeDifficulty());
    /* 2 */
    // Create block traffic list
    List<Block> blockTraffic = new ArrayList<>();
    for (BlockTck blockTck : testCase.getBlocks()) {
        Block block = build(blockTck.getBlockHeader(), blockTck.getTransactions(), blockTck.getUncleHeaders());
        Block tBlock = null;
        try {
            byte[] rlp = parseData(blockTck.getRlp());
            tBlock = blockFactory.decodeBlock(rlp);
            ArrayList<String> outputSummary = BlockHeaderValidator.valid(tBlock.getHeader(), block.getHeader(), null);
            if (!outputSummary.isEmpty()) {
                for (String output : outputSummary) logger.error("at block {}: {}", Integer.toString(blockTraffic.size()), output);
            }
            blockTraffic.add(tBlock);
        } catch (Exception e) {
            System.out.println("*** Exception");
        }
    }
    // Inject blocks to the blockchain execution
    for (Block block : blockTraffic) {
        ImportResult importResult = blockchain.tryToConnect(block);
        logger.debug("{} ~ {} difficulty: {} ::: {}", block.getPrintableHash(), toPrintableHash(block.getParentHash().getBytes()), block.getCumulativeDifficulty(), importResult.toString());
    }
    // Check state root matches last valid block
    List<String> results = new ArrayList<>();
    String currRoot = ByteUtil.toHexString(repository.getRoot());
    byte[] bestHash = Hex.decode(testCase.getLastblockhash());
    String finalRoot = ByteUtil.toHexString(blockStore.getBlockByHash(bestHash).getStateRoot());
    if (validateStateRoots) {
        if (!finalRoot.equals(currRoot)) {
            String formattedString = String.format("Root hash doesn't match best: expected: %s current: %s", finalRoot, currRoot);
            results.add(formattedString);
        }
    }
    Repository postRepository = RepositoryBuilder.build(testCase.getPostState());
    List<String> repoResults = RepositoryValidator.valid(repository, postRepository, validateStateRoots, validateBalances, null);
    results.addAll(repoResults);
    return results;
}
Also used : BlockChainImpl(co.rsk.core.bc.BlockChainImpl) TrieStore(co.rsk.trie.TrieStore) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) BlockTck(org.ethereum.jsontestsuite.model.BlockTck) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) TrieStoreImpl(co.rsk.trie.TrieStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) HashMapDB(org.ethereum.datasource.HashMapDB) IOException(java.io.IOException) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) ValidationStats(org.ethereum.jsontestsuite.validators.ValidationStats)

Example 2 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class BlockChainImplTest method setup.

@Before
public void setup() {
    objects = new RskTestFactory() {

        @Override
        protected GenesisLoader buildGenesisLoader() {
            return new TestGenesisLoader(getTrieStore(), "rsk-unittests.json", BigInteger.ZERO, true, true, true);
        }

        @Override
        protected CompositeEthereumListener buildCompositeEthereumListener() {
            return new BlockExecutorTest.SimpleEthereumListener();
        }
    };
    config = objects.getRskSystemProperties();
    blockChain = objects.getBlockchain();
    blockStore = objects.getBlockStore();
    blockExecutor = objects.getBlockExecutor();
    listener = (BlockExecutorTest.SimpleEthereumListener) objects.getCompositeEthereumListener();
}
Also used : GenesisLoader(org.ethereum.core.genesis.GenesisLoader) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) RskTestFactory(org.ethereum.util.RskTestFactory) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) Before(org.junit.Before)

Example 3 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class BlocksBloomServiceTest method processFirstAndSecondRangeUsingEmitter.

@Test
public void processFirstAndSecondRangeUsingEmitter() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();
    BlockChainBuilder.extend(blockchain, 10, false, false);
    CompositeEthereumListener emitter = new CompositeEthereumListener();
    KeyValueDataSource dataSource = new HashMapDB();
    BlocksBloomStore blocksBloomStore = new BlocksBloomStore(4, 2, dataSource);
    BlocksBloomService blocksBloomService = new BlocksBloomService(emitter, blocksBloomStore, world.getBlockStore());
    blocksBloomService.start();
    emitter.onBlock(blockchain.getBlockByNumber(4), null);
    emitter.onBlock(blockchain.getBlockByNumber(6), null);
    emitter.onBlock(blockchain.getBlockByNumber(9), null);
    blocksBloomService.stop();
    Assert.assertFalse(dataSource.keys().isEmpty());
    Assert.assertEquals(2, dataSource.keys().size());
    Assert.assertNotNull(dataSource.get(longToKey(0)));
    Assert.assertNotNull(dataSource.get(longToKey(4)));
}
Also used : CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) Blockchain(org.ethereum.core.Blockchain) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) World(co.rsk.test.World) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 4 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class BlocksBloomServiceTest method processFirstRange.

@Test
public void processFirstRange() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();
    BlockChainBuilder.extend(blockchain, 8, false, false);
    CompositeEthereumListener emitter = new CompositeEthereumListener();
    KeyValueDataSource dataSource = new HashMapDB();
    BlocksBloomStore blocksBloomStore = new BlocksBloomStore(4, 2, dataSource);
    BlocksBloomService blocksBloomService = new BlocksBloomService(emitter, blocksBloomStore, world.getBlockStore());
    blocksBloomService.processNewBlock(4);
    blocksBloomService.processNewBlock(6);
    Assert.assertFalse(dataSource.keys().isEmpty());
    Assert.assertEquals(1, dataSource.keys().size());
    Assert.assertNotNull(dataSource.get(longToKey(0)));
}
Also used : CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) Blockchain(org.ethereum.core.Blockchain) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) World(co.rsk.test.World) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 5 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class RskWireProtocolTest method setup.

@Before
public void setup() {
    config = mock(RskSystemProperties.class);
    peerScoringManager = mock(PeerScoringManager.class);
    messageHandler = mock(MessageHandler.class);
    compositeEthereumListener = mock(CompositeEthereumListener.class);
    genesis = mock(Genesis.class);
    messageRecorder = mock(MessageRecorder.class);
    statusResolver = mock(StatusResolver.class);
    messageQueue = mock(MessageQueue.class);
    channel = mock(Channel.class);
    target = new RskWireProtocol(config, peerScoringManager, messageHandler, compositeEthereumListener, genesis, messageRecorder, statusResolver, messageQueue, channel);
    EmbeddedChannel ch = new EmbeddedChannel();
    ch.pipeline().addLast(target);
    ctx = ch.pipeline().firstContext();
}
Also used : StatusResolver(co.rsk.net.StatusResolver) PeerScoringManager(co.rsk.scoring.PeerScoringManager) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) MessageHandler(co.rsk.net.MessageHandler) MessageQueue(org.ethereum.net.MessageQueue) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(org.ethereum.net.server.Channel) Genesis(org.ethereum.core.Genesis) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) RskSystemProperties(co.rsk.config.RskSystemProperties) Before(org.junit.Before)

Aggregations

CompositeEthereumListener (org.ethereum.listener.CompositeEthereumListener)9 HashMapDB (org.ethereum.datasource.HashMapDB)6 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)6 World (co.rsk.test.World)4 Blockchain (org.ethereum.core.Blockchain)4 Test (org.junit.Test)4 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)2 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 BlockExecutor (co.rsk.core.bc.BlockExecutor)2 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)2 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)2 TestCompositeEthereumListener (org.ethereum.listener.TestCompositeEthereumListener)2 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)2 Before (org.junit.Before)2 MiningConfig (co.rsk.config.MiningConfig)1 RskSystemProperties (co.rsk.config.RskSystemProperties)1 RskAddress (co.rsk.core.RskAddress)1 TestGenesisLoader (co.rsk.core.genesis.TestGenesisLoader)1 RepositoryLocator (co.rsk.db.RepositoryLocator)1 StateRootHandler (co.rsk.db.StateRootHandler)1