Files
aevolution/tests/region_checkpoint_tests.cpp
T
dingo 50b6e25c0c
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
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 (checks) (push) Canceled after 2m3s
Foundation / checks (postgres) (push) Canceled after 1m48s
Foundation / checks (ecs) (push) Canceled after 1m53s
Fix cellular checkpoint migration expectation
2026-10-11 06:55:22 -04:00

535 lines
27 KiB
C++

#include "evo/persistence/region_checkpoint.hpp"
#include "fixtures/environmental_region.hpp"
#include <cstdio>
#include <source_location>
#include <stdexcept>
#include <string>
#include <string_view>
namespace {
using namespace evo::persistence;
using evo::test::advance_region;
using evo::test::region_community;
using evo::test::region_input;
void check(bool ok, std::source_location at = std::source_location::current()) {
if (!ok)
throw std::runtime_error("region checkpoint line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
template <std::size_t N> std::array<std::uint8_t, N> filled(std::uint8_t value) {
std::array<std::uint8_t, N> out{};
out.fill(value);
return out;
}
constexpr RegionKey key{7, 3};
const auto build = filled<32>(0xB1);
LeaseGrant lease() {
return {filled<16>(0x11), 4, 9, std::chrono::milliseconds{20000}};
}
CheckpointManifest genesis(std::uint64_t payload_bytes = 100) {
auto g =
genesis_manifest(key, 9, filled<16>(0x01), 50000, build, payload_bytes, filled<32>(0xA0));
CHECK(g);
return *g;
}
// Synthetic batch evidence of the right size for `ticks` (content is not checked here).
BatchDigests batch_for(std::uint64_t ticks, std::uint32_t decisions = 0) {
return {trace_bytes_for(ticks), filled<32>(0x7C), decisions,
decisions == 0 ? Sha256Digest{} : filled<32>(0x7D)};
}
CheckpointManifest next(std::uint64_t end_tick = 16) {
auto n = successor_manifest(genesis(), filled<32>(0xD0), filled<16>(0x02), lease(), end_tick,
build, 200, filled<32>(0xA1), batch_for(end_tick, 1));
CHECK(n);
return *n;
}
std::uint64_t at(const std::vector<std::uint8_t>& b, std::size_t offset, unsigned width) {
std::uint64_t value{};
for (unsigned i = 0; i < width; ++i)
value |= static_cast<std::uint64_t>(b[offset + i]) << (8U * i);
return value;
}
void layout_and_round_trip() {
const auto m = next();
auto bytes = encode_manifest(m);
CHECK(bytes && bytes->size() == checkpoint_manifest_bytes);
// Golden offsets from schemas/region-commit.md.
CHECK(std::string_view(reinterpret_cast<const char*>(bytes->data()), 8) == "AEVORCM1");
CHECK(at(*bytes, 8, 4) == 2 && at(*bytes, 12, 4) == 1);
CHECK(at(*bytes, 16, 8) == 7 && at(*bytes, 24, 8) == 3 && at(*bytes, 32, 8) == 9);
CHECK((*bytes)[40] == 0x02 && at(*bytes, 56, 8) == 1 && (*bytes)[64] == 0x01);
CHECK((*bytes)[80] == 0xD0 && at(*bytes, 112, 8) == 0 && at(*bytes, 120, 8) == 16);
CHECK((*bytes)[128] == 0x11 && at(*bytes, 144, 8) == 4 && at(*bytes, 152, 8) == 50000);
CHECK(at(*bytes, 160, 4) == 2 && at(*bytes, 164, 4) == 2 && at(*bytes, 192, 4) == 1);
CHECK((*bytes)[196] == 0xB1 && at(*bytes, 228, 4) == 0 && at(*bytes, 232, 4) == 0);
CHECK(at(*bytes, 236, 4) == 1 && at(*bytes, 240, 8) == 200 && (*bytes)[248] == 0xA1);
CHECK(at(*bytes, 8, 4) == 2 && at(*bytes, 280, 8) == trace_bytes_for(16));
CHECK((*bytes)[288] == 0x7C && at(*bytes, 320, 4) == 1 && at(*bytes, 324, 4) == 0);
CHECK((*bytes)[328] == 0x7D);
auto decoded = decode_manifest(*bytes);
CHECK(decoded && *decoded == m && supported(*decoded));
auto g = encode_manifest(genesis());
CHECK(g && decode_manifest(*g) == genesis());
}
void malformed_and_unsupported() {
auto bytes = *encode_manifest(next());
CHECK(decode_manifest(std::span{bytes}.first(359)).error() == CheckpointError::format);
// Version 1 (M7.4 commits) still decodes with no batch evidence; v2 is never
// written as v1 and v1 bytes cannot carry batch fields.
std::vector<std::uint8_t> v1(bytes.begin(), bytes.begin() + 280);
v1[8] = 1;
auto old = decode_manifest(v1);
CHECK(old && old->manifest_version == 1 && old->batch == BatchDigests{});
CHECK(!encode_manifest(*old));
auto stretched = bytes;
stretched[8] = 1;
CHECK(decode_manifest(stretched).error() == CheckpointError::format);
auto reserved = bytes;
reserved[324] = 1;
CHECK(decode_manifest(reserved).error() == CheckpointError::format);
auto grown = bytes;
grown.push_back(0);
CHECK(decode_manifest(grown).error() == CheckpointError::format);
auto magic = bytes;
magic[0] ^= 1U;
CHECK(decode_manifest(magic).error() == CheckpointError::format);
auto version = bytes;
version[8] = 3;
CHECK(decode_manifest(version).error() == CheckpointError::unsupported);
// Structurally invalid: zero world, 65-tick batch, oversized payload, zero digest.
for (const auto& [offset, value] :
{std::pair{16, 0}, std::pair{120, 65}, std::pair{242, 0x11}, std::pair{144, 0}}) {
auto b = bytes;
b[static_cast<std::size_t>(offset)] = static_cast<std::uint8_t>(value);
if (offset == 144)
std::fill_n(b.begin() + 144, 8, std::uint8_t{0}); // Epoch zero off genesis.
CHECK(decode_manifest(b).error() == CheckpointError::format);
}
auto sha = bytes;
std::fill_n(sha.begin() + 248, 32, std::uint8_t{0});
CHECK(decode_manifest(sha).error() == CheckpointError::format);
// Parsable but not admitted by this build: decode succeeds, supported() refuses.
// 13/237 make profile/durability 257: never truncated onto a supported value.
for (const std::size_t offset : {12U, 13U, 160U, 164U, 192U, 228U, 232U, 236U, 237U}) {
auto b = bytes;
b[offset] = static_cast<std::uint8_t>(b[offset] + 1);
auto d = decode_manifest(b);
CHECK(d && !supported(*d));
}
auto g = genesis();
g.holder = filled<16>(1);
CHECK(encode_manifest(g).error() == CheckpointError::format);
g = genesis();
g.end_tick = 1;
CHECK(encode_manifest(g).error() == CheckpointError::format);
CHECK(
!genesis_manifest(key, 9, filled<16>(1), 50000, build, 1024 * 1024 + 1, filled<32>(0xA0)));
CHECK(!genesis_manifest(key, 0, filled<16>(1), 50000, build, 1, filled<32>(0xA0)));
}
void successor_chain() {
const auto g = genesis();
const auto d = filled<32>(0xD0);
const auto payload = filled<32>(0xA1);
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 0, build, 1, payload, batch_for(1))
.error() == CheckpointError::chain);
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 65, build, 1, payload, batch_for(1))
.error() == CheckpointError::chain);
auto foreign = lease();
foreign.frame = 8;
CHECK(successor_manifest(g, d, filled<16>(2), foreign, 1, build, 1, payload, batch_for(1))
.error() == CheckpointError::chain);
CHECK(successor_manifest(g, d, g.commit, lease(), 1, build, 1, payload, batch_for(1)).error() ==
CheckpointError::format); // Reused commit identity.
auto old = g;
old.versions.rules = 1;
CHECK(successor_manifest(old, d, filled<16>(2), lease(), 1, build, 1, payload, batch_for(1))
.error() == CheckpointError::unsupported);
auto last = next();
last.sequence = ~std::uint64_t{0};
CHECK(successor_manifest(last, d, filled<16>(3), lease(), 17, build, 1, payload, batch_for(1))
.error() == CheckpointError::chain);
// Batch evidence must match the tick range: one trace step per tick.
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 2, build, 1, payload, batch_for(1))
.error() == CheckpointError::format);
auto untraced = batch_for(1);
untraced.trace_sha256 = {};
CHECK(
successor_manifest(g, d, filled<16>(2), lease(), 1, build, 1, payload, untraced).error() ==
CheckpointError::format);
auto unsigned_decisions = batch_for(1, 1);
unsigned_decisions.decisions_sha256 = {};
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 1, build, 1, payload, unsigned_decisions)
.error() == CheckpointError::format);
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 1, build, 1, payload, batch_for(1, 9))
.error() == CheckpointError::format);
const auto n = next(64);
CHECK(n.sequence == 1 && n.predecessor_commit == g.commit && n.predecessor_digest == d);
CHECK(n.begin_tick == 0 && n.holder == lease().holder && n.epoch == 4 && n.frame == 9);
}
void payload_validation_and_restored_trajectory() {
const RegionKey region{evo::test::region_identity.world, 3};
auto original = region_community();
auto opening = original->snapshot();
CHECK(opening);
auto g = genesis_manifest(region, evo::test::region_identity.frame, filled<16>(1), 50000, build,
opening->size(), filled<32>(0xA0));
CHECK(g && restore_environmental_payload(*opening, *g, 8000000));
advance_region(*original, 16);
auto payload = original->snapshot();
CHECK(payload);
auto lease_at_frame = lease();
lease_at_frame.frame = evo::test::region_identity.frame;
auto m = successor_manifest(*g, filled<32>(0xD0), filled<16>(2), lease_at_frame, 16, build,
payload->size(), filled<32>(0xA1), batch_for(16));
CHECK(m);
auto restored = restore_environmental_payload(*payload, *m, 8000000);
CHECK(restored);
// The restored checkpoint continues exactly like the uninterrupted original.
for (std::uint64_t tick = 17; tick <= 40; ++tick) {
auto a = original->advance(tick, region_input(tick, true));
auto b = (*restored)->advance(tick, region_input(tick, true));
CHECK(a && b && *a == *b);
}
CHECK(original->snapshot() == (*restored)->snapshot());
const auto refused = [&](auto change, CheckpointError error) {
auto bytes = *payload;
auto manifest = *m;
change(bytes, manifest);
auto r = restore_environmental_payload(bytes, manifest, 8000000);
return !r && r.error() == error;
};
CHECK(refused(
[](auto&, auto& x) {
x.end_tick = 15;
x.batch = batch_for(15);
},
CheckpointError::payload));
CHECK(refused([](auto&, auto& x) { x.key.world = 8; }, CheckpointError::payload));
CHECK(refused([](auto&, auto& x) { x.frame = 10; }, CheckpointError::payload));
CHECK(refused([](auto&, auto& x) { x.tick_microseconds = 25000; }, CheckpointError::payload));
CHECK(refused([](auto&, auto& x) { --x.payload_bytes; }, CheckpointError::payload));
CHECK(refused([](auto& b, auto&) { b[b.size() / 2] ^= 1U; }, CheckpointError::payload));
CHECK(refused([](auto&, auto& x) { x.versions.rules = 1; }, CheckpointError::unsupported));
CHECK(refused([](auto&, auto& x) { x.rng_streams = 1; }, CheckpointError::unsupported));
CHECK(refused([](auto&, auto& x) { x.history_profile = 1; }, CheckpointError::unsupported));
CHECK(refused([](auto& b, auto&) { b[8] = 1; }, CheckpointError::unsupported));
CHECK(!restore_environmental_payload(*payload, *m, 1000)); // Budget still charged.
}
void lineage_profile() {
// The SQL parser hard-codes this cap (migrations/0004_lineage_profile.sql).
static_assert(max_lineage_payload_bytes == 4268144);
static_assert(max_payload_bytes(CheckpointProfile::unknown) == 0);
const RegionKey region{evo::test::region_identity.world, 5};
auto state = evo::test::lineage_region();
auto opening = state->snapshot();
CHECK(opening);
auto g = genesis_manifest(region, evo::test::region_identity.frame, filled<16>(1), 50000, build,
opening->size(), filled<32>(0xA0),
CheckpointProfile::environmental_lineage_v1);
CHECK(g && g->history_profile == 1 && supported(*g));
auto bytes = encode_manifest(*g);
CHECK(bytes && at(*bytes, 12, 4) == 2 && at(*bytes, 232, 4) == 1);
CHECK(decode_manifest(*bytes) == *g);
// Profile and history profile travel together.
auto mixed = *g;
mixed.history_profile = 0;
CHECK(!supported(mixed));
mixed = genesis();
mixed.history_profile = 1;
CHECK(!supported(mixed));
// Per-profile payload caps are structural.
CHECK(!genesis_manifest(region, 9, filled<16>(1), 50000, build, (1024 * 1024) + 1,
filled<32>(0xA0)));
CHECK(genesis_manifest(region, 9, filled<16>(1), 50000, build, (1024 * 1024) + 1,
filled<32>(0xA0), CheckpointProfile::environmental_lineage_v1));
CHECK(!genesis_manifest(region, 9, filled<16>(1), 50000, build, 4268145, filled<32>(0xA0),
CheckpointProfile::environmental_lineage_v1));
auto restored = restore_lineage_payload(*opening, *g, 8000000);
CHECK(restored && (*restored)->archive().recorded() == 3);
CHECK(restore_environmental_payload(*opening, *g, 8000000).error() ==
CheckpointError::unsupported);
auto plain = evo::test::region_community()->snapshot();
auto env =
genesis_manifest(region, 9, filled<16>(1), 50000, build, plain->size(), filled<32>(0xA0));
CHECK(restore_lineage_payload(*plain, *env, 8000000).error() == CheckpointError::unsupported);
// Successors inherit the profile; a lineage batch with a death restores exactly.
evo::test::advance_lineage(*state, 24, true);
auto payload = state->snapshot();
auto lease_at_frame = lease();
lease_at_frame.frame = evo::test::region_identity.frame;
auto m = successor_manifest(*g, filled<32>(0xD0), filled<16>(2), lease_at_frame, 24, build,
payload->size(), filled<32>(0xA1), batch_for(24));
CHECK(m && m->profile == CheckpointProfile::environmental_lineage_v1 &&
m->history_profile == 1);
auto later = restore_lineage_payload(*payload, *m, 8000000);
CHECK(later && !(*later)->archive().organism(11)->alive);
auto wrong_tick = *m;
wrong_tick.end_tick = 23;
wrong_tick.batch = batch_for(23);
CHECK(restore_lineage_payload(*payload, wrong_tick, 8000000).error() ==
CheckpointError::payload);
auto nested = *payload;
nested[64] = 1; // Nested envelope format 1 is not this profile's envelope.
CHECK(restore_lineage_payload(nested, *m, 8000000).error() == CheckpointError::unsupported);
}
// ADR-0067 clone genesis: sequence 0 at the source tick, naming its origin.
void clone_genesis() {
const auto source = next(16);
const auto digest = filled<32>(0xD1);
const RegionKey target{8, 3};
const BatchDigests inherited{0, {}, 1, filled<32>(0x7E)};
auto c =
clone_manifest(source, digest, target, filled<16>(0x05), 300, filled<32>(0xA5), inherited);
CHECK(c && c->sequence == 0 && c->key == target && c->frame == source.frame);
CHECK(c->begin_tick == 16 && c->end_tick == 16 && c->predecessor_commit == source.commit);
CHECK(c->predecessor_digest == digest && c->epoch == 0 && c->holder == Uuid{});
CHECK(c->versions == source.versions && c->profile == source.profile &&
c->tick_microseconds == source.tick_microseconds && c->build == source.build);
auto bytes = encode_manifest(*c);
CHECK(bytes && decode_manifest(*bytes) == *c && supported(*c));
// A successor chains from the clone exactly as from any genesis.
auto after = successor_manifest(*c, filled<32>(0xD2), filled<16>(0x06), lease(), 20, build, 1,
filled<32>(0xA6), batch_for(4));
CHECK(after && after->sequence == 1 && after->begin_tick == 16 && after->key == target);
// Isolation and shape: another world, a fresh commit, no trace, bounded outcomes.
CHECK(
clone_manifest(source, digest, {7, 4}, filled<16>(5), 300, filled<32>(0xA5), {}).error() ==
CheckpointError::chain);
CHECK(
clone_manifest(source, digest, target, source.commit, 300, filled<32>(0xA5), {}).error() ==
CheckpointError::chain);
CHECK(clone_manifest(source, digest, target, filled<16>(5), 300, filled<32>(0xA5),
{trace_bytes_for(1), filled<32>(1), 0, {}})
.error() == CheckpointError::chain);
CHECK(
clone_manifest(source, digest, target, filled<16>(5), 300, filled<32>(0xA5), {0, {}, 1, {}})
.error() == CheckpointError::format);
CHECK(clone_manifest(source, digest, target, filled<16>(5), 300, filled<32>(0xA5),
{0, {}, 9, filled<32>(1)})
.error() == CheckpointError::format);
CHECK(clone_manifest(source, {}, target, filled<16>(5), 300, filled<32>(0xA5), {}).error() ==
CheckpointError::format);
auto old = source;
old.versions.rules = 1;
CHECK(clone_manifest(old, digest, target, filled<16>(5), 300, filled<32>(0xA5), {}).error() ==
CheckpointError::unsupported);
// A provisioned genesis still starts at tick 0 with no origin or outcomes.
auto g = genesis();
g.batch = inherited;
CHECK(encode_manifest(g).error() == CheckpointError::format);
// Manifest v1 never carried an origin.
auto v1 = *c;
v1.manifest_version = 1;
v1.batch = {};
CHECK(encode_manifest(v1).error() == CheckpointError::format);
// Half an origin is malformed.
auto half = *c;
half.predecessor_commit = {};
CHECK(encode_manifest(half).error() == CheckpointError::format);
}
void primitive_profile() {
using namespace evo::server;
const auto endowment = evo::biology::primitive_endowment();
CHECK(endowment);
auto funding = endowment->body;
funding.energy.value = endowment->reserve.energy.value + endowment->construction.value;
auto state = PrimitiveLives::create({7, 3, 9, 1, funding, {{0, 0}}});
CHECK(state);
const auto opening = (*state)->snapshot();
auto g = genesis_manifest(key, 9, filled<16>(1), 50000, build, opening.size(), filled<32>(2),
CheckpointProfile::primitive_lives_v1);
CHECK(g && supported(*g) && g->history_profile == primitive_history_profile &&
g->versions == primitive_v1_versions);
CHECK(restore_primitive_payload(opening, *g));
CHECK(decode_manifest(*encode_manifest(*g)) == *g);
CHECK(!restore_environmental_payload(opening, *g, 8000000));
CHECK(!restore_lineage_payload(opening, *g, 8000000));
CHECK(!clone_manifest(*g, filled<32>(1), {8, 3}, filled<16>(3), opening.size(), filled<32>(2),
{}));
LifeRequest r{filled<16>(4), 1};
CHECK((*state)->spawn(r, {12, 12, 12, 12, {5}}));
const auto born = (*state)->snapshot();
auto n = successor_manifest(
*g, filled<32>(3), filled<16>(2), lease(), 5, build, born.size(), filled<32>(4),
{primitive_batch_header_bytes + primitive_birth_bytes, filled<32>(5), 0, {}});
CHECK(n && supported(*n));
CHECK(restore_primitive_payload(born, *n));
const auto invalid = [&](auto mutate, CheckpointError error) {
auto changed = *n;
mutate(changed);
const auto result = restore_primitive_payload(born, changed);
CHECK(!result && result.error() == error);
};
invalid([](auto& m) { m.end_tick = 4; }, CheckpointError::payload);
invalid([](auto& m) { m.key.region = 99; }, CheckpointError::payload);
invalid([](auto& m) { m.frame = 99; }, CheckpointError::payload);
invalid([](auto& m) { --m.payload_bytes; }, CheckpointError::payload);
invalid([](auto& m) { ++m.versions.envelope; }, CheckpointError::unsupported);
invalid([](auto& m) { m.history_profile = 1; }, CheckpointError::unsupported);
invalid([](auto& m) { m.tick_microseconds = 100000; }, CheckpointError::format);
invalid([](auto& m) { ++m.batch.trace_bytes; }, CheckpointError::format);
invalid([](auto& m) { m.batch.trace_bytes = 0; }, CheckpointError::format);
invalid(
[](auto& m) { m.batch.trace_bytes = max_primitive_batch_bytes + primitive_birth_bytes; },
CheckpointError::format);
invalid(
[](auto& m) {
m.batch.decision_count = 1;
m.batch.decisions_sha256 = filled<32>(6);
},
CheckpointError::format);
auto forged_genesis = *g;
forged_genesis.payload_bytes = born.size();
CHECK(!restore_primitive_payload(born, forged_genesis));
// An idle checkpoint preserves biology while the manifest advances its clock.
auto idle =
successor_manifest(*n, filled<32>(6), filled<16>(3), lease(), 10, build, born.size(),
filled<32>(4), {primitive_batch_header_bytes, filled<32>(7), 0, {}});
CHECK(idle && restore_primitive_payload(born, *idle));
auto mismatched_ids = PrimitiveLives::create({7, 3, 9, 1, funding, {{0, 0}}});
CHECK(mismatched_ids && (*mismatched_ids)->spawn(r, {12, 13, 14, 15, {5}}));
CHECK(!restore_primitive_payload((*mismatched_ids)->snapshot(), *n));
}
void cellular_profile() {
using namespace evo::biology;
using namespace evo::server;
auto endowment = primitive_endowment();
CHECK(endowment);
auto funding = endowment->body;
funding.energy.value = endowment->reserve.energy.value + endowment->construction.value;
auto primitive = PrimitiveLives::create({7, 3, 9, 17, funding, {{0, 0}}});
CHECK(primitive);
auto habitat = CellularHabitat::create({7, 3, 9, 1'000, 1'000, {}});
CHECK(habitat);
auto owner =
CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
CHECK(owner && (*owner)->lives().empty() && (*owner)->tick() == 0);
const auto payload = (*owner)->snapshot();
auto manifest = genesis_manifest(key, 9, filled<16>(0x02), 50000, build, payload.size(),
filled<32>(0xA2), CheckpointProfile::cellular_lives_v1);
CHECK(manifest);
manifest->cellular_versions = cellular_v2_versions;
CHECK(manifest && supported(*manifest) &&
manifest->history_profile == cellular_history_profile &&
manifest->cellular_versions == cellular_v2_versions &&
max_payload_bytes(CheckpointProfile::cellular_lives_v1) == max_cellular_lives_bytes);
const auto encoded = encode_manifest(*manifest);
CHECK(encoded && decode_manifest(*encoded) == *manifest);
const auto restored = restore_cellular_payload(payload, *manifest);
CHECK(restored && (*restored)->snapshot() == payload);
auto mismatched_bundle = *manifest;
mismatched_bundle.cellular_versions = cellular_v1_versions;
CHECK(!restore_cellular_payload(payload, mismatched_bundle));
CHECK(!restore_primitive_payload(payload, *manifest));
const auto successor =
successor_manifest(*manifest, filled<32>(0xA5), filled<16>(0x04), lease(), 1, build,
payload.size(), filled<32>(0xA6), batch_for(1, 1));
CHECK(successor && supported(*successor) &&
successor->cellular_versions == cellular_v2_versions);
auto short_cellular_trace = *successor;
short_cellular_trace.batch.trace_bytes =
cellular_batch_header_bytes + cellular_batch_tick_header_bytes - 1;
CHECK(!encode_manifest(short_cellular_trace));
auto legacy_cellular_trace = *successor;
legacy_cellular_trace.batch.trace_bytes = cellular_batch_header_bytes + sizeof(std::uint32_t);
CHECK(encode_manifest(legacy_cellular_trace));
auto large_cellular_trace = *successor;
large_cellular_trace.batch.trace_bytes =
cellular_batch_header_bytes + cellular_batch_tick_header_bytes +
max_cellular_tick_lives * cellular_batch_intent_bytes + 1;
CHECK(!encode_manifest(large_cellular_trace));
const auto clone = clone_manifest(*manifest, filled<32>(0xA3), {8, 3}, filled<16>(0x03),
payload.size(), filled<32>(0xA4), {});
CHECK(!clone && clone.error() == CheckpointError::unsupported);
auto bad_versions = *manifest;
++bad_versions.cellular_versions.archive;
CHECK(!supported(bad_versions));
CHECK(!restore_cellular_payload(payload, bad_versions));
const auto legacy_genesis =
genesis_manifest(key, 9, filled<16>(0x10), 50000, build, payload.size(), filled<32>(0x11),
CheckpointProfile::cellular_lives_v1);
CHECK(legacy_genesis);
const auto legacy_head =
successor_manifest(*legacy_genesis, filled<32>(0x12), filled<16>(0x13), lease(), 1, build,
payload.size(), filled<32>(0x14), batch_for(1, 1));
CHECK(legacy_head && legacy_head->cellular_versions == cellular_v1_versions);
const auto migration =
cellular_profile_migration_manifest(*legacy_head, filled<32>(0x15), filled<16>(0x16),
lease(), build, payload.size(), filled<32>(0x17));
CHECK(migration && supported(*migration) && migration->sequence == 2 &&
migration->begin_tick == 1 && migration->end_tick == 1 &&
migration->cellular_versions == cellular_v2_versions &&
migration->batch == BatchDigests{});
const auto migration_bytes = encode_manifest(*migration);
CHECK(migration_bytes && decode_manifest(*migration_bytes) == *migration);
const auto direct_revision_migration = cellular_profile_migration_manifest(
*migration, filled<32>(0x18), filled<16>(0x19), lease(), build, payload.size(),
filled<32>(0x20));
CHECK(direct_revision_migration && supported(*direct_revision_migration) &&
direct_revision_migration->history_profile == cellular_revision_history_profile &&
direct_revision_migration->cellular_versions == cellular_v3_versions);
const auto after_migration =
successor_manifest(*migration, filled<32>(0x21), filled<16>(0x22), lease(), 2, build,
payload.size(), filled<32>(0x23), batch_for(1, 1));
CHECK(after_migration && after_migration->cellular_versions == cellular_v2_versions);
const auto revision_migration =
cellular_profile_migration_manifest(*after_migration, filled<32>(0x24), filled<16>(0x25),
lease(), build, payload.size(), filled<32>(0x26));
CHECK(revision_migration && supported(*revision_migration) &&
revision_migration->history_profile == cellular_revision_history_profile &&
revision_migration->cellular_versions == cellular_v3_versions &&
revision_migration->begin_tick == after_migration->end_tick &&
revision_migration->end_tick == after_migration->end_tick &&
revision_migration->batch == BatchDigests{});
const auto revision_migration_bytes = encode_manifest(*revision_migration);
CHECK(revision_migration_bytes &&
decode_manifest(*revision_migration_bytes) == *revision_migration);
const auto after_revision_migration = successor_manifest(
*revision_migration, filled<32>(0x27), filled<16>(0x28), lease(),
revision_migration->end_tick + 1, build, payload.size(), filled<32>(0x29), batch_for(1, 1));
CHECK(after_revision_migration &&
after_revision_migration->cellular_versions == cellular_v3_versions &&
after_revision_migration->history_profile == cellular_revision_history_profile);
auto bad_identity = *manifest;
bad_identity.key.region = 4;
const auto wrong_identity = restore_cellular_payload(payload, bad_identity);
CHECK(!wrong_identity && wrong_identity.error() == CheckpointError::payload);
auto wrong_length = *manifest;
++wrong_length.payload_bytes;
const auto length_result = restore_cellular_payload(payload, wrong_length);
CHECK(!length_result && length_result.error() == CheckpointError::payload);
}
} // namespace
int main() {
try {
layout_and_round_trip();
malformed_and_unsupported();
successor_chain();
payload_validation_and_restored_trajectory();
lineage_profile();
clone_genesis();
primitive_profile();
cellular_profile();
std::puts("region checkpoint contracts passed");
return 0;
} catch (const std::exception& e) {
std::fprintf(stderr, "%s\n", e.what());
return 1;
}
}