Persist fed mutation offers in cellular v2
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 5m28s
Foundation / checks (checks) (push) Canceled after 7m39s
Foundation / checks (client) (push) Canceled after 7m39s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 5m28s
Foundation / checks (checks) (push) Canceled after 7m39s
Foundation / checks (client) (push) Canceled after 7m39s
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <source_location>
|
||||
#include <span>
|
||||
#include <stdexcept>
|
||||
@@ -152,6 +153,126 @@ void reserved_birth_is_funded_and_detached() {
|
||||
CellularLivesError::no_placement);
|
||||
}
|
||||
|
||||
void cellular_profile_migration_is_explicit_and_no_tick() {
|
||||
auto primitive = PrimitiveLives::create({91, 1, 1, 17, founder_price(1), {{0, 0}}});
|
||||
CHECK(primitive);
|
||||
LifeRequest request{};
|
||||
request.account.back() = 5;
|
||||
request.action = 1;
|
||||
CHECK((*primitive)->spawn(request, {1, 101, 201, 301, {1}}));
|
||||
auto habitat = evo::biology::CellularHabitat::create({91, 1, 1, 1'000, 1'000, {}});
|
||||
CHECK(habitat);
|
||||
auto created =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 1, 293'150});
|
||||
CHECK(created && (*created)->lives().size() == 1);
|
||||
auto current = std::move(*created);
|
||||
auto legacy_bytes = current->snapshot();
|
||||
legacy_bytes.erase(legacy_bytes.begin() + 220 + 168, legacy_bytes.begin() + 220 + 480);
|
||||
constexpr std::uint64_t legacy_magic = 0x3130564C43564541ULL;
|
||||
for (unsigned index = 0; index < 8; ++index)
|
||||
legacy_bytes[index] = static_cast<std::uint8_t>(legacy_magic >> (index * 8U));
|
||||
legacy_bytes[8] = 1;
|
||||
legacy_bytes[9] = legacy_bytes[10] = legacy_bytes[11] = 0;
|
||||
legacy_bytes[12] = 1;
|
||||
legacy_bytes[13] = legacy_bytes[14] = legacy_bytes[15] = 0;
|
||||
refresh_checksum(legacy_bytes);
|
||||
const auto legacy = CellularLives::restore(legacy_bytes, current->world(), current->region(),
|
||||
current->frame(), current->tick());
|
||||
CHECK(legacy && (*legacy)->format_version() == cellular_lives_legacy_format &&
|
||||
(*legacy)->rules_version() == 1 && (*legacy)->snapshot() == legacy_bytes &&
|
||||
(*legacy)->lives().size() == 1);
|
||||
const auto legacy_life_id = (*legacy)->lives()[0].identity.life;
|
||||
const std::array legacy_idle{CellularLifeIntent{legacy_life_id, {}}};
|
||||
CHECK((*legacy)->advance_tick(legacy_idle) &&
|
||||
(*legacy)->format_version() == cellular_lives_legacy_format &&
|
||||
(*legacy)->rules_version() == 1 && (*legacy)->tick() == 2);
|
||||
const auto before = (*legacy)->snapshot();
|
||||
const auto biological_state = (*legacy)->lives()[0];
|
||||
const auto migrated = (*legacy)->migrate_to_v2();
|
||||
CHECK(migrated && (*migrated)->format_version() == cellular_lives_format &&
|
||||
(*migrated)->rules_version() == cellular_lives_rules &&
|
||||
(*migrated)->tick() == (*legacy)->tick() &&
|
||||
(*migrated)->current_total() == (*legacy)->current_total() &&
|
||||
(*migrated)->lives().size() == 1 &&
|
||||
(*migrated)->lives()[0].account == biological_state.account &&
|
||||
(*migrated)->lives()[0].identity == biological_state.identity &&
|
||||
(*migrated)->lives()[0].source == biological_state.source &&
|
||||
(*migrated)->lives()[0].growth == biological_state.growth &&
|
||||
(*migrated)->lives()[0].position == biological_state.position &&
|
||||
(*migrated)->lives()[0].body == biological_state.body &&
|
||||
(*migrated)->lives()[0].reserve == biological_state.reserve &&
|
||||
(*migrated)->lives()[0].mutation == CellularMutationProgress{} &&
|
||||
(*legacy)->snapshot() == before && (*migrated)->snapshot() != before);
|
||||
const auto restored =
|
||||
CellularLives::restore((*migrated)->snapshot(), current->world(), current->region(),
|
||||
current->frame(), (*migrated)->tick());
|
||||
CHECK(restored && (*restored)->snapshot() == (*migrated)->snapshot());
|
||||
const auto migrated_life_id = (*migrated)->lives()[0].identity.life;
|
||||
const std::array migrated_idle{CellularLifeIntent{migrated_life_id, {}}};
|
||||
CHECK((*migrated)->advance_tick(migrated_idle) &&
|
||||
(*migrated)->format_version() == cellular_lives_format &&
|
||||
(*migrated)->rules_version() == cellular_lives_rules && (*migrated)->tick() == 3);
|
||||
}
|
||||
|
||||
void retained_feeding_earns_a_persistent_mutation_offer() {
|
||||
auto primitive = PrimitiveLives::create({93, 1, 1, 17, founder_price(1), {{0, 0}}});
|
||||
CHECK(primitive);
|
||||
LifeRequest request{};
|
||||
request.account.back() = 3;
|
||||
request.action = 1;
|
||||
CHECK((*primitive)->spawn(request, {1, 101, 201, 301, {1}}));
|
||||
Inventory patch_stock{{1'000'000'000'000ULL},
|
||||
{{{1'000'000'000'000ULL},
|
||||
{1'000'000'000'000ULL},
|
||||
{1'000'000'000'000ULL},
|
||||
{1'000'000'000'000ULL}}}};
|
||||
auto habitat = evo::biology::CellularHabitat::create(
|
||||
{93, 1, 1, 1'000, 1'000, {{{0, 0}, 29, patch_stock}}});
|
||||
CHECK(habitat);
|
||||
auto created =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 1, 293'150});
|
||||
CHECK(created && (*created)->lives().size() == 1 &&
|
||||
(*created)->lives()[0].mutation.fed_energy_credit_pj == 0);
|
||||
auto& owner = **created;
|
||||
const auto life_id = owner.lives()[0].identity.life;
|
||||
CHECK(owner.mutation_offer(life_id) && !*owner.mutation_offer(life_id));
|
||||
const auto founder = owner.archive().find(owner.lives()[0].identity.genome);
|
||||
CHECK(founder);
|
||||
const auto founder_budget = evo::biology::metabolic_budget(
|
||||
*founder, owner.lives()[0].growth, {owner.ambient_temperature_millikelvin(), {}});
|
||||
CHECK(founder_budget &&
|
||||
founder_budget->maintenance.value <=
|
||||
std::numeric_limits<std::uint64_t>::max() / cellular_mutation_surplus_seconds);
|
||||
const auto threshold = founder_budget->maintenance.value * cellular_mutation_surplus_seconds;
|
||||
std::uint64_t total_acquired{};
|
||||
bool offered = false;
|
||||
for (std::size_t step = 0; step < 10'000 && !offered; ++step) {
|
||||
const std::array intent{CellularLifeIntent{life_id, {{0, 0}, {{0, 0}}}}};
|
||||
const auto advanced = owner.advance_tick(intent);
|
||||
CHECK(advanced && advanced->lives.size() == 1 && advanced->lives[0].candidate.intake);
|
||||
const auto& intake = advanced->lives[0].candidate.intake.value();
|
||||
total_acquired += intake.transfer.acquired.energy.value;
|
||||
const auto offer = owner.mutation_offer(life_id);
|
||||
CHECK(offer);
|
||||
offered = offer->has_value();
|
||||
}
|
||||
CHECK(offered);
|
||||
const auto earned = owner.mutation_offer(life_id);
|
||||
CHECK(earned && *earned && (*earned)->candidates.size() <= cellular_mutation_candidate_count &&
|
||||
!(*earned)->candidates.empty() && owner.lives()[0].mutation.event_index == 1 &&
|
||||
owner.lives()[0].mutation.offer_tick == owner.tick() &&
|
||||
total_acquired == threshold + owner.lives()[0].mutation.fed_energy_credit_pj);
|
||||
const auto saved = owner.snapshot();
|
||||
const auto recovered = CellularLives::restore(saved, 93, 1, 1, owner.tick());
|
||||
CHECK(recovered && (*recovered)->snapshot() == saved);
|
||||
const auto replayed_offer = (*recovered)->mutation_offer(life_id);
|
||||
CHECK(replayed_offer && replayed_offer == earned);
|
||||
const std::array idle{CellularLifeIntent{life_id, {}}};
|
||||
CHECK(owner.advance_tick(idle));
|
||||
const auto after_tick = owner.mutation_offer(life_id);
|
||||
CHECK(after_tick && after_tick == earned);
|
||||
}
|
||||
|
||||
void owner_advances_and_closes_death_atomically() {
|
||||
auto primitive = PrimitiveLives::create({90, 1, 7, 17, founder_price(2), {{0, 0}, {20, 0}}});
|
||||
CHECK(primitive);
|
||||
@@ -197,6 +318,9 @@ void owner_advances_and_closes_death_atomically() {
|
||||
CHECK(fed && owner.tick() == 2 && owner.lives().size() == 2);
|
||||
CHECK(fed->lives.size() == 2 &&
|
||||
fed->lives[0].candidate.intake_status == evo::biology::CellularIntakeStatus::acquired);
|
||||
CHECK(owner.format_version() == cellular_lives_format &&
|
||||
owner.lives()[0].mutation.fed_energy_credit_pj > 0 &&
|
||||
owner.mutation_offer(first_life_id) && !*owner.mutation_offer(first_life_id));
|
||||
CHECK(owner.last_tick_feedback().size() == 2 &&
|
||||
owner.last_tick_feedback()[0].tick == owner.tick() &&
|
||||
owner.last_tick_feedback()[0].life_id == owner.lives()[0].identity.life &&
|
||||
@@ -315,6 +439,8 @@ void owner_advances_and_closes_death_atomically() {
|
||||
int main() {
|
||||
try {
|
||||
reserved_birth_is_funded_and_detached();
|
||||
cellular_profile_migration_is_explicit_and_no_tick();
|
||||
retained_feeding_earns_a_persistent_mutation_offer();
|
||||
owner_advances_and_closes_death_atomically();
|
||||
std::puts("PASS cellular lives: feeding, tick ownership and terminal closure");
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
Reference in New Issue
Block a user