@@ -148,6 +148,34 @@ class FastSyncItSpec extends FlatSpecBase with Matchers with BeforeAndAfterAll {
148
148
assert(peer1.bl.getBestBlockNumber() == peer2.bl.getBestBlockNumber() - peer2.testSyncConfig.pivotBlockOffset)
149
149
}
150
150
}
151
+
152
+ it should " follow the longest chains" in customTestCaseResourceM(
153
+ FakePeer .start4FakePeersRes()
154
+ ) { case (peer1, peer2, peer3, peer4) =>
155
+ for {
156
+ _ <- peer2.importBlocksUntil(1000 )(IdentityUpdate )
157
+ _ <- peer3.importBlocksUntil(1000 )(IdentityUpdate )
158
+ _ <- peer4.importBlocksUntil(1000 )(IdentityUpdate )
159
+
160
+ _ <- peer2.importBlocksUntil(2000 )(IdentityUpdate )
161
+ _ <- peer3.importBlocksUntil(3000 )(updateStateAtBlock(1001 , endAccount = 3000 ))
162
+ _ <- peer4.importBlocksUntil(3000 )(updateStateAtBlock(1001 , endAccount = 3000 ))
163
+
164
+ _ <- peer1.connectToPeers(Set (peer2.node, peer3.node, peer4.node))
165
+ _ <- peer1.startFastSync().delayExecution(50 .milliseconds)
166
+ _ <- peer1.waitForFastSyncFinish()
167
+ } yield {
168
+ val trie = peer1.getBestBlockTrie()
169
+ val synchronizingPeerHaveAllData = peer1.containsExpectedDataUpToAccountAtBlock(3000 , 1001 )
170
+ // due to the fact that function generating state is deterministic both peer3 and peer4 ends up with exactly same
171
+ // state, so peer1 can get whole trie from both of them.
172
+ assert(peer1.bl.getBestBlockNumber() == peer3.bl.getBestBlockNumber() - peer3.testSyncConfig.pivotBlockOffset)
173
+ assert(peer1.bl.getBestBlockNumber() == peer4.bl.getBestBlockNumber() - peer4.testSyncConfig.pivotBlockOffset)
174
+ assert(trie.isDefined)
175
+ assert(synchronizingPeerHaveAllData)
176
+ }
177
+ }
178
+
151
179
}
152
180
153
181
object FastSyncItSpec {
0 commit comments