@@ -57,7 +57,7 @@ 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
63
forAll(nums) { case (k, m, n) =>
@@ -70,14 +70,40 @@ class CheckpointingServiceSpec
70
70
val expectedResponse = GetLatestBlockResponse (Some (BlockInfo (block.hash, block.number)))
71
71
72
72
(blockchain.getBestBlockNumber _).expects().returning(bestBlockNum)
73
- (blockchain.getBlockHeaderByHash _).expects(hash).returning(Some (previousCheckpoint.header))
73
+ (blockchain.getBlockHeaderByHash _).expects(hash).returning(Some (previousCheckpoint.header.copy(number = 0 ) ))
74
74
(blockchain.getBlockByNumber _).expects(checkpointedBlockNum).returning(Some (block))
75
75
val result = service.getLatestBlock(request)
76
76
77
77
result.runSyncUnsafe() shouldEqual Right (expectedResponse)
78
78
}
79
79
}
80
80
81
+ it should " not return a block that is at the same height as the passed parent checkpoint block" in new TestSetup {
82
+ val nums = for {
83
+ k <- Gen .choose[Int ](1 , 10 ) // checkpointing interval
84
+ m <- Gen .choose(0 , 1000 ) // number of checkpoints in the chain
85
+ n <- Gen .choose(0 , k - 1 ) // distance from best block to checkpointed block
86
+ } yield (k, m, n)
87
+
88
+ val previousCheckpoint = Fixtures .Blocks .ValidBlock .block
89
+ val hash = previousCheckpoint.hash
90
+
91
+ forAll(nums) { case (k, m, n) =>
92
+ val checkpointedBlockNum : BigInt = k * m
93
+ val bestBlockNum : BigInt = checkpointedBlockNum + n
94
+
95
+ val request = GetLatestBlockRequest (k, Some (hash))
96
+ val expectedResponse = GetLatestBlockResponse (None )
97
+
98
+ (blockchain.getBestBlockNumber _).expects().returning(bestBlockNum)
99
+ (blockchain.getBlockHeaderByHash _).expects(hash).returning(Some (previousCheckpoint.header.copy(number = bestBlockNum)))
100
+ (blockchain.getBlockByNumber _).expects(* ).returning(Some (previousCheckpoint))
101
+ val result = service.getLatestBlock(request)
102
+
103
+ result.runSyncUnsafe() shouldEqual Right (expectedResponse)
104
+ }
105
+ }
106
+
81
107
it should " return an empty response if the descendant is not a part of a local blockchain" in new TestSetup {
82
108
val nums = for {
83
109
k <- Gen .choose[Int ](1 , 10 ) // checkpointing interval
0 commit comments