@@ -9,7 +9,7 @@ import io.iohk.ethereum.jsonrpc.CheckpointingService._
9
9
import io .iohk .ethereum .ledger .Ledger
10
10
import io .iohk .ethereum .{Fixtures , NormalPatience , WithActorSystemShutDown }
11
11
import monix .execution .Scheduler .Implicits .global
12
- import org .scalacheck .Gen
12
+ import org .scalacheck .{ Gen , Shrink }
13
13
import org .scalamock .scalatest .MockFactory
14
14
import org .scalatest .concurrent .ScalaFutures
15
15
import org .scalatest .flatspec .AnyFlatSpecLike
@@ -57,9 +57,11 @@ class CheckpointingServiceSpec
57
57
n <- Gen .choose(0 , k - 1 ) // distance from best block to checkpointed block
58
58
} yield (k, m, n)
59
59
60
- val previousCheckpoint = Fixtures .Blocks .ValidBlock .block
60
+ val previousCheckpoint = Fixtures .Blocks .Block3125369 .block
61
61
val hash = previousCheckpoint.hash
62
62
63
+ implicit val noShrink : Shrink [Int ] = Shrink .shrinkAny
64
+
63
65
forAll(nums) { case (k, m, n) =>
64
66
val checkpointedBlockNum : BigInt = k * m
65
67
val bestBlockNum : BigInt = checkpointedBlockNum + n
@@ -70,14 +72,42 @@ class CheckpointingServiceSpec
70
72
val expectedResponse = GetLatestBlockResponse (Some (BlockInfo (block.hash, block.number)))
71
73
72
74
(blockchain.getBestBlockNumber _).expects().returning(bestBlockNum)
73
- (blockchain.getBlockHeaderByHash _).expects(hash).returning(Some (previousCheckpoint.header))
75
+ (blockchain.getBlockHeaderByHash _).expects(hash).returning(Some (previousCheckpoint.header.copy(number = 0 ) ))
74
76
(blockchain.getBlockByNumber _).expects(checkpointedBlockNum).returning(Some (block))
75
77
val result = service.getLatestBlock(request)
76
78
77
79
result.runSyncUnsafe() shouldEqual Right (expectedResponse)
78
80
}
79
81
}
80
82
83
+ it should " not return a block that is at the same height as the passed parent checkpoint block" in new TestSetup {
84
+ val nums = for {
85
+ k <- Gen .choose[Int ](1 , 10 ) // checkpointing interval
86
+ m <- Gen .choose(0 , 1000 ) // number of checkpoints in the chain
87
+ n <- Gen .choose(0 , k - 1 ) // distance from best block to checkpointed block
88
+ } yield (k, m, n)
89
+
90
+ val previousCheckpoint = Fixtures .Blocks .ValidBlock .block
91
+ val hash = previousCheckpoint.hash
92
+
93
+ implicit val noShrink : Shrink [Int ] = Shrink .shrinkAny
94
+
95
+ forAll(nums) { case (k, m, n) =>
96
+ val checkpointedBlockNum : BigInt = k * m
97
+ val bestBlockNum : BigInt = checkpointedBlockNum + n
98
+
99
+ val request = GetLatestBlockRequest (k, Some (hash))
100
+ val expectedResponse = GetLatestBlockResponse (None )
101
+
102
+ (blockchain.getBestBlockNumber _).expects().returning(bestBlockNum)
103
+ (blockchain.getBlockHeaderByHash _).expects(hash).returning(Some (previousCheckpoint.header.copy(number = bestBlockNum)))
104
+ (blockchain.getBlockByNumber _).expects(* ).returning(Some (previousCheckpoint))
105
+ val result = service.getLatestBlock(request)
106
+
107
+ result.runSyncUnsafe() shouldEqual Right (expectedResponse)
108
+ }
109
+ }
110
+
81
111
it should " return an empty response if the descendant is not a part of a local blockchain" in new TestSetup {
82
112
val nums = for {
83
113
k <- Gen .choose[Int ](1 , 10 ) // checkpointing interval
0 commit comments