Skip to content

test: #1274 #1272 #1271 #1273 add tests for fees, token config, donor… - #1393

Merged
cyber-punk112 merged 2 commits into
Web3Novalabs:mainfrom
feyisaralawal:main
Sep 24, 2026
Merged

cyber-punk112 merged 2 commits into
Web3Novalabs:mainfrom
feyisaralawal:main

Conversation

@feyisaralawal

Copy link
Copy Markdown
Contributor

… count, and fee validation

Closes #1274, Closes #1272, Closes #1271, Closes #1273

Detailed breakdown of changes and implementation:

  1. Issue Add tests for campaign creation with fees #1274: Add tests for campaign creation with fees
  • Implemented create_pool_with_fee and create_campaign_with_fee in lib.rs:
    • Enforces creator authorization (creator.require_auth()).
    • Fetches the configured creation fee via get_creation_fee.
    • If fee > 0, transfers fee tokens from creator to contract address using Soroban token client.
    • Accumulates collected fees into persistent storage (UNCLAIMED_FEES).
    • Emits creation_fee_paid and fee_paid events with creator and fee amount.
    • If fee == 0, creates the pool directly without token transfer or balance checks.
  • Created test_issue_1274_creation_fees.rs with 5 tests:
    • (1) Creator with sufficient balance pays fee successfully (test_campaign_creation_fee_sufficient_balance_succeeds).
    • (2) Creator with insufficient balance fails with panic (test_campaign_creation_fee_insufficient_balance_fails).
    • (3) Zero fee allows creation without balance check or tokens (test_campaign_creation_zero_fee_no_balance_check).
    • (4) Fee tokens transferred from creator to contract (test_campaign_creation_fee_tokens_transferred_to_contract).
    • (5) Creation fee event emitted on successful creation (test_campaign_creation_fee_event_emitted).
  1. Issue Add tests for crowdfunding token configuration #1272: Add tests for crowdfunding token configuration
  • Added set_crowdfunding_token and get_crowdfunding_token in lib.rs:
    • Enforces admin authorization (admin.require_auth()).
    • Validates caller against stored admin, rejecting non-admins with ContractError::UnauthorizedAdmin.
    • Validates token address to ensure contract's own address cannot be set as crowdfunding token (InvalidTokenAddress).
    • Persists token under CROWDFUNDING_TOKEN_KEY and emits crowdfunding_token_set and tok_set events.
    • get_crowdfunding_token retrieves the configured token address from persistent storage.
  • Created test_issue_1272_crowdfunding_token.rs with 5 tests:
    • (1) Admin can update token successfully (test_admin_can_update_crowdfunding_token_successfully).
    • (2) Non-admin gets authorization error (test_non_admin_update_token_authorization_error).
    • (3) Setting invalid token address handled properly (test_setting_invalid_token_address_handled_properly).
    • (4) Token update emits correct event (test_token_update_emits_correct_event).
    • (5) Get function returns updated token (test_get_crowdfunding_token_returns_updated_token).
  1. Issue Add tests for donor count tracking accuracy #1271: Add tests for donor count tracking accuracy
  • Validated get_donor_count in lib.rs, which returns the persistent count of unique contributors tracked per campaign.
  • Created test_issue_1271_donor_count_accuracy.rs with 5 tests:
    • (1) New campaign has 0 donors (test_new_campaign_has_zero_donors).
    • (2) First donation increments donor count to 1 (test_first_donation_increments_donor_count_to_one).
    • (3) Same donor's multiple donations keeps count at 1 (test_same_donor_multiple_donations_keeps_count_at_one).
    • (4) Different donors increment count correctly (test_different_donors_increment_count_correctly).
    • (5) Nonexistent campaign returns error (test_nonexistent_campaign_donor_count_returns_error and try variant returning ContractError::PoolNotFound).
  1. Issue Add tests for creation fee configuration validation #1273: Add tests for creation fee configuration validation
  • Validated set_creation_fee and get_creation_fee in lib.rs:
    • Enforces admin authorization and verifies against stored admin (ContractError::UnauthorizedAdmin).
    • Enforces non-negative fee validation, rejecting negative fees with ContractError::InvalidFee.
    • Updates persistent storage and publishes fee update events.
  • Created test_issue_1273_creation_fee_validation.rs with 6 tests:
    • (1) Admin can set positive fee (test_admin_can_set_positive_creation_fee).
    • (2) Admin can set zero fee (test_admin_can_set_zero_creation_fee).
    • (3) Negative fee fails with InvalidFee (test_negative_fee_fails_with_invalid_fee and try variant returning ContractError::InvalidFee).
    • (4) Non-admin authorization fails (test_non_admin_authorization_fails).
    • (5) Fee update emits event (test_fee_update_emits_event).
    • (6) Get function returns updated fee (test_get_function_returns_updated_fee).
  1. Registered all 4 test modules in lib.rs.

Summary

Related Issue

Closes #

Layer Touched

This PR modifies exactly one layer (per the single-layer-per-PR convention in AGENTS.md):

  • nevo_frontend — Next.js frontend
  • nevo_server — NestJS backend API
  • nevo_contract — Soroban smart contract (Rust)
  • Other (docs, CI, repo config — no source layer changed)

If your changes span more than one source layer, stop and split this PR.

Checklist

All PRs

  • The branch is up to date with main
  • No .env files, secrets, or API keys are included
  • No auto-generated files (node_modules/, target/, .next/, dist/) are committed

Frontend (nevo_frontend/) — if applicable

  • npm run build passes locally (run from nevo_frontend/)
  • No TypeScript errors (npx tsc --noEmit)
  • No MOCK_ constants left in app/ or src/store/
  • New or updated tests added where appropriate

