nx_billing_gate.nx source
↩ module page · 49 lines · 2800 B
1// nx_billing_gate.nx -- INDEPENDENT gate for time & billing (imports the SAME shipped
2// nx_billing_lib = atlas validation edge). Proves: per-matter time totals, matter isolation,
3// integer-cents exactness, RPC 1.15 fee application from trust, exact trust decrement,
4// NO-OVERDRAW refusal, and refused-leaves-trust-untouched. SELF-PUBLISHES
5// knowledge/status/office_billing_gate.log. license_tier: ORIGINAL
6
7import "nx_billing_lib.nx"
8
9func main() -> i64 {
10 var pass: i64 = 0
11 let bp: *u8 = "/tmp/nx_billing_gate-" as *u8
12 let tp: *u8 = "/tmp/nx_billing_gatetrust-" as *u8
13 trust_put(tp, "acme" as *u8, 0, "M-001" as *u8, "deposit" as *u8, 200000)
14 bl_time_put(bp, "M-001" as *u8, 0, 250, 30000, "research" as *u8)
15 bl_time_put(bp, "M-001" as *u8, 1, 100, 30000, "drafting" as *u8)
16 bl_time_put(bp, "M-002" as *u8, 0, 1000, 30000, "trial" as *u8)
17 // T1 matter total = sum of its time entries ($750 + $300 = $1050)
18 if bl_matter_total(bp, "M-001" as *u8) == 105000 { pass = pass + 1 }
19 // T2 per-matter isolation (M-002 tracked separately)
20 if bl_matter_total(bp, "M-002" as *u8) == 300000 { pass = pass + 1 }
21 // T3 integer-cents exactness (1.5h @ $333.33 = 150*33333/100 = 49999, no float drift)
22 let ep: *u8 = "/tmp/nx_billing_gateexact-" as *u8
23 bl_time_put(ep, "MX" as *u8, 0, 150, 33333, "x" as *u8)
24 if bl_matter_total(ep, "MX" as *u8) == 49999 { pass = pass + 1 }
25 // T4 RPC 1.15 fee application: trust covers the $1050 invoice -> applied
26 let applied: i64 = bl_bill_from_trust(bp, "acme" as *u8, "M-001" as *u8, tp, 1)
27 if applied == 105000 { pass = pass + 1 }
28 // T5 trust decremented by EXACTLY the invoice (fees moved trust->operating)
29 if trust_balance(tp, "acme" as *u8) == 95000 { pass = pass + 1 }
30 // T6 NO-OVERDRAW: M-002 $3000 > $950 remaining trust -> REFUSED
31 let m2: i64 = bl_bill_from_trust(bp, "acme" as *u8, "M-002" as *u8, tp, 2)
32 if m2 == 0 - 1 { pass = pass + 1 }
33 // T7 refused billing leaves trust UNTOUCHED (no partial disbursement)
34 if trust_balance(tp, "acme" as *u8) == 95000 { pass = pass + 1 }
35
36 let out: *u8 = sys_mmap(512)
37 var o: i64 = 0
38 o = mt_catcopy(out, o, "OFFICE-BILLING-GATE tests=7 pass=" as *u8)
39 o = mt_catn(out, o, pass)
40 o = mt_catcopy(out, o, " time-total+matter-isolation+integer-cents-exact+bill-from-trust+trust-decremented+no-overdraw-refused+refused-untouched VERDICT=" as *u8)
41 if pass == 7 { o = mt_catcopy(out, o, "GREEN" as *u8) }
42 if pass != 7 { o = mt_catcopy(out, o, "RED" as *u8) }
43 out[o] = 10 as u8
44 o = o + 1
45 ss_writefile("knowledge/status/office_billing_gate.log" as *u8, out, o)
46 sys_write(1, out, o)
47 if pass == 7 { return __syscall(93, 0, 0, 0, 0, 0, 0) }
48 return __syscall(93, 100 + pass, 0, 0, 0, 0, 0)
49}