#include "evo/network/intent_admission.hpp" #include #include #include #include namespace { using namespace evo::network; void check(bool value, std::source_location at = std::source_location::current()) { if (!value) throw std::runtime_error("cellular intent admission line " + std::to_string(at.line())); } #define CHECK(...) check(static_cast(__VA_ARGS__)) AccountId account(std::uint8_t id) { AccountId value{}; value.bytes.back() = id; return value; } void admission_and_rejections() { auto made = IntentAdmission::create({}); CHECK(made); auto queue = std::move(*made); CHECK(queue.open(22, account(2))); CHECK(queue.open(33, account(1))); CHECK(queue.open(11, account(1))); const AdmissionFacts facts{true, 7, 10}; const CellularIntention b{22, 7, 1, 12, -500, 500, true, 3'000, 2'000}; const CellularIntention a{11, 7, 1, 12, 0, 1000, false, 0, 0}; CHECK(queue.intention(22, b, facts).status == AdmitStatus::admitted); CHECK(queue.intention(11, a, facts).status == AdmitStatus::admitted); const auto rejected_epoch = queue.intention(11, CellularIntention{11, 8, 2, 13}, facts); CHECK(rejected_epoch.status == AdmitStatus::stale_epoch); const auto rejected_vector = queue.intention(11, CellularIntention{11, 7, 2, 13, 1000, 1000}, facts); CHECK(rejected_vector.status == AdmitStatus::invalid_vector); const auto rejected_window = queue.intention(11, CellularIntention{11, 7, 2, 19}, facts); CHECK(rejected_window.status == AdmitStatus::outside_window); const auto rejected_replay = queue.intention(11, a, facts); CHECK(rejected_replay.status == AdmitStatus::replayed); const auto rejected_connection = queue.intention(11, CellularIntention{99, 7, 2, 13}, facts); CHECK(rejected_connection.status == AdmitStatus::unknown_session); } void scheduled_inputs_are_stable_until_simulated() { auto made = IntentAdmission::create({}); CHECK(made); auto queue = std::move(*made); CHECK(queue.open(22, account(2))); CHECK(queue.open(33, account(1))); CHECK(queue.open(11, account(1))); const AdmissionFacts facts{true, 7, 10}; CHECK(queue.intention(22, CellularIntention{22, 7, 1, 12, -500, 500, true, 3'000, 2'000}, facts) .status == AdmitStatus::admitted); CHECK(queue.intention(33, CellularIntention{33, 7, 1, 12, 0, 0}, facts).status == AdmitStatus::admitted); CHECK(queue.intention(11, CellularIntention{11, 7, 1, 12, 0, 1000}, facts).status == AdmitStatus::admitted); CHECK(queue.scheduled_cellular_intentions(11).empty()); const auto before = queue.scheduled_cellular_intentions(12); CHECK(before.size() == 3); CHECK(before[0].account == account(1)); // Stable account order, not connection order. CHECK(before[0].intention == CellularIntention{11, 7, 1, 12, 0, 1000, false, 0, 0}); CHECK(before[1].account == account(1)); CHECK(before[1].intention == CellularIntention{33, 7, 1, 12, 0, 0, false, 0, 0}); CHECK(before[2].account == account(2)); CHECK(before[2].intention == CellularIntention{22, 7, 1, 12, -500, 500, true, 3'000, 2'000}); CHECK(queue.scheduled_cellular_intentions(12) == before); // Read does not consume input. const auto marks = queue.simulated({true, 7, 12}); CHECK(marks.size() == 3); CHECK(queue.scheduled_cellular_intentions(12).empty()); } } // namespace int main() { try { admission_and_rejections(); scheduled_inputs_are_stable_until_simulated(); std::puts("PASS cellular intent admission: authority, ordering and retry-stable schedule"); } catch (const std::exception& error) { std::fprintf(stderr, "%s\n", error.what()); return 1; } }