Skip to content

Commit 3b30bcb

Browse files
author
Aurélien Richez
committed
use property test to test BlockchainReader
1 parent db204da commit 3b30bcb

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
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

6-
import io.iohk.ethereum.Fixtures
8+
import io.iohk.ethereum.ObjectGenerators
79
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
10+
import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.NewBlock
11+
import io.iohk.ethereum.security.SecureRandomBuilder
812

9-
class BlockchainReaderSpec extends AnyFlatSpec with Matchers {
13+
class BlockchainReaderSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyChecks with SecureRandomBuilder {
1014

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

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

16-
blockchainReader.getBestBlock() shouldBe Some(validBlock)
21+
blockchainReader.getBestBlock() shouldBe Some(block)
22+
}
1723
}
1824

1925
}

0 commit comments

Comments
 (0)