Skip to content

Commit

Permalink
fix instant unlocking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
epanchee committed Sep 13, 2024
1 parent 0b01016 commit 76358a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions contracts/emissions_controller/tests/common/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ impl ControllerHelper {
)
}

pub fn total_vp(&self, timestamp: Option<u64>) -> StdResult<Uint128> {
self.app.wrap().query_wasm_smart(
&self.vxastro,
&voting_escrow::QueryMsg::TotalVotingPower { timestamp },
)
}

pub fn user_info(&self, user: &Addr, timestamp: Option<u64>) -> StdResult<UserInfoResponse> {
self.app.wrap().query_wasm_smart(
&self.emission_controller,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ fn test_instant_unlock_vxastro() {
.unwrap();

let alice = helper.app.api().addr_make("alice");
helper.lock(&alice, 4_000000).unwrap();
helper.lock(&alice, 10_000000).unwrap();

helper
.vote(
Expand All @@ -1122,7 +1122,7 @@ fn test_instant_unlock_vxastro() {
// Assert pools voting power
for pool in [&pool1, &pool2] {
let pool_vp = helper.query_pool_vp(pool.as_str(), None).unwrap();
assert_eq!(pool_vp.u128(), 2_000000);
assert_eq!(pool_vp.u128(), 5_000000);
}

// Ensure random user can't instantly unlock
Expand Down Expand Up @@ -1169,9 +1169,13 @@ fn test_instant_unlock_vxastro() {
// Assert pools voting power is reduced
for pool in [&pool1, &pool2] {
let pool_vp = helper.query_pool_vp(pool.as_str(), None).unwrap();
assert_eq!(pool_vp.u128(), 1_000000);
assert_eq!(pool_vp.u128(), 4_000000);
}

// Total voting power must be 8
let total_vp = helper.total_vp(None).unwrap();
assert_eq!(total_vp.u128(), 8_000000);

let lock_info: voting_escrow::LockInfoResponse = helper
.app
.wrap()
Expand All @@ -1185,7 +1189,7 @@ fn test_instant_unlock_vxastro() {
assert_eq!(
lock_info,
voting_escrow::LockInfoResponse {
amount: 2_000000u128.into(),
amount: 8_000000u128.into(),
unlock_status: None
}
);
Expand Down
4 changes: 2 additions & 2 deletions contracts/voting_escrow/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ impl Lock {
self.amount = self.amount.checked_sub(amount)?;
LOCKED.save(storage, &self.user, self, self.block_time)?;

// Remove user's voting power from the total
// Remove unlocked voting power from the total
TOTAL_POWER.update(storage, self.block_time, |total| -> StdResult<_> {
Ok(total.unwrap_or_default().checked_sub(self.amount)?)
Ok(total.unwrap_or_default().checked_sub(amount)?)
})?;

Ok(())
Expand Down

0 comments on commit 76358a9

Please sign in to comment.