Skip to content

Commit

Permalink
tests: add arbitrary proposal test
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveVodrazka committed Oct 1, 2024
1 parent d82b3cb commit 2006725
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
135 changes: 135 additions & 0 deletions tests/add_options_proposal.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
use snforge_std::{
CheatSpan, CheatTarget, ContractClassTrait, ContractClass, prank, start_warp, declare
};

use starknet::{ContractAddress, get_block_timestamp};

use amm_governance::proposals::{IProposalsDispatcherTrait, IProposalsDispatcher};

use konoha::upgrades::IUpgradesDispatcher;
use konoha::upgrades::IUpgradesDispatcherTrait;

fn get_voter_addresses() -> @Span<felt252> {
let arr = array![
0x0011d341c6e841426448ff39aa443a6dbb428914e05ba2259463c18308b86233,
0x0583a9d956d65628f806386ab5b12dccd74236a3c6b930ded9cf3c54efc722a1,
0x03d1525605db970fa1724693404f5f64cba8af82ec4aab514e6ebd3dec4838ad,
0x00d79a15d84f5820310db21f953a0fae92c95e25d93cb983cc0c27fc4c52273c,
0x0428c240649b76353644faF011B0d212e167f148fdd7479008Aa44eEaC782BfC,
0x06717eaf502baac2b6b2c6ee3ac39b34a52e726a73905ed586e757158270a0af,
];
@arr.span()
}

fn get_option_calldata() -> @Span<felt252> {
// calldata generated by FE
let arr = array![
0x16, // array length
0x5354524b2d555344432d43414c4c2d4c4f4e47, // str_to_felt STRK-USDC-CALL-LONG
0x5354524b2d555344432d43414c4c2d53484f5254, // str_to_felt STRK-USDC-CALL-SHORT
0x675B78FF, // maturity
0x6666666666666666, // strike price 0.4
0x0, // fixed sign
0x0, // option type
0x2b629088a1d30019ef18b893cebab236f84a365402fa0df2f51ec6a01506b1d, // lp address
0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8, // quote address
0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d, // base address
0x5a0000000000000000, // volatility
0x0, // fixed sign
0x5354524b2d555344432d43414c4c2d4c4f4e47, // str_to_felt STRK-USDC-CALL-LONG
0x5354524b2d555344432d43414c4c2d53484f5254, // str_to_felt STRK-USDC-CALL-SHORT
0x675B78FF, // maturity
0x8000000000000000, // strike price 0.5
0x0, // fixed sign
0x0, // option type
0x2b629088a1d30019ef18b893cebab236f84a365402fa0df2f51ec6a01506b1d, // lp address
0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8, // quote address
0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d, // base address
0x5a0000000000000000,
0x0,
];
@arr.span()
}

#[test]
#[fork("MAINNET")]
fn test_add_custom_proposal() {
let _option_deployer_contract_class: ContractClass = declare("OptionDeployer")
.expect('unable to declare op dep'); // need to declare, is not used
let arbitrary_proposal_contract_class: ContractClass = declare("ArbitraryProposalAddOptions")
.expect('unable to declare arb prop');
let arbitrary_proposal: felt252 = arbitrary_proposal_contract_class.class_hash.into();
let gov_addr = 0x001405ab78ab6ec90fba09e6116f373cda53b0ba557789a4578d8c1ec374ba0f
.try_into()
.unwrap();
let props = IProposalsDispatcher { contract_address: gov_addr };

let user1: ContractAddress =
0x0011d341c6e841426448ff39aa443a6dbb428914e05ba2259463c18308b86233 // team m 1
.try_into()
.unwrap();

prank(CheatTarget::One(gov_addr), user1, CheatSpan::TargetCalls(1));

// propose arbitrary proposal
let prop_id = props.submit_proposal(arbitrary_proposal, 0x6);

let mut voter_addresses = *get_voter_addresses();

// vote yay with all users
loop {
match voter_addresses.pop_front() {
Option::Some(address) => {
let current_voter: ContractAddress = (*address).try_into().unwrap();
prank(CheatTarget::One(gov_addr), current_voter, CheatSpan::TargetCalls(1));
props.vote(prop_id, 1);
},
Option::None(()) => { break (); }
}
};

let curr_timestamp = get_block_timestamp();
let proposal_wait_time = consteval_int!(60 * 60 * 24 * 7) + 420;
let warped_timestamp = curr_timestamp + proposal_wait_time;

start_warp(CheatTarget::One(gov_addr), warped_timestamp);
assert(props.get_proposal_status(prop_id) == 1, 'arbitrary proposal not passed');
println!("add arbitrary proposal passed");

let upgrades = IUpgradesDispatcher { contract_address: gov_addr };

upgrades.apply_passed_proposal(prop_id);

prank(CheatTarget::One(gov_addr), user1, CheatSpan::TargetCalls(1));

let add_options_calldata = get_option_calldata();

println!("add options calldata: {:?}", add_options_calldata);

// propose arbitrary proposal
let prop_id2: felt252 = props.submit_custom_proposal(0x2, *add_options_calldata).into();

let mut voter_addresses2 = *get_voter_addresses();

// vote yay with all users
loop {
match voter_addresses2.pop_front() {
Option::Some(address) => {
let current_voter: ContractAddress = (*address).try_into().unwrap();
prank(CheatTarget::One(gov_addr), current_voter, CheatSpan::TargetCalls(1));
props.vote(prop_id2, 1);
},
Option::None(()) => { break (); }
}
};

let warped_timestamp2 = curr_timestamp + proposal_wait_time * 2;

start_warp(CheatTarget::One(gov_addr), warped_timestamp2);
assert(props.get_proposal_status(prop_id2) == 1, 'add options not passed');
println!("add options passed");

upgrades.apply_passed_proposal(prop_id2);

println!("add options applied");
}
1 change: 1 addition & 0 deletions tests/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ mod test_prop_pass;
//mod unstake_airdrop;
//mod add_options;
mod upgrade;
mod add_options_proposal;
pub mod utils;
2 changes: 1 addition & 1 deletion tests/upgrade.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn scenario_airdrop_staked_carm() {
0x0583a9d956d65628f806386ab5b12dccd74236a3c6b930ded9cf3c54efc722a1 // team
.try_into()
.unwrap();
let investor1: ContractAddress =
let _investor1: ContractAddress =
0x056d761e1e5d1918dba05de02afdbd8de8da01a63147dce828c9b1fe9227077d
.try_into()
.unwrap();
Expand Down

0 comments on commit 2006725

Please sign in to comment.