test: #1274 #1272 #1271 #1273 add tests for fees, token config, donor… - #1393
Merged
Merged
Conversation
…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`.
|
@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! 🚀 |
Contributor
|
Kindly resolve conflicts |
1 similar comment
Contributor
|
Kindly resolve conflicts |
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.
… count, and fee validation
Closes #1274, Closes #1272, Closes #1271, Closes #1273
Detailed breakdown of changes and implementation:
create_pool_with_feeandcreate_campaign_with_feeinlib.rs:creator.require_auth()).get_creation_fee.UNCLAIMED_FEES).creation_fee_paidandfee_paidevents with creator and fee amount.test_issue_1274_creation_fees.rswith 5 tests:test_campaign_creation_fee_sufficient_balance_succeeds).test_campaign_creation_fee_insufficient_balance_fails).test_campaign_creation_zero_fee_no_balance_check).test_campaign_creation_fee_tokens_transferred_to_contract).test_campaign_creation_fee_event_emitted).set_crowdfunding_tokenandget_crowdfunding_tokeninlib.rs:admin.require_auth()).ContractError::UnauthorizedAdmin.InvalidTokenAddress).CROWDFUNDING_TOKEN_KEYand emitscrowdfunding_token_setandtok_setevents.get_crowdfunding_tokenretrieves the configured token address from persistent storage.test_issue_1272_crowdfunding_token.rswith 5 tests:test_admin_can_update_crowdfunding_token_successfully).test_non_admin_update_token_authorization_error).test_setting_invalid_token_address_handled_properly).test_token_update_emits_correct_event).test_get_crowdfunding_token_returns_updated_token).get_donor_countinlib.rs, which returns the persistent count of unique contributors tracked per campaign.test_issue_1271_donor_count_accuracy.rswith 5 tests:test_new_campaign_has_zero_donors).test_first_donation_increments_donor_count_to_one).test_same_donor_multiple_donations_keeps_count_at_one).test_different_donors_increment_count_correctly).test_nonexistent_campaign_donor_count_returns_errorand try variant returningContractError::PoolNotFound).set_creation_feeandget_creation_feeinlib.rs:ContractError::UnauthorizedAdmin).ContractError::InvalidFee.test_issue_1273_creation_fee_validation.rswith 6 tests:test_admin_can_set_positive_creation_fee).test_admin_can_set_zero_creation_fee).InvalidFee(test_negative_fee_fails_with_invalid_feeand try variant returningContractError::InvalidFee).test_non_admin_authorization_fails).test_fee_update_emits_event).test_get_function_returns_updated_fee).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 frontendnevo_server— NestJS backend APInevo_contract— Soroban smart contract (Rust)Checklist
All PRs
main.envfiles, secrets, or API keys are includednode_modules/,target/,.next/,dist/) are committedFrontend (
nevo_frontend/) — if applicablenpm run buildpasses locally (run fromnevo_frontend/)npx tsc --noEmit)MOCK_constants left inapp/orsrc/store/Backend (
nevo_server/) — if applicablenpm run buildpasses locally (run fromnevo_server/)Contract (
nevo_contract/) — if applicablecargo build --release --target wasm32-unknown-unknownpassescargo test --libpasses — all tests greenTesting Notes