From 754175461785ca553983f272dcbea5875ae32f46 Mon Sep 17 00:00:00 2001 From: Mario Fernando Araya Royo Date: Sat, 2 Nov 2024 18:00:43 -0600 Subject: [PATCH 1/4] set minimun goal const --- contracts/src/constants/funds/fund_constants.cairo | 1 + contracts/src/fundManager.cairo | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/contracts/src/constants/funds/fund_constants.cairo b/contracts/src/constants/funds/fund_constants.cairo index 43e5c7a..281aa0e 100644 --- a/contracts/src/constants/funds/fund_constants.cairo +++ b/contracts/src/constants/funds/fund_constants.cairo @@ -5,4 +5,5 @@ pub mod FundConstants { pub const UP_VOTES_NEEDED: u32 = 100; pub const INITIAL_UP_VOTES: u32 = 0; pub const INITIAL_GOAL: u256 = 0; + pub const MINIMUM_GOAL: u256 = 500_u256; } diff --git a/contracts/src/fundManager.cairo b/contracts/src/fundManager.cairo index aea48dd..44026a3 100755 --- a/contracts/src/fundManager.cairo +++ b/contracts/src/fundManager.cairo @@ -22,6 +22,9 @@ pub mod FundManager { use starknet::class_hash::ClassHash; use starknet::get_caller_address; use openzeppelin::utils::serde::SerializedAppend; + use gostarkme::constants::{ + funds::{fund_constants::FundConstants, fund_manager_constants::FundManagerConstants}, + }; // *************************************************************************************** @@ -33,6 +36,7 @@ pub mod FundManager { current_id: u128, funds: LegacyMap::, fund_class_hash: ClassHash, + minimum_goal_state: u256, } // *************************************************************************************** @@ -43,6 +47,7 @@ pub mod FundManager { self.owner.write(get_caller_address()); self.fund_class_hash.write(fund_class_hash.try_into().unwrap()); self.current_id.write(1); + self.minimum_goal_state.write(FundConstants::MINIMUM_GOAL); } @@ -71,6 +76,7 @@ pub mod FundManager { #[abi(embed_v0)] impl FundManagerImpl of super::IFundManager { fn newFund(ref self: ContractState, name: felt252, goal: u256) { + assert(goal >= self.minimum_goal_state.read(), 'Goal must be at least 500'); let mut call_data: Array = array![]; Serde::serialize(@self.current_id.read(), ref call_data); Serde::serialize(@get_caller_address(), ref call_data); From 7723ae1c2ab52f47f055d049616f2a34f46badce Mon Sep 17 00:00:00 2001 From: Mario Fernando Araya Royo Date: Sat, 2 Nov 2024 18:24:19 -0600 Subject: [PATCH 2/4] fix comments required --- contracts/src/constants/funds/fund_constants.cairo | 2 +- contracts/src/fundManager.cairo | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/contracts/src/constants/funds/fund_constants.cairo b/contracts/src/constants/funds/fund_constants.cairo index 281aa0e..709e176 100644 --- a/contracts/src/constants/funds/fund_constants.cairo +++ b/contracts/src/constants/funds/fund_constants.cairo @@ -5,5 +5,5 @@ pub mod FundConstants { pub const UP_VOTES_NEEDED: u32 = 100; pub const INITIAL_UP_VOTES: u32 = 0; pub const INITIAL_GOAL: u256 = 0; - pub const MINIMUM_GOAL: u256 = 500_u256; + pub const MINIMUM_GOAL: u256 = 500; } diff --git a/contracts/src/fundManager.cairo b/contracts/src/fundManager.cairo index 44026a3..f338b18 100755 --- a/contracts/src/fundManager.cairo +++ b/contracts/src/fundManager.cairo @@ -36,7 +36,6 @@ pub mod FundManager { current_id: u128, funds: LegacyMap::, fund_class_hash: ClassHash, - minimum_goal_state: u256, } // *************************************************************************************** @@ -47,7 +46,6 @@ pub mod FundManager { self.owner.write(get_caller_address()); self.fund_class_hash.write(fund_class_hash.try_into().unwrap()); self.current_id.write(1); - self.minimum_goal_state.write(FundConstants::MINIMUM_GOAL); } @@ -76,7 +74,7 @@ pub mod FundManager { #[abi(embed_v0)] impl FundManagerImpl of super::IFundManager { fn newFund(ref self: ContractState, name: felt252, goal: u256) { - assert(goal >= self.minimum_goal_state.read(), 'Goal must be at least 500'); + assert(goal >= FundConstants::MINIMUM_GOAL, 'Goal must be at least 500'); let mut call_data: Array = array![]; Serde::serialize(@self.current_id.read(), ref call_data); Serde::serialize(@get_caller_address(), ref call_data); From 5c5265b5f8bb8e12c63ab0901550d7acf6e533be Mon Sep 17 00:00:00 2001 From: Mario Fernando Araya Royo Date: Sat, 2 Nov 2024 18:36:55 -0600 Subject: [PATCH 3/4] fix change requested --- contracts/src/fundManager.cairo | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contracts/src/fundManager.cairo b/contracts/src/fundManager.cairo index f338b18..484d7e5 100755 --- a/contracts/src/fundManager.cairo +++ b/contracts/src/fundManager.cairo @@ -22,9 +22,7 @@ pub mod FundManager { use starknet::class_hash::ClassHash; use starknet::get_caller_address; use openzeppelin::utils::serde::SerializedAppend; - use gostarkme::constants::{ - funds::{fund_constants::FundConstants, fund_manager_constants::FundManagerConstants}, - }; + use gostarkme::constants::{ funds::{fund_constants::FundConstants}, }; // *************************************************************************************** From 7e76e02881b9b12db55075390f1cd568b0676b5c Mon Sep 17 00:00:00 2001 From: Mario Fernando Araya Royo Date: Sun, 3 Nov 2024 14:19:03 -0600 Subject: [PATCH 4/4] add testing for fix fund --- contracts/tests/test_fund_manager.cairo | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/contracts/tests/test_fund_manager.cairo b/contracts/tests/test_fund_manager.cairo index 42fae28..9fae5a6 100755 --- a/contracts/tests/test_fund_manager.cairo +++ b/contracts/tests/test_fund_manager.cairo @@ -34,6 +34,9 @@ fn REASON() -> ByteArray { fn GOAL() -> u256 { 1000 } +fn BAD_GOAL() -> u256 { + 400 + } fn _setup_() -> (ContractAddress, ClassHash) { // Fund @@ -82,6 +85,14 @@ fn test_new_fund() { assert(current_id == 2, 'Invalid current ID'); } +#[test] +#[should_panic(expected: 'Goal must be at least 500')] +fn test_new_fund_bad_goal() { + start_cheat_caller_address_global(OWNER()); + let (contract_address, _) = _setup_(); + let fund_manager_contract = IFundManagerDispatcher { contract_address }; + fund_manager_contract.newFund(NAME(), BAD_GOAL()); +} #[test] fn test_fund_deployed_event() {