Skip to content

Commit

Permalink
scarb fmt (CarmineOptions#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
scobi7 committed Aug 6, 2024
1 parent 17d5cdd commit a6f9ff1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ mod Governance {
self.governance_token_address.read()
}
}
}
}
1 change: 0 additions & 1 deletion src/proposals.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ trait IProposals<TContractState> {
prop_id: felt252,
);
fn get_total_delegated_to(self: @TContractState, to_addr: ContractAddress) -> u128;

}

#[starknet::component]
Expand Down
2 changes: 1 addition & 1 deletion src/staking.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,4 @@ mod staking {
}
}
}
}
}
16 changes: 4 additions & 12 deletions src/testing/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,13 @@ fn test_vote_upgrade_root(new_merkle_root: felt252) {
assert(check_if_healthy(gov_contract_addr), 'new gov not healthy');
}

//fn check_if_healthy(self: @TContractState, gov_contract_addr: ContractAddress) -> bool;
fn check_if_healthy(gov_address: ContractAddress) -> bool {
let proposals_dispatcher = IProposalsDispatcher { contract_address: gov_address };
let upgrades_dispatcher = IUpgradesDispatcher { contract_address: gov_address };

fn check_if_health(gov_contract_addr: ContractAddress) -> bool {
let proposals_dispatcher = IProposalsDispatcher { contract_address: gov.contract_address };
let upgrades_dispatcher = IUpgradesDispatcher { contract_address: gov.contract_address };

//this is the type of the current governance
let (_, last_upgrade_type) = upgrades_dispatcher.get_latest_upgrade();

let current_prop_id = proposals_dispatcher.get_latest_proposal_id();

let current_prop_details = proposals_dispatcher.get_proposal_details(current_prop_id);

if current_prop_details.to_upgrade != last_upgrade_type{
return false;
}
return true;
last_upgrade_type.into() == current_prop_details.to_upgrade
}
2 changes: 1 addition & 1 deletion tests/staking_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ fn test_unstake_before_unlock(mut amount_to_stake: u16, duration_seed: u8) {
let stake_id = staking.stake(duration, amount_to_stake.into());

staking.unstake(stake_id);
}
}
69 changes: 49 additions & 20 deletions tests/test_setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use openzeppelin::token::erc20::interface::{
IERC20CamelOnlyDispatcherTrait
};

use konoha::health::{IHealthDispatcher, IHealthDispatcherTrait};

