nx_dms_catalog_store_gate.nx source
↩ module page · 47 lines · 2436 B
1// nx_dms_catalog_store_gate.nx -- durability gate for the media catalog.
2//
3// Build catalog (incl. a soft-removed asset) -> save -> reload into a FRESH
4// catalog (simulated restart) -> every record survived (count, talent/use,
5// soft-remove flag) AND the reloaded catalog still consent-gates against the
6// rights ledger, including revoke-after-reload.
7// Returns 0 iff durable + correct; nonzero pinpoints the first failure.
8
9import "nx_syscalls.nx"
10import "nx_rights_ledger.nx"
11import "nx_dms_catalog.nx"
12import "nx_dms_catalog_store.nx"
13
14func main() -> i64 {
15 let l: *NxRightsLedger = nx_rights_ledger_new(16)
16 let c: *NxDmsCatalog = nx_dms_catalog_new(16)
17
18 // licenses: 7 -> MERCH, 9 -> AD
19 if nx_rights_grant(l, 1, 7, NX_USE_MERCH, 1000, 10000) != NX_RL_OK { return 1 }
20 if nx_rights_grant(l, 2, 9, NX_USE_AD_CAMPAIGN, 1000, 10000) != NX_RL_OK { return 2 }
21
22 // catalog: 101 licensed, 102 unlicensed-use, 103 soft-removed, 104 unlicensed-talent
23 if nx_dms_catalog_add(c, 101, 7, NX_USE_MERCH, 11, 1500) != NX_DMS_OK { return 3 }
24 if nx_dms_catalog_add(c, 102, 7, NX_USE_WEB_GALLERY, 12, 1500) != NX_DMS_OK { return 4 }
25 if nx_dms_catalog_add(c, 103, 9, NX_USE_AD_CAMPAIGN, 13, 1500) != NX_DMS_OK { return 5 }
26 if nx_dms_catalog_add(c, 104, 8, NX_USE_MERCH, 14, 1500) != NX_DMS_OK { return 6 }
27 if nx_dms_catalog_remove(c, 103, 2000) != NX_DMS_OK { return 7 }
28
29 // SAVE then reload into a brand-new catalog
30 if nx_dms_catalog_save(c, "/tmp/nx_dms_cat-" as *u8, 1) != 0 { return 8 }
31 let c2: *NxDmsCatalog = nx_dms_catalog_load("/tmp/nx_dms_cat-" as *u8)
32
33 // all 4 rows survived (incl. the soft-removed one -- history sacred)
34 if nx_dms_catalog_count(c2) != 4 { return 9 }
35 // records survived -> consent gating still correct on the reloaded catalog
36 if nx_dms_is_visible(c2, l, 101, 5000) != 1 { return 10 } // licensed
37 if nx_dms_is_visible(c2, l, 102, 5000) != 0 { return 11 } // unlicensed use survived
38 if nx_dms_is_visible(c2, l, 103, 5000) != 0 { return 12 } // SOFT-REMOVE flag survived
39 if nx_dms_is_visible(c2, l, 104, 5000) != 0 { return 13 } // unlicensed talent survived
40 if nx_dms_count_visible(c2, l, 5000) != 1 { return 14 }
41
42 // revoke after reload -> consent still gates the reloaded catalog
43 if nx_rights_revoke(l, 1, 4000) != NX_RL_OK { return 15 }
44 if nx_dms_is_visible(c2, l, 101, 5000) != 0 { return 16 }
45
46 return 0
47}