From f2fd9d96c040513baabe659867caba249be6f0a8 Mon Sep 17 00:00:00 2001 From: Artyom Sayadyan Date: Wed, 16 Nov 2022 16:49:59 +0300 Subject: [PATCH] Correctly calculate hit source in tests (#3771) --- .../events/BlockchainUpdatesSpec.scala | 4 +- .../api/common/CommonAccountApiSpec.scala | 98 ++++++++----------- ...ockchainUpdaterSponsoredFeeBlockTest.scala | 45 ++++----- .../com/wavesplatform/history/Domain.scala | 34 +++++-- .../wavesplatform/mining/BlockV5Test.scala | 31 ++---- .../state/BlockchainUpdaterImplSpec.scala | 9 +- .../wavesplatform/state/RollbackSpec.scala | 38 ++++--- .../diffs/AssetTransactionsDiffTest.scala | 19 +--- .../transaction/BlockchainUpdaterTest.scala | 30 ++++-- 9 files changed, 141 insertions(+), 167 deletions(-) diff --git a/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala b/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala index 7ef8910792f..35d087f2882 100644 --- a/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala +++ b/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala @@ -212,9 +212,7 @@ class BlockchainUpdatesSpec extends FreeSpec with WithBUDomain with ScalaFutures } } - "should survive invalid rollback" in withDomainAndRepo( - SettingsFromDefaultConfig.copy(dbSettings = SettingsFromDefaultConfig.dbSettings.copy(maxRollbackDepth = 0)) - ) { (d, repo) => + "should survive invalid rollback" in withDomainAndRepo(RideV6.copy(dbSettings = dbSettings.copy(maxRollbackDepth = 0))) { (d, repo) => for (_ <- 1 to 10) d.appendBlock() intercept[RuntimeException](d.rollbackTo(1)) // Should fail d.appendBlock() diff --git a/node/src/test/scala/com/wavesplatform/api/common/CommonAccountApiSpec.scala b/node/src/test/scala/com/wavesplatform/api/common/CommonAccountApiSpec.scala index 21cf0c3ec86..0b4ac1df431 100644 --- a/node/src/test/scala/com/wavesplatform/api/common/CommonAccountApiSpec.scala +++ b/node/src/test/scala/com/wavesplatform/api/common/CommonAccountApiSpec.scala @@ -1,7 +1,7 @@ package com.wavesplatform.api.common import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.common.utils._ +import com.wavesplatform.common.utils.* import com.wavesplatform.db.WithDomain import com.wavesplatform.db.WithState.AddrWithBalance import com.wavesplatform.features.BlockchainFeatures @@ -10,7 +10,10 @@ import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.lang.v1.traits.domain.{Lease, Recipient} import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.{DataEntry, Diff, EmptyDataEntry, StringDataEntry, diffs} +import com.wavesplatform.test.DomainPresets.RideV4 import com.wavesplatform.test.FreeSpec +import com.wavesplatform.transaction.TxHelpers.data +import com.wavesplatform.transaction.TxVersion.V2 import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, TxHelpers} import com.wavesplatform.{BlocksTransactionsHelpers, history} import monix.execution.Scheduler.Implicits.global @@ -23,47 +26,29 @@ class CommonAccountApiSpec extends FreeSpec with WithDomain with BlocksTransacti val entry2 = StringDataEntry("test1", "test") val entry3 = StringDataEntry("test2", "test") - val preconditions = for { - acc <- accountGen - ts = System.currentTimeMillis() - fee <- smallFeeGen - genesis = GenesisTransaction.create(acc.toAddress, diffs.ENOUGH_AMT, ts).explicitGet() - data1 = DataTransaction.selfSigned(1.toByte, acc, Seq(entry1), fee, ts).explicitGet() - data2 = DataTransaction.selfSigned(1.toByte, acc, Seq(entry2), fee, ts).explicitGet() - data3 = DataTransaction.selfSigned(1.toByte, acc, Seq(entry3), fee, ts).explicitGet() - data4 = DataTransaction.selfSigned(2.toByte, acc, Seq(EmptyDataEntry("test"), EmptyDataEntry("test1")), fee, ts).explicitGet() - data5 = DataTransaction.selfSigned(2.toByte, acc, Seq(EmptyDataEntry("test2"), entry1, entry2), fee, ts).explicitGet() - (block1, mbs1) = UnsafeBlocks.unsafeChainBaseAndMicro(history.randomSig, Seq(genesis), Seq(Seq(data1)), acc, 3, ts) - (block2, mbs2) = UnsafeBlocks.unsafeChainBaseAndMicro(mbs1.last.totalResBlockSig, Seq(data2), Seq(Seq(data3)), acc, 3, ts) - (block3, mbs3) = UnsafeBlocks.unsafeChainBaseAndMicro(mbs2.last.totalResBlockSig, Seq(data4), Seq(Seq(data5)), acc, 3, ts) - } yield (acc, block1, mbs1.head, block2, mbs2.head, block3, mbs3.head) - - forAll(preconditions) { - case (acc, block1, mb1, block2, mb2, block3, mb3) => - withDomain( - domainSettingsWithFS( - TestFunctionalitySettings.withFeatures( - BlockchainFeatures.NG, - BlockchainFeatures.DataTransaction, - BlockchainFeatures.BlockV5 - ) - ) - ) { d => - val commonAccountsApi = CommonAccountsApi(() => d.blockchainUpdater.bestLiquidDiff.getOrElse(Diff.empty), d.db, d.blockchainUpdater) - def dataList(): Set[DataEntry[_]] = commonAccountsApi.dataStream(acc.toAddress, None).toListL.runSyncUnsafe().toSet - - d.appendBlock(block1) - d.appendMicroBlock(mb1) - dataList() shouldBe Set(entry1) - d.appendBlock(block2) - dataList() shouldBe Set(entry1, entry2) - d.appendMicroBlock(mb2) - dataList() shouldBe Set(entry1, entry2, entry3) - d.appendBlock(block3) - dataList() shouldBe Set(entry3) - d.appendMicroBlock(mb3) - dataList() shouldBe Set(entry1, entry2) - } + val acc = accountGen.sample.get + val genesis = TxHelpers.genesis(acc.toAddress) + val data1 = data(acc, Seq(entry1)) + val data2 = data(acc, Seq(entry2)) + val data3 = data(acc, Seq(entry3)) + val data4 = data(acc, Seq(EmptyDataEntry("test"), EmptyDataEntry("test1")), version = V2) + val data5 = data(acc, Seq(EmptyDataEntry("test2"), entry1, entry2), version = V2) + + withDomain(RideV4) { d => + val commonAccountsApi = CommonAccountsApi(() => d.blockchainUpdater.bestLiquidDiff.getOrElse(Diff.empty), d.db, d.blockchainUpdater) + def dataList(): Set[DataEntry[_]] = commonAccountsApi.dataStream(acc.toAddress, None).toListL.runSyncUnsafe().toSet + + d.appendBlock(genesis) + d.appendMicroBlock(data1) + dataList() shouldBe Set(entry1) + d.appendBlock(data2) + dataList() shouldBe Set(entry1, entry2) + d.appendMicroBlock(data3) + dataList() shouldBe Set(entry1, entry2, entry3) + d.appendBlock(data4) + dataList() shouldBe Set(entry3) + d.appendMicroBlock(data5) + dataList() shouldBe Set(entry1, entry2) } } @@ -84,21 +69,20 @@ class CommonAccountApiSpec extends FreeSpec with WithDomain with BlocksTransacti (block2, mbs2) = UnsafeBlocks.unsafeChainBaseAndMicro(mbs1.last.totalResBlockSig, Seq(data2), Seq(Seq(data3)), acc, 3, ts) } yield (acc, block1, mbs1.head, block2, mbs2.head) - forAll(preconditions) { - case (acc, block1, mb1, block2, mb2) => - withDomain(domainSettingsWithFS(TestFunctionalitySettings.withFeatures(BlockchainFeatures.NG, BlockchainFeatures.DataTransaction))) { d => - val commonAccountsApi = CommonAccountsApi(() => d.blockchainUpdater.bestLiquidDiff.getOrElse(Diff.empty), d.db, d.blockchainUpdater) - def dataList(): Set[DataEntry[_]] = commonAccountsApi.dataStream(acc.toAddress, Some("test_.*")).toListL.runSyncUnsafe().toSet - - d.appendBlock(block1) - dataList() shouldBe empty - d.appendMicroBlock(mb1) - dataList() shouldBe Set(entry1) - d.appendBlock(block2) - dataList() shouldBe Set(entry1) - d.appendMicroBlock(mb2) - dataList() shouldBe Set(entry1, entry3) - } + forAll(preconditions) { case (acc, block1, mb1, block2, mb2) => + withDomain(domainSettingsWithFS(TestFunctionalitySettings.withFeatures(BlockchainFeatures.NG, BlockchainFeatures.DataTransaction))) { d => + val commonAccountsApi = CommonAccountsApi(() => d.blockchainUpdater.bestLiquidDiff.getOrElse(Diff.empty), d.db, d.blockchainUpdater) + def dataList(): Set[DataEntry[_]] = commonAccountsApi.dataStream(acc.toAddress, Some("test_.*")).toListL.runSyncUnsafe().toSet + + d.appendBlock(block1) + dataList() shouldBe empty + d.appendMicroBlock(mb1) + dataList() shouldBe Set(entry1) + d.appendBlock(block2) + dataList() shouldBe Set(entry1) + d.appendMicroBlock(mb2) + dataList() shouldBe Set(entry1, entry3) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala index fba6d82daf6..5f2a716f8cf 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala @@ -1,22 +1,22 @@ package com.wavesplatform.history -import com.wavesplatform.account.KeyPair import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 -import com.wavesplatform.crypto._ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.settings.{BlockchainSettings, WavesSettings} -import com.wavesplatform.state._ -import com.wavesplatform.state.diffs._ -import com.wavesplatform.test._ +import com.wavesplatform.state.* +import com.wavesplatform.state.diffs.* +import com.wavesplatform.test.* import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.assets.{IssueTransaction, SponsorFeeTransaction} -import com.wavesplatform.transaction.transfer._ +import com.wavesplatform.transaction.transfer.* import com.wavesplatform.transaction.{Asset, GenesisTransaction} import org.scalacheck.Gen class BlockchainUpdaterSponsoredFeeBlockTest extends PropSpec with DomainScenarioDrivenPropertyCheck { + private val time = new TestTime + private def ts = time.getTimestamp() private val amtTx = 100000 @@ -26,7 +26,6 @@ class BlockchainUpdaterSponsoredFeeBlockTest extends PropSpec with DomainScenari val sponsorPreconditions: Gen[Setup] = for { master <- accountGen - ts <- timestampGen transferAssetWavesFee <- smallFeeGen _ <- accountGen alice <- accountGen @@ -90,33 +89,29 @@ class BlockchainUpdaterSponsoredFeeBlockTest extends PropSpec with DomainScenari val SponsoredFeeActivatedAt0BlockchainSettings: BlockchainSettings = DefaultBlockchainSettings.copy( functionalitySettings = DefaultBlockchainSettings.functionalitySettings - .copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = Map( + .copy( + featureCheckBlocksPeriod = 1, + blocksForFeatureActivation = 1, + preActivatedFeatures = Map( BlockchainFeatures.FeeSponsorship.id -> 0, BlockchainFeatures.NG.id -> 0, BlockchainFeatures.BlockV5.id -> 0 - )) + ) + ) ) val SponsoredActivatedAt0WavesSettings: WavesSettings = settings.copy(blockchainSettings = SponsoredFeeActivatedAt0BlockchainSettings) property("not enough waves to sponsor sponsored tx") { scenario(sponsorPreconditions, SponsoredActivatedAt0WavesSettings) { - case (domain, (genesis, masterToAlice, feeAsset, sponsor, aliceToBob, bobToMaster, bobToMaster2)) => - val (block0, microBlocks) = chainBaseAndMicro(randomSig, genesis, Seq(masterToAlice, feeAsset, sponsor).map(Seq(_))) - val block1 = - customBuildBlockOfTxs(microBlocks.last.totalResBlockSig, Seq.empty, KeyPair(Array.fill(KeyLength)(1: Byte)), 3: Byte, sponsor.timestamp + 1) - val block2 = customBuildBlockOfTxs(block1.id(), Seq.empty, KeyPair(Array.fill(KeyLength)(1: Byte)), 3: Byte, sponsor.timestamp + 1) - val block3 = buildBlockOfTxs(block2.id(), Seq(aliceToBob, bobToMaster)) - val block4 = buildBlockOfTxs(block3.id(), Seq(bobToMaster2)) - - domain.blockchainUpdater.processBlock(block0) should beRight - domain.blockchainUpdater.processMicroBlock(microBlocks(0)) should beRight - domain.blockchainUpdater.processMicroBlock(microBlocks(1)) should beRight - domain.blockchainUpdater.processMicroBlock(microBlocks(2)) should beRight - domain.blockchainUpdater.processBlock(block1) should beRight - domain.blockchainUpdater.processBlock(block2) should beRight - domain.blockchainUpdater.processBlock(block3) should beRight - domain.blockchainUpdater.processBlock(block4) should produce("negative waves balance" /*"unavailable funds"*/ ) + case (d, (genesis, masterToAlice, feeAsset, sponsor, aliceToBob, bobToMaster, bobToMaster2)) => + d.appendBlock(genesis) + d.appendBlock() + d.appendMicroBlock(masterToAlice) + d.appendMicroBlock(feeAsset) + d.appendMicroBlock(sponsor) + d.appendBlock(aliceToBob, bobToMaster) + d.appendBlockE(bobToMaster2) should produce("negative waves balance" /*"unavailable funds"*/ ) } } diff --git a/node/src/test/scala/com/wavesplatform/history/Domain.scala b/node/src/test/scala/com/wavesplatform/history/Domain.scala index 21f144178b6..9010071d1eb 100644 --- a/node/src/test/scala/com/wavesplatform/history/Domain.scala +++ b/node/src/test/scala/com/wavesplatform/history/Domain.scala @@ -11,6 +11,7 @@ import com.wavesplatform.consensus.nxt.NxtLikeConsensusBlockData import com.wavesplatform.consensus.{PoSCalculator, PoSSelector} import com.wavesplatform.database.{DBExt, Keys, LevelDBWriter} import com.wavesplatform.events.BlockchainUpdateTriggers +import com.wavesplatform.features.BlockchainFeatures.{BlockV5, RideV6} import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.script.Script @@ -23,7 +24,7 @@ import com.wavesplatform.transaction.{BlockchainUpdater, *} import com.wavesplatform.utils.{EthEncoding, SystemTime} import com.wavesplatform.utx.UtxPoolImpl import com.wavesplatform.wallet.Wallet -import com.wavesplatform.{Application, TestValues, database} +import com.wavesplatform.{Application, TestValues, crypto, database} import monix.execution.Scheduler.Implicits.global import org.iq80.leveldb.DB import org.scalatest.matchers.should.Matchers.* @@ -53,7 +54,7 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite lazy val utxPool: UtxPoolImpl = new UtxPoolImpl(SystemTime, blockchain, settings.utxSettings, settings.maxTxErrorLogSize, settings.minerSettings.enable) - lazy val wallet: Wallet = Wallet(settings.walletSettings.copy(file = None)) + lazy val wallet: Wallet = Wallet(settings.walletSettings.copy(file = None)) object commonApi { @@ -220,12 +221,15 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite def appendBlockE(txs: Transaction*): Either[ValidationError, Seq[Diff]] = appendBlockE(createBlock(Block.PlainBlockVersion, txs)) - def appendBlock(txs: Transaction*): Block = { - val block = createBlock(Block.PlainBlockVersion, txs) + def appendBlock(version: Byte, txs: Transaction*): Block = { + val block = createBlock(version, txs) appendBlock(block) lastBlock } + def appendBlock(txs: Transaction*): Block = + appendBlock(Block.PlainBlockVersion, txs: _*) + def appendKeyBlock(ref: Option[ByteStr] = None): Block = { val block = createBlock(Block.NgBlockVersion, Nil, ref.orElse(Some(lastBlockId))) val discardedDiffs = appendBlock(block) @@ -237,7 +241,7 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite def appendMicroBlockE(txs: Transaction*): Either[Throwable, BlockId] = Try(appendMicroBlock(txs*)).toEither - def appendMicroBlock(txs: Transaction*): BlockId = { + def createMicroBlock(txs: Transaction*): MicroBlock = { val lastBlock = this.lastBlock val block = Block .buildAndSign( @@ -252,7 +256,11 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite lastBlock.header.rewardVote ) .explicitGet() - val mb = MicroBlock.buildAndSign(lastBlock.header.version, defaultSigner, txs, blockchainUpdater.lastBlockId.get, block.signature).explicitGet() + MicroBlock.buildAndSign(lastBlock.header.version, defaultSigner, txs, blockchainUpdater.lastBlockId.get, block.signature).explicitGet() + } + + def appendMicroBlock(txs: Transaction*): BlockId = { + val mb = createMicroBlock(txs: _*) blockchainUpdater.processMicroBlock(mb).explicitGet() } @@ -406,9 +414,17 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite } object Domain { - implicit class BlockchainUpdaterExt[A <: BlockchainUpdater](bcu: A) { - def processBlock(block: Block): Either[ValidationError, Seq[Diff]] = - bcu.processBlock(block, block.header.generationSignature) + implicit class BlockchainUpdaterExt[A <: BlockchainUpdater with Blockchain](bcu: A) { + def processBlock(block: Block): Either[ValidationError, Seq[Diff]] = { + val hitSource = + if (bcu.height == 0 || !bcu.activatedFeaturesAt(bcu.height + 1).contains(BlockV5.id)) + block.header.generationSignature + else { + val hs = bcu.hitSource(bcu.height).get + crypto.verifyVRF(block.header.generationSignature, hs.arr, block.header.generator, bcu.isFeatureActivated(RideV6)).explicitGet() + } + bcu.processBlock(block, hitSource) + } } def portfolio(address: Address, db: DB, blockchainUpdater: BlockchainUpdaterImpl): Seq[(IssuedAsset, Long)] = db.withResource { resource => diff --git a/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala b/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala index 9cbb75e1f7c..ac34037f782 100644 --- a/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala +++ b/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala @@ -1,7 +1,5 @@ package com.wavesplatform.mining -import java.util.concurrent.atomic.AtomicReference - import com.typesafe.config.ConfigFactory import com.wavesplatform.account.{AddressOrAlias, KeyPair} import com.wavesplatform.block.serialization.{BlockHeaderSerializer, BlockSerializer} @@ -36,12 +34,13 @@ import org.scalacheck.Gen import org.scalatest.* import org.scalatest.enablers.Length +import java.util.concurrent.atomic.AtomicReference import scala.concurrent.Await import scala.concurrent.duration.* class BlockV5Test extends FlatSpec with WithDomain with OptionValues with EitherValues with BlocksTransactionsHelpers { import BlockV5Test.* - private val testTime = new TestTime(1) + private val testTime = TestTime(1) def shiftTime(miner: MinerImpl, minerAcc: KeyPair): Unit = { val offset = miner.getNextBlockGenerationOffset(minerAcc).explicitGet() testTime.advance(offset + 1.milli) @@ -392,14 +391,8 @@ class BlockV5Test extends FlatSpec with WithDomain with OptionValues with Either d => def applyBlock(txs: Transaction*): SignedBlockHeader = { d.appendBlock( - TestBlock.create( - System.currentTimeMillis(), - d.blockchainUpdater.lastBlockId.getOrElse(TestBlock.randomSignature()), - txs, - version = - if (d.blockchainUpdater.height >= 1) Block.ProtoBlockVersion - else Block.PlainBlockVersion - ) + if (d.blockchainUpdater.height >= 1) Block.ProtoBlockVersion else Block.PlainBlockVersion, + txs: _* ) lastBlock } @@ -419,19 +412,11 @@ class BlockV5Test extends FlatSpec with WithDomain with OptionValues with Either block3.header.reference shouldBe block2.id() block3.id() should have length crypto.DigestLength - val (keyBlock, microBlocks) = - UnsafeBlocks.unsafeChainBaseAndMicro( - block3.id(), - Nil, - Seq(Seq(TxHelpers.transfer()), Seq(TxHelpers.transfer())), - acc, - Block.ProtoBlockVersion, - System.currentTimeMillis() - ) - d.appendBlock(keyBlock) - microBlocks.foreach(d.appendMicroBlock) + val keyBlock = d.appendKeyBlock() + val mb1 = d.createMicroBlock(TxHelpers.transfer()) + d.blockchain.processMicroBlock(mb1) + d.appendMicroBlock(TxHelpers.transfer()) - val mb1 = d.microBlocks.head mb1.totalResBlockSig should have length crypto.SignatureLength mb1.reference should not be keyBlock.signature mb1.reference shouldBe keyBlock.id() diff --git a/node/src/test/scala/com/wavesplatform/state/BlockchainUpdaterImplSpec.scala b/node/src/test/scala/com/wavesplatform/state/BlockchainUpdaterImplSpec.scala index 754647c48da..1ec799696a6 100644 --- a/node/src/test/scala/com/wavesplatform/state/BlockchainUpdaterImplSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/BlockchainUpdaterImplSpec.scala @@ -5,13 +5,14 @@ import com.typesafe.config.ConfigFactory import com.wavesplatform.TestHelpers.enableNG import com.wavesplatform.account.{Address, KeyPair} import com.wavesplatform.block.Block +import com.wavesplatform.block.Block.PlainBlockVersion import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.database.loadActiveLeases import com.wavesplatform.db.WithState.AddrWithBalance import com.wavesplatform.db.{DBCacheSettings, WithDomain} import com.wavesplatform.events.BlockchainUpdateTriggers import com.wavesplatform.history.Domain.BlockchainUpdaterExt -import com.wavesplatform.history.{chainBaseAndMicro, randomSig} +import com.wavesplatform.history.{Domain, chainBaseAndMicro, randomSig} import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.settings.{WavesSettings, loadConfig} @@ -313,9 +314,9 @@ class BlockchainUpdaterImplSpec extends FreeSpec with EitherMatchers with WithDo loadActiveLeases(db, _, _) ) - val block = TestBlock.create(Seq(genesis(defaultAddress))) - blockchain.processBlock(block) - blockchain.processBlock(TestBlock.create(block.header.timestamp, block.id(), Seq(transfer()))) + val d = Domain(db, blockchain, levelDb, RideV6) + blockchain.processBlock(d.createBlock(PlainBlockVersion, Seq(genesis(defaultAddress)), generator = TestBlock.defaultSigner)) + blockchain.processBlock(d.createBlock(PlainBlockVersion, Seq(transfer()), generator = TestBlock.defaultSigner)) ps.onComplete() Await.result(items, 2.seconds) shouldBe Seq( diff --git a/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala b/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala index cfb2b30c499..168e898316d 100644 --- a/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala @@ -484,13 +484,7 @@ class RollbackSpec extends FreeSpec with WithDomain { TxHelpers.invoke(dApp.toAddress, func = Some(fc.function.funcName), args = fc.args, invoker = invoker, fee = fee) )(setScript => diffs.ci.toInvokeExpression(setScript, invoker, Some(fee), Some(fc))) - d.appendBlock( - TestBlock.create( - nextTs, - parentBlockId, - Seq(invoke) - ) - ) + d.appendBlock(invoke) invoke.id() } @@ -503,7 +497,7 @@ class RollbackSpec extends FreeSpec with WithDomain { val (setScriptToConvert, checkAddress) = if (useInvokeExpression) (Some(setScript), invoker.toAddress) else (None, dApp.toAddress) val append = appendBlock(d, invoker, dApp, setScriptToConvert) _ - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq(setScript))) + d.appendBlock(setScript) val startBlockId = d.lastBlockId @@ -520,7 +514,7 @@ class RollbackSpec extends FreeSpec with WithDomain { // hardened block rollback val issueTxId = append(startBlockId, issueFc) val asset = getAsset(d, issueTxId) - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq())) + d.appendBlock() d.balance(checkAddress, asset) shouldBe quantity d.blockchainUpdater.removeAfter(startBlockId).explicitGet() d.balance(checkAddress, asset) shouldBe 0L @@ -538,7 +532,7 @@ class RollbackSpec extends FreeSpec with WithDomain { val (setScriptToConvert, checkAddress) = if (useInvokeExpression) (Some(setScript), invoker.toAddress) else (None, dApp.toAddress) val append = appendBlock(d, invoker, dApp, setScriptToConvert) _ - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq(setScript))) + d.appendBlock(setScript) val startBlockId = d.lastBlockId @@ -546,7 +540,7 @@ class RollbackSpec extends FreeSpec with WithDomain { val issueTxId = append(startBlockId, issueFc) val asset = getAsset(d, issueTxId) - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq())) + d.appendBlock() val issueBlockId = d.lastBlockId val issueDescription = d.blockchainUpdater.assetDescription(asset) @@ -563,7 +557,7 @@ class RollbackSpec extends FreeSpec with WithDomain { // hardened block rollback append(issueBlockId, reissueFc) d.balance(checkAddress, asset) shouldBe reissued + quantity - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq())) + d.appendBlock() d.blockchainUpdater.removeAfter(issueBlockId).explicitGet() d.balance(checkAddress, asset) shouldBe quantity d.blockchainUpdater.assetDescription(asset) shouldBe issueDescription @@ -579,7 +573,7 @@ class RollbackSpec extends FreeSpec with WithDomain { ) { d => val (setScriptToConvert, checkAddress) = if (useInvokeExpression) (Some(setScript), invoker.toAddress) else (None, dApp.toAddress) val append = appendBlock(d, invoker, dApp, setScriptToConvert) _ - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq(setScript))) + d.appendBlock(setScript) val startBlockId = d.lastBlockId @@ -587,7 +581,7 @@ class RollbackSpec extends FreeSpec with WithDomain { val issueTxId = append(startBlockId, issueFc) val asset = getAsset(d, issueTxId) - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq())) + d.appendBlock() val issueBlockId = d.lastBlockId val issueDescription = d.blockchainUpdater.assetDescription(asset) @@ -604,7 +598,7 @@ class RollbackSpec extends FreeSpec with WithDomain { // hardened block rollback append(issueBlockId, burntFc) d.balance(checkAddress, asset) shouldBe quantity - burnt - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq())) + d.appendBlock() d.blockchainUpdater.removeAfter(issueBlockId).explicitGet() d.balance(checkAddress, asset) shouldBe quantity d.blockchainUpdater.assetDescription(asset) shouldBe issueDescription @@ -621,7 +615,7 @@ class RollbackSpec extends FreeSpec with WithDomain { val setScriptToConvert = if (useInvokeExpression) Some(setScript) else None val append = appendBlock(d, invoker, dApp, setScriptToConvert) _ - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq(setScript))) + d.appendBlock(setScript) val startBlockId = d.lastBlockId @@ -629,7 +623,7 @@ class RollbackSpec extends FreeSpec with WithDomain { val issueTxId = append(startBlockId, issueFc) val asset = getAsset(d, issueTxId) - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq())) + d.appendBlock() val issueBlockId = d.lastBlockId val issueDescription = d.blockchainUpdater.assetDescription(asset) @@ -645,7 +639,7 @@ class RollbackSpec extends FreeSpec with WithDomain { // hardened block rollback append(issueBlockId, sponsorFc) d.blockchainUpdater.assetDescription(asset).get.sponsorship shouldBe sponsorship - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq())) + d.appendBlock() d.blockchainUpdater.removeAfter(issueBlockId).explicitGet() d.blockchainUpdater.assetDescription(asset).get.sponsorship shouldBe 0L d.blockchainUpdater.assetDescription(asset) shouldBe issueDescription @@ -663,7 +657,7 @@ class RollbackSpec extends FreeSpec with WithDomain { if (useInvokeExpression) (Some(setScript), invoker.toAddress, invoker.publicKey) else (None, dApp.toAddress, dApp.publicKey) val append = appendBlock(d, invoker, dApp, setScriptToConvert) _ - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq(setScript))) + d.appendBlock(setScript) val beforeInvoke1 = d.lastBlockId val (leaseAmount, leaseFc) = leaseFunctionCall(leaseRecipientAddress.toAddress) @@ -804,10 +798,12 @@ class RollbackSpec extends FreeSpec with WithDomain { val leaseAmount = smallFeeGen.sample.get val leaseTx = - LeaseTransaction.selfSigned(2.toByte, leaseSender, leaseRecipientAddress.toAddress, leaseAmount, setScript.fee.value, nextTs).explicitGet() + LeaseTransaction + .selfSigned(2.toByte, leaseSender, leaseRecipientAddress.toAddress, leaseAmount, setScript.fee.value, nextTs) + .explicitGet() val leaseId = leaseTx.id() - d.appendBlock(TestBlock.create(nextTs, d.lastBlockId, Seq(setScript, leaseTx))) + d.appendBlock(setScript, leaseTx) assertLeaseCancel( dApp, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala index ef22877b426..8df85588cd6 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala @@ -333,23 +333,14 @@ class AssetTransactionsDiffTest extends PropSpec with BlocksTransactionsHelpers } property(s"Can update with CompositeBlockchain") { - val (gen, issues, signer, update1) = genesisIssueUpdateWithSecondAsset + val (gen, issues, _, update1) = genesisIssueUpdateWithSecondAsset withDomain(domainSettingsWithFS(assetInfoUpdateEnabled.copy(minAssetInfoUpdateInterval = 0))) { d => val blockchain = d.blockchainUpdater val genesisBlock = TestBlock.create(gen ++ issues) d.appendBlock(genesisBlock) - val (keyBlock, mbs) = - UnsafeBlocks.unsafeChainBaseAndMicro( - genesisBlock.id(), - Nil, - Seq(Seq(update1)), - signer, - Block.ProtoBlockVersion, - genesisBlock.header.timestamp + 100 - ) - d.appendBlock(keyBlock) - val microBlockId = d.appendMicroBlock(mbs.head) + d.appendBlock() + d.appendMicroBlock(update1) val issue = issues(0) val issue1 = issues(1) @@ -367,9 +358,7 @@ class AssetTransactionsDiffTest extends PropSpec with BlocksTransactionsHelpers desc1.lastUpdatedAt shouldBe blockchain.height } - val (keyBlock1, _) = - UnsafeBlocks.unsafeChainBaseAndMicro(microBlockId, Nil, Nil, signer, Block.ProtoBlockVersion, keyBlock.header.timestamp + 100) - d.appendBlock(keyBlock1) + d.appendKeyBlock() { // Check after new key block val desc = blockchain.assetDescription(issue.asset).get diff --git a/node/src/test/scala/com/wavesplatform/transaction/BlockchainUpdaterTest.scala b/node/src/test/scala/com/wavesplatform/transaction/BlockchainUpdaterTest.scala index 91ed316c1fa..dcd4e0db44b 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/BlockchainUpdaterTest.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/BlockchainUpdaterTest.scala @@ -1,17 +1,17 @@ package com.wavesplatform.transaction -import java.security.Permission -import java.util.concurrent.{Semaphore, TimeUnit} - import com.wavesplatform.block.Block import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain import com.wavesplatform.features.BlockchainFeatureStatus -import com.wavesplatform.history.Domain.BlockchainUpdaterExt -import com.wavesplatform.state._ import com.wavesplatform.history +import com.wavesplatform.history.Domain.BlockchainUpdaterExt +import com.wavesplatform.state.* +import com.wavesplatform.test.DomainPresets.RideV6 import com.wavesplatform.test.FreeSpec +import java.security.Permission +import java.util.concurrent.{Semaphore, TimeUnit} import scala.util.Try class BlockchainUpdaterTest extends FreeSpec with HistoryTest with WithDomain { @@ -20,18 +20,20 @@ class BlockchainUpdaterTest extends FreeSpec with HistoryTest with WithDomain { private val WavesSettings = history.DefaultWavesSettings.copy( blockchainSettings = history.DefaultWavesSettings.blockchainSettings.copy( - functionalitySettings = history.DefaultWavesSettings.blockchainSettings.functionalitySettings.copy(featureCheckBlocksPeriod = ApprovalPeriod, blocksForFeatureActivation = (ApprovalPeriod * 0.9).toInt, preActivatedFeatures = Map.empty) + functionalitySettings = history.DefaultWavesSettings.blockchainSettings.functionalitySettings + .copy(featureCheckBlocksPeriod = ApprovalPeriod, blocksForFeatureActivation = (ApprovalPeriod * 0.9).toInt, preActivatedFeatures = Map.empty) ), featuresSettings = history.DefaultWavesSettings.featuresSettings.copy(autoShutdownOnUnsupportedFeature = true) ) private val WavesSettingsWithDoubling = WavesSettings.copy( blockchainSettings = WavesSettings.blockchainSettings.copy( - functionalitySettings = WavesSettings.blockchainSettings.functionalitySettings.copy(preActivatedFeatures = Map.empty, doubleFeaturesPeriodsAfterHeight = 300) + functionalitySettings = + WavesSettings.blockchainSettings.functionalitySettings.copy(preActivatedFeatures = Map.empty, doubleFeaturesPeriodsAfterHeight = 300) ) ) - def appendBlock(block: Block, blockchainUpdater: BlockchainUpdater): Unit = { + def appendBlock(block: Block, blockchainUpdater: BlockchainUpdater with Blockchain): Unit = { blockchainUpdater.processBlock(block) } @@ -219,8 +221,7 @@ class BlockchainUpdaterTest extends FreeSpec with HistoryTest with WithDomain { b.processBlock(getNextTestBlockWithVotes(b, Seq(-1))) should beRight } - Try(b.processBlock(getNextTestBlockWithVotes(b, Seq(-1)))).recover { - case _: SecurityException => // NOP + Try(b.processBlock(getNextTestBlockWithVotes(b, Seq(-1)))).recover { case _: SecurityException => // NOP } signal.tryAcquire(10, TimeUnit.SECONDS) @@ -350,4 +351,13 @@ class BlockchainUpdaterTest extends FreeSpec with HistoryTest with WithDomain { b.processBlock(getNextTestBlockWithVotes(b, Seq())) should beRight b.featureStatus(2, b.height) should be(BlockchainFeatureStatus.Activated) } + + "correct calculate hit source in tests" in + withDomain(RideV6) { d => + d.appendBlock() + d.appendBlock() + d.appendBlock() + d.rollbackTo(2) + d.appendBlock() + } }