Skip to content

Commit 6ebd60a

Browse files
author
Aurélien Richez
committed
use property test to test BlockchainReader
1 parent dd56de9 commit 6ebd60a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
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
)

src/test/scala/io/iohk/ethereum/domain/BlockchainReaderSpec.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ package io.iohk.ethereum.domain
22

33
import org.scalatest.flatspec.AnyFlatSpec
44
import org.scalatest.matchers.should.Matchers
5-
6-
import io.iohk.ethereum.Fixtures
5+
import io.iohk.ethereum.{Fixtures, ObjectGenerators}
76
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
7+
import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.NewBlock
8+
import io.iohk.ethereum.security.SecureRandomBuilder
9+
import org.bouncycastle.util.encoders.Hex
10+
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
811

9-
class BlockchainReaderSpec extends AnyFlatSpec with Matchers {
12+
class BlockchainReaderSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyChecks with SecureRandomBuilder {
1013

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
14+
val chainId: Option[Byte] = Hex.decode("3d").headOption
1315

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

16-
blockchainReader.getBestBlock() shouldBe Some(validBlock)
20+
blockchainReader.getBestBlock() shouldBe Some(block)
21+
}
1722
}
1823

1924
}

0 commit comments

Comments
 (0)