<commit_before>package com.wavesplatform.state2

import com.wavesplatform.settings.{BlockchainSettings, FunctionalitySettings, GenesisSettings}
import org.h2.mvstore.MVStore
import org.scalatest.{FreeSpec, Matchers}
import scorex.account.{Account, AddressScheme}
import scorex.block.Block
import scorex.consensus.nxt.{NxtLikeConsensusBlockData, WavesConsensusModule}
import scorex.transaction._
import scorex.transaction.assets.IssueTransaction
import scorex.transaction.state.database.BlockStorageImpl
import scorex.transaction.state.database.blockchain.{StoredBlockchain, StoredState}
import scorex.transaction.state.database.state.storage._

class StateResponseComparisonTests extends FreeSpec with Matchers {

  import StateResponseComparisonTests._

  AddressScheme.current = new AddressScheme {
    override val chainId: Byte = 'W'
  }

  val BlocksOnDisk = "C:\\Users\\ilyas\\.babun\\cygwin\\home\\ilyas\\waves\\data\\blockchain.dat"


  "provide the same answers to questions after each block from mainnet applied" - {
    val oldStore = BlockStorageImpl.createMVStore("")
    val old = storedBC(oldState(oldStore), new StoredBlockchain(oldStore))

    val newStore = BlockStorageImpl.createMVStore("")
    val nev = storedBC(newState(newStore), new StoredBlockchain(newStore))

    val currentMainnetStore = BlockStorageImpl.createMVStore(BlocksOnDisk)
    val currentMainnet = storedBC(oldState(currentMainnetStore), new StoredBlockchain(currentMainnetStore))

    val CHECK_FROM = 70
    val CHECK_TO = 300

    // 0 doesn't exist, 1 is genesis
    val end = currentMainnet.history.height() + 1
    Range(1, CHECK_TO).foreach { blockNumber =>
      s"[$blockNumber]" - {
        def block = currentMainnet.history.blockAt(blockNumber).get

        "Block appended successfully" in {
          val oldTime = withTime(old.appendBlock(block).get)._1
          val newTime = withTime(nev.appendBlock(block).get)._1
        }
        if (blockNumber >= CHECK_FROM) {
          // should I do this with more ids, like with final state too, to assert negatives too?
          s"findTransaction" in {
            assert(block.transactionData.forall(tx => nev.state.findTransaction[Transaction](tx.id).contains(tx)))
          }
          s"included" in {
            assert(block.transactionData.forall(tx => nev.state.included(tx.id).contains(nev.state.stateHeight)))
          }

          def aliveAccounts = old.state.wavesDistributionAtHeight(old.state.stateHeight)
            .map(_._1)
            .map(Account.fromString(_).right.get)

          s"accountTransactions" in {
            for (acc <- aliveAccounts) {
              val oldtxs = old.state.accountTransactions(acc, Int.MaxValue).toList<commit_msg>T442: Too long StateComparisonTest trimmed<commit_after>package com.wavesplatform.state2

import com.wavesplatform.settings.{BlockchainSettings, FunctionalitySettings, GenesisSettings}
import org.h2.mvstore.MVStore
import org.scalatest.{FreeSpec, Matchers}
import scorex.account.{Account, AddressScheme}
import scorex.block.Block
import scorex.consensus.nxt.{NxtLikeConsensusBlockData, WavesConsensusModule}
import scorex.transaction._
import scorex.transaction.assets.IssueTransaction
import scorex.transaction.state.database.BlockStorageImpl
import scorex.transaction.state.database.blockchain.{StoredBlockchain, StoredState}
import scorex.transaction.state.database.state.storage._

class StateResponseComparisonTests extends FreeSpec with Matchers {

  import StateResponseComparisonTests._

  AddressScheme.current = new AddressScheme {
    override val chainId: Byte = 'W'
  }

  val BlocksOnDisk = "C:\\Users\\ilyas\\.babun\\cygwin\\home\\ilyas\\waves\\data\\blockchain.dat"


  "provide the same answers to questions after each block from mainnet applied" - {
    val oldStore = BlockStorageImpl.createMVStore("")
    val old = storedBC(oldState(oldStore), new StoredBlockchain(oldStore))

    val newStore = BlockStorageImpl.createMVStore("")
    val nev = storedBC(newState(newStore), new StoredBlockchain(newStore))

    val currentMainnetStore = BlockStorageImpl.createMVStore(BlocksOnDisk)
    val currentMainnet = storedBC(oldState(currentMainnetStore), new StoredBlockchain(currentMainnetStore))

    val CHECK_FROM = 70
    val CHECK_TO = 80

    // 0 doesn't exist, 1 is genesis
    val end = currentMainnet.history.height() + 1
    Range(1, CHECK_TO).foreach { blockNumber =>
      s"[$blockNumber]" - {
        def block = currentMainnet.history.blockAt(blockNumber).get

        "Block appended successfully" in {
          val oldTime = withTime(old.appendBlock(block).get)._1
          val newTime = withTime(nev.appendBlock(block).get)._1
        }
        if (blockNumber >= CHECK_FROM) {
          // should I do this with more ids, like with final state too, to assert negatives too?
          s"findTransaction" in {
            assert(block.transactionData.forall(tx => nev.state.findTransaction[Transaction](tx.id).contains(tx)))
          }
          s"included" in {
            assert(block.transactionData.forall(tx => nev.state.included(tx.id).contains(nev.state.stateHeight)))
          }

          def aliveAccounts = old.state.wavesDistributionAtHeight(old.state.stateHeight)
            .map(_._1)
            .map(Account.fromString(_).right.get)

          s"accountTransactions" in {
            for (acc <- aliveAccounts) {
              val oldtxs = old.state.accountTransactions(acc, Int.MaxValue).toList
{'fraction_non_alphanumeric': 0.10073126142595978, 'fraction_numerical': 0.005484460694698354, 'mean_word_length': 3.672075149444919, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3753125', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1544, 'n_words': 321}