Skip to content

Commit

Permalink
Add test for per_tranche info on lockups
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Dec 18, 2024
1 parent 1b9ec10 commit 0940181
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions contracts/hydro/src/testing_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::str::FromStr;
use crate::contract::{
compute_current_round_id, query_all_user_lockups, query_user_votes, scale_lockup_power,
};
use crate::msg::ProposalToLockups;
use crate::state::{
RoundLockPowerSchedule, ValidatorInfo, Vote, CONSTANTS, VALIDATORS_INFO, VOTE_MAP,
};
Expand Down Expand Up @@ -81,6 +82,50 @@ fn query_user_lockups_test() {
let res = execute(deps.as_mut(), env.clone(), info.clone(), msg);
assert!(res.is_ok());

// add two proposals with different deployment durations

// proposal 1 has a 1 month deployment duration
let msg1 = ExecuteMsg::CreateProposal {
round_id: None,
tranche_id: 1,
title: "proposal title 1".to_string(),
description: "proposal description 1".to_string(),
deployment_duration: 1,
minimum_atom_liquidity_request: Uint128::zero(),
};
let res = execute(deps.as_mut(), env.clone(), info.clone(), msg1.clone());
assert!(res.is_ok());

// proposal 2 has a 3 month deployment duration
let msg2 = ExecuteMsg::CreateProposal {
round_id: None,
tranche_id: 1,
title: "proposal title 2".to_string(),
description: "proposal description 2".to_string(),
deployment_duration: 3,
minimum_atom_liquidity_request: Uint128::zero(),
};
let res = execute(deps.as_mut(), env.clone(), info.clone(), msg2.clone());
assert!(res.is_ok());

// vote for proposal 1 with the first lockup and for proposal 2 with the second lockup
// vote for the first proposal
let msg = ExecuteMsg::Vote {
tranche_id: 1,
proposals_votes: vec![
ProposalToLockups {
proposal_id: 0,
lock_ids: vec![0],
},
ProposalToLockups {
proposal_id: 1,
lock_ids: vec![1],
},
],
};
let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone());
assert!(res.is_ok());

// at this moment user doesn't have any expired lockups
let expired_lockups = get_expired_user_lockups(&deps, env.clone(), info.sender.to_string());
assert_eq!(0, expired_lockups.len());
Expand Down Expand Up @@ -127,6 +172,14 @@ fn query_user_lockups_test() {
res.lockups[1].lock_with_power.current_voting_power.u128()
);

// check that the votes on the lockups are correct
assert!(res.lockups[0].per_tranche_info[0]
.current_voted_on_proposal
.is_some_and(|x| x == 0),);
assert!(res.lockups[1].per_tranche_info[0]
.current_voted_on_proposal
.is_some_and(|x| x == 1),);

// advance the chain for a month and verify that the first lockup has expired
env.block.time = env.block.time.plus_nanos(ONE_MONTH_IN_NANO_SECONDS);
let expired_lockups = get_expired_user_lockups(&deps, env.clone(), info.sender.to_string());
Expand Down Expand Up @@ -194,6 +247,27 @@ fn query_user_lockups_test() {
.u128()
);

println!("{:#?}", all_lockups);

// check that neither lockup has voted on a proposal
// check that the votes on the lockups are correct
assert!(all_lockups.lockups[0].per_tranche_info[0]
.current_voted_on_proposal
.is_none(),);
assert!(all_lockups.lockups[1].per_tranche_info[0]
.current_voted_on_proposal
.is_none(),);

// check that the next voting rounds are correct
assert_eq!(
1,
all_lockups.lockups[0].per_tranche_info[0].next_round_lockup_can_vote
);
assert_eq!(
3,
all_lockups.lockups[1].per_tranche_info[0].next_round_lockup_can_vote
);

// advance the chain for 3 more months and verify that the second lockup has expired as well
env.block.time = env.block.time.plus_nanos(3 * ONE_MONTH_IN_NANO_SECONDS);
let expired_lockups = get_expired_user_lockups(&deps, env.clone(), info.sender.to_string());
Expand Down

0 comments on commit 0940181

Please sign in to comment.