use of org.ethereum.jsontestsuite.validators.ValidationStats in project rskj by rsksmart.
the class StateTestRunner method runImpl.
public List<String> runImpl() {
vStats = new ValidationStats();
logger.info("");
trieStore = new TrieStoreImpl(new HashMapDB());
repository = RepositoryBuilder.build(trieStore, stateTestCase.getPre());
logger.info("loaded repository");
transaction = TransactionBuilder.build(stateTestCase.getTransaction());
logger.info("transaction: {}", transaction.toString());
BlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
blockchain = new BlockChainImpl(blockStore, null, null, null, null, new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, blockFactory, new ProgramInvokeFactoryImpl(), precompiledContracts, new BlockTxSignatureCache(new ReceivedTxSignatureCache()))), stateRootHandler);
env = EnvBuilder.build(stateTestCase.getEnv());
invokeFactory = new TestProgramInvokeFactory(env);
block = build(env);
block.setStateRoot(repository.getRoot());
block.flushRLP();
blockchain.setStatus(block, block.getCumulativeDifficulty());
// blockchain.setProgramInvokeFactory(invokeFactory);
// blockchain.startTracking();
ProgramResult programResult = executeTransaction(transaction);
trieStore.flush();
List<LogInfo> origLogs = programResult.getLogInfoList();
List<LogInfo> postLogs = LogBuilder.build(stateTestCase.getLogs());
List<String> logsResult = LogsValidator.valid(origLogs, postLogs, vStats);
Repository postRepository = RepositoryBuilder.build(stateTestCase.getPost());
// Balances cannot be validated because has consumption for CALLs differ.
List<String> repoResults = RepositoryValidator.valid(repository, postRepository, false, false, vStats);
logger.info("--------- POST Validation---------");
List<String> outputResults = OutputValidator.valid(ByteUtil.toHexString(programResult.getHReturn()), stateTestCase.getOut(), vStats);
List<String> results = new ArrayList<>();
results.addAll(repoResults);
results.addAll(logsResult);
results.addAll(outputResults);
for (String result : results) {
logger.error(result);
}
if ((vStats.storageChecks == 0) && (vStats.logChecks == 0) && (vStats.balancetChecks == 0) && (vStats.outputChecks == 0) && (vStats.blockChecks == 0)) {
// This generally mean that the test didn't check anything
// AccountChecks are considered not indicative of the result of the test
logger.info("IRRELEVANT\n");
}
logger.info("\n\n");
return results;
}
use of org.ethereum.jsontestsuite.validators.ValidationStats 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;
}
Aggregations