Storage example#36
Draft
mohammadfawaz wants to merge 2 commits into
Draft
Conversation
6a86ed0 to
716997b
Compare
716997b to
5f014e0
Compare
Treasury improvements - Added `correct_deposit(index, amount)` and `drop_deposit(index)` so the example demonstrates `vec.set` and `vec.swap_remove` (previously listed in the comments but not exercised). - Renamed `pop_last_deposit` -> `undo_last_deposit` and made it consistent with the rest of the model: it now refunds `balance` and decrements `deposit_count` along with popping the log, so the treasury's three storage shapes never drift out of sync. - Header comment now lists every supported vector op for quick reference. Unit tests (new) - `treasury/tests/test_treasury.leo` (16 cases) drives every transition and asserts on the resulting on-chain state via `treasury.aleo::<var>` reads from inside finalize blocks. Covers defaults, initialize, deposit/withdraw, freeze gating, config update, every vector op, reset, and `@should_fail` paths for overdraw, withdraw-without-balance, freeze-blocks-deposit, freeze-blocks-withdraw, and undo-on-empty-log. - `auditor/tests/test_auditor.leo` (10 cases) exercises cross-program reads: snapshot mirrors treasury state, defaults when treasury is empty, detects freeze, clears alert after unfreeze, fee-config thresholding (default/low/high/fallback), and deposit-log checks. - Both run with `leo test` against an in-memory ledger; no devnode needed. README + run.sh - README now documents the new vector ops, points to the unit tests, and adds a "Part 2 - Unit tests" section. - run.sh demos `correct_deposit` and `drop_deposit` in the local-execution walkthrough.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a storage example demonstrating storage singletons, struct storage, vector storage, and external storage access in Leo 4.
What's in the example
Two programs that together showcase on-chain storage and cross-program reads:
treasury.aleo— Declares and manages on-chain state using Leo 4 storage variables:storage balance: u64,storage is_frozen: bool,storage deposit_count: u32storage config: FeeConfig— stored and read atomicallystorage deposit_log: [u64]— dynamically-sized on-chain list withpush,pop,get,len,clearunwrap/unwrap_orfor reading optional slots,noneassignment for clearing, and theFinalreturn typeauditor.aleo— Reads treasury storage externally without any getter functions:treasury.aleo::balance.unwrap_or(0u64)treasury.aleo::config.unwrap_or(treasury.aleo::FeeConfig { ... })treasury.aleo::deposit_log.len(),treasury.aleo::deposit_log.get(0u32)treasury.aleo::FeeConfigHow to run
run.shhandles the full flow:leo devnode): deploys both programs, performs treasury operations on-chain, then runs auditor functions that read treasury storage cross-program — including detecting a treasury freeze