From a6f9ff1c19714293448c9d3205765a8e7202b28a Mon Sep 17 00:00:00 2001 From: scobi Date: Tue, 6 Aug 2024 09:17:10 +0000 Subject: [PATCH] scarb fmt (#116) --- src/contract.cairo | 2 +- src/proposals.cairo | 1 - src/staking.cairo | 2 +- src/testing/setup.cairo | 16 +++------ tests/staking_tests.cairo | 2 +- tests/test_setup.cairo | 69 +++++++++++++++++++++++++++------------ 6 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/contract.cairo b/src/contract.cairo index d3c5f99f..7ff078ab 100644 --- a/src/contract.cairo +++ b/src/contract.cairo @@ -174,4 +174,4 @@ mod Governance { self.governance_token_address.read() } } -} \ No newline at end of file +} diff --git a/src/proposals.cairo b/src/proposals.cairo index 8c2697a7..6ed2aafe 100644 --- a/src/proposals.cairo +++ b/src/proposals.cairo @@ -36,7 +36,6 @@ trait IProposals { prop_id: felt252, ); fn get_total_delegated_to(self: @TContractState, to_addr: ContractAddress) -> u128; - } #[starknet::component] diff --git a/src/staking.cairo b/src/staking.cairo index 51284d65..cfaea115 100644 --- a/src/staking.cairo +++ b/src/staking.cairo @@ -322,4 +322,4 @@ mod staking { } } } -} \ No newline at end of file +} diff --git a/src/testing/setup.cairo b/src/testing/setup.cairo index 1bd88447..4801f9d6 100644 --- a/src/testing/setup.cairo +++ b/src/testing/setup.cairo @@ -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 } diff --git a/tests/staking_tests.cairo b/tests/staking_tests.cairo index f5c06b91..5adf5859 100644 --- a/tests/staking_tests.cairo +++ b/tests/staking_tests.cairo @@ -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); -} \ No newline at end of file +} diff --git a/tests/test_setup.cairo b/tests/test_setup.cairo index ede80b36..ff057e9e 100644 --- a/tests/test_setup.cairo +++ b/tests/test_setup.cairo @@ -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 @@ -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(); @@ -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."); @@ -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); }