(*--------------------------------------------------------------------------- Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) open Crowbar let gen_eid = choose [ const Bundle.Dtn_none; map [ bytes ] (fun s -> Bundle.Dtn s); map [ int64; int64 ] (fun n s -> Bundle.Ipn (n, s)); ] let gen_status = map [ gen_eid; float; range 1000; range 1000; range 1000; range 1000; range 100; ] (fun node_id uptime_secs stored fwd del drop contacts -> Admin.Status_report { node_id; uptime_secs; bundles_stored = stored; bundles_forwarded = fwd; bundles_delivered = del; bundles_dropped = drop; active_contacts = contacts; }) let gen_query = choose [ const (Admin.Query Admin.Query_status); const (Admin.Query Admin.Query_contacts); const (Admin.Query Admin.Query_policy); map [ option bytes ] (fun filter -> Admin.Query (Admin.Query_bundles { filter })); ] let gen_contact = map [ bytes; bytes; float; float; float; float ] (fun from_node to_node start_time stop_time rate_bps owlt_secs -> { Admin.from_node; to_node; start_time; stop_time; rate_bps; owlt_secs }) let gen_contact_plan = map [ list gen_contact ] (fun contacts -> Admin.Contact_update { contacts }) let gen_record = choose [ gen_status; gen_query; gen_contact_plan ] let test_roundtrip record = let encoded = Admin.encode record in match Admin.decode encoded with | Error _ -> () | Ok decoded -> let re_encoded = Admin.encode decoded in check_eq ~pp:Fmt.string encoded re_encoded let () = add_test ~name:"admin roundtrip" [ gen_record ] test_roundtrip