use snforge_std::{
BlockId, declare, ContractClassTrait, ContractClass, start_prank, start_warp, CheatTarget,
prank, CheatSpan, get_class_hash
Expand All @@ -27,13 +25,14 @@ use starknet::ContractAddress;

use starknet::get_block_timestamp;

use super::setup::check_if_healthy;

use super::setup::{
admin_addr, first_address, second_address, deploy_governance, deploy_and_distribute_gov_tokens,
deploy_governance_and_both_tokens, test_vote_upgrade_root
};
use super::staking_tests::{set_staking_curve, stake_all, stake_half};


#[test]
fn test_healthy_upgrade() {
let (gov, _voting, floating) = deploy_governance_and_both_tokens();
Expand Down Expand Up @@ -70,7 +69,27 @@ fn test_healthy_upgrade() {
proposals_dispatcher.vote(prop_id1, 1);

// Check the status of the second proposal
assert_eq!(proposals_dispatcher.get_proposal_status(prop_id1), 1, "Proposal not passed!");
assert_eq!(
proposals_dispatcher.get_proposal_status(prop_id1), 1, "second Proposal not passed!"
);
let proposals_dispatcher = IProposalsDispatcher { contract_address: gov.contract_address };
let upgrades_dispatcher = IUpgradesDispatcher { contract_address: gov.contract_address };

//this is the type of the current governance
let (_, last_upgrade_type) = upgrades_dispatcher.get_latest_upgrade();

let current_prop_id = proposals_dispatcher.get_latest_proposal_id();

let current_prop_details = proposals_dispatcher.get_proposal_details(current_prop_id);
let mut health: u64 = 0;

if last_upgrade_type.into() == current_prop_details.to_upgrade {
health = 1;
}

println!("Health: {}", health);
println!("Governance Type: {}", last_upgrade_type);
println!("Upgrading Type: {}", current_prop_details.to_upgrade);

let is_healthy = check_if_healthy(gov.contract_address);
assert!(is_healthy, "Governance should be healthy after same type to type (3) upgrade.");
Expand All @@ -81,39 +100,49 @@ fn test_healthy_upgrade() {
#[test]
fn test_unhealthy_upgrade() {
let (gov, _voting, floating) = deploy_governance_and_both_tokens();
set_staking_curve(gov.contract_address);
stake_all(gov.contract_address, floating, admin_addr.try_into().unwrap());
let dispatcher = IProposalsDispatcher { contract_address: gov.contract_address };
let gov_address = gov.contract_address;

//println!("Governance contract address: {}", gov_address);

set_staking_curve(gov_address);
stake_all(gov_address, floating, admin_addr.try_into().unwrap());

let dispatcher = IProposalsDispatcher { contract_address: gov_address };

// Submit first proposal
start_prank(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap());
start_prank(CheatTarget::One(gov_address), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(42, 3);
dispatcher.vote(prop_id, 1);
assert!(dispatcher.get_proposal_status(prop_id) == 1, "proposal not passed!");

// Check health (should be healthy)
let is_healthy = check_if_healthy(gov.contract_address);
assert!(is_healthy == true, "Governance should be healthy after first proposal");
let is_healthy = check_if_healthy(gov_address);
println!("After first proposal, is_healthy: {}", is_healthy);
assert!(is_healthy, "Governance should be healthy after first proposal");

// Apply the proposal
IUpgradesDispatcher { contract_address: gov.contract_address }.apply_passed_proposal(prop_id);
IUpgradesDispatcher { contract_address: gov_address }.apply_passed_proposal(prop_id);

// Submit second proposal (different type)
start_prank(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap());
start_prank(CheatTarget::One(gov_address), admin_addr.try_into().unwrap());
let prop_id2 = dispatcher.submit_proposal(43, 5);
dispatcher.vote(prop_id2, 1);
assert!(dispatcher.get_proposal_status(prop_id2) == 1, "second proposal not passed!");

let proposals_dispatcher = IProposalsDispatcher { contract_address: gov.contract_address };
let upgrades_dispatcher = IUpgradesDispatcher { contract_address: gov.contract_address };

let proposals_dispatcher = IProposalsDispatcher { contract_address: gov_address };
let upgrades_dispatcher = IUpgradesDispatcher { contract_address: gov_address };

let (_, last_upgrade_type) = upgrades_dispatcher.get_latest_upgrade();
let current_prop_id = proposals_dispatcher.get_latest_proposal_id();
let current_prop_details = proposals_dispatcher.get_proposal_details(current_prop_id);

println!("Governance Type {}:", last_upgrade_type);
println!("Upgrading Type {}:", current_prop_details.to_upgrade );
println!("Before final check_if_healthy:");
println!("Governance Type: {}", last_upgrade_type);
println!("Upgrading Type: {}", current_prop_details.to_upgrade);

// Check health again (should be unhealthy due to type mismatch)
let is_healthy = check_if_healthy(gov.contract_address);
assert!(is_healthy == false, "Governance should be unhealthy after second proposal of different type");
let is_healthy = check_if_healthy(gov_address);
println!("After second proposal, is_healthy: {}", is_healthy);
assert!(!is_healthy, "Governance should be unhealthy after second proposal of different type");

IUpgradesDispatcher { contract_address: gov_address }.apply_passed_proposal(prop_id2);
}

0 comments on commit a6f9ff1

Please sign in to comment.