@@ -207,6 +207,59 @@ struct
207207 [% test_eq: Migrated.Account. t] stored_migrated_account
208208 (Db_converting. convert primary_account) ) ) ) )
209209
210+ let () =
211+ add_test
212+ " sync detection fails without crashing after accounts are added at high \
213+ addresses" (fun () ->
214+ with_primary ~f: (fun primary ->
215+ let depth = Db. depth primary in
216+ let max_height = Int. min 5 depth - 1 in
217+ populate_primary_db primary max_height ;
218+ with_migrated ~f: (fun migrated ->
219+ let _converting =
220+ Db_converting. of_ledgers_with_migration primary migrated
221+ in
222+ let additional_account = Quickcheck. random_value Account. gen in
223+ let high_index = (1 lsl Int. min 5 depth) - 1 in
224+ let additional_account_addr =
225+ Db.Addr. of_int_exn ~ledger_depth: depth high_index
226+ in
227+ (* Using set_batch_accounts with a high address like this leaves
228+ the databases in an inconsistent state, because it updates
229+ the last added account in the databases but doesn't fill in
230+ the accounts at lower addresses. This state is similar to
231+ what you might get after an incomplete ledger sync. *)
232+ Db. set_batch_accounts primary
233+ [ (additional_account_addr, additional_account) ] ;
234+ Db_migrated. set_batch_accounts migrated
235+ [ ( additional_account_addr
236+ , Db_converting. convert additional_account )
237+ ] ;
238+ assert (Db_converting. dbs_synced primary migrated) ) ) )
239+
240+ let () =
241+ add_test " sync detection fails after converting ledger account is mutated"
242+ (fun () ->
243+ with_primary ~f: (fun primary ->
244+ let depth = Db. depth primary in
245+ let max_height = Int. min 5 depth in
246+ populate_primary_db primary max_height ;
247+ let account_to_mutate = Db. get_at_index_exn primary 0 in
248+ let new_balance, _overflow_flag =
249+ Balance. add_amount_flagged account_to_mutate.balance
250+ Currency.Amount. one
251+ in
252+ let mutated_account =
253+ Db_converting. convert
254+ { account_to_mutate with balance = new_balance }
255+ in
256+ with_migrated ~f: (fun migrated ->
257+ let _converting =
258+ Db_converting. of_ledgers_with_migration primary migrated
259+ in
260+ Db_migrated. set_at_index_exn migrated 0 mutated_account ;
261+ assert (not (Db_converting. dbs_synced primary migrated)) ) ) )
262+
210263 let () =
211264 add_test " create converting ledger, populate randomly, test iteration order"
212265 (fun () ->
0 commit comments