Skip to content

Commit 68e270b

Browse files
author
Aurélien Richez
committed
use property test to test BlockchainReader
1 parent 1145496 commit 68e270b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/main/scala/io/iohk/ethereum/db/storage/AppStateStorage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AppStateStorage(val dataSource: DataSource) extends TransactionalKeyValueS
3232
getBigInt(Keys.BestBlockNumber)
3333

3434
def getBestBlockInfo(): BestBlockInfo =
35-
BestBlockInfo( // FIXME default value for hash ?
35+
BestBlockInfo( // TODO ETCM-1090 provide the genesis hash as default
3636
get(Keys.BestBlockHash).map(v => ByteString(Hex.decode(v))).getOrElse(ByteString.empty),
3737
getBigInt(Keys.BestBlockNumber)
3838
)
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
package io.iohk.ethereum.domain
22

3+
import org.bouncycastle.util.encoders.Hex
34
import org.scalatest.flatspec.AnyFlatSpec
45
import org.scalatest.matchers.should.Matchers
6+
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
57

68
import io.iohk.ethereum.Fixtures
9+
import io.iohk.ethereum.ObjectGenerators
710
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
11+
import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.NewBlock
12+
import io.iohk.ethereum.security.SecureRandomBuilder
813

9-
class BlockchainReaderSpec extends AnyFlatSpec with Matchers {
14+
class BlockchainReaderSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyChecks with SecureRandomBuilder {
1015

11-
"BlockchainReader" should "be able to get the best block after it was stored by BlockchainWriter" in new EphemBlockchainTestSetup {
12-
val validBlock = Fixtures.Blocks.ValidBlock.block
16+
val chainId: Option[Byte] = Hex.decode("3d").headOption
1317

14-
blockchainWriter.save(validBlock, Nil, ChainWeight.zero, true)
18+
"BlockchainReader" should "be able to get the best block after it was stored by BlockchainWriter" in new EphemBlockchainTestSetup {
19+
forAll(ObjectGenerators.newBlockGen(secureRandom, chainId)) { case NewBlock(block, weight) =>
20+
blockchainWriter.save(block, Nil, ChainWeight(0, weight), true)
1521

16-
blockchainReader.getBestBlock() shouldBe Some(validBlock)
22+
blockchainReader.getBestBlock() shouldBe Some(block)
23+
}
1724
}
1825

1926
}

0 commit comments

Comments
 (0)