wallet-kit / dist / selftest.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import { $APP, shadow$provide } from "./shared.js";
import "./paylink.js";
import "./index.js";
var X=function(a,b){if(!$APP.h(a))throw Error("wallet-kit self-test FAILED: "+$APP.v(b));},yc=function(){if(typeof globalThis.localStorage==="undefined"){var a=new Map;globalThis.localStorage=function(){return{getItem:function(b){b=a.get(b);return b===void 0?null:b},setItem:function(b,c){a.set(b,c)},removeItem:function(b){a.delete(b)}}}()}},Y=function(a){return a.publicKeyB64},Z=function(a,b){return a.balances()[b]},zc=function(a,b,c,d){return $APP.sb().then(function(e){X($APP.Ka.test(e.pre),"hashlock preimage is well shaped");
return $APP.tb(e.pre,e.hash).then(function(f){return $APP.tb(e.hash,e.hash).then(function(m){return $APP.tb(null,e.hash).then(function(p){X(f,"the preimage opens its own digest");X($APP.r(m),"a wrong preimage does not");X($APP.r(p),"and a malformed one is false, not a throw");return $APP.Eb(b,function(){var g={};g.cur=d;g.amt=100;g.to=Y(c);g.seq=1;g.hash=e.hash;g.ctx="selftest:match";return g}()).then(function(g){return $APP.Fb(g,null).then(function(k){X(k!=null,"the lock verifies");X($APP.cb(g,null)==
null,"and a lock is never readable as a payment order");return $APP.Gb(a,g,{seq:"selftest-claim-1"}).then(function(q){return $APP.Hb(q,Y(a),null).then(function(n){return $APP.Hb(q,Y(c),null).then(function(l){return $APP.Ib(c,function(){var x={};x.cur=d;x.lh="selftest-lock-entry";return x}()).then(function(x){return $APP.Jb(x,Y(c),null).then(function(t){return $APP.Jb(x,Y(b),null).then(function(u){X(n!=null,"the lock receipt verifies");X(l==null,"a receipt expected from another bank is rejected");
X(t!=null,"the beneficiary's release verifies");X(u==null,"a release expected from another party is rejected")})})})})})})})})})})})})};export const runWalletKitSelfTest=function(){return Promise.resolve(null).then(function(){yc();X($APP.K("~.GAZ"),"neutral unit recognised");X($APP.r($APP.M("~.GAZ")),"neutral unit is not payable");X($APP.Oa("~.GAZ").banker==="~","neutral unit still parses");return $APP.z.fromSeed($APP.z.newSeed()).then(function(a){return $APP.z.fromSeed($APP.z.newSeed()).then(function(b){return $APP.z.fromSeed($APP.z.newSeed()).then(function(c){var d=""+$APP.v(Y(a))+".LEI",e=new $APP.xc(Y(b)),f=new $APP.xc(Y(c)),
m=new $APP.xc(Y(a));X($APP.P(d)===Y(a),"banker parsed");X(e.nextSeq(d)===1,"the first sequence is 1");return $APP.ib(c,function(){var p={};p.cur=d;p.amt=250;p.tox=Y(c);p.memo="cafea";return p}()).then(function(p){return $APP.Ca($APP.za(p)).then(function(g){X(g!=null&&g.amt===250&&g.memo==="cafea"&&g.to===Y(c),"pay link round trip");g=Object.assign({},p);g.amt=999;return $APP.ya(g,void 0).then(function(k){X(k==null,"tampered request rejected");return $APP.jb(b,function(){var q={};q.cur=d;q.amt=250;
q.to=Y(c);q.seq=e.nextSeq(d);return q}()).then(function(q){return e.addOrder(q).then(function(n){X(n===1,"order recorded and persisted");X(Z(e,d).settled===0,"a pending order settles nothing");X(Z(e,d).held===250&&Z(e,d).available===-250,"a pending order holds");X(e.nextSeq(d)===2,"the sequence advances");return $APP.ob(a,q,{seq:"log-1"}).then(function(l){return $APP.pb(l,Y(a),void 0).then(function(x){return $APP.pb(l,Y(c),void 0).then(function(t){X(x!=null,"receipt verifies");X(t==null,"a receipt replayed under another bank is rejected");
return e.applyReceipt(l).then(function(u){return e.applyReceipt(l).then(function(Fa){X(u===1,"receipt folds and persists");X(Fa===0,"receipt fold is idempotent");X(Z(e,d).settled===-250&&Z(e,d).held===0,"settlement moves held into settled");X(e.pendingOrders().length===0,"a settled order leaves the pending list");return $APP.qb(a,function(){var E={};E.cur=d;E.seq=1;E.to=Y(b);E.amt=40;E.h="selftest-mint-1";return E}()).then(function(E){return $APP.rb(E,Y(a),void 0).then(function(kb){return $APP.rb(E,
Y(c),void 0).then(function(Ga){return e.applyIssuance(E).then(function(lb){return e.applyIssuance(E).then(function(da){return f.applyReceipt(l).then(function(){return zc(a,b,c,d).then(function(){X(kb!=null,"issuance receipt verifies");X(Ga==null,"an issuance expected from another bank is rejected");X(lb===1,"issuance folds and persists");X(da===0,"issuance fold is idempotent");X(Z(e,d).settled===-210,"a mint credits the recipient: -250 + 40");X(Z(f,d).settled===250,"the payee is credited by the same receipt");
X(Z(f,d).settledExact===BigInt(250),"and the exact fold agrees with the Number");return m.importJson(f.exportJson()).then(function(ea){X(ea===0,"another identity's exported ledger is refused");ea=f.exportJson();f.prune(function(){return!1});X(f.receipts().length===0,"prune is the only deletion, and it deleted");return f.importJson(ea).then(function(Ha){X(Ha===1,"export/import round trip");console.info("✅ wallet-kit self-test passed")})})})})})})})})})})})})})})})})})})})})})})})};

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/wallet-kit.git