code wiki / (root) / probe_blob_journal.nx

probe_blob_journal.nx source

↩ module page · 60 lines · 1807 B

1// probe_blob_journal.nx -- Verifies the functionality of blob store and journal log APIs in the Nishi sovereign ecosystem. 2// Minimal probe: verify blob_store + journal_log APIs 3import "nx_syscalls.nx" 4import "nx_blob_store.nx" 5import "nx_journal_log.nx" 6 7func main() -> i64 { 8 // Test blob store 9 let bs: *NxBlobStore = nx_blob_store_new() 10 11 // Put a simple byte string 12 let data: *u8 = sys_mmap(10) 13 data[0] = 72 14 data[1] = 105 15 data[2] = 0 16 17 let hash: *NxBlobHash = nx_blob_hash_new() 18 let rc_put: i64 = nx_blob_store_put(bs, data, 3, hash) 19 if rc_put != 0 { return 1 } 20 21 // Verify get works 22 let buf: *u8 = sys_mmap(10) 23 let rc_get: i64 = nx_blob_store_get(bs, hash, buf, 10) 24 if rc_get != 3 { return 2 } 25 if buf[0] != 72 { return 3 } 26 27 // Test journal log 28 let jl: *NxJournalLog = nx_journal_log_new(bs) 29 30 // Append an entry 31 let payload: *u8 = sys_mmap(5) 32 payload[0] = 70 33 payload[1] = 97 34 payload[2] = 99 35 payload[3] = 116 36 37 let seq: i64 = nx_journal_log_append(jl, payload, 4, 42) 38 if seq < 0 { return 4 } 39 40 // Read it back 41 let read_buf: *u8 = sys_mmap(10) 42 let read_schema: *i64 = sys_mmap(8) as *i64 43 let rc_read: i64 = nx_journal_log_read(jl, 0, read_buf, 10, read_schema) 44 if rc_read != 4 { return 5 } 45 if *read_schema != 42 { return 6 } 46 47 // Verify chain 48 let rc_verify: i64 = nx_journal_log_verify_chain(jl) 49 if rc_verify != -1 { return 7 } 50 51 // Get latest hash 52 let w0: *i64 = sys_mmap(8) as *i64 53 let w1: *i64 = sys_mmap(8) as *i64 54 let w2: *i64 = sys_mmap(8) as *i64 55 let w3: *i64 = sys_mmap(8) as *i64 56 let rc_latest: i64 = nx_journal_log_latest_hash(jl, w0, w1, w2, w3) 57 if rc_latest != 0 { return 8 } 58 59 return 0 60}