diff --git a/node/src/test/scala/com/wavesplatform/history/Domain.scala b/node/src/test/scala/com/wavesplatform/history/Domain.scala index 772da80e8e..ab2401b7c5 100644 --- a/node/src/test/scala/com/wavesplatform/history/Domain.scala +++ b/node/src/test/scala/com/wavesplatform/history/Domain.scala @@ -381,8 +381,9 @@ case class Domain(rdb: RDB, blockchainUpdater: BlockchainUpdaterImpl, rocksDBWri generator: KeyPair = defaultSigner, stateHash: Option[Option[ByteStr]] = None, challengedHeader: Option[ChallengedHeader] = None, - rewardVote: Long = -1L - ): Block = createBlockE(version, txs, ref, strictTime, generator, stateHash, challengedHeader, rewardVote).explicitGet() + rewardVote: Long = -1L, + timestamp: Option[Long] = None + ): Block = createBlockE(version, txs, ref, strictTime, generator, stateHash, challengedHeader, rewardVote, timestamp).explicitGet() def createBlockE( version: Byte, @@ -392,7 +393,8 @@ case class Domain(rdb: RDB, blockchainUpdater: BlockchainUpdaterImpl, rocksDBWri generator: KeyPair = defaultSigner, stateHash: Option[Option[ByteStr]] = None, challengedHeader: Option[ChallengedHeader] = None, - rewardVote: Long = -1L + rewardVote: Long = -1L, + timestamp: Option[Long] = None ): Either[ValidationError, Block] = { val reference = ref.getOrElse(randomSig) @@ -401,12 +403,16 @@ case class Domain(rdb: RDB, blockchainUpdater: BlockchainUpdaterImpl, rocksDBWri val greatGrandParent = blockchain.blockHeader(parentHeight - 2).map(_.header) for { - timestamp <- - if (blockchain.height > 0) - posSelector - .getValidBlockDelay(blockchain.height, generator, parent.baseTarget, blockchain.balance(generator.toAddress) max 1e11.toLong) - .map(_ + parent.timestamp) - else + resultTimestamp <- + if (blockchain.height > 0) { + timestamp + .map(Right(_)) + .getOrElse( + posSelector + .getValidBlockDelay(blockchain.height, generator, parent.baseTarget, blockchain.balance(generator.toAddress) max 1e11.toLong) + .map(_ + parent.timestamp) + ) + } else Right(System.currentTimeMillis() - (1 hour).toMillis) consensus <- if (blockchain.height > 0) @@ -418,7 +424,7 @@ case class Domain(rdb: RDB, blockchainUpdater: BlockchainUpdaterImpl, rocksDBWri parent.baseTarget, parent.timestamp, greatGrandParent.map(_.timestamp), - timestamp + resultTimestamp ) else Right(NxtLikeConsensusBlockData(60, generationSignature)) resultBt = @@ -429,7 +435,7 @@ case class Domain(rdb: RDB, blockchainUpdater: BlockchainUpdaterImpl, rocksDBWri blockWithoutStateHash <- Block .buildAndSign( version = if (consensus.generationSignature.size == 96) Block.ProtoBlockVersion else version, - timestamp = if (strictTime) timestamp else SystemTime.getTimestamp(), + timestamp = if (strictTime) resultTimestamp else SystemTime.getTimestamp(), reference = reference, baseTarget = resultBt, generationSignature = consensus.generationSignature, @@ -471,7 +477,7 @@ case class Domain(rdb: RDB, blockchainUpdater: BlockchainUpdaterImpl, rocksDBWri resultBlock <- Block .buildAndSign( version = if (consensus.generationSignature.size == 96) Block.ProtoBlockVersion else version, - timestamp = if (strictTime) timestamp else SystemTime.getTimestamp(), + timestamp = if (strictTime) resultTimestamp else SystemTime.getTimestamp(), reference = reference, baseTarget = resultBt, generationSignature = consensus.generationSignature, diff --git a/node/src/test/scala/com/wavesplatform/state/BlockChallengeTest.scala b/node/src/test/scala/com/wavesplatform/state/BlockChallengeTest.scala index c749b2a535..50819fcc40 100644 --- a/node/src/test/scala/com/wavesplatform/state/BlockChallengeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/BlockChallengeTest.scala @@ -117,7 +117,16 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes val challengingMiner = d.wallet.generateNewAccount().get d.appendBlock(TxHelpers.transfer(TxHelpers.defaultSigner, challengingMiner.toAddress, 1000.waves)) (1 to 999).foreach(_ => d.appendBlock()) - appendAndCheck(d.createBlock(Block.ProtoBlockVersion, Seq.empty, strictTime = true, stateHash = Some(Some(invalidStateHash))), d) { block => + appendAndCheck( + d.createBlock( + Block.ProtoBlockVersion, + Seq.empty, + strictTime = true, + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) + ), + d + ) { block => block.header.challengedHeader shouldBe defined val challengedHeader = block.header.challengedHeader.get @@ -142,7 +151,14 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes (1 to 999).foreach(_ => d.appendBlock()) appendAndCheck( - d.createBlock(Block.ProtoBlockVersion, Seq.empty, strictTime = true, generator = challengedMiner, stateHash = Some(Some(invalidStateHash))), + d.createBlock( + Block.ProtoBlockVersion, + Seq.empty, + strictTime = true, + generator = challengedMiner, + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) + ), d ) { block => block.header.challengedHeader shouldBe defined @@ -153,7 +169,14 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes (1 to 999).foreach(_ => d.appendBlock()) appendAndCheck( - d.createBlock(Block.ProtoBlockVersion, Seq.empty, strictTime = true, generator = challengedMiner, stateHash = Some(Some(invalidStateHash))), + d.createBlock( + Block.ProtoBlockVersion, + Seq.empty, + strictTime = true, + generator = challengedMiner, + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) + ), d ) { block => block.header.challengedHeader shouldBe defined @@ -189,7 +212,13 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes val challengingMiner = d.wallet.generateNewAccount().get d.appendBlock(TxHelpers.transfer(TxHelpers.defaultSigner, challengingMiner.toAddress, 1000.waves)) (1 to 999).foreach(_ => d.appendBlock()) - val originalBlock = d.createBlock(Block.ProtoBlockVersion, Seq.empty, strictTime = true, stateHash = Some(Some(invalidStateHash))) + val originalBlock = d.createBlock( + Block.ProtoBlockVersion, + Seq.empty, + strictTime = true, + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) + ) appendAndCheck(originalBlock, d) { block => block.header.challengedHeader shouldBe defined val challengedHeader = block.header.challengedHeader.get @@ -232,7 +261,13 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes val challengingMiner = d.wallet.generateNewAccount().get d.appendBlock(TxHelpers.transfer(TxHelpers.defaultSigner, challengingMiner.toAddress, 1000.waves)) (1 to 999).foreach(_ => d.appendBlock()) - val originalBlock = d.createBlock(Block.ProtoBlockVersion, Seq.empty, strictTime = true, stateHash = Some(Some(invalidStateHash))) + val originalBlock = d.createBlock( + Block.ProtoBlockVersion, + Seq.empty, + strictTime = true, + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) + ) appendAndCheck(originalBlock, d) { block => block.transactionData shouldBe originalBlock.transactionData } @@ -269,7 +304,13 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes val challengingMiner = d.wallet.generateNewAccount().get d.appendBlock(TxHelpers.transfer(TxHelpers.defaultSigner, challengingMiner.toAddress, 1000.waves)) (1 to 999).foreach(_ => d.appendBlock()) - val originalBlock = d.createBlock(Block.ProtoBlockVersion, Seq.empty, strictTime = true, stateHash = Some(Some(invalidStateHash))) + val originalBlock = d.createBlock( + Block.ProtoBlockVersion, + Seq.empty, + strictTime = true, + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) + ) appendAndCheck(originalBlock, d) { block => block.header.reference shouldBe originalBlock.header.reference } @@ -651,7 +692,8 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes Seq(challengedBlockTx), strictTime = true, generator = challengedMiner, - stateHash = Some(Some(invalidStateHash)) + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) ) appendAndCheck(originalBlock, d) { block => @@ -970,7 +1012,8 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes Block.ProtoBlockVersion, Seq.empty, strictTime = true, - stateHash = Some(Some(invalidStateHash)) + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) ) appendAndCheck(originalBlock, d) { block => @@ -999,14 +1042,7 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes val challengingMiner = d.wallet.generateNewAccount().get d.appendBlock(TxHelpers.transfer(defaultSigner, challengingMiner.toAddress, 1000.waves)) - (1 to 999).foreach(_ => d.appendBlock()) - d.appendBlock( - d.createBlock( - Block.ProtoBlockVersion, - Seq.empty, - strictTime = true - ) - ) + (1 to 1000).foreach(_ => d.appendBlock()) d.blockchain.isFeatureActivated(BlockchainFeatures.TransactionStateSnapshot) shouldBe false @@ -1014,7 +1050,8 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes Block.ProtoBlockVersion, Seq.empty, strictTime = true, - stateHash = Some(Some(invalidStateHash)) + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) ) appendAndCheck(originalBlock, d) { block => @@ -1551,7 +1588,14 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes val txs = Seq(TxHelpers.transfer(amount = 1.waves), TxHelpers.transfer(amount = 2.waves)) val invalidBlock = - d.createBlock(Block.ProtoBlockVersion, txs, strictTime = true, generator = challengedMiner, stateHash = Some(Some(invalidStateHash))) + d.createBlock( + Block.ProtoBlockVersion, + txs, + strictTime = true, + generator = challengedMiner, + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) + ) val blockChallenger: Option[BlockChallenger] = Some( @@ -1718,7 +1762,14 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes (1 to 999).foreach(_ => d.appendBlock()) val txs = Seq(TxHelpers.transfer(sender, amount = 1), TxHelpers.transfer(sender, amount = 2)) val originalBlock = - d.createBlock(Block.ProtoBlockVersion, txs, strictTime = true, generator = challengedMiner, stateHash = Some(Some(invalidStateHash))) + d.createBlock( + Block.ProtoBlockVersion, + txs, + strictTime = true, + generator = challengedMiner, + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) + ) txs.foreach(d.utxPool.putIfNew(_)) d.utxPool.size shouldBe txs.size @@ -1854,7 +1905,8 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes txs, strictTime = true, generator = challengedMiner, - stateHash = Some(Some(invalidStateHash)) + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) ) appendAndCheck(originalBlock, d)(_ => (1 to 10).foreach(_ => d.appendBlock())) @@ -1870,7 +1922,8 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes txs, strictTime = true, generator = challengedMiner, - stateHash = Some(Some(invalidStateHash)) + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) ) appendAndCheck(originalBlock, d)(_ => ()) @@ -1888,7 +1941,8 @@ class BlockChallengeTest extends PropSpec with WithDomain with ScalatestRouteTes txs, strictTime = true, generator = challengedMiner, - stateHash = Some(Some(invalidStateHash)) + stateHash = Some(Some(invalidStateHash)), + timestamp = Some(Long.MaxValue) ) appendAndCheck(originalBlock, d)(_ => ())