Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"[fix] Update contracts variable and function names" #244

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions contracts/src/donator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use starknet::ContractAddress;

#[starknet::interface]
pub trait IDonator<TContractState> {
fn getOwner(self: @TContractState) -> ContractAddress;
fn getLevel(self: @TContractState) -> u32;
fn getTotalStarkDonations(self: @TContractState) -> u256;
fn getMaxStarkDonationsToNextLevel(self: @TContractState) -> u256;
fn updateDonatorValues(ref self: TContractState, donated_starks: u256);
fn get_owner(self: @TContractState) -> ContractAddress;
fn get_level(self: @TContractState) -> u32;
fn get_total_stark_donations(self: @TContractState) -> u256;
fn get_max_stark_donations_to_next_level(self: @TContractState) -> u256;
fn update_donator_values(ref self: TContractState, donated_starks: u256);
}

#[starknet::contract]
Expand Down Expand Up @@ -46,19 +46,19 @@ mod Donator {
// *************************************************************************
#[abi(embed_v0)]
impl DonatorImpl of super::IDonator<ContractState> {
fn getOwner(self: @ContractState) -> ContractAddress {
fn get_owner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn getLevel(self: @ContractState) -> u32 {
fn get_level(self: @ContractState) -> u32 {
return self.level.read();
}
fn getTotalStarkDonations(self: @ContractState) -> u256 {
fn get_total_stark_donations(self: @ContractState) -> u256 {
return self.total_stark_donations.read();
}
fn getMaxStarkDonationsToNextLevel(self: @ContractState) -> u256 {
fn get_max_stark_donations_to_next_level(self: @ContractState) -> u256 {
return self.max_stark_donations_to_next_level.read();
}
fn updateDonatorValues(ref self: ContractState, donated_starks: u256) {
fn update_donator_values(ref self: ContractState, donated_starks: u256) {
let total_donator_pod = self.total_stark_donations.read() + donated_starks;
self.total_stark_donations.write(total_donator_pod);
if (total_donator_pod > self.max_stark_donations_to_next_level.read()) {
Expand Down
22 changes: 11 additions & 11 deletions contracts/src/donatorManager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use starknet::class_hash::ClassHash;

#[starknet::interface]
pub trait IDonatorManager<TContractState> {
fn newDonator(ref self: TContractState);
fn getOwner(self: @TContractState) -> ContractAddress;
fn getDonatorClassHash(self: @TContractState) -> ClassHash;
fn getDonatorByAddress(self: @TContractState, owner: ContractAddress) -> ContractAddress;
fn new_donator(ref self: TContractState);
fn get_owner(self: @TContractState) -> ContractAddress;
fn get_donator_class_hash(self: @TContractState) -> ClassHash;
fn get_donator_by_address(self: @TContractState, owner: ContractAddress) -> ContractAddress;
}

#[starknet::contract]
Expand Down Expand Up @@ -60,12 +60,12 @@ pub mod DonatorManager {
// *************************************************************************
#[abi(embed_v0)]
impl DonatorManagerImpl of super::IDonatorManager<ContractState> {
fn newDonator(ref self: ContractState) {
let mut calldata = ArrayTrait::<felt252>::new();
calldata.append(get_caller_address().try_into().unwrap());
fn new_donator(ref self: ContractState) {
let mut call_data = ArrayTrait::<felt252>::new();
call_data.append(get_caller_address().try_into().unwrap());

let (new_donator_address, _) = deploy_syscall(
self.donator_class_hash.read(), 12345, calldata.span(), false
self.donator_class_hash.read(), 12345,call_data.span(), false
)
.unwrap();
self.donators.write(get_caller_address().try_into().unwrap(), new_donator_address);
Expand All @@ -76,13 +76,13 @@ pub mod DonatorManager {
}
)
}
fn getOwner(self: @ContractState) -> ContractAddress {
fn get_owner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn getDonatorClassHash(self: @ContractState) -> ClassHash {
fn get_donator_class_hash(self: @ContractState) -> ClassHash {
return self.donator_class_hash.read();
}
fn getDonatorByAddress(self: @ContractState, owner: ContractAddress) -> ContractAddress {
fn get_donator_by_address(self: @ContractState, owner: ContractAddress) -> ContractAddress {
return self.donators.read(owner);
}
}
Expand Down
60 changes: 30 additions & 30 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ use starknet::ContractAddress;

#[starknet::interface]
pub trait IFund<TContractState> {
fn getId(self: @TContractState) -> u128;
fn getOwner(self: @TContractState) -> ContractAddress;
fn setName(ref self: TContractState, name: ByteArray);
fn getName(self: @TContractState) -> ByteArray;
fn setReason(ref self: TContractState, reason: ByteArray);
fn getReason(self: @TContractState) -> ByteArray;
fn receiveVote(ref self: TContractState);
fn getUpVotes(self: @TContractState) -> u32;
fn setGoal(ref self: TContractState, goal: u256);
fn getGoal(self: @TContractState) -> u256;
fn get_id(self: @TContractState) -> u128;
fn get_owner(self: @TContractState) -> ContractAddress;
fn set_name(ref self: TContractState, name: ByteArray);
fn get_name(self: @TContractState) -> ByteArray;
fn set_reason(ref self: TContractState, reason: ByteArray);
fn get_reason(self: @TContractState) -> ByteArray;
fn receive_vote(ref self: TContractState);
fn get_up_votes(self: @TContractState) -> u32;
fn set_goal(ref self: TContractState, goal: u256);
fn get_goal(self: @TContractState) -> u256;
fn update_receive_donation(ref self: TContractState, strks: u256);
fn get_current_goal_state(self: @TContractState) -> u256;
fn setState(ref self: TContractState, state: u8);
fn getState(self: @TContractState) -> u8;
fn getVoter(self: @TContractState) -> u32;
fn set_state(ref self: TContractState, state: u8);
fn get_state(self: @TContractState) -> u8;
fn get_voter(self: @TContractState) -> u32;
fn withdraw(ref self: TContractState);
fn set_evidence_link(ref self: TContractState, evidence: ByteArray);
fn get_evidence_link(self: @TContractState) -> ByteArray;
Expand Down Expand Up @@ -122,29 +122,29 @@ pub mod Fund {
// *************************************************************************
#[abi(embed_v0)]
impl FundImpl of super::IFund<ContractState> {
fn getId(self: @ContractState) -> u128 {
fn get_id(self: @ContractState) -> u128 {
return self.id.read();
}
fn getOwner(self: @ContractState) -> ContractAddress {
fn get_owner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn setName(ref self: ContractState, name: ByteArray) {
fn set_name(ref self: ContractState, name: ByteArray) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
self.name.write(name);
}
fn getName(self: @ContractState) -> ByteArray {
fn get_name(self: @ContractState) -> ByteArray {
return self.name.read();
}
fn setReason(ref self: ContractState, reason: ByteArray) {
fn set_reason(ref self: ContractState, reason: ByteArray) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
self.reason.write(reason);
}
fn getReason(self: @ContractState) -> ByteArray {
fn get_reason(self: @ContractState) -> ByteArray {
return self.reason.read();
}
fn receiveVote(ref self: ContractState) {
fn receive_vote(ref self: ContractState) {
assert(self.voters.read(get_caller_address()) == 0, 'User already voted!');
assert(
self.state.read() == FundStates::RECOLLECTING_VOTES, 'Fund not recollecting votes!'
Expand All @@ -164,18 +164,18 @@ pub mod Fund {
}
);
}
fn getUpVotes(self: @ContractState) -> u32 {
fn get_up_votes(self: @ContractState) -> u32 {
return self.up_votes.read();
}
fn setGoal(ref self: ContractState, goal: u256) {
fn set_goal(ref self: ContractState, goal: u256) {
let caller = get_caller_address();
let fund_manager_address = contract_address_const::<
FundManagerConstants::FUND_MANAGER_ADDRESS
>();
assert!(fund_manager_address == caller, "You are not the fund manager");
self.goal.write(goal);
}
fn getGoal(self: @ContractState) -> u256 {
fn get_goal(self: @ContractState) -> u256 {
return self.goal.read();
}
fn update_receive_donation(ref self: ContractState, strks: u256) {
Expand All @@ -196,7 +196,7 @@ pub mod Fund {
fn get_current_goal_state(self: @ContractState) -> u256 {
self.token_dispatcher().balance_of(get_contract_address())
}
fn setState(ref self: ContractState, state: u8) {
fn set_state(ref self: ContractState, state: u8) {
let caller = get_caller_address();
let valid_address_1 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();
Expand All @@ -206,26 +206,26 @@ pub mod Fund {
);
self.state.write(state);
}
fn getState(self: @ContractState) -> u8 {
fn get_state(self: @ContractState) -> u8 {
return self.state.read();
}
fn getVoter(self: @ContractState) -> u32 {
fn get_voter(self: @ContractState) -> u32 {
return self.voters.read(get_caller_address());
}
fn withdraw(ref self: ContractState) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
assert(self.state.read() == FundStates::CLOSED, 'Fund not close goal yet.');
assert(
self.get_current_goal_state() >= self.getGoal(), 'Fund hasnt reached its goal yet'
self.get_current_goal_state() >= self.get_goal(), 'Fund hasnt reached its goal yet'
);

let valid_address = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
let withdrawn_amount = (self.get_current_goal_state() * 95) / 100;
let fund_manager_amount = (self.get_current_goal_state() * 5) / 100;

self.token_dispatcher().approve(self.getOwner(), withdrawn_amount);
self.token_dispatcher().transfer(self.getOwner(), withdrawn_amount);
self.token_dispatcher().approve(self.get_owner(), withdrawn_amount);
self.token_dispatcher().transfer(self.get_owner(), withdrawn_amount);

self.token_dispatcher().approve(valid_address, fund_manager_amount);
self.token_dispatcher().transfer(valid_address, fund_manager_amount);
Expand All @@ -236,7 +236,7 @@ pub mod Fund {
self
.emit(
DonationWithdraw {
owner_address: self.getOwner(),
owner_address: self.get_owner(),
fund_contract_address: get_contract_address(),
withdrawn_amount
}
Expand Down
20 changes: 10 additions & 10 deletions contracts/src/fundManager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use starknet::class_hash::ClassHash;

#[starknet::interface]
pub trait IFundManager<TContractState> {
fn newFund(
fn new_fund(
ref self: TContractState,
name: ByteArray,
goal: u256,
evidence_link: ByteArray,
contact_handle: ByteArray,
reason: ByteArray
);
fn getCurrentId(self: @TContractState) -> u128;
fn getFund(self: @TContractState, id: u128) -> ContractAddress;
fn getOwner(self: @TContractState) -> ContractAddress;
fn getFundClassHash(self: @TContractState) -> ClassHash;
fn get_current_id(self: @TContractState) -> u128;
fn get_fund(self: @TContractState, id: u128) -> ContractAddress;
fn get_owner(self: @TContractState) -> ContractAddress;
fn get_fund_class_hash(self: @TContractState) -> ClassHash;
}

#[starknet::contract]
Expand Down Expand Up @@ -78,7 +78,7 @@ pub mod FundManager {

#[abi(embed_v0)]
impl FundManagerImpl of super::IFundManager<ContractState> {
fn newFund(
fn new_fund(
ref self: ContractState,
name: ByteArray,
goal: u256,
Expand Down Expand Up @@ -112,16 +112,16 @@ pub mod FundManager {

self.current_id.write(self.current_id.read() + 1);
}
fn getCurrentId(self: @ContractState) -> u128 {
fn get_current_id(self: @ContractState) -> u128 {
return self.current_id.read();
}
fn getFund(self: @ContractState, id: u128) -> ContractAddress {
fn get_fund(self: @ContractState, id: u128) -> ContractAddress {
return self.funds.read(id);
}
fn getOwner(self: @ContractState) -> ContractAddress {
fn get_owner(self: @ContractState) -> ContractAddress {
return self.owner.read();
}
fn getFundClassHash(self: @ContractState) -> ClassHash {
fn get_fund_class_hash(self: @ContractState) -> ClassHash {
return self.fund_class_hash.read();
}
}
Expand Down
26 changes: 13 additions & 13 deletions contracts/tests/test_donator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,50 @@ fn __setup__() -> ContractAddress {
fn test_get_owner() {
let contract_address = __setup__();
let dispatcher = IDonatorDispatcher { contract_address };
let owner = dispatcher.getOwner();
let owner = dispatcher.get_owner();
assert(owner == OWNER(), 'Invalid owner');
}

#[test]
fn test_get_level() {
let contract_address = __setup__();
let dispatcher = IDonatorDispatcher { contract_address };
let level = dispatcher.getLevel();
let level = dispatcher.get_level();
assert(level == 1, 'Invalid level');
}

#[test]
fn test_get_total_stark_donations() {
let contract_address = __setup__();
let dispatcher = IDonatorDispatcher { contract_address };
let total_stark_donations = dispatcher.getTotalStarkDonations();
let total_stark_donations = dispatcher.get_total_stark_donations();
assert(total_stark_donations == 0, 'Invalid total stark donations');
}

#[test]
fn test_get_max_stark_donations_to_next_level() {
let contract_address = __setup__();
let dispatcher = IDonatorDispatcher { contract_address };
let max_stark_donations_to_next_level = dispatcher.getMaxStarkDonationsToNextLevel();
let max_stark_donations_to_next_level = dispatcher.get_max_stark_donations_to_next_level();
assert(max_stark_donations_to_next_level == 10, 'Invalid total stark donations');
}

#[test]
fn test_update_donator_values() {
let contract_address = __setup__();
let dispatcher = IDonatorDispatcher { contract_address };
dispatcher.updateDonatorValues(5);
let level = dispatcher.getLevel();
let total_stark_donations = dispatcher.getTotalStarkDonations();
dispatcher.update_donator_values(5);
let level = dispatcher.get_level();
let total_stark_donations = dispatcher.get_total_stark_donations();
assert(level == 1, 'Invalid level');
assert(total_stark_donations == 5, 'Invalid total stark donations');
dispatcher.updateDonatorValues(5);
let level = dispatcher.getLevel();
dispatcher.update_donator_values(5);
let level = dispatcher.get_level();
assert(level == 1, 'Invalid level');
dispatcher.updateDonatorValues(1);
let level = dispatcher.getLevel();
let total_stark_donations = dispatcher.getTotalStarkDonations();
let max_stark_donations_to_next_level = dispatcher.getMaxStarkDonationsToNextLevel();
dispatcher.update_donator_values(1);
let level = dispatcher.get_level();
let total_stark_donations = dispatcher.get_total_stark_donations();
let max_stark_donations_to_next_level = dispatcher.get_max_stark_donations_to_next_level();
assert(level == 2, 'Invalid level');
assert(total_stark_donations == 11, 'Invalid total stark donations');
assert(max_stark_donations_to_next_level == 20, 'Invalid total stark donations');
Expand Down
12 changes: 6 additions & 6 deletions contracts/tests/test_donator_manager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fn test_constructor() {
start_cheat_caller_address_global(OWNER());
let (contract_address, donator_class_hash) = __setup__();
let donator_manager_contract = IDonatorManagerDispatcher { contract_address };
let expected_donator_address = donator_manager_contract.getDonatorClassHash();
let owner = donator_manager_contract.getOwner();
let expected_donator_address = donator_manager_contract.get_donator_class_hash();
let owner = donator_manager_contract.get_owner();
assert(owner == OWNER(), 'Invalid owner');
assert(donator_class_hash == expected_donator_address, 'Invalid donator class hash');
}
Expand All @@ -57,9 +57,9 @@ fn test_new_donator() {
start_cheat_caller_address_global(OWNER());
let (contract_address, donator_class_hash) = __setup__();
let donator_manager_contract = IDonatorManagerDispatcher { contract_address };
donator_manager_contract.newDonator();
donator_manager_contract.new_donator();
let expected_donator_class_hash = get_class_hash(
donator_manager_contract.getDonatorByAddress(OWNER())
donator_manager_contract.get_donator_by_address(OWNER())
);
assert(expected_donator_class_hash == donator_class_hash, 'Invalid donator address');
}
Expand All @@ -70,7 +70,7 @@ fn test_emit_event_donator_contract_deployed() {
let (contract_address, _) = __setup__();
let donator_manager_contract = IDonatorManagerDispatcher { contract_address };
let mut spy = spy_events();
donator_manager_contract.newDonator();
donator_manager_contract.new_donator();

spy
.assert_emitted(
Expand All @@ -79,7 +79,7 @@ fn test_emit_event_donator_contract_deployed() {
contract_address,
DonatorManager::Event::DonatorContractDeployed(
DonatorManager::DonatorContractDeployed {
new_donator: donator_manager_contract.getDonatorByAddress(OWNER()),
new_donator: donator_manager_contract.get_donator_by_address(OWNER()),
owner: OWNER()
}
)
Expand Down
Loading
Loading