content: package org.aion.zero.impl.blockchain;
  
  import static com.google.common.truth.Truth.assertThat;
  
  import java.math.BigInteger;
  import java.util.Arrays;
  import java.util.Collections;
  import org.aion.base.AionTransaction;
  import org.aion.base.AionTxReceipt;
  import org.aion.base.ConstantUtil;
  import org.aion.base.InternalVmType;
  import org.aion.base.TransactionTypes;
  import org.aion.base.TxUtil;
  import org.aion.base.db.Repository;
  import org.aion.crypto.ECKey;
  import org.aion.log.AionLoggerFactory;
  import org.aion.types.AionAddress;
  import org.aion.util.bytes.ByteUtil;
  import org.aion.util.types.AddressUtils;
  import org.aion.zero.impl.core.ImportResult;
  import org.aion.zero.impl.db.ContractInformation;
  import org.aion.zero.impl.types.AionBlockSummary;
  import org.aion.zero.impl.types.Block;
  import org.aion.zero.impl.types.BlockContext;
  import org.aion.zero.impl.types.MiningBlock;
  import org.aion.zero.impl.types.MiningBlockHeader;
  import org.aion.zero.impl.vm.AvmTestConfig;
  import org.apache.commons.lang3.tuple.Pair;
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  
  /**
   * Blockchain integration test is for used to ensuring that each functionality within the blockchain
   * operates correctly.
   */
  public class BlockchainIntegrationTest {
  
      public static byte[] TEST_COINBASE =
              ByteUtil.hexStringToBytes(
                      "CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3");
      public static byte[] TEST_EXTRADATA = "One ring to rule them all".getBytes();
      private long energyPrice = 10_000_000_000L;
  
      @Before
      public void setup() {
          // reduce default logging levels
          AionLoggerFactory.initAll();
  
          AvmTestConfig.supportOnlyAvmVersion1();
      }
  
      @After
      public void tearDown() {
          AvmTestConfig.clearConfigurations();
      }
  
      /**
       * Property test, simple test to verify that all variables are set correctly and no null
       * pointers occur.
       */
      @Test
      public void testSimpleBlockchainNullPointer() {
          /** Mock Setups */
          StandaloneBlockchain bc = (new StandaloneBlockchain.Builder()).build().bc;
  
          // after instantiation, check that the following elements are set correctly
          // note that this is pre-best block setting
          assertThat(bc.getBestBlock()).isNotEqualTo(null);
          assertThat(bc.getRepository()).isNotEqualTo(null);
          assertThat(bc.getTotalDifficulty()).isEqualTo(bc.getBestBlock().getTotalDifficulty());
          assertThat(bc.getTransactionStore()).isNotEqualTo(null);
          assertThat(bc.getMinerCoinbase()).isNotEqualTo(null);
      }
  
      // check that all accounts are loaded correctly
      @Test
      public void testSimpleBlockchainLoad() {
          StandaloneBlockchain.Bundle b =
                  (new StandaloneBlockchain.Builder()).withDefaultAccounts().build();
          for (ECKey k : b.privateKeys) {
              assertThat(b.bc.getRepository().getBalance(new AionAddress(k.getAddress())))
                      .isNotEqualTo(BigInteger.ZERO);
          }
          assertThat(b.privateKeys.size()).isEqualTo(10);
      }
  
      @Test
      public void testCreateNewEmptyBlock() {
          StandaloneBlockchain.Bundle bundle =
                  (new StandaloneBlockchain.Builder()).withDefaultAccounts().build();
          StandaloneBlockchain bc = bundle.bc;
          MiningBlock block = bc.createNewMiningBlock(bc.getBestBlock(), Collections.EMPTY_LIST, true);
          assertThat(block.getParentHash()).isEqualTo(bc.getGenesis().getHash());
      }
  
      @Test
      public void testSimpleFailedTransactionInsufficientBalance() {
          // generate a recipient
          final AionAddress receiverAddress =
                  AddressUtils.wrapAddress(
                          "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE");
  
          StandaloneBlockchain.Bundle bundle =
                  (new StandaloneBlockchain.Builder())
                          .withValidatorConfiguration("simple")
                          .withDefaultAccounts()
                          .build();
          StandaloneBlockchain bc = bundle.bc;
  
          // (byte[] nonce, byte[] from, byte[] to, byte[] value, byte[] data)
          ECKey key = bundle.privateKeys.get(0);
          AionTransaction tx =
                  AionTransaction.create(
                          key,
                          BigInteger.valueOf(1).toByteArray(),
                          receiverAddress,
                          BigInteger.valueOf(100).toByteArray(),
                          ByteUtil.EMPTY_BYTE_ARRAY,
                          1L,
                          energyPrice,
                          TransactionTypes.DEFAULT, null);
  
          MiningBlock block = bc.createNewMiningBlock(bc.getBestBlock(), Collections.singletonList(tx), true);
  
          assertThat(block.getTransactionsList()).isEmpty();
          assertThat(block.getTxTrieRoot()).isEqualTo(ConstantUtil.EMPTY_TRIE_HASH);
  
          ImportResult connection = bc.tryToConnect(block);
          assertThat(connection).isEqualTo(ImportResult.IMPORTED_BEST);
      }
  
      @Test
      public void testSimpleOneTokenBalanceTransfer() {
          // generate a recipient
          final AionAddress receiverAddress =
                  AddressUtils.wrapAddress(
                          "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE");
  
          StandaloneBlockchain.Bundle bundle =
                  (new StandaloneBlockchain.Builder())
                          .withValidatorConfiguration("simple")
                          .withDefaultAccounts()
                          .build();
          StandaloneBlockchain bc = bundle.bc;
  
          final ECKey sender = bundle.privateKeys.get(0);
          final BigInteger senderInitialBalance =
                  bc.getRepository().getBalance(new AionAddress(sender.getAddress()));
  
          AionTransaction tx =
                  AionTransaction.create(
                          sender,
                          BigInteger.valueOf(0).toByteArray(),
                          receiverAddress,
                          BigInteger.valueOf(100).toByteArray(),
                          ByteUtil.EMPTY_BYTE_ARRAY,
                          21000L,
                          energyPrice,
                          TransactionTypes.DEFAULT, null);
  
          MiningBlock block = bc.createNewMiningBlock(bc.getBestBlock(), Collections.singletonList(tx), true);
  
          assertThat(block.getTransactionsList().size()).isEqualTo(1);
          assertThat(block.getTransactionsList().get(0)).isEqualTo(tx);
  
          ImportResult connection = bc.tryToConnect(block);
          assertThat(connection).isEqualTo(ImportResult.IMPORTED_BEST);
  
          // to be sure, perform some DB tests
          Repository repo = bc.getRepository();
  
          assertThat(repo.getBalance(receiverAddress)).isEqualTo(BigInteger.valueOf(100));
          assertThat(repo.getBalance(new AionAddress(sender.getAddress())))
                  .isEqualTo(
                          senderInitialBalance
                                  .subtract(BigInteger.valueOf(21000).multiply(BigInteger.valueOf(energyPrice)))
                                  .subtract(BigInteger.valueOf(100)));
      }
  
      @Test
      public void testPruningEnabledBalanceTransfer() {
          // generate a recipient
          final AionAddress receiverAddress =
                  AddressUtils.wrapAddress(
                          "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE");
  
          // generate bc bundle with pruning enabled
          StandaloneBlockchain.Bundle bundle =
                  (new StandaloneBlockchain.Builder())
                          .withValidatorConfiguration("simple")
                          .withDefaultAccounts()
                          .build();
          StandaloneBlockchain bc = bundle.bc;
  
          // desginate the first account in our list of private keys as the sender
          // (each key in the bundle is preloaded with balance)
          final ECKey sender = bundle.privateKeys.get(0);
  
          // generate transaction that transfers 100 tokens from sender to receiver
          // pk[0] -> receiverAddress
          AionTransaction tx =
                  AionTransaction.create(
                          sender,
                          BigInteger.valueOf(0).toByteArray(),
                          receiverAddress,
                          BigInteger.valueOf(100).toByteArray(),
                          ByteUtil.EMPTY_BYTE_ARRAY,
                          21000L,
                          energyPrice,
                          TransactionTypes.DEFAULT, null);
  
          // create a new block containing a single transaction (tx)
          MiningBlock block = bc.createNewMiningBlock(bc.getBestBlock(), Collections.singletonList(tx), true);
  
          // import the block to our blockchain
          ImportResult connection = bc.tryToConnect(block);
          assertThat(connection).isEqualTo(ImportResult.IMPORTED_BEST);
  
          assertThat(bc.getRepository().getBalance(receiverAddress))
                  .isEqualTo(BigInteger.valueOf(100));
      }
  
      @Test
      public void testDeployCryptoKitties() {
          String cryptoKittiesCode =
                  "0x60506040526000600660006101000a81548160ff02191690831515021790555060e060405190810160405280603c63ffffffff1663ffffffff168152601001607863ffffffff1663ffffffff16815260100161012c63ffffffff1663ffffffff16815260100161025863ffffffff1663ffffffff16815260100161070863ffffffff1663ffffffff168152601001610e1063ffffffff1663ffffffff168152601001611c2063ffffffff1663ffffffff16815260100161384063ffffffff1663ffffffff16815260100161708063ffffffff1663ffffffff16815260100161e10063ffffffff1663ffffffff1681526010016201518063ffffffff1663ffffffff1681526010016202a30063ffffffff1663ffffffff1681526010016205460063ffffffff1663ffffffff16815260100162093a8063ffffffff1663ffffffff16815260100150600760005090600e6200015b92919062000673565b50600f600b60005090905566071afd498d000060176000509090553415620001835760006000fd5b5b6001600660006101000a81548160ff021916908315150217905550336000600050828290918060010183905555505050336004600050828290918060010183905555505050620002026000600060006fffffffffffffffffffffffffffffffff600060006200020a640100000000026200335e176401000000009004565b505b620008df565b60006000620002186200071f565b60008963ffffffff168a141515620002305760006000fd5b8863ffffffff1689141515620002465760006000fd5b8761ffff16881415156200025a5760006000fd5b6002888115156200026757fe5b049250600d8361ffff1611156200027f57600d925082505b6080604051908101604052808881526010014267ffffffffffffffff168152601001600067ffffffffffffffff1681526010018b63ffffffff1681526010018a63ffffffff168152601001600063ffffffff1681526010018461ffff1681526010018961ffff1681526010015091506001600c600050805480600101828162000309919062000795565b9190906000526010600020905090600191828204019190066010025b85909190915060008201518160000160005090905560108201518160010160006101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555060208201518160010160086101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555060308201518160020160006101000a81548163ffffffff021916908363ffffffff16021790555060408201518160020160046101000a81548163ffffffff021916908363ffffffff16021790555060508201518160020160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600201600c6101000a81548161ffff021916908361ffff160217905550607082015181600201600e6101000a81548161ffff021916908361ffff16021790555050500390508063ffffffff16811415156200046e5760006000fd5b7f355092523187d7f20a6cdccceeea14bc7c399e83c75232c899b1ab5753c1e8b5878784866030015163ffffffff16876040015163ffffffff16886000015160405180878782528160100152602001858152601001848152601001838152601001828152601001965050505050505060405180910390a16200050a60006000888885620005206401000000000262003a4a176401000000009004565b80935062000513565b5050509695505050505050565b600e6000506000848482528160100152602001908152601001600020905060008181505480929190600101919050909055508282600d600050600084815260100190815260100160002090506000508282909180600101839055555050506000600086869091149190141615156200061457600e60005060008686825281601001526020019081526010016000209050600081815054809291906001900391905090905550601060005060008281526010019081526010016000209050600050806000905560010160009055600f600050600082815260100190815260100160002090506000508060009055600101600090555b7f27772adc63db07aae765b71eb2b533064fa781bd57457e1b138592d8198d09598686868686604051808686825281601001526020018484825281601001526020018281526010019550505050505060405180910390a15b5050505050565b82600e90906003016004900481019282156200070c5791601002820160005b83821115620006d857835183826101000a81548163ffffffff021916908363ffffffff160217905550926010019260040160108160030104928301926001030262000692565b80156200070a5782816101000a81549063ffffffff0219169055600401601081600301049283019260010302620006d8565b505b5090506200071b9190620007cc565b5090565b60806040519081016040528060008152601001600067ffffffffffffffff168152601001600067ffffffffffffffff168152601001600063ffffffff168152601001600063ffffffff168152601001600063ffffffff168152601001600061ffff168152601001600061ffff1681526010015090565b815481835581811511620007c7576003028160030283600052601060002090509182019101620007c6919062000807565b5b505050565b620008049190620007d8565b808211156200080057600081816101000a81549063ffffffff021916905550600101620007d8565b5090565b90565b620008dc919062000813565b80821115620008d857600060008201600050600090556001820160006101000a81549067ffffffffffffffff02191690556001820160086101000a81549067ffffffffffffffff02191690556002820160006101000a81549063ffffffff02191690556002820160046101000a81549063ffffffff02191690556002820160086101000a81549063ffffffff021916905560028201600c6101000a81549061ffff021916905560028201600e6101000a81549061ffff02191690555060030162000813565b5090565b90565b61418680620008ef6000396000f300605060405236156102b1576000356c01000000000000000000000000900463ffffffff16806301ffc9a7146102f05780630519ce791461033b57806305e455461461036c57806306fdde03146103965780630a0f8168146104265780630e583df01461045757806314001f4c1461048157806318160ddd146104ad578063183a7947146104d757806319c2f2011461050157806321717ebf1461052b57806322d1d20b1461055c57806324e7a38a1461059457806325ae86da146105c057806327d7874c146105ff5780632ba73c151461062b578063399153aa146106575780633c3fce591461068c5780633cfb772a146106cb5780633f4ba83a146106ef578063421182b7146107055780634e0a3379146107295780635761e2e3146107555780635c975abb1461078a5780635fd8c710146107b85780636044a275146107ce578063680eba27146107ef5780636a1f17a2146108195780636af04a57146108985780636fbde40d146108c957806370a08231146108f557806371587988146109355780637a7d4937146109615780637b7814521461098b5780638456cb59146109d15780638462151c146109e757806391876e5714610a69578063951dc01014610a7f5780639530ab0e14610ac4578063958ec7d114610b0357806395d89b4114610b38578063960cf3ad14610bc8578063aee0237914610c7a578063b047fb5014610c9b578063b0c35c0514610ccc578063bc4006f514610cf6578063c477e0c014610d27578063cd3301d814610d4b578063d357fb2e14610d8f578063defb958414610dcb578063dfebeffa14610df5578063e17b25af14610e34578063e6cbe35114610e60578063eff2762e14610e91578063f1ca941014610ed0578063f2a3789a14610efa578063f2b47d5214610f39578063fb59730414610f6a578063fbb001d614610fa6576102b1565b5b6011600050806001015490543390911491901416806102e1575060136000508060010154905433909114919014165b15156102ed5760006000fd5b5b005b34156102fc5760006000fd5b61032160048080356bffffffffffffffffffffffff1916906010019091905050610fdb565b604051808215151515815260100191505060405180910390f35b34156103475760006000fd5b61034f6112c2565b604051808383825281601001526020019250505060405180910390f35b34156103785760006000fd5b6103806112d1565b6040518082815260100191505060405180910390f35b34156103a25760006000fd5b6103aa6112da565b6040518080601001828103825283818151815260100191508051906010019080838360005b838110156103eb5780820151818401525b6010810190506103cf565b50505050905090810190600f1680156104185780820380516001836010036101000a031916815260100191505b509250505060405180910390f35b34156104325760006000fd5b61043a611307565b604051808383825281601001526020019250505060405180910390f35b34156104635760006000fd5b61046b611316565b6040518082815260100191505060405180910390f35b341561048d5760006000fd5b6104ab60048080806010013590359091602001909192905050611321565b005b34156104b95760006000fd5b6104c16113d7565b6040518082815260100191505060405180910390f35b34156104e35760006000fd5b6104eb6113ef565b6040518082815260100191505060405180910390f35b341561050d5760006000fd5b6105156113f8565b6040518082815260100191505060405180910390f35b34156105375760006000fd5b61053f6113ff565b604051808383825281601001526020019250505060405180910390f35b34156105685760006000fd5b61057e600480803590601001909190505061140e565b6040518082815260100191505060405180910390f35b34156105a05760006000fd5b6105be60048080806010013590359091602001909192905050611821565b005b34156105cc5760006000fd5b6105e260048080359060100190919050506118d7565b604051808383825281601001526020019250505060405180910390f35b341561060b5760006000fd5b61062960048080806010013590359091602001909192905050611925565b005b34156106375760006000fd5b6106556004808080601001359035909160200190919290505061197b565b005b34156106635760006000fd5b61068a600480803590601001909190808060100135903590916020019091929050506119d1565b005b34156106985760006000fd5b6106c96004808035906010019091908035906010019091908035906010019091908035906010019091905050611a6f565b005b34156106d75760006000fd5b6106ed6004808035906010019091905050611b76565b005b34156106fb5760006000fd5b610703611ba7565b005b34156107115760006000fd5b6107276004808035906010019091905050611c85565b005b34156107355760006000fd5b61075360048080806010013590359091602001909192905050611dac565b005b34156107615760006000fd5b61078860048080806010013590359091602001909192908035906010019091905050611e02565b005b34156107965760006000fd5b61079e611e6e565b604051808215151515815260100191505060405180910390f35b34156107c45760006000fd5b6107cc611e81565b005b6107ed6004808035906010019091908035906010019091905050611ef9565b005b34156107fb5760006000fd5b610803612092565b6040518082815260100191505060405180910390f35b34156108255760006000fd5b61083b6004808035906010019091905050612098565b604051808b1515151581526010018a1515151581526010018981526010018881526010018781526010018681526010018581526010018481526010018381526010018281526010019a505050505050505050505060405180910390f35b34156108a45760006000fd5b6108ac612226565b604051808383825281601001526020019250505060405180910390f35b34156108d55760006000fd5b6108f360048080806010013590359091602001909192905050612235565b005b34156109015760006000fd5b61091f600480808060100135903590916020019091929050506122eb565b6040518082815260100191505060405180910390f35b34156109415760006000fd5b61095f6004808080601001359035909160200190919290505061231c565b005b341561096d5760006000fd5b6109756123b4565b6040518082815260100191505060405180910390f35b34156109975760006000fd5b6109cf6004808080601001359035909160200190919290808060100135903590916020019091929080359060100190919050506123bd565b005b34156109dd5760006000fd5b6109e5612460565b005b34156109f35760006000fd5b610a11600480808060100135903590916020019091929050506124f3565b6040518080601001828103825283818151815260100191508051906010019060100280838360005b83811015610a555780820151818401525b601081019050610a39565b505050509050019250505060405180910390f35b3415610a755760006000fd5b610a7d612621565b005b3415610a8b5760006000fd5b610aaa6004808035906010019091908035906010019091905050612735565b604051808215151515815260100191505060405180910390f35b3415610ad05760006000fd5b610b0160048080359060100190919080359060100190919080359060100190919080359060100190919050506127f2565b005b3415610b0f5760006000fd5b610b36600480808060100135903590916020019091929080359060100190919050506128f8565b005b3415610b445760006000fd5b610b4c61299f565b6040518080601001828103825283818151815260100191508051906010019080838360005b83811015610b8d5780820151818401525b601081019050610b71565b50505050905090810190600f168015610bba5780820380516001836010036101000a031916815260100191505b509250505060405180910390f35b3415610bd45760006000fd5b610bfe600480803590601001909190803590601001908201803590601001919091929050506129cc565b6040518080601001828103825283818151815260100191508051906010019080838360005b83811015610c3f5780820151818401525b601081019050610c23565b50505050905090810190600f168015610c6c5780820380516001836010036101000a031916815260100191505b509250505060405180910390f35b610c996004808035906010019091908035906010019091905050612ae7565b005b3415610ca75760006000fd5b610caf612e83565b604051808383825281601001526020019250505060405180910390f35b3415610cd85760006000fd5b610ce0612e92565b6040518082815260100191505060405180910390f35b3415610d025760006000fd5b610d0a612e9b565b604051808383825281601001526020019250505060405180910390f35b3415610d335760006000fd5b610d496004808035906010019091905050612eaa565b005b3415610d575760006000fd5b610d6d6004808035906010019091905050612f57565b604051808263ffffffff1663ffffffff16815260100191505060405180910390f35b3415610d9b5760006000fd5b610db16004808035906010019091905050612f8e565b604051808215151515815260100191505060405180910390f35b3415610dd75760006000fd5b610ddf61311f565b6040518082815260100191505060405180910390f35b3415610e015760006000fd5b610e176004808035906010019091905050613125565b604051808383825281601001526020019250505060405180910390f35b3415610e405760006000fd5b610e5e60048080806010013590359091602001909192905050613148565b005b3415610e6c5760006000fd5b610e74613180565b604051808383825281601001526020019250505060405180910390f35b3415610e9d5760006000fd5b610eb3600480803590601001909190505061318f565b604051808383825281601001526020019250505060405180910390f35b3415610edc5760006000fd5b610ee46131b2565b6040518082815260100191505060405180910390f35b3415610f065760006000fd5b610f1c60048080359060100190919050506131bb565b604051808383825281601001526020019250505060405180910390f35b3415610f455760006000fd5b610f4d6131de565b604051808383825281601001526020019250505060405180910390f35b3415610f765760006000fd5b610f8c60048080359060100190919050506131ed565b604051808215151515815260100191505060405180910390f35b3415610fb25760006000fd5b610fd960048080806010013590359091602001909192908035906010019091905050613256565b005b600060405180806f737570706f727473496e74657266616381526010016f652862797465733429000000000000008152601001506019019050604051809103902090506bffffffffffffffffffffffff1916826bffffffffffffffffffffffff191614806112b6575060405180806f746f6b656e4d6574616461746128756981526010016f6e743132382c737472696e6729000000815260100150601d0190506040518091039020905060405180806f746f6b656e734f664f776e657228616481526010016f6472657373290000000000000000000081526010015060160190506040518091039020905060405180806f7472616e7366657246726f6d2861646481526010016f726573732c616464726573732c75696e81526010016f7431323829000000000000000000000081526010015060250190506040518091039020905060405180806f7472616e73666572286164647265737381526010016f2c75696e74313238290000000000000081526010015060190190506040518091039020905060405180806f617070726f766528616464726573732c81526010016f75696e7431323829000000000000000081526010015060180190506040518091039020905060405180806f6f776e65724f662875696e743132382981526010015060100190506040518091039020905060405180806f62616c616e63654f662861646472657381526010016f7329000000000000000000000000000081526010015060120190506040518091039020905060405180806f746f74616c537570706c792829000000815260100150600d0190506040518091039020905060405180806f73796d626f6c2829000000000000000081526010015060080190506040518091039020905060405180806f6e616d652829000000000000000000008152601001506006019050604051809103902090501818181818181818186bffffffffffffffffffffffff1916826bffffffffffffffffffffffff1916145b90506112bd565b919050565b60026000508060010154905482565b601b6000505481565b602060405190810160405280600d81526010016f43727970746f4b69747469657300000081526010015081565b60006000508060010154905482565b662386f26fc1000081565b60006000600060005080600101549054339091149190141615156113455760006000fd5b83839150915081816376190f8f6000604051601001526040518163ffffffff166c010000000000000000000000000281526004016010604051808303816000888881813b15156113955760006000fd5b5af115156113a35760006000fd5b505050506040518051906010015015156113bd5760006000fd5b8181601360005082828255906001015550505b5b50505050565b60006001600c600050805490500390506113ec565b90565b60186000505481565b6201518081565b60136000508060010154905482565b600060006000600060006000600060006000600660009054906101000a900460ff1615151561143d5760006000fd5b600c6000508a81548110151561144f57fe5b906000526010600020905090600191828204019190066010025b50975060008860010160009054906101000a900467ffffffffffffffff1667ffffffffffffffff161415151561149f5760006000fd5b6115e08860806040519081016040529081600082016000505481526010016001820160009054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526010016001820160089054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526010016002820160009054906101000a900463ffffffff1663ffffffff1663ffffffff1681526010016002820160049054906101000a900463ffffffff1663ffffffff1663ffffffff1681526010016002820160089054906101000a900463ffffffff1663ffffffff1663ffffffff16815260100160028201600c9054906101000a900461ffff1661ffff1661ffff16815260100160028201600e9054906101000a900461ffff1661ffff1661ffff168152601001505061331d63ffffffff16565b15156115ec5760006000fd5b8760020160089054906101000a900463ffffffff1663ffffffff169650600c6000508781548110151561161b57fe5b906000526010600020905090600191828204019190066010025b50955087600201600e9054906101000a900461ffff16945087600201600e9054906101000a900461ffff1661ffff1686600201600e9054906101000a900461ffff1661ffff1611156116995785600201600e9054906101000a900461ffff16945084505b60196000508060010154905463614778d28a60000160005054896000016000505460018d60010160089054906101000a900467ffffffffffffffff16036000604051601001526040518463ffffffff166c01000000000000000000000000028152600401808481526010018381526010018267ffffffffffffffff16815260100193505050506010604051808303816000888881813b151561173b5760006000fd5b5af115156117495760006000fd5b50505050604051805190601001509350600d60005060008b8152601001908152601001600020905060005080600101549054925092506117b48a8960020160089054906101000a900463ffffffff1663ffffffff166001880161ffff1687878761335e63ffffffff16565b90508760020160086101000a81549063ffffffff02191690556018600081815054809291906001900391905090905550336108fc601760005054908115029060405160006040518083038185898989f194505050505050809850611813565b5b5050505050505050919050565b60006000600060005080600101549054339091149190141615156118455760006000fd5b83839150915081816354c15b826000604051601001526040518163ffffffff166c010000000000000000000000000281526004016010604051808303816000888881813b15156118955760006000fd5b5af115156118a35760006000fd5b505050506040518051906010015015156118bd5760006000fd5b8181601960005082828255906001015550505b5b50505050565b60006000600d600050600084815260100190815260100160002090506000508060010154905491509150818150506000600083839091149190141615151561191f5760006000fd5b5b915091565b600060005080600101549054339091149190141615156119455760006000fd5b6000600083839091149190141615151561195f5760006000fd5b818160006000508282909180600101839055555050505b5b5050565b6000600050806001015490543390911491901416151561199b5760006000fd5b600060008383909114919014161515156119b55760006000fd5b818160046000508282909180600101839055555050505b5b5050565b60006000600460005080600101549054339091149190141615156119f55760006000fd5b8383915091506000600083839091149190141615611a225760046000508060010154905491509150818150505b611388601b60005054101515611a385760006000fd5b601b6000818150548092919060010191905090905550611a6560006000600088868661335e63ffffffff16565b505b5b5050505050565b600660009054906101000a900460ff16151515611a8c5760006000fd5b611a9c338661365963ffffffff16565b1515611aa85760006000fd5b611ab7846131ed63ffffffff16565b151515611ac45760006000fd5b611adf8460116000508060010154905461369463ffffffff16565b601160005080600101549054631ea1c62a86868686336040518763ffffffff166c010000000000000000000000000281526004018087815260100186815260100185815260100184815260100183838252816010015260200196505050505050506000604051808303816000888881813b1515611b5c5760006000fd5b5af11515611b6a5760006000fd5b505050505b5b50505050565b60046000508060010154905433909114919014161515611b965760006000fd5b8060176000508190909055505b5b50565b60006000508060010154905433909114919014161515611bc75760006000fd5b600660009054906101000a900460ff161515611be35760006000fd5b6000600060116000508060010154905490911491901416151515611c075760006000fd5b6000600060136000508060010154905490911491901416151515611c2b5760006000fd5b6000600060196000508060010154905490911491901416151515611c4f5760006000fd5b60006000601d60005080600101549054909114919014161515611c725760006000fd5b611c806136c663ffffffff16565b5b5b5b565b600060046000508060010154905433909114919014161515611ca75760006000fd5b61afc8601c60005054101515611cbd5760006000fd5b611cd3600060006000853061335e63ffffffff16565b9050611cf08160116000508060010154905461369463ffffffff16565b601160005080600101549054631ea1c62a83611d1061372263ffffffff16565b600062015180306040518763ffffffff166c010000000000000000000000000281526004018087815260100186815260100185815260100184815260100183838252816010015260200196505050505050506000604051808303816000888881813b1515611d7e5760006000fd5b5af11515611d8c5760006000fd5b50505050601c60008181505480929190600101919050909055505b5b5050565b60006000508060010154905433909114919014161515611dcc5760006000fd5b60006000838390911491901416151515611de65760006000fd5b818160026000508282909180600101839055555050505b5b5050565b600660009054906101000a900460ff16151515611e1f5760006000fd5b611e2f338361365963ffffffff16565b1515611e3b5760006000fd5b82826010600050600084815260100190815260100160002090506000508282909180600101839055555050505b5b505050565b600660009054906101000a900460ff1681565b6000600060026000508060010154905433909114919014161515611ea55760006000fd5b3031915060176000505460016018600050540102905080821115611ef3576002600050806001015490546108fc838503908115029060405160006040518083038185898989f1945050505050505b5b5b5050565b6000600660009054906101000a900460ff16151515611f185760006000fd5b611f28338461365963ffffffff16565b1515611f345760006000fd5b611f4382612f8e63ffffffff16565b1515611f4f5760006000fd5b611f5f82846137e363ffffffff16565b1515611f6b5760006000fd5b601360005080600101549054632cdc0f94856000604051601001526040518263ffffffff166c01000000000000000000000000028152600401808281526010019150506010604051808303816000888881813b1515611fca5760006000fd5b5af11515611fd85760006000fd5b5050505060405180519060100150905060176000505481013410151515611fff5760006000fd5b60136000508060010154905463478350a26017600050543403866040518363ffffffff166c010000000000000000000000000281526004018082815260100191505060006040518083038185898981813b151561205c5760006000fd5b5af1151561206a5760006000fd5b505050505061208b8263ffffffff168463ffffffff1661386863ffffffff16565b5b5b505050565b61afc881565b60006000600060006000600060006000600060006000600c6000508c8154811015156120c057fe5b906000526010600020905090600191828204019190066010025b50905060008160020160089054906101000a900463ffffffff1663ffffffff1614159a508a50438160010160089054906101000a900467ffffffffffffffff1667ffffffffffffffff1611159950895080600201600c9054906101000a900461ffff1661ffff16985088508060010160089054906101000a900467ffffffffffffffff1667ffffffffffffffff16975087508060020160089054906101000a900463ffffffff1663ffffffff16965086508060010160009054906101000a900467ffffffffffffffff1667ffffffffffffffff16955085508060020160009054906101000a900463ffffffff1663ffffffff16945084508060020160049054906101000a900463ffffffff1663ffffffff169350835080600201600e9054906101000a900461ffff1661ffff16925082508060000160005054915081505b509193959799509193959799565b601d6000508060010154905482565b60006000600060005080600101549054339091149190141615156122595760006000fd5b83839150915081816385b861886000604051601001526040518163ffffffff166c010000000000000000000000000281526004016010604051808303816000888881813b15156122a95760006000fd5b5af115156122b75760006000fd5b505050506040518051906010015015156122d15760006000fd5b8181601160005082828255906001015550505b5b50505050565b6000600e60005060008484825281601001526020019081526010016000209050600050549050612316565b92915050565b6000600050806001015490543390911491901416151561233c5760006000fd5b600660009054906101000a900460ff1615156123585760006000fd5b8181601d6000508282909180600101839055555050507f450db8da6efbe9c22f2347f7c2021231df1fc58d3ae9a2fa75d39fa4461993058383604051808383825281601001526020019250505060405180910390a15b5b5b5050565b600b6000505481565b600660009054906101000a900460ff161515156123da5760006000fd5b600060008484909114919014161515156123f45760006000fd5b3084849091149190141615151561240b5760006000fd5b61241b3383613a0f63ffffffff16565b15156124275760006000fd5b61243885858361365963ffffffff16565b15156124445760006000fd5b6124578585858585613a4a63ffffffff16565b5b5b5050505050565b60046000508060010154905433909114919014168061248f575060006000508060010154905433909114919014165b806124aa575060026000508060010154905433909114919014165b15156124b65760006000fd5b600660009054906101000a900460ff161515156124d35760006000fd5b6001600660006101000a81548160ff0219169083151502179055505b5b5b565b6124fb613f79565b6000612505613f79565b60006000600061251b88886122eb63ffffffff16565b945060008514156125585760006040518059106125355750595b90808252806010026010018201604052801561254c575b50955061261656612615565b846040518059106125665750595b90808252806010026010018201604052801561257d575b50935061258e6113d763ffffffff16565b9250600091506001905080505b828111151561260d578787600d600050600084815260100190815260100160002090506000508060010154905490911491901416156125ff578084838151811015156125e357fe5b9060100190601002019090818152601001505081806001019250505b5b808060010191505061259b565b839550612616565b5b505050505092915050565b600460005080600101549054339091149190141680612650575060006000508060010154905433909114919014165b8061266b575060026000508060010154905433909114919014165b15156126775760006000fd5b601160005080600101549054635fd8c7106040518163ffffffff166c010000000000000000000000000281526004016000604051808303816000888881813b15156126c25760006000fd5b5af115156126d05760006000fd5b50505050601360005080600101549054635fd8c7106040518163ffffffff166c010000000000000000000000000281526004016000604051808303816000888881813b151561271f5760006000fd5b5af1151561272d5760006000fd5b505050505b5b565b60006000600060008511151561274b5760006000fd5b60008411151561275b5760006000fd5b600c6000508581548110151561276d57fe5b906000526010600020905090600191828204019190066010025b509150600c6000508481548110151561279c57fe5b906000526010600020905090600191828204019190066010025b5090506127cb82868387613b9c63ffffffff16565b80156127e357506127e28486613db563ffffffff16565b5b92506127ea565b505092915050565b600660009054906101000a900460ff1615151561280f5760006000fd5b61281f338661365963ffffffff16565b151561282b5760006000fd5b61283a84612f8e63ffffffff16565b15156128465760006000fd5b6128618460136000508060010154905461369463ffffffff16565b601360005080600101549054631ea1c62a86868686336040518763ffffffff166c010000000000000000000000000281526004018087815260100186815260100185815260100184815260100183838252816010015260200196505050505050506000604051808303816000888881813b15156128de5760006000fd5b5af115156128ec5760006000fd5b505050505b5b50505050565b600660009054906101000a900460ff161515156129155760006000fd5b612925338361365963ffffffff16565b15156129315760006000fd5b61294281848461369463ffffffff16565b7f444360fd9f99263247bc59eb6f6c9f5d7f1096ba7962aa22cb94c3f5b743eded33868686604051808686825281601001526020018484825281601001526020018281526010019550505050505060405180910390a15b5b505050565b602060405190810160405280600281526010016f434b000000000000000000000000000081526010015081565b6129d4613f90565b6129dc613fa7565b60006000600060156000508060010154905490911491901416151515612a025760006000fd5b60156000508060010154905463d46752918888886000604051609001526040518463ffffffff166c010000000000000000000000000281526004018084815260100180601001828103825284848281815260100192508082843782019150509450505050506090604051808303816000888881813b1515612a835760006000fd5b5af11515612a915760006000fd5b50505050604051806080018051906010016040528092508193505050602060405190810160405280600d81526010016f6e6f7420737570706f727465640000008152601001509250612ade565b50509392505050565b60006000600660009054906101000a900460ff16151515612b085760006000fd5b6017600050543410151515612b1d5760006000fd5b612b2d338661365963ffffffff16565b1515612b395760006000fd5b612b498385613db563ffffffff16565b1515612b555760006000fd5b600c60005084815481101515612b6757fe5b906000526010600020905090600191828204019190066010025b509150612cc58260806040519081016040529081600082016000505481526010016001820160009054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526010016001820160089054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526010016002820160009054906101000a900463ffffffff1663ffffffff1663ffffffff1681526010016002820160049054906101000a900463ffffffff1663ffffffff1663ffffffff1681526010016002820160089054906101000a900463ffffffff1663ffffffff1663ffffffff16815260100160028201600c9054906101000a900461ffff1661ffff1661ffff16815260100160028201600e9054906101000a900461ffff1661ffff1661ffff1681526010015050613e5963ffffffff16565b1515612cd15760006000fd5b600c60005083815481101515612ce357fe5b906000526010600020905090600191828204019190066010025b509050612e418160806040519081016040529081600082016000505481526010016001820160009054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526010016001820160089054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526010016002820160009054906101000a900463ffffffff1663ffffffff1663ffffffff1681526010016002820160049054906101000a900463ffffffff1663ffffffff1663ffffffff1681526010016002820160089054906101000a900463ffffffff1663ffffffff1663ffffffff16815260100160028201600c9054906101000a900461ffff1661ffff1661ffff16815260100160028201600e9054906101000a900461ffff1661ffff1661ffff1681526010015050613e5963ffffffff16565b1515612e4d5760006000fd5b612e5f82858386613b9c63ffffffff16565b1515612e6b5760006000fd5b612e7b848461386863ffffffff16565b5b5b50505050565b60046000508060010154905482565b60176000505481565b60156000508060010154905482565b600460005080600101549054339091149190141680612ed9575060006000508060010154905433909114919014165b80612ef4575060026000508060010154905433909114919014165b1515612f005760006000fd5b60076000506000600e81101515612f1357fe5b9090600491828204019190066004025b9054906101000a900463ffffffff1663ffffffff1681101515612f465760006000fd5b80600b6000508190909055505b5b50565b600760005081600e81101515612f6957fe5b9090600491828204019190066004025b9150909054906101000a900463ffffffff1681565b60006000600083111515612fa25760006000fd5b600c60005083815481101515612fb457fe5b906000526010600020905090600191828204019190066010025b5090506131128160806040519081016040529081600082016000505481526010016001820160009054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526010016001820160089054906101000a900467ffffffffffffffff1667ffffffffffffffff1667ffffffffffffffff1681526010016002820160009054906101000a900463ffffffff1663ffffffff1663ffffffff1681526010016002820160049054906101000a900463ffffffff1663ffffffff1663ffffffff1681526010016002820160089054906101000a900463ffffffff1663ffffffff1663ffffffff16815260100160028201600c9054906101000a900461ffff1661ffff1661ffff16815260100160028201600e9054906101000a900461ffff1661ffff1661ffff1681526010015050613e5963ffffffff16565b9150613119565b50919050565b61138881565b601060005060105280600052602060002090506000915090508060010154905482565b600060005080600101549054339091149190141615156131685760006000fd5b8181601560005082828255906001015550505b5b5050565b60116000508060010154905482565b600d60005060105280600052602060002090506000915090508060010154905482565b601c6000505481565b600f60005060105280600052602060002090506000915090508060010154905482565b60196000508060010154905482565b60006000821115156131ff5760006000fd5b6000600c6000508381548110151561321357fe5b906000526010600020905090600191828204019190066010025b5060020160089054906101000a900463ffffffff1663ffffffff1614159050613251565b919050565b600660009054906101000a900460ff161515156132735760006000fd5b6000600084849091149190141615151561328d5760006000fd5b308484909114919014161515156132a45760006000fd5b6011600050806001015490548484909114919014161515156132c65760006000fd5b6013600050806001015490548484909114919014161515156132e85760006000fd5b6132f8338361365963ffffffff16565b15156133045760006000fd5b61331633858585613a4a63ffffffff16565b5b5b505050565b60006000826050015163ffffffff161415801561335257504367ffffffffffffffff16826020015167ffffffffffffffff1611155b9050613359565b919050565b6000600061336a613fdc565b60008963ffffffff168a1415156133815760006000fd5b8863ffffffff16891415156133965760006000fd5b8761ffff16881415156133a95760006000fd5b6002888115156133b557fe5b049250600d8361ffff1611156133cc57600d925082505b6080604051908101604052808881526010014267ffffffffffffffff168152601001600067ffffffffffffffff1681526010018b63ffffffff1681526010018a63ffffffff168152601001600063ffffffff1681526010018461ffff1681526010018961ffff1681526010015091506001600c60005080548060010182816134549190614052565b9190906000526010600020905090600191828204019190066010025b85909190915060008201518160000160005090905560108201518160010160006101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555060208201518160010160086101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555060308201518160020160006101000a81548163ffffffff021916908363ffffffff16021790555060408201518160020160046101000a81548163ffffffff021916908363ffffffff16021790555060508201518160020160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600201600c6101000a81548161ffff021916908361ffff160217905550607082015181600201600e6101000a81548161ffff021916908361ffff16021790555050500390508063ffffffff16811415156135b85760006000fd5b7f355092523187d7f20a6cdccceeea14bc7c399e83c75232c899b1ab5753c1e8b5878784866030015163ffffffff16876040015163ffffffff16886000015160405180878782528160100152602001858152601001848152601001838152601001828152601001965050505050505060405180910390a161364460006000888885613a4a63ffffffff16565b80935061364c565b5050509695505050505050565b60008383600d600050600085815260100190815260100160002090506000508060010154905490911491901416905061368d565b9392505050565b8181600f600050600086815260100190815260100160002090506000508282909180600101839055555050505b505050565b600060005080600101549054339091149190141615156136e65760006000fd5b600660009054906101000a900460ff1615156137025760006000fd5b6000600660006101000a81548160ff0219169083151502179055505b5b5b565b60006000600060116000508060010154905463eac9d94c6000604051601001526040518163ffffffff166c010000000000000000000000000281526004016010604051808303816000888881813b151561377c5760006000fd5b5af1151561378a5760006000fd5b5050505060405180519060100150915081821415156137a95760006000fd5b6002828115156137b557fe5b0482019050662386f26fc100008110156137d657662386f26fc10000905080505b8092506137de565b505090565b600060006000600c600050858154811015156137fb57fe5b906000526010600020905090600191828204019190066010025b509150600c6000508481548110151561382a57fe5b906000526010600020905090600191828204019190066010025b50905061385982868387613b9c63ffffffff16565b9250613860565b505092915050565b60006000600c6000508381548110151561387e57fe5b906000526010600020905090600191828204019190066010025b509150600c600050848154811015156138ad57fe5b906000526010600020905090600191828204019190066010025b509050828160020160086101000a81548163ffffffff021916908363ffffffff1602179055506138fc82613e9963ffffffff16565b61390b81613e9963ffffffff16565b601060005060008581526010019081526010016000209050600050806000905560010160009055601060005060008481526010019081526010016000209050600050806000905560010160009055601860008181505480929190600101919050909055507fd7ecf8f5c809c3fff8976b62cd1c220e031c4645f79970544e6faec4b5d6a5e1600d600050600087815260100190815260100160002090506000508060010154905487878660010160089054906101000a900467ffffffffffffffff16604051808686825281601001526020018481526010018381526010018267ffffffffffffffff1681526010019550505050505060405180910390a15b50505050565b60008383600f6000506000858152601001908152601001600020905060005080600101549054909114919014169050613a43565b9392505050565b600e6000506000848482528160100152602001908152601001600020905060008181505480929190600101919050909055508282600d60005060008481526010019081526010016000209050600050828290918060010183905555505050600060008686909114919014161515613b3d57600e60005060008686825281601001526020019081526010016000209050600081815054809291906001900391905090905550601060005060008281526010019081526010016000209050600050806000905560010160009055600f600050600082815260100190815260100160002090506000508060009055600101600090555b7f27772adc63db07aae765b71eb2b533064fa781bd57457e1b138592d8198d09598686868686604051808686825281601001526020018484825281601001526020018281526010019550505050505060405180910390a15b5050505050565b600081841415613baf5760009050613dad565b818560020160009054906101000a900463ffffffff1663ffffffff161480613bf05750818560020160049054906101000a900463ffffffff1663ffffffff16145b15613bfe5760009050613dad565b838360020160009054906101000a900463ffffffff1663ffffffff161480613c3f5750838360020160049054906101000a900463ffffffff1663ffffffff16145b15613c4d5760009050613dad565b60008360020160009054906101000a900463ffffffff1663ffffffff161480613c90575060008560020160009054906101000a900463ffffffff1663ffffffff16145b15613c9e5760019050613dad565b8460020160009054906101000a900463ffffffff1663ffffffff168360020160009054906101000a900463ffffffff1663ffffffff161480613d1357508460020160049054906101000a900463ffffffff1663ffffffff168360020160009054906101000a900463ffffffff1663ffffffff16145b15613d215760009050613dad565b8460020160009054906101000a900463ffffffff1663ffffffff168360020160049054906101000a900463ffffffff1663ffffffff161480613d9657508460020160049054906101000a900463ffffffff1663ffffffff168360020160049054906101000a900463ffffffff1663ffffffff16145b15613da45760009050613dad565b60019050613dad565b949350505050565b60006000600060006000600d600050600087815260100190815260100160002090506000508060010154905493509350600d600050600088815260100190815260100160002090506000508060010154905491509150818185859091149190141680613e4857508383601060005060008a8152601001908152601001600020905060005080600101549054909114919014165b9450613e4f565b5050505092915050565b60006000826050015163ffffffff16148015613e8d57504367ffffffffffffffff16826020015167ffffffffffffffff1611155b9050613e94565b919050565b43600b60005054600760005083600201600c9054906101000a900461ffff1661ffff16600e81101515613ec857fe5b9090600491828204019190066004025b9054906101000a900463ffffffff1663ffffffff16811515613ef657fe5b04018160010160086101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550600d81600201600c9054906101000a900461ffff1661ffff161015613f7557600181600201600c8282829054906101000a900461ffff160192506101000a81548161ffff021916908361ffff1602179055505b5b50565b601060405190810160405280600081526010015090565b601060405190810160405280600081526010015090565b6080604051908101604052806004905b600060009060001916908252816010015260200190600190039081613fb75790505090565b60806040519081016040528060008152601001600067ffffffffffffffff168152601001600067ffffffffffffffff168152601001600063ffffffff168152601001600063ffffffff168152601001600063ffffffff168152601001600061ffff168152601001600061ffff1681526010015090565b8154818355818115116140815760030281600302836000526010600020905091820191016140809190614086565b5b505050565b6141579190614090565b8082111561415357600060008201600050600090556001820160006101000a81549067ffffffffffffffff02191690556001820160086101000a81549067ffffffffffffffff02191690556002820160006101000a81549063ffffffff02191690556002820160046101000a81549063ffffffff02191690556002820160086101000a81549063ffffffff021916905560028201600c6101000a81549061ffff021916905560028201600e6101000a81549061ffff021916905550600301614090565b5090565b905600a165627a7a723058205a41e86a51d82b3c7931ed02876f350497bda81536da3ef5301643203f2a362c0029";
  
          // generate bc bundle with pruning enabled
          StandaloneBlockchain.Bundle bundle =
                  (new StandaloneBlockchain.Builder())
                          .withValidatorConfiguration("simple")
                          .withDefaultAccounts()
                          .build();
          StandaloneBlockchain blockchain = bundle.bc;
  
          final ECKey sender = bundle.privateKeys.get(0);
  
          AionTransaction contractDeploymentTx =
                  AionTransaction.create(
                          sender,
                          BigInteger.ZERO.toByteArray(),
                          null,
                          BigInteger.ZERO.toByteArray(),
                          ByteUtil.hexStringToBytes(cryptoKittiesCode),
                          4699999L,
                          energyPrice,
                          TransactionTypes.DEFAULT, null);
  
          MiningBlock block =
                  blockchain.createNewMiningBlock(
                          blockchain.getGenesis(), Arrays.asList(contractDeploymentTx), true);
  
          Pair<ImportResult, AionBlockSummary> connectResult =
                  blockchain.tryToConnectAndFetchSummary(block);
          AionTxReceipt receipt = connectResult.getRight().getReceipts().get(0);
  
          assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
          assertThat(receipt.isSuccessful()).isTrue();
  
          // ensure the contract information was saved
          ContractInformation ci =
                  blockchain
                          .getRepository()
                          .getIndexedContractInformation(TxUtil.calculateContractAddress(contractDeploymentTx));
          assertThat(ci).isNotNull();
          byte[] codeHash =
                  blockchain
                          .getRepository()
                          .getAccountState(TxUtil.calculateContractAddress(contractDeploymentTx))
                          .getCodeHash();
          assertThat(ci.getInceptionBlocks(codeHash)).contains(block.getHashWrapper());
          assertThat(ci.getVmUsed(codeHash)).isEqualTo(InternalVmType.FVM);
          assertThat(ci.isComplete(codeHash, block.getHash())).isEqualTo(true);
      }
  
      /**
       * This is a special case for testing that the blockchain stores disconnected blocks if we
       * violate the contract of changing the block contents after importing best
       *
       * <p>This behaviour was originally observed when running a pooled miner
       */
      @Test
      public void testDisconnection() {
          StandaloneBlockchain.Bundle bundle =
                  (new StandaloneBlockchain.Builder())
                          .withValidatorConfiguration("simple")
                          .withDefaultAccounts()
                          .build();
          StandaloneBlockchain bc = bundle.bc;
  
          // store this as the best block,
          MiningBlock block = bundle.bc.createNewMiningBlock(bc.getGenesis(), Collections.emptyList(), true);
          byte[] block1Hash = block.getHash();
  
          // now modify this block to have a different value after connecting
          ImportResult result = bundle.bc.tryToConnect(block);
          assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
  
          // now modify the block in some way
          MiningBlockHeader newBlockHeader =
              MiningBlockHeader.Builder.newInstance()
                  .withHeader(block.getHeader())
                  .withExtraData("other block".getBytes())
                  .build();
          block.updateHeader(newBlockHeader);
  
          // now try submitting the block again
          result = bundle.bc.tryToConnect(block);
          assertThat(result).isEqualTo(ImportResult.IMPORTED_NOT_BEST);
  
          // now try creating a new block
          MiningBlock newBlock =
                  bundle.bc.createNewMiningBlock(bundle.bc.getBestBlock(), Collections.emptyList(), true);
  
          // gets the first main-chain block
          Block storedBlock1 = bundle.bc.getBlockByNumber(1L);
          System.out.println(ByteUtil.toHexString(storedBlock1.getHash()));
          System.out.println(ByteUtil.toHexString(newBlock.getParentHash()));
  
          assertThat(newBlock.getParentHash()).isNotEqualTo(storedBlock1.getHash());
          assertThat(newBlock.getParentHash()).isEqualTo(block.getHash());
      }
  
      @Test
      public void testBlockContextCreation() {
          StandaloneBlockchain.Bundle bundle =
                  (new StandaloneBlockchain.Builder())
                          .withValidatorConfiguration("simple")
                          .withDefaultAccounts()
                          .build();
          StandaloneBlockchain bc = bundle.bc;
  
          BlockContext context =
                  bc.createNewMiningBlockContext(bc.getBestBlock(), Collections.emptyList(), false);
  
          ChainConfiguration configuration = new ChainConfiguration();
  
          // check some basic fields match first
          assertThat(context.block).isNotNull();
          assertThat(context.baseBlockReward).isNotNull();
          assertThat(context.transactionFee).isNotNull();
  
          // no transaction so fee should be zero
          assertThat(context.transactionFee).isEqualTo(BigInteger.ZERO);
          AionAddress beneficiary = context.block.getCoinbase();
  
          ImportResult result = bc.tryToConnect(context.block);
          // check that the correct amount was stored
          assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
          assertThat(bc.getRepository().getBalance(beneficiary)).isEqualTo(context.baseBlockReward);
  
          // check that the correct amount was calculated
          assertThat(configuration
              .getRewardsCalculatorBeforeSignatureSchemeSwap(false)
              .calculateReward(context.block.getHeader().getNumber()))
              .isEqualTo(context.baseBlockReward);
      }
  }
  