"""Owned image transaction and rollback/crash boundaries; no actor loading or thaw.""" import subprocess import tempfile import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[2] class CubeImage(unittest.TestCase): def test_owner_authorized_terminal_release(self): with tempfile.TemporaryDirectory() as folder: exe=Path(folder)/'release' subprocess.run(['c++','-std=c++17','-fsanitize=address,undefined','-fno-sanitize-recover=all', '-I'+str(ROOT),str(ROOT/'tests/features/fixtures/cube_release_probe.cpp'),'-lsqlite3','-o',str(exe)],check=True) subprocess.run([str(exe),str(Path(folder)/'cube.db')],check=True) def test_durable_exact_live_image_ack(self): with tempfile.TemporaryDirectory() as folder: exe=Path(folder)/'ack' subprocess.run(['c++','-std=c++17','-fsanitize=address,undefined','-fno-sanitize-recover=all', '-I'+str(ROOT),str(ROOT/'tests/features/fixtures/cube_image_ack_probe.cpp'),'-lsqlite3','-o',str(exe)],check=True) subprocess.run([str(exe),str(Path(folder)/'cube.db')],check=True) def test_live_image_wire_and_exact_local_expectation(self): source=r''' #define main cubeBaseMain #include "tests/features/fixtures/cube_batch_probe.cpp" #undef main #include "src/server/common/cube_live_image.h" int main(){auto b=batch();const auto plan=SettlePlan(b,std::string("\1\144\1",3),proto);CraftReceipt receipt{plan.result,plan.successes,plan.fee,plan.awards}; std::string expected;assert(CraftImage(b,receipt,60,proto,expected));InventoryImage parsed;assert(DecodeInventoryImage(expected,parsed,proto)&&parsed.gold==760&&parsed.items.size()==3); auto identity=ArmFrame(b,8);identity.cookie=7;identity.body.clear();identity.message=Message::LiveImageRequest;assert(ValidHandshake(identity)&&EncodeHandshake(identity).size()==102&&!IsDbHandshakeReply(identity.message)&&IsDbHandshakeReply(Message::LiveImageAnswer)); LiveImageFlow flow;assert(!flow.Start(identity,b,receipt,60,proto,false)&&flow.Start(identity,b,receipt,60,proto,true));assert(flow.Request().message==Message::LiveImageRequest); auto reply=identity;reply.message=Message::LiveImageAnswer;reply.status=Status::LiveImageReady;reply.body=expected;auto stale=reply;stale.cookie++;assert(!flow.Answer(stale)&&flow.MayRetry()); assert(flow.Answer(reply)&&flow.State()==LiveImageFlow::Ready&&flow.Image()==expected&&flow.Answer(reply));parsed.gold++;reply.body=EncodeInventoryImage(parsed);assert(!flow.Answer(reply)&&flow.State()==LiveImageFlow::Held); auto nonok=receipt;nonok.result="gold_changed";assert(!CraftImage(b,nonok,0,proto,expected));assert(!CraftImage(b,receipt,uint64_t(PortEconomy::GoldLimit),proto,expected)); LiveImageFlow acknowledged;assert(acknowledged.Start(identity,b,receipt,60,proto,true));auto issued=identity;issued.message=Message::LiveImageAnswer;issued.status=Status::LiveImageReady;issued.body=acknowledged.Image();assert(acknowledged.Answer(issued)&&acknowledged.MarkApplied(issued.body)&&acknowledged.BeginAcknowledge(issued.body)); auto ack=acknowledged.Acknowledgement();const auto wire=EncodeHandshake(ack);Handshake decoded;assert(!wire.empty()&&DecodeHandshake(wire.data(),wire.size(),decoded)&&decoded.body==issued.body&&!IsDbHandshakeReply(ack.message));for(size_t n=0;n