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;
}
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();
}
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)));
}
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)));
}
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();
}
Aggregations