Skip to content

Commit

Permalink
Add quorum tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerrolol committed May 24, 2024
1 parent 9f61980 commit d837e28
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions tests/proposals_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ use snforge_std::{
BlockId, declare, ContractClassTrait, ContractClass, start_prank, start_warp, CheatTarget
};

use governance::testing::setup::{
use konoha::testing::setup::{
admin_addr, first_address, second_address, deploy_governance, deploy_and_distribute_gov_tokens, test_vote_upgrade_root, check_if_healthy
};
use governance::contract::IGovernanceDispatcher;
use governance::contract::IGovernanceDispatcherTrait;
use governance::proposals::IProposalsDispatcher;
use governance::proposals::IProposalsDispatcherTrait;
use governance::upgrades::IUpgradesDispatcher;
use governance::upgrades::IUpgradesDispatcherTrait;
use governance::constants;
use konoha::contract::IGovernanceDispatcher;
use konoha::contract::IGovernanceDispatcherTrait;
use konoha::proposals::IProposalsDispatcher;
use konoha::proposals::IProposalsDispatcherTrait;
use konoha::upgrades::IUpgradesDispatcher;
use konoha::upgrades::IUpgradesDispatcherTrait;
use konoha::constants;
use starknet::get_block_timestamp;


Expand Down Expand Up @@ -79,3 +79,43 @@ fn test_vote_on_expired_proposal() {
start_prank(CheatTarget::One(gov_contract_addr), first_address.try_into().unwrap());
dispatcher.vote(prop_id, 1);
}

#[test]
fn test_vote_on_quorum_not_met() {
let token_contract = deploy_and_distribute_gov_tokens(admin_addr.try_into().unwrap());
let gov_contract = deploy_governance(token_contract.contract_address);
let gov_contract_addr = gov_contract.contract_address;

let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(42, 1);

start_prank(CheatTarget::One(gov_contract_addr), first_address.try_into().unwrap());
dispatcher.vote(prop_id, 1);

let (yay_votes, nay_votes) = dispatcher.get_vote_counts(prop_id);
let total_votes = yay_votes + nay_votes;
let total_eligible_votes: u128 = IERC20Dispatcher {
contract_address: token_contract.contract_address
}
.totalSupply()
.low;
let quorum_threshold = total_eligible_votes * constants::QUORUM / 100;

assert!(total_votes < quorum_threshold, "Total votes should be less than quorum threshold");
assert!(dispatcher.get_proposal_status(prop_id) == constants::MINUS_ONE, "Proposal shouldn't pass when quorum not met");
}

#[test]
#[should_panic(expected: ('not enough tokens to submit proposal',))]
fn_test_submit_proposal_under_quorum() {
let token_contract = deploy_and_distribute_gov_tokens(admin_addr.try_into().unwrap());
let gov_contract = deploy_governance(token_contract.contract_address);
let gov_contract_addr = gov_contract.contract_address;

let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

start_prank(CheatTarget::One(gov_contract_addr), first_address);
dispatcher.submit_proposal(42,1);
}

0 comments on commit d837e28

Please sign in to comment.