Files
aevolution/tests/cellular_intent_admission_tests.cpp
T
dingo c81c1bfc56
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m52s
Foundation / checks (client) (push) Failing after 4m25s
Foundation / checks (network) (push) Failing after 3m2s
Foundation / checks (tsan) (push) Failing after 33s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 5m47s
Foundation / checks (postgres) (push) Canceled after 1m24s
Format M11 cellular code with clang-format 19
2026-10-11 02:59:41 -04:00

124 lines
5.3 KiB
C++

#include "evo/network/intent_admission.hpp"
#include <cstdio>
#include <source_location>
#include <stdexcept>
#include <string>
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<bool>(__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());
}
void cellular_actions_keep_exact_retry_identity() {
IntentLimits limits;
limits.max_actions_per_window = 8;
auto made = IntentAdmission::create(limits);
CHECK(made);
auto queue = std::move(*made);
CHECK(queue.open(22, account(2)));
const AdmissionFacts facts{true, 7, 10};
const CellularAction action{22, 7, 77, 11, 500, 0, true, 1'000, 2'000};
CHECK(queue.admit(22, action, facts) ==
std::optional<ActionReceipt>{ActionReceipt{77, AdmitStatus::admitted, 10, 11}});
CHECK(queue.admit(22, action, facts) ==
std::optional<ActionReceipt>{ActionReceipt{77, AdmitStatus::duplicate, 10, 11}});
auto changed = action;
changed.move_x = 501;
CHECK(queue.admit(22, changed, facts) ==
std::optional<ActionReceipt>{ActionReceipt{77, AdmitStatus::invalid_action, 10, 11}});
const auto carried = queue.carry(11);
CHECK(carried.size() == 1 && carried.front().kind == ActionKind::cellular);
CHECK(carried.front().cellular_input ==
encode_cellular_action_input({11, 500, 0, true, 1'000, 2'000}));
const auto outcome = queue.committed(carried, 3);
CHECK(outcome.size() == 1 &&
outcome.front().outcome == ActionOutcome{77, ActionResult::committed, 11, 3});
CHECK(queue.admit(22, action, facts) ==
std::optional<ActionReceipt>{ActionReceipt{77, AdmitStatus::duplicate, 10, 11}});
CHECK(queue.admit(22, changed, facts) ==
std::optional<ActionReceipt>{ActionReceipt{77, AdmitStatus::invalid_action, 10, 11}});
}
} // namespace
int main() {
try {
admission_and_rejections();
scheduled_inputs_are_stable_until_simulated();
cellular_actions_keep_exact_retry_identity();
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;
}
}