Backend (nevo_server/) — if applicable

  • npm run build passes locally (run from nevo_server/)
  • No TypeScript errors
  • New endpoints follow RESTful conventions

Contract (nevo_contract/) — if applicable

  • cargo build --release --target wasm32-unknown-unknown passes
  • cargo test --lib passes — all tests green
  • No unsafe code introduced without justification

Testing Notes

…abs#1273 add tests for fees, token config, donor count, and fee validation

Closes Web3Novalabs#1274, Closes Web3Novalabs#1272, Closes Web3Novalabs#1271, Closes Web3Novalabs#1273

Detailed breakdown of changes and implementation:

1. Issue Web3Novalabs#1274: Add tests for campaign creation with fees
- Implemented `create_pool_with_fee` and `create_campaign_with_fee` in `lib.rs`:
  * Enforces creator authorization (`creator.require_auth()`).
  * Fetches the configured creation fee via `get_creation_fee`.
  * If fee > 0, transfers fee tokens from creator to contract address using Soroban token client.
  * Accumulates collected fees into persistent storage (`UNCLAIMED_FEES`).
  * Emits `creation_fee_paid` and `fee_paid` events with creator and fee amount.
  * If fee == 0, creates the pool directly without token transfer or balance checks.
- Created `test_issue_1274_creation_fees.rs` with 5 tests:
  * (1) Creator with sufficient balance pays fee successfully (`test_campaign_creation_fee_sufficient_balance_succeeds`).
  * (2) Creator with insufficient balance fails with panic (`test_campaign_creation_fee_insufficient_balance_fails`).
  * (3) Zero fee allows creation without balance check or tokens (`test_campaign_creation_zero_fee_no_balance_check`).
  * (4) Fee tokens transferred from creator to contract (`test_campaign_creation_fee_tokens_transferred_to_contract`).
  * (5) Creation fee event emitted on successful creation (`test_campaign_creation_fee_event_emitted`).

2. Issue Web3Novalabs#1272: Add tests for crowdfunding token configuration
- Added `set_crowdfunding_token` and `get_crowdfunding_token` in `lib.rs`:
  * Enforces admin authorization (`admin.require_auth()`).
  * Validates caller against stored admin, rejecting non-admins with `ContractError::UnauthorizedAdmin`.
  * Validates token address to ensure contract's own address cannot be set as crowdfunding token (`InvalidTokenAddress`).
  * Persists token under `CROWDFUNDING_TOKEN_KEY` and emits `crowdfunding_token_set` and `tok_set` events.
  * `get_crowdfunding_token` retrieves the configured token address from persistent storage.
- Created `test_issue_1272_crowdfunding_token.rs` with 5 tests:
  * (1) Admin can update token successfully (`test_admin_can_update_crowdfunding_token_successfully`).
  * (2) Non-admin gets authorization error (`test_non_admin_update_token_authorization_error`).
  * (3) Setting invalid token address handled properly (`test_setting_invalid_token_address_handled_properly`).
  * (4) Token update emits correct event (`test_token_update_emits_correct_event`).
  * (5) Get function returns updated token (`test_get_crowdfunding_token_returns_updated_token`).

3. Issue Web3Novalabs#1271: Add tests for donor count tracking accuracy
- Validated `get_donor_count` in `lib.rs`, which returns the persistent count of unique contributors tracked per campaign.
- Created `test_issue_1271_donor_count_accuracy.rs` with 5 tests:
  * (1) New campaign has 0 donors (`test_new_campaign_has_zero_donors`).
  * (2) First donation increments donor count to 1 (`test_first_donation_increments_donor_count_to_one`).
  * (3) Same donor's multiple donations keeps count at 1 (`test_same_donor_multiple_donations_keeps_count_at_one`).
  * (4) Different donors increment count correctly (`test_different_donors_increment_count_correctly`).
  * (5) Nonexistent campaign returns error (`test_nonexistent_campaign_donor_count_returns_error` and try variant returning `ContractError::PoolNotFound`).

4. Issue Web3Novalabs#1273: Add tests for creation fee configuration validation
- Validated `set_creation_fee` and `get_creation_fee` in `lib.rs`:
  * Enforces admin authorization and verifies against stored admin (`ContractError::UnauthorizedAdmin`).
  * Enforces non-negative fee validation, rejecting negative fees with `ContractError::InvalidFee`.
  * Updates persistent storage and publishes fee update events.
- Created `test_issue_1273_creation_fee_validation.rs` with 6 tests:
  * (1) Admin can set positive fee (`test_admin_can_set_positive_creation_fee`).
  * (2) Admin can set zero fee (`test_admin_can_set_zero_creation_fee`).
  * (3) Negative fee fails with `InvalidFee` (`test_negative_fee_fails_with_invalid_fee` and try variant returning `ContractError::InvalidFee`).
  * (4) Non-admin authorization fails (`test_non_admin_authorization_fails`).
  * (5) Fee update emits event (`test_fee_update_emits_event`).
  * (6) Get function returns updated fee (`test_get_function_returns_updated_fee`).

5. Registered all 4 test modules in `lib.rs`.
@drips-wave

drips-wave Bot commented Sep 24, 2026

Copy link
Copy Markdown

@feyisaralawal 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

@cyber-punk112

Copy link
Copy Markdown
Contributor

Kindly resolve conflicts

1 similar comment
@cyber-punk112

Copy link
Copy Markdown
Contributor

Kindly resolve conflicts

@cyber-punk112
cyber-punk112 merged commit 6f5c788 into Web3Novalabs:main Sep 24, 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

2 participants