Skip to content

Commit

Permalink
Polish format
Browse files Browse the repository at this point in the history
  • Loading branch information
tensojka committed Jun 11, 2024
1 parent c9c113e commit 1c49f7d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
16 changes: 12 additions & 4 deletions tests/proposals_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use snforge_std::{
};

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, check_if_healthy
admin_addr, first_address, second_address, deploy_governance, deploy_and_distribute_gov_tokens,
deploy_governance_and_both_tokens, test_vote_upgrade_root, check_if_healthy
};
use super::staking_tests::{set_staking_curve, stake_all};
use konoha::contract::IGovernanceDispatcher;
Expand Down Expand Up @@ -78,15 +78,23 @@ fn test_vote_on_expired_proposal() {

let dispatcher = IProposalsDispatcher { contract_address: gov.contract_address };

prank(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap(), CheatSpan::TargetCalls(1));
prank(
CheatTarget::One(gov.contract_address),
admin_addr.try_into().unwrap(),
CheatSpan::TargetCalls(1)
);
let prop_id = dispatcher.submit_proposal(42, 1);

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

prank(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap(), CheatSpan::TargetCalls(1));
prank(
CheatTarget::One(gov.contract_address),
admin_addr.try_into().unwrap(),
CheatSpan::TargetCalls(1)
);
dispatcher.vote(prop_id, 1);
}

Expand Down
28 changes: 21 additions & 7 deletions tests/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,29 @@ fn deploy_governance(token_address: ContractAddress) -> IGovernanceDispatcher {
}

// return governance, voting token, floating token.
fn deploy_governance_and_both_tokens() -> (IGovernanceDispatcher, IERC20Dispatcher, IERC20Dispatcher) {
fn deploy_governance_and_both_tokens() -> (
IGovernanceDispatcher, IERC20Dispatcher, IERC20Dispatcher
) {
let gov_contract = declare("Governance").expect('unable to declare governance');
let mut args: Array<felt252> = ArrayTrait::new();
args.append(voting_token_address);
gov_contract.deploy_at(@args, governance_address.try_into().unwrap()).expect('unable to deploy governance');
let gov_dispatcher = IGovernanceDispatcher { contract_address: governance_address.try_into().unwrap() };
gov_contract
.deploy_at(@args, governance_address.try_into().unwrap())
.expect('unable to deploy governance');
let gov_dispatcher = IGovernanceDispatcher {
contract_address: governance_address.try_into().unwrap()
};

println!("Deploying VotingToken");
let voting_token_class = declare("VotingToken").expect('unable to declare VotingToken');
let mut voting_token_constructor_calldata = ArrayTrait::new();
voting_token_constructor_calldata.append(governance_address);
voting_token_class.deploy_at(@voting_token_constructor_calldata, voting_token_address.try_into().unwrap()).expect('unable to deploy VotingToken');
let voting_token_dispatcher = IERC20Dispatcher { contract_address: voting_token_address.try_into().unwrap() };
voting_token_class
.deploy_at(@voting_token_constructor_calldata, voting_token_address.try_into().unwrap())
.expect('unable to deploy VotingToken');
let voting_token_dispatcher = IERC20Dispatcher {
contract_address: voting_token_address.try_into().unwrap()
};

let mut calldata = ArrayTrait::new();
calldata.append(GOV_TOKEN_INITIAL_SUPPLY.low.into());
Expand All @@ -64,10 +74,14 @@ fn deploy_governance_and_both_tokens() -> (IGovernanceDispatcher, IERC20Dispatch
floating_token_class
.deploy_at(@calldata, floating_token_address.try_into().unwrap())
.expect('unable to deploy FloatingToken');
let floating_token_dispatcher = IERC20Dispatcher { contract_address: floating_token_address.try_into().unwrap() };
let floating_token_dispatcher = IERC20Dispatcher {
contract_address: floating_token_address.try_into().unwrap()
};

// set floating token address in staking component
set_floating_token_address(governance_address.try_into().unwrap(), floating_token_address.try_into().unwrap());
set_floating_token_address(
governance_address.try_into().unwrap(), floating_token_address.try_into().unwrap()
);

(gov_dispatcher, voting_token_dispatcher, floating_token_dispatcher)
}
Expand Down
29 changes: 6 additions & 23 deletions tests/staking_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use super::setup::{
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};

use snforge_std::{
BlockId, declare, ContractClassTrait, ContractClass, CheatTarget,
prank, CheatSpan
BlockId, declare, ContractClassTrait, ContractClass, CheatTarget, prank, CheatSpan
};
use konoha::staking::{IStakingDispatcher, IStakingDispatcherTrait};
use debug::PrintTrait;
Expand All @@ -15,23 +14,15 @@ const ONE_MONTH: u64 = 2629743;

fn set_staking_curve(gov: ContractAddress) {
// simulate calling this from a proposal
prank(
CheatTarget::One(gov),
gov,
CheatSpan::TargetCalls(1)
);
prank(CheatTarget::One(gov), gov, CheatSpan::TargetCalls(1));

let staking = IStakingDispatcher { contract_address: gov };
staking.set_curve_point(ONE_MONTH, 100); // 1 KONOHA = 1 veKONOHA if staked for 1 month
}

fn set_floating_token_address(gov: ContractAddress, floating_token_address: ContractAddress) {
// simulate calling this from a proposal
prank(
CheatTarget::One(gov),
gov,
CheatSpan::TargetCalls(1)
);
prank(CheatTarget::One(gov), gov, CheatSpan::TargetCalls(1));

let staking = IStakingDispatcher { contract_address: gov };
staking.set_floating_token_address(floating_token_address);
Expand All @@ -41,17 +32,9 @@ fn stake_all(gov: ContractAddress, floating: IERC20Dispatcher, staker: ContractA
let staking = IStakingDispatcher { contract_address: gov };

let balance_of_staker = floating.balance_of(staker).low;
prank(
CheatTarget::One(floating.contract_address),
staker,
CheatSpan::TargetCalls(1)
);
prank(CheatTarget::One(floating.contract_address), staker, CheatSpan::TargetCalls(1));
floating.approve(gov, balance_of_staker.into());
prank(
CheatTarget::One(gov),
staker,
CheatSpan::TargetCalls(1)
);
prank(CheatTarget::One(gov), staker, CheatSpan::TargetCalls(1));
staking.stake(ONE_MONTH, balance_of_staker);
println!("staked");
}
}

0 comments on commit 1c49f7d

Please sign in to comment.