Skip to content

Commit

Permalink
Test that new fields are prohibited for an interval
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 committed Dec 4, 2023
1 parent 054505e commit 1fab951
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.wavesplatform.features.BlockchainFeatures.LightNode
import com.wavesplatform.mining.MultiDimensionalMiningConstraint.Unlimited
import com.wavesplatform.mining.microblocks.MicroBlockMinerImpl
import com.wavesplatform.test.DomainPresets.*
import com.wavesplatform.test.PropSpec
import com.wavesplatform.test.{PropSpec, produce}
import com.wavesplatform.transaction.TxHelpers.{defaultSigner, secondSigner, transfer}
import com.wavesplatform.transaction.TxValidationError.GenericError
import io.netty.channel.group.DefaultChannelGroup
Expand Down Expand Up @@ -110,4 +110,33 @@ class LightNodeBlockFieldsTest extends PropSpec with WithDomain {
}
}
}

property(
"blocks with challenged header or state hash should be allowed only `lightNodeBlockFieldsAbsenceInterval` blocks after LightNode activation"
) {
withDomain(
TransactionStateSnapshot.setFeaturesHeight(LightNode -> 2).configure(_.copy(lightNodeBlockFieldsAbsenceInterval = 10)),
AddrWithBalance.enoughBalances(defaultSigner, secondSigner)
) { d =>
withMiner(d.blockchain, d.testTime, d.settings, verify = false, timeDrift = Int.MaxValue) { case (_, append) =>
(1 to 9).foreach(_ => d.appendBlock())
d.blockchain.height shouldBe 10
val challengedBlock = d.createBlock(ProtoBlockVersion, Nil, stateHash = Some(Some(ByteStr.fill(DigestLength)(1))))
val challengingBlock = d.createChallengingBlock(defaultSigner, challengedBlock)
append(challengedBlock) should produce("UnexpectedLightNodeFields")
append(challengingBlock) should produce("UnexpectedLightNodeFields")

d.appendBlock()
d.blockchain.height shouldBe 11
val correctBlockWithStateHash = d.createBlock(ProtoBlockVersion, Nil)
correctBlockWithStateHash.header.stateHash shouldBe defined
append(correctBlockWithStateHash) shouldBe a[Right[?, ?]]

d.rollbackTo(11)
val invalidBlock = d.createBlock(ProtoBlockVersion, Nil, stateHash = Some(Some(ByteStr.fill(DigestLength)(1))))
val challengingBlock2 = d.createChallengingBlock(defaultSigner, invalidBlock)
append(challengingBlock2) shouldBe a[Right[?, ?]]
}
}
}
}

0 comments on commit 1fab951

Please sign in to comment.