From 3ac592e4dc7733748d0f72313811acf113522fdb Mon Sep 17 00:00:00 2001 From: Sakariyah Abdulhazeem <150973162+zeemscript@users.noreply.github.com> Date: Sat, 1 Aug 2026 00:28:06 +0100 Subject: [PATCH 1/3] fix(#461): add regression tests for verify_with_votes overflow handling The checked_add guards in verify_with_votes are already in place; these tests lock in the behavior so vote-count and token-weight aggregation return Error::Overflow instead of silently wrapping on i128/u32 overflow. --- src/tests/test_voting_verify.rs | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/tests/test_voting_verify.rs b/src/tests/test_voting_verify.rs index b4fa3142..63f9d8dd 100644 --- a/src/tests/test_voting_verify.rs +++ b/src/tests/test_voting_verify.rs @@ -1,4 +1,7 @@ use super::helpers::*; +use crate::storage::{ + set_approve_votes, set_approve_weight, set_reject_votes, set_reject_weight, +}; use crate::{Category, CreateCampaignParams, Error}; use soroban_sdk::String; @@ -221,6 +224,62 @@ fn test_verify_campaign_with_votes_threshold_not_met() { assert_eq!(res.unwrap_err().unwrap(), Error::VotingThresholdNotMet); } +#[test] +fn test_verify_with_votes_weight_overflow_returns_overflow() { + let (env, admin, creator, _, _, _token, _token_admin, client) = setup_env(); + client.set_voting_params(&admin, &1, &6000); + + let campaign_id = client.create_campaign(&make_params( + creator.clone(), + String::from_str(&env, "Weight Overflow Verify"), + String::from_str(&env, "Weight overflow guard"), + 1000, + 30, + Category::Learner, + false, + 0, + 0i128, + )); + + // Satisfy quorum, then make approve_weight + reject_weight exceed i128::MAX. + env.as_contract(&client.address, || { + set_approve_votes(&env, campaign_id, 2); + set_reject_votes(&env, campaign_id, 1); + set_approve_weight(&env, campaign_id, i128::MAX); + set_reject_weight(&env, campaign_id, 1); + }); + + let res = client.try_verify_campaign_with_votes(&campaign_id); + assert_eq!(res.unwrap_err().unwrap(), Error::Overflow); +} + +#[test] +fn test_verify_with_votes_count_overflow_returns_overflow() { + let (env, admin, creator, _, _, _token, _token_admin, client) = setup_env(); + client.set_voting_params(&admin, &3, &6000); + + let campaign_id = client.create_campaign(&make_params( + creator.clone(), + String::from_str(&env, "Vote Count Overflow Verify"), + String::from_str(&env, "Vote count overflow guard"), + 1000, + 30, + Category::Learner, + false, + 0, + 0i128, + )); + + // Make approve_votes + reject_votes exceed u32::MAX. + env.as_contract(&client.address, || { + set_approve_votes(&env, campaign_id, u32::MAX); + set_reject_votes(&env, campaign_id, 1); + }); + + let res = client.try_verify_campaign_with_votes(&campaign_id); + assert_eq!(res.unwrap_err().unwrap(), Error::Overflow); +} + #[test] fn test_verify_campaign_with_votes_success() { let (env, admin, creator, contributor1, contributor2, _token, token_admin, client) = From 9f74d5e3b51539e13b5837b450b22c9bfebd4b9a Mon Sep 17 00:00:00 2001 From: Sakariyah Abdulhazeem <150973162+zeemscript@users.noreply.github.com> Date: Sat, 1 Aug 2026 00:32:50 +0100 Subject: [PATCH 2/3] style: run cargo fmt on pre-existing unformatted files PR #618 left src/admin.rs and src/lib.rs failing `cargo fmt --all -- --check` (import ordering, missing trailing newlines). Format them so the fmt CI gate passes; also collapse the storage import in the new test file. --- src/tests/test_voting_verify.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tests/test_voting_verify.rs b/src/tests/test_voting_verify.rs index 63f9d8dd..c1f11e21 100644 --- a/src/tests/test_voting_verify.rs +++ b/src/tests/test_voting_verify.rs @@ -1,7 +1,5 @@ use super::helpers::*; -use crate::storage::{ - set_approve_votes, set_approve_weight, set_reject_votes, set_reject_weight, -}; +use crate::storage::{set_approve_votes, set_approve_weight, set_reject_votes, set_reject_weight}; use crate::{Category, CreateCampaignParams, Error}; use soroban_sdk::String; From 2df5a3ab308b224c02a354195879d94b23c7e13a Mon Sep 17 00:00:00 2001 From: Sakariyah Abdulhazeem <150973162+zeemscript@users.noreply.github.com> Date: Sat, 1 Aug 2026 00:42:42 +0100 Subject: [PATCH 3/3] test: fix stale campaign_metadata_updated event shape in tests new_description) to (old_title, old_description, new_title, new_description) for indexers. Two tests in test_campaign_update still unpacked the old 2-tuple, causing UnexpectedSize host errors. Update them to the 4-tuple. --- src/tests/test_campaign_update.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/test_campaign_update.rs b/src/tests/test_campaign_update.rs index e68cd0c2..2218a606 100644 --- a/src/tests/test_campaign_update.rs +++ b/src/tests/test_campaign_update.rs @@ -66,6 +66,8 @@ fn test_update_campaign_emits_title_and_description() { let payload: (String, String, String, String) = soroban_sdk::FromVal::from_val(&env, &last_event.2); + assert_eq!(payload.0, String::from_str(&env, "Original Title")); + assert_eq!(payload.1, String::from_str(&env, "Original Description")); assert_eq!(payload.2, new_title); assert_eq!(payload.3, new_desc); }