| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Currently, we don't have support for F[_] effectful computation in tests so tests are using _.runSyncUnsafe() to get the value and assert result. This is not desired, recommended, runs slower and also more more difficult to read and write.
Introduce libraries to extend Scalatest and scalacheck to support working with F[_] values without hacks.
https://typelevel.org/cats-effect/docs/2.x/guides/testing
Two libraries that we need are:
rchain/casper/src/test/scala/coop/rchain/casper/util/BlockHashSignatureSpec.scala
Lines 14 to 72 in 40d15bf
| "block hash" should "not match for changed block hash" in { | |
| implicit val aBlockHash = arbitraryBlockHash | |
| check { | |
| forAll { (block: BlockMessage, genBlockHash: ByteString) => | |
| val isModified = genBlockHash != block.blockHash | |
| val hash = block.blockHash | |
| val blockModified = block.copy(blockHash = genBlockHash) | |
| val hashModified = ProtoUtil.hashBlock(blockModified) | |
| // Check hashes are different for modified block | |
| hashModified !== hash ?= isModified | |
| } | |
| } | |
| } | |
| "block hash" should "not match for changed sequence number" in { | |
| check { | |
| forAll { (block: BlockMessage, genSeqNum: Int) => | |
| val isModified = genSeqNum != block.seqNum | |
| val hash = ProtoUtil.hashBlock(block) | |
| val blockModified = block.copy(seqNum = genSeqNum) | |
| val hashModified = ProtoUtil.hashBlock(blockModified) | |
| // Check hashes are different for modified block | |
| hashModified !== hash ?= isModified | |
| } | |
| } | |
| } | |
| "block hash" should "not match for changed block number" in { | |
| check { | |
| forAll { (block: BlockMessage, genBlockNumber: Long) => | |
| val isModified = genBlockNumber != block.body.state.blockNumber | |
| val hash = ProtoUtil.hashBlock(block) | |
| val blockModified = block.copy( | |
| body = block.body.copy(state = block.body.state.copy(blockNumber = genBlockNumber)) | |
| ) | |
| val hashModified = ProtoUtil.hashBlock(blockModified) | |
| // Check hashes are different for modified block | |
| hashModified !== hash ?= isModified | |
| } | |
| } | |
| } | |
| "block hash" should "not match for changed justifications" in { | |
| implicit val aJustification = arbitraryJustification | |
| check { | |
| forAll { (block: BlockMessage, genJustifications: List[Justification]) => | |
| val isModified = genJustifications != block.justifications | |
| val hash = ProtoUtil.hashBlock(block) | |
| val blockModified = block.copy(justifications = genJustifications) | |
| val hashModified = ProtoUtil.hashBlock(blockModified) | |
| // Check hashes are different for modified block | |
| hashModified !== hash ?= isModified | |
| } | |
| } | |
| } |
| Back | FazBrowse Home | New Git URL |
Activity