From 1114f5f72fe08248de56367f1a1786706cb7c9ba Mon Sep 17 00:00:00 2001 From: root Date: Mon, 20 Jul 2026 01:34:52 +0200 Subject: [PATCH] docs: add insurance_pool crate test targets and storage layout (refs #407-420) --- CONTRIBUTING.md | 4 +++- docs/storage-layout.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6be6c966..815fdcd4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -308,10 +308,11 @@ cargo test -p invoice_liquidity cargo test -p iln_governance cargo test -p iln_distribution cargo test -p reputation_bonus +cargo test -p insurance_pool # Useful flags cargo test -p invoice_liquidity -- --nocapture # show stdout -cargo test -p invoice_liquidity test_name # filter by name +cargo test -p insurance_pool test_name # filter by name ``` Tests run on your native architecture via `soroban-sdk` test utilities — no WASM build needed. @@ -416,6 +417,7 @@ Closes #101 - [ ] `cargo clippy --all-targets -- -D warnings` — zero warnings - [ ] `cargo test` — all tests pass - [ ] `cargo test -p iln_fuzz` — fuzz suite passes +- [ ] `cargo test -p insurance_pool` — insurance pool tests pass - [ ] Coverage ≥ 95 % if `invoice_liquidity` was modified - [ ] New behaviour is covered by tests - [ ] `cargo build-wasm` succeeds (required for any contract change) diff --git a/docs/storage-layout.md b/docs/storage-layout.md index a5ccc295..1882f8fe 100644 --- a/docs/storage-layout.md +++ b/docs/storage-layout.md @@ -46,6 +46,36 @@ Used for short-lived data that is cheap but can be cleared out automatically by | `TotalVolumeEurc` | Persistent | `i128` | Global protocol stat | | `TotalVolumeXlm` | Persistent | `i128` | Global protocol stat | +## 3b. InsurancePool Storage Layout + +The `InsurancePool` contract (separate deployment) uses its own `DataKey` +subset. Storage-type semantics follow the same rules as above: `Instance` +keys live for the contract's lifetime and are cheaper; `Persistent` keys +survive upgrades but cost more to read/write. + +| Variant | Storage Type | Stored Value | Purpose | +| ------- | ------------ | ------------ | ------- | +| `Admin` | Instance | `Address` | The liquidity contract (admin) | +| `Balance` | Instance | `i128` | Total pool balance (sum of premiums minus payouts) | +| `Coverage` | Instance | `u32` | Flat per-claim coverage cap | +| `Enrolled(Address)` | Persistent | `bool` | Enrollment flag per LP | +| `Premiums(Address)` | Persistent | `i128` | Cumulative premium paid per LP | +| `Claimed(u64)` | Persistent | `bool` | Whether a claim has been processed for an invoice | + +### TTL settings for persistent keys + +Persistent keys in Soroban require a TTL extension to avoid archival. The +ILN contracts set TTL bounds as follows: + +- **Minimum TTL:** `1,000,000` ledgers +- **Maximum TTL:** `2,000,000` ledgers + +These bounds apply to all `Persistent` `DataKey` variants above (including the +`InsurancePool` entries). Instance keys (`Admin`, `Balance`, `Coverage`) have +no separate TTL — they live for the contract instance's lifetime. + +Source: `contracts/insurance_pool/src/lib.rs:49-64`. + ## 4. Collision Prevention Strategy The unification into the `DataKey` enum inherently prevents key collision: - In Soroban SDK, custom enum variants serialize into `ScVal::Vec` where the first element is the string literal (Symbol) of the variant name.