38 lines
3.0 KiB
C++
38 lines
3.0 KiB
C++
// Synthetic: native petition requests -> Tortoise bodies, charter identity inverse, rename response.
|
|
#include "gateway/guild_notifications.hpp"
|
|
#include <cassert>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
template<class F>static void rejects(F f){bool r=false;try{f();}catch(const Error&){r=true;}assert(r);}
|
|
static Bytes raw(uint64_t lo,uint64_t hi){Bytes b;le(b,lo,8);le(b,hi,8);return b;}
|
|
int main(){
|
|
const uint64_t source_item=(uint64_t(0x40000000)<<32)|777;
|
|
const Bytes charter=raw(777,uint64_t(3)<<58);
|
|
const Bytes vendor=raw(0x1234,0x5678);
|
|
const uint64_t vendor_legacy=0xF130000000000042ull;
|
|
auto npc=[&](const Bytes& g)->uint64_t{return g==vendor?vendor_legacy:0;};
|
|
assert(legacy_charter_item(charter)==source_item);
|
|
assert(!legacy_charter_item(raw(777,0)) && !legacy_charter_item(raw(0,uint64_t(3)<<58)) && !legacy_charter_item(raw(1ull<<32,uint64_t(3)<<58)));
|
|
auto one=[&](uint32_t op,const Bytes& body){return source_petition_request(op,body,npc);};
|
|
{Bytes b=pack_guid(vendor);auto s=one(0x3f005e,b);assert(s && s->opcode==0x1bb);Reader r(s->body);assert(r.le(8)==vendor_legacy);r.end();}
|
|
{Bytes b{uint8_t(5<<1)};append(b,pack_guid(vendor));le(b,0,4);b.insert(b.end(),{'G','u','i','l','d'});
|
|
auto s=one(0x3f005f,b);assert(s && s->opcode==0x1bd);Reader r(s->body);assert(r.le(8)==vendor_legacy && r.le(4)==0 && r.le(8)==0 && r.cstring(64)=="Guild");
|
|
for(int i=0;i<10;++i)assert(r.le(4)==0);assert(r.le(2)==0 && r.le(1)==0 && r.le(4)==1 && r.le(4)==0);r.end();}
|
|
{auto s=one(0x3f0060,pack_guid(charter));assert(s && s->opcode==0x1be);Reader r(s->body);assert(r.le(8)==source_item);r.end();}
|
|
{Bytes b;le(b,55,4);append(b,pack_guid(charter));auto s=one(0x3e014b,b);assert(s && s->opcode==0x1c6);Reader r(s->body);assert(r.le(4)==55 && r.le(8)==source_item);r.end();}
|
|
{Bytes b=pack_guid(charter);b.push_back(1);auto s=one(0x3f00d8,b);assert(s && s->opcode==0x1c0);Reader r(s->body);assert(r.le(8)==source_item && r.le(1)==1);r.end();}
|
|
{auto s=one(0x3f00d9,pack_guid(charter));assert(s && s->opcode==0x1c2);}
|
|
{auto s=one(0x3f00da,pack_guid(charter));assert(s && s->opcode==0x1c4);}
|
|
{Bytes b=pack_guid(charter);b.push_back(uint8_t(3<<1));b.insert(b.end(),{'N','e','w'});
|
|
auto s=one(0x4400f8,b);assert(s && s->opcode==0x2c1);Reader r(s->body);assert(r.le(8)==source_item && r.cstring(64)=="New");r.end();}
|
|
// Holds and rejects: unknown vendor, foreign item identity, trailing bytes.
|
|
assert(!one(0x3f005e,pack_guid(raw(9,9))));
|
|
assert(!one(0x3f0060,pack_guid(raw(777,0))));
|
|
{auto b=pack_guid(charter);b.push_back(0);rejects([&]{one(0x3f00d9,b);});}
|
|
// Rename response: Source {u64 item, cstring} -> native {Guid, bits7, name}.
|
|
Bytes src;le(src,source_item,8);src.insert(src.end(),{'N','e','w',0});
|
|
auto resp=petition_notification(0x2c1,src,70,{});assert(resp && resp->opcode==0x530041);
|
|
{Reader r(resp->body);assert(unpack_guid(r,16)==charter && r.le(1)==(3u<<1));auto n=r.take(3);assert(std::string(n.begin(),n.end())=="New");r.end();}
|
|
std::cout<<"petition requests PASS\n";
|
|
}
|