Skip to content

test: add security, gas benchmark, cross-contract, and event emission tests (#286, #287, #288, #289) - #383

Merged
DeFiVC merged 4 commits into
ChainLearnOfficial:mainfrom
markdavid000:feat/tests-286-287-288-289
Aug 31, 2026
Merged

test: add security, gas benchmark, cross-contract, and event emission tests (#286, #287, #288, #289)#383
DeFiVC merged 4 commits into
ChainLearnOfficial:mainfrom
markdavid000:feat/tests-286-287-288-289

Conversation

@markdavid000

Copy link
Copy Markdown
Contributor

Resolves

closes #286
closes #287
closes #288
closes #289

Changes

  • . Add security test for double-spending #289 — Security tests for double-spending prevention
    tests/integration/security_double_spending_tests.rs
  • Double-claim reward prevented with clear error message
  • Double-mint credential prevented with clear error message
  • Double-enroll prevented with clear error message
  • Double-complete module, double-submit quiz, double-revoke credential prevented
  • State corruption verified impossible after failed attempts
  • Cross-contract operations (claim reward + mint credential) are independent
    . Add gas benchmark tests #288 — Gas benchmark tests
    tests/benchmarks/gas_benchmarks.rs
  • CPU instruction cost measurement for every major function across all 3 contracts
  • ProgressTracker: create_course, enroll, complete_module, submit_quiz_score, get_progress
  • LearnToken: claim_reward, transfer, approve, transfer_from, mint, burn
  • CredentialNft: mint_credential, verify_credential, revoke_credential
  • Regression detection: batch vs individual claim cost ratio
  • Full end-to-end flow benchmark (enroll → complete → claim → mint)
    . Add unit test for cross-contract calls #287 — Cross-contract call unit tests
    tests/unit/xcontract_call_tests.rs
  • learn-token → progress-tracker calls verified correct
  • Score fetched and used for reward calculation
  • Failure cases handled (score 0, non-existent quiz/course)
  • No state corruption after failed cross-contract calls
  • batch_claim_reward handles mixed success/failure
  • Progress-tracker state unaffected by token claims
  • Cross-contract isolation verified per learner
    . Add unit test for event emissions #286 — Event emission unit tests
    tests/unit/event_emission_tests.rs
  • All ProgressTracker events: course_created, enrolled, module_completed, quiz_submitted, credential_eligible, quiz_retaken, course_archived
  • All LearnToken events: mint, transfer, burn, approve, reward_claimed, role_granted/revoked, max_supply_updated, vesting_created
  • All CredentialNft events: credential_minted, credential_revoked
  • Topics indexed correctly for server-s

…ficial#289)

Verifies that double-spending is impossible across all contracts:
- Double-claim reward is prevented with clear error message
- Double-mint credential is prevented with clear error message
- Double-enroll is prevented with clear error message
- Double-complete module and double-submit quiz are prevented
- Double-revoke credential is prevented
- State is not corrupted after failed double-spend attempts
- Cross-contract operations (claim + mint) are independent

All error messages are clear and specific.
Tests verify learn-token -> progress-tracker cross-contract calls:
- claim_reward correctly fetches score and calculates reward
- Score 0 (unsubmitted quiz) causes cross-contract call failure
- Non-existent quiz and course produce clear error messages
- Failed cross-contract calls do not corrupt token state
- batch_claim_reward handles mixed success and failure gracefully
- Progress-tracker state is unaffected by token claims
- Cross-contract calls are isolated per learner
…fficial#288)

Measures CPU instruction costs via env.budget() for each contract function:
- ProgressTracker: create_course, enroll, complete_module, submit_quiz_score, get_progress
- LearnToken: claim_reward, transfer, approve, transfer_from, mint, burn
- CredentialNft: mint_credential, verify_credential, revoke_credential

Includes:
- Regression detection comparing batch vs individual claim costs
- Full end-to-end flow benchmark (enroll→complete→claim→mint)
- Results are repeatable with fresh environments per test
- Ratios are relative (not absolute) for cross-host stability
Verifies all events are emitted with correct topics and data:

ProgressTracker events:
- course_created, enrolled (with timestamp), module_completed,
  quiz_submitted, credential_eligible, quiz_retaken, course_archived

LearnToken events:
- mint, transfer (indexed topics), burn, approve, reward_claimed,
  role_granted, role_revoked, max_supply_updated, vesting_created

CredentialNft events:
- credential_minted (with metadata_uri), credential_revoked
  (indexed, with audit details)

All event topics and data payloads are verified for correctness.
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@markdavid000 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 443ff18 into ChainLearnOfficial:main Aug 31, 2026
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 security test for double-spending . Add gas benchmark tests . Add unit test for cross-contract calls . Add unit test for event emissions

2 participants