gt:             byte[] msgData = exec.getData();
context: /*
   * Copyright (c) [2016] [ <ether.camp> ]
   * This file is part of the ethereumJ library.
   *
   * The ethereumJ library is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * The ethereumJ library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
   */
  package org.ethereum.jsontestsuite.suite;
  
  import org.ethereum.config.CommonConfig;
  import org.ethereum.config.SystemProperties;
  import org.ethereum.core.Block;
  import org.ethereum.core.BlockchainImpl;
  import org.ethereum.core.ImportResult;
  import org.ethereum.core.PendingStateImpl;
  import org.ethereum.core.Repository;
  import org.ethereum.datasource.inmem.HashMapDB;
  import org.ethereum.db.*;
  import org.ethereum.jsontestsuite.suite.builder.BlockBuilder;
  import org.ethereum.jsontestsuite.suite.builder.RepositoryBuilder;
  import org.ethereum.jsontestsuite.suite.model.BlockTck;
  import org.ethereum.jsontestsuite.suite.validators.BlockHeaderValidator;
  import org.ethereum.jsontestsuite.suite.validators.RepositoryValidator;
  import org.ethereum.listener.EthereumListenerAdapter;
  import org.ethereum.util.ByteUtil;
  import org.ethereum.validator.DependentBlockHeaderRuleAdapter;
  import org.ethereum.vm.DataWord;
  import org.ethereum.vm.LogInfo;
  import org.ethereum.vm.VM;
  import org.ethereum.vm.program.Program;
  import org.ethereum.vm.program.invoke.ProgramInvoke;
  import org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl;
  import org.ethereum.vm.program.invoke.ProgramInvokeImpl;
  import org.ethereum.vm.trace.ProgramTrace;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.spongycastle.util.encoders.Hex;
  
  import java.math.BigInteger;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  import static org.ethereum.crypto.HashUtil.shortHash;
  import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY;
  import static org.ethereum.vm.VMUtils.saveProgramTraceFile;
  
  /**
   * @author Roman Mandeleil
   * @since 02.07.2014
   */
  public class TestRunner {
  
      private Logger logger = LoggerFactory.getLogger("TCK-Test");
      private ProgramTrace trace = null;
      private boolean setNewStateRoot;
      private String bestStateRoot;
  
      public List<String> runTestSuite(TestSuite testSuite) {
  
          Iterator<TestCase> testIterator = testSuite.iterator();
          List<String> resultCollector = new ArrayList<>();
  
          while (testIterator.hasNext()) {
  
              TestCase testCase = testIterator.next();
  
              TestRunner runner = new TestRunner();
              List<String> result = runner.runTestCase(testCase);
              resultCollector.addAll(result);
          }
  
          return resultCollector;
      }
  
  
      public List<String> runTestCase(BlockTestCase testCase) {
  
  
          /* 1 */ // Create genesis + init pre state
          Block genesis = BlockBuilder.build(testCase.getGenesisBlockHeader(), null, null);
          Repository repository = RepositoryBuilder.build(testCase.getPre());
  
          IndexedBlockStore blockStore = new IndexedBlockStore();
          blockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
          blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
  
          ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
  
          BlockchainImpl blockchain = new BlockchainImpl(blockStore, repository)
                  .withParentBlockHeaderValidator(CommonConfig.getDefault().parentHeaderValidator());
          blockchain.byTest = true;
  
          PendingStateImpl pendingState = new PendingStateImpl(new EthereumListenerAdapter());
  
          blockchain.setBestBlock(genesis);
          blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
          blockchain.setParentHeaderValidator(new CommonConfig().parentHeaderValidator());
          blockchain.setProgramInvokeFactory(programInvokeFactory);
  
          blockchain.setPendingState(pendingState);
          pendingState.setBlockchain(blockchain);
  
          /* 2 */ // Create block traffic list
          List<Block> blockTraffic = new ArrayList<>();
          for (BlockTck blockTck : testCase.getBlocks()) {
              Block block = BlockBuilder.build(blockTck.getBlockHeader(),
                      blockTck.getTransactions(),
                      blockTck.getUncleHeaders());
  
              setNewStateRoot = !((blockTck.getTransactions() == null)
                  && (blockTck.getUncleHeaders() == null)
                  && (blockTck.getBlockHeader() == null));
  
              Block tBlock = null;
              try {
                  byte[] rlp = Utils.parseData(blockTck.getRlp());
                  tBlock = new Block(rlp);
  
                  ArrayList<String> outputSummary =
                          BlockHeaderValidator.valid(tBlock.getHeader(), block.getHeader());
  
                  if (!outputSummary.isEmpty()){
                      for (String output : outputSummary)
                          logger.error("{}", output);
                  }
  
                  blockTraffic.add(tBlock);
              } catch (Exception e) {
                  System.out.println("*** Exception");
              }
          }
  
          /* 3 */ // Inject blocks to the blockchain execution
          for (Block block : blockTraffic) {
  
              ImportResult importResult = blockchain.tryToConnect(block);
              logger.debug("{} ~ {} difficulty: {} ::: {}", block.getShortHash(), shortHash(block.getParentHash()),
                      block.getCumulativeDifficulty(), importResult.toString());
          }
  
          repository = blockchain.getRepository();
  
          //Check state root matches last valid block
          List<String> results = new ArrayList<>();
          String currRoot = Hex.toHexString(repository.getRoot());
  
          byte[] bestHash = Hex.decode(testCase.getLastblockhash().startsWith("0x") ?
                  testCase.getLastblockhash().substring(2) : testCase.getLastblockhash());
          String finalRoot = Hex.toHexString(blockStore.getBlockByHash(bestHash).getStateRoot());
  
          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);
          results.addAll(repoResults);
  
          return results;
      }
  
  
      public List<String> runTestCase(TestCase testCase) {
  
          logger.info("\n***");
          logger.info(" Running test case: [" + testCase.getName() + "]");
          logger.info("***\n");
          List<String> results = new ArrayList<>();
  
  
          logger.info("--------- PRE ---------");
          IterableTestRepository testRepository = new IterableTestRepository(new RepositoryRoot(new HashMapDB<byte[]>()));
          testRepository.environmental = true;
          Repository repository = loadRepository(testRepository, testCase.getPre());
  
          try {
  
  
              /* 2. Create ProgramInvoke - Env/Exec */
              Env env = testCase.getEnv();
              Exec exec = testCase.getExec();
              Logs logs = testCase.getLogs();
  
              byte[] address = exec.getAddress();
              byte[] origin = exec.getOrigin();
              byte[] caller = exec.getCaller();
              byte[] balance = ByteUtil.bigIntegerToBytes(repository.getBalance(exec.getAddress()));
              byte[] gasPrice = exec.getGasPrice();
              byte[] gas = exec.getGas();
              byte[] callValue = exec.getValue();
  