Skip to content

Feat/implement missing features - #365

Merged
DeFiVC merged 7 commits into
ChainLearnOfficial:mainfrom
devwallaydev:feat/implement-missing-features
Aug 30, 2026
Merged

Feat/implement missing features#365
DeFiVC merged 7 commits into
ChainLearnOfficial:mainfrom
devwallaydev:feat/implement-missing-features

Conversation

@devwallaydev

Copy link
Copy Markdown
Contributor

Description

This PR implements several missing features across the ChainLearn smart contracts to improve security, authorization, and the reward claiming experience, while also introducing end-to-end integration tests.

Changes Included

  • Integration Tests: Added cross-contract integration tests (tests/integration/full_flow.rs) that cover a full learner journey, including course creation, enrollment, module completion, batch claiming rewards from learn-token, and minting via credential-nft.
  • Batch Reward Claim: Introduced batch_claim_reward in the learn-token contract. This enables a user to claim rewards for multiple completed quizzes in a single transaction. It processes successfully claimed quizzes while gracefully skipping invalid or already-claimed ones.
  • Emergency Pause Mechanism: Implemented an emergency pause state across all contracts (learn-token, credential-nft, progress-tracker). All state-changing methods are guarded by a require_not_paused modifier.
  • Admin Roles: Refactored admin authorization in learn-token to support fine-grained roles (Admin, Minter, and Pauser). Only assigned Minters can mint new tokens, and only Pausers can trigger the emergency pause.

Related Issues

Closes #187
Closes #188
Closes #189
Closes #190

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Test addition (adds missing tests)

Verification

  • Unit tests updated and pass successfully.
  • Integration test simulating the full learner flow added and passes successfully.
  • cargo test --all executes cleanly with no warnings or errors.

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@devwallaydev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@DeFiVC
DeFiVC merged commit 70c3beb into ChainLearnOfficial:main Aug 30, 2026
DeFiVC added a commit that referenced this pull request Aug 30, 2026
…ddress minting, claim history, and pause (#373)

* fix(learn-token): remove duplicate is_paused/set_paused definitions

storage.rs defined is_paused/set_paused twice with identical bodies --
once under the original Emergency Pause section (#189) and again under
the pause-events section (#238), added by two PRs merged back to back
without either noticing the other had already added the same pair.
Rust rejects the duplicate definitions (E0428), so main currently
fails to build. Keep the original definitions and drop the redundant
pair; both events and pause/unpause logic already call through the
one storage.rs API surface, so nothing else changes.

* fix(learn-token): repair test suite broken by role-gated mint/pause

PR #365 added Minter/Pauser role checks to mint(), pause(), and
unpause(), giving each an extra caller: Address parameter, and updated
the call sites that existed at the time. It landed back to back with
two other PRs (#363, #366) that added their own tests calling the
pre-refactor 2-and-0-argument signatures, or referencing an admin
binding some of those same tests never captured (destructured as _ or
_admin because they didn't need it before). None of the three PRs
conflicted at the git-diff level, so all three merged cleanly and the
test suite has been failing to compile since.

Capture admin from setup() wherever a fixed test now needs it as the
mint/pause/unpause caller, and fix one unrelated pre-existing
get_proposal(prop_id) call that needed a borrow. No behavioral changes
-- cargo test -p learn-token now compiles and all 63 tests pass.

* feat(learn-token): add persistent storage entry-count tracking

Soroban prices persistent storage by entry count and size but gives a
contract no host API to enumerate or count its own keys, so there is
currently no way to answer "how much storage is this contract using"
short of an off-chain state export.

Add get_storage_size(), backed by a StorageEntryCount counter that
storage.rs increments/decrements around every write to a per-entity
key -- reward claims, claim history, roles, whitelist entries,
snapshots, vesting schedules and claimed amounts, proposals, votes,
allowance-spender registries, permit nonces, and per-address minting
totals -- guarded by a has() check so overwriting an existing entry
never double-counts it.

Deliberately excluded: singleton config (admin, name/symbol/decimal,
total/max supply, metadata, transfer restriction, wasm hash, upgrade
version, paused flag, proposal counter) since those don't grow with
usage, and Balance/Allowance since balances are written on every
transfer/mint/burn (the issue's "no performance impact" criterion
argues against adding a has() check to that path) and allowances live
in temporary rather than persistent storage.

Closes #254

* test(learn-token): extend coverage for per-address minting, claim history, and pause

total_minted_to() (#251), get_claim_history() (#252), and pause/unpause
(#253) were already implemented and tested on main (merged in #363 for
near-duplicate issues #236/#237/#238, before this repo's issue numbers
#251-253 were filed against the same scope). Add the edge cases their
existing coverage didn't reach:

- total_minted_to: a zero-amount mint is allowed (only negative amounts
  are rejected) and should leave the queryable total at 0.
- get_claim_history: existing tests only covered multiple quizzes
  within one course; verify records also stay correctly distinguished
  by course_id when a learner claims across different courses.
- pause: existing coverage only exercised transfer and mint; burn,
  claim_reward, and claim_vested are also gated by
  require_not_paused() and hadn't been exercised while paused.

Closes #251, Closes #252, Closes #253

---------

Co-authored-by: DeFiVC <136683573+DeFiVC@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add admin role separation Add emergency pause mechanism Add batch claim reward function Add integration tests for cross-contract interactions

2 participants