Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tensojka committed Aug 22, 2024
1 parent 0487558 commit fc6b45b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
38 changes: 20 additions & 18 deletions src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ mod Governance {
ref self: ContractState,
voting_token_class: ClassHash,
floating_token_class: ClassHash,
treasury_classhash: ClassHash,
recipient: ContractAddress
) {
// This is not used in production on mainnet, because the governance token is already deployed (and distributed).
Expand Down Expand Up @@ -170,26 +171,27 @@ mod Governance {
staking.set_curve_point(SIX_MONTHS, 160);
staking.set_curve_point(ONE_YEAR, 250);

let treasury_classhash = 0x06a38a382eddf3d7ebf9673516ac7cf1ff185a1ecbf490cb07f1687e531eb9ec
.try_into()
.unwrap();
let mut treasury_calldata: Array<felt252> = ArrayTrait::new();
treasury_calldata.append(governance_address.into());
treasury_calldata.append(0x1); // carmine amm addr
treasury_calldata.append(0x1); // zklend addr
let (treasury_address, _) = deploy_syscall(
treasury_classhash, 42, treasury_calldata.span(), true
)
.unwrap();
let proposals = IProposalsDispatcher { contract_address: governance_address };
let send_tokens_custom_proposal_config: CustomProposalConfig = CustomProposalConfig {
target: treasury_address.into(),
selector: selector!("send_tokens_to_address"),
library_call: false,
proposal_voting_time: 0 // use global default
};

proposals.add_custom_proposal_config(send_tokens_custom_proposal_config);
if (treasury_classhash.into() != 0) {
let mut treasury_calldata: Array<felt252> = ArrayTrait::new();
treasury_calldata.append(governance_address.into());
treasury_calldata.append(0x1); // carmine amm addr
treasury_calldata.append(0x1); // zklend addr
let (treasury_address, _) = deploy_syscall(
treasury_classhash, 42, treasury_calldata.span(), true
)
.unwrap();

let send_tokens_custom_proposal_config: CustomProposalConfig = CustomProposalConfig {
target: treasury_address.into(),
selector: selector!("send_tokens_to_address"),
library_call: false,
proposal_voting_time: 0 // use global default
};

proposals.add_custom_proposal_config(send_tokens_custom_proposal_config);
}

let set_default_proposal_params_custom_proposal_config: CustomProposalConfig =
CustomProposalConfig {
Expand Down
2 changes: 2 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ successfully

[] Re-applying a proposal that has already passed : make sure the contract rejects the submission of a proposal that has expired in the past

[] Change the quorum and proposal voting time


### Delegate_vote and withdraw_delegation functions

Expand Down
2 changes: 1 addition & 1 deletion tests/basic.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn test_upgrade_mainnet_to_master() {

//simulate passage of time
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
let end_timestamp = current_timestamp + consteval_int!(60 * 60 * 24 * 7);
start_warp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);

assert(dispatcher.get_proposal_status(new_prop_id) == 1, 'proposal not passed!');
Expand Down
1 change: 1 addition & 0 deletions tests/deploy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn test_deploy() {
let mut args: Array<felt252> = ArrayTrait::new();
args.append(voting_token_class);
args.append(floating_token_class);
args.append(0);
args.append(0x03f37e36c20E85e6F39b2C6F6e7ECEB2e3aAb40b94064f20983588cfe9f6fc60);
gov_contract.deploy(@args).expect('unable to deploy governance');
}
13 changes: 7 additions & 6 deletions tests/proposals_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use super::staking_tests::{set_staking_curve, stake_all, stake_half};


const GOV_TOKEN_INITIAL_SUPPLY: felt252 = 1000000000000000000;

const PROPOSAL_VOTING_SECONDS: u64 = consteval_int!(60 * 60 * 24 * 7);
const QUORUM: u128 = 10;

#[test]
fn test_express_proposal() {
Expand Down Expand Up @@ -62,7 +63,7 @@ fn test_proposal_expiry() {

//simulate passage of time
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
let end_timestamp = current_timestamp + PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov.contract_address), end_timestamp + 1);

let status = dispatcher.get_proposal_status(prop_id);
Expand All @@ -87,7 +88,7 @@ fn test_vote_on_expired_proposal() {

//simulate passage of time
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
let end_timestamp = current_timestamp + PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov.contract_address), end_timestamp + 1);

prank(
Expand Down Expand Up @@ -137,11 +138,11 @@ fn test_vote_on_quorum_not_met() {
}
.totalSupply()
.low;
let quorum_threshold = total_eligible_votes * constants::QUORUM / 100;
let quorum_threshold = total_eligible_votes * QUORUM / 100;

assert(total_votes < quorum_threshold, 'Total votes >= quorum threshold');
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
let end_timestamp = current_timestamp + PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);
assert(
dispatcher.get_proposal_status(prop_id) == constants::MINUS_ONE,
Expand Down Expand Up @@ -462,7 +463,7 @@ fn test_add_comment_on_non_live_proposal() {

//simulate passage of time
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
let end_timestamp = current_timestamp + PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);

IDiscussionDispatcher { contract_address: gov_contract_addr }
Expand Down
1 change: 1 addition & 0 deletions tests/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn deploy_governance_and_both_tokens() -> (
let mut args: Array<felt252> = ArrayTrait::new();
args.append(voting_token_class.class_hash.into());
args.append(floating_token_class.class_hash.into());
args.append(0); // treasury – no treasury
args.append(admin_addr);
gov_contract
.deploy_at(@args, governance_address.try_into().unwrap())
Expand Down

0 comments on commit fc6b45b

Please sign in to comment.