Skip to content

Commit

Permalink
Add tests on proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerrolol committed Apr 26, 2024
1 parent d561c54 commit 33eb62a
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion tests/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ use core::traits::TryInto;
use debug::PrintTrait;
use starknet::ContractAddress;
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use snforge_std::{BlockId, declare, ContractClassTrait, ContractClass, start_prank, CheatTarget};
use snforge_std::{
BlockId, declare, ContractClassTrait, ContractClass, start_prank, start_warp, CheatTarget
};

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 starknet::get_block_timestamp;


const GOV_TOKEN_INITIAL_SUPPLY: felt252 = 1000000000000000000;

Expand Down Expand Up @@ -103,3 +108,57 @@ fn test_vote_upgrade_root(new_merkle_root: felt252) {
assert(check_if_healthy(gov_contract_addr), 'new gov not healthy');
}


fn test_express_proposal() {
let gov_contract = deploy_governance();
let gov_contract_addr = gov_contract.contract_address;
let token_contract = deploy_and_distribute_gov_tokens(admin_addr);

let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

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

start_prank(CheatTarget::One(gov_contract_addr), admin_addr);
dispatcher.vote(prop_id, 1);

assert(dispatcher.get_proposal_status(prop_id) == 1, 'proposal not passed!');
}

#[should_panic]
fn test_proposal_expiry() {
let gov_contract = deploy_governance();
let gov_contract_addr = gov_contract.contract_address;
let token_contract = deploy_and_distribute_gov_tokens(admin_addr);

let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

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

let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
start_warp(current_timestamp, end_timestamp + 1);

let status = dispatcher.get_proposal_status(prop_id);
}

#[should_panic]
fn test_vote_on_expired_proposal() {
let gov_contract = deploy_governance();
let gov_contract_addr = gov_contract.contract_address;
let token_contract = deploy_and_distribute_gov_tokens(admin_addr);

let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

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

let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
start_warp(current_timestamp, end_timestamp + 1);

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

0 comments on commit 33eb62a

Please sign in to comment.