diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index ccb3781..da227f1 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -97,7 +97,13 @@ pub mod Fund { // ************************************************************************* #[constructor] fn constructor( - ref self: ContractState, id: u128, owner: ContractAddress, name: ByteArray, goal: u256 + ref self: ContractState, + id: u128, + owner: ContractAddress, + name: ByteArray, + goal: u256, + evidence_link: ByteArray, + contact_handle: ByteArray ) { self.id.write(id); self.owner.write(owner); @@ -106,8 +112,8 @@ pub mod Fund { self.up_votes.write(FundConstants::INITIAL_UP_VOTES); self.goal.write(goal); self.state.write(FundStates::RECOLLECTING_VOTES); - self.evidence_link.write(" "); - self.contact_handle.write(" "); + self.evidence_link.write(evidence_link); + self.contact_handle.write(contact_handle); } // ************************************************************************* diff --git a/contracts/src/fundManager.cairo b/contracts/src/fundManager.cairo index e1176a9..84a4005 100755 --- a/contracts/src/fundManager.cairo +++ b/contracts/src/fundManager.cairo @@ -3,7 +3,13 @@ use starknet::class_hash::ClassHash; #[starknet::interface] pub trait IFundManager { - fn newFund(ref self: TContractState, name: ByteArray, goal: u256); + fn newFund( + ref self: TContractState, + name: ByteArray, + goal: u256, + evidence_link: ByteArray, + contact_handle: ByteArray + ); fn getCurrentId(self: @TContractState) -> u128; fn getFund(self: @TContractState, id: u128) -> ContractAddress; fn getOwner(self: @TContractState) -> ContractAddress; @@ -22,7 +28,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}, }; + use gostarkme::constants::{funds::{fund_constants::FundConstants},}; // *************************************************************************************** @@ -71,13 +77,21 @@ pub mod FundManager { #[abi(embed_v0)] impl FundManagerImpl of super::IFundManager { - fn newFund(ref self: ContractState, name: ByteArray, goal: u256) { + fn newFund( + ref self: ContractState, + name: ByteArray, + goal: u256, + evidence_link: ByteArray, + contact_handle: ByteArray + ) { 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); Serde::serialize(@name, ref call_data); Serde::serialize(@goal, ref call_data); + Serde::serialize(@evidence_link, ref call_data); + Serde::serialize(@contact_handle, ref call_data); let (new_fund_address, _) = deploy_syscall( self.fund_class_hash.read(), 12345, call_data.span(), false ) diff --git a/contracts/tests/test_fund.cairo b/contracts/tests/test_fund.cairo index 23dc9b2..b26ae69 100644 --- a/contracts/tests/test_fund.cairo +++ b/contracts/tests/test_fund.cairo @@ -34,7 +34,7 @@ fn FUND_MANAGER() -> ContractAddress { contract_address_const::() } fn NAME() -> ByteArray { - "NAME_FUND_TEST" + "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" } fn REASON() -> ByteArray { "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" @@ -42,10 +42,16 @@ fn REASON() -> ByteArray { fn GOAL() -> u256 { 1000 } -fn EVIDENCE_LINK() -> ByteArray { +fn EVIDENCE_LINK_1() -> ByteArray { + "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" +} +fn EVIDENCE_LINK_2() -> ByteArray { + "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" +} +fn CONTACT_HANDLE_1() -> ByteArray { "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" } -fn CONTACT_HANDLE() -> ByteArray { +fn CONTACT_HANDLE_2() -> ByteArray { "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" } fn _setup_() -> ContractAddress { @@ -55,6 +61,8 @@ fn _setup_() -> ContractAddress { calldata.append_serde(OWNER()); calldata.append_serde(NAME()); calldata.append_serde(GOAL()); + calldata.append_serde(EVIDENCE_LINK_1()); + calldata.append_serde(CONTACT_HANDLE_1()); let (contract_address, _) = contract.deploy(@calldata).unwrap(); contract_address } @@ -406,11 +414,11 @@ fn test_set_evidence_link() { let contract_address = _setup_(); let dispatcher = IFundDispatcher { contract_address }; let evidence_link = dispatcher.get_evidence_link(); - assert(evidence_link == " ", 'Invalid evidence_link'); + assert(evidence_link == EVIDENCE_LINK_1(), 'Invalid evidence_link'); start_cheat_caller_address_global(OWNER()); - dispatcher.set_evidence_link(EVIDENCE_LINK()); + dispatcher.set_evidence_link(EVIDENCE_LINK_2()); let new_evidence_link = dispatcher.get_evidence_link(); - assert(new_evidence_link == EVIDENCE_LINK(), 'Set evidence method not working') + assert(new_evidence_link == EVIDENCE_LINK_2(), 'Set evidence method not working') } #[test] @@ -420,7 +428,7 @@ fn test_set_evidence_link_wrong_owner() { // call set_evidence_link fn with wrong owner start_cheat_caller_address_global(OTHER_USER()); - IFundDispatcher { contract_address }.set_evidence_link(EVIDENCE_LINK()); + IFundDispatcher { contract_address }.set_evidence_link(EVIDENCE_LINK_2()); } #[test] @@ -428,11 +436,11 @@ fn test_set_contact_handle() { let contract_address = _setup_(); let dispatcher = IFundDispatcher { contract_address }; let contact_handle = dispatcher.get_contact_handle(); - assert(contact_handle == " ", 'Invalid contact handle'); + assert(contact_handle == CONTACT_HANDLE_1(), 'Invalid contact handle'); start_cheat_caller_address_global(OWNER()); - dispatcher.set_contact_handle(CONTACT_HANDLE()); + dispatcher.set_contact_handle(CONTACT_HANDLE_2()); let new_contact_handle = dispatcher.get_contact_handle(); - assert(new_contact_handle == CONTACT_HANDLE(), 'Set contact method not working') + assert(new_contact_handle == CONTACT_HANDLE_2(), 'Set contact method not working') } #[test] @@ -442,5 +450,5 @@ fn test_set_contact_handle_wrong_owner() { // call set_contact_handle fn with wrong owner start_cheat_caller_address_global(OTHER_USER()); - IFundDispatcher { contract_address }.set_contact_handle(CONTACT_HANDLE()); + IFundDispatcher { contract_address }.set_contact_handle(CONTACT_HANDLE_2()); } diff --git a/contracts/tests/test_fund_manager.cairo b/contracts/tests/test_fund_manager.cairo index d817730..d293811 100755 --- a/contracts/tests/test_fund_manager.cairo +++ b/contracts/tests/test_fund_manager.cairo @@ -26,7 +26,7 @@ fn OTHER_USER() -> ContractAddress { contract_address_const::<'USER'>() } fn NAME() -> ByteArray { - "NAME_FUND_TEST" + "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" } fn REASON() -> ByteArray { "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" @@ -36,7 +36,13 @@ fn GOAL() -> u256 { } fn BAD_GOAL() -> u256 { 400 - } +} +fn EVIDENCE_LINK() -> ByteArray { + "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" +} +fn CONTACT_HANDLE() -> ByteArray { + "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" +} fn _setup_() -> (ContractAddress, ClassHash) { // Fund @@ -46,6 +52,9 @@ fn _setup_() -> (ContractAddress, ClassHash) { fund_calldata.append_serde(OWNER()); fund_calldata.append_serde(NAME()); fund_calldata.append_serde(GOAL()); + fund_calldata.append_serde(EVIDENCE_LINK()); + fund_calldata.append_serde(CONTACT_HANDLE()); + let (fund_contract_address, _) = fund.deploy(@fund_calldata).unwrap(); let fund_class_hash = get_class_hash(fund_contract_address); @@ -78,7 +87,7 @@ fn test_new_fund() { start_cheat_caller_address_global(OWNER()); let (contract_address, fund_class_hash) = _setup_(); let fund_manager_contract = IFundManagerDispatcher { contract_address }; - fund_manager_contract.newFund(NAME(), GOAL()); + fund_manager_contract.newFund(NAME(), GOAL(), EVIDENCE_LINK(), CONTACT_HANDLE()); let expected_fund_class_hash = get_class_hash(fund_manager_contract.getFund(1)); let current_id = fund_manager_contract.getCurrentId(); assert(expected_fund_class_hash == fund_class_hash, 'Invalid fund address'); @@ -91,7 +100,7 @@ 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()); + fund_manager_contract.newFund(NAME(), BAD_GOAL(), EVIDENCE_LINK(), CONTACT_HANDLE()); } #[test] @@ -104,7 +113,7 @@ fn test_fund_deployed_event() { let mut spy = spy_events(); let current_id = fund_manager_contract.getCurrentId(); - fund_manager_contract.newFund(NAME(), GOAL()); + fund_manager_contract.newFund(NAME(), GOAL(), EVIDENCE_LINK(), CONTACT_HANDLE()); let expected_fund_class_hash = fund_manager_contract.getFund(1);