Skip to content

Commit

Permalink
feat: check lock period not changed on renew endpoint
Browse files Browse the repository at this point in the history
Refs: #1
  • Loading branch information
bucurdavid committed Mar 14, 2024
1 parent 89b45d4 commit 46f44a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ pub trait LifeBondingContract:

require!(bond_cache.address == caller, ERR_BOND_NOT_FOUND);

require!(
self.lock_periods().contains(&bond_cache.lock_period),
ERR_INVALID_LOCK_PERIOD
);

let current_timestamp = self.blockchain().get_block_timestamp();

bond_cache.unbound_timestamp = current_timestamp + bond_cache.lock_period;
Expand Down
10 changes: 10 additions & 0 deletions tests/endpoints/renew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ fn renew() {
remaining_amount: managed_biguint!(100u64),
}),
);

state.remove_lock_period_and_bond(OWNER_BONDING_CONTRACT_ADDRESS_EXPR, 10u64, None);
state.set_lock_period_and_bond(OWNER_BONDING_CONTRACT_ADDRESS_EXPR, 20u64, 200u64, None);

state.renew(
FIRST_USER_ADDRESS_EXPR,
DATA_NFT_IDENTIFIER,
1u64,
Some(TxExpect::user_error("str:Invalid lock period")),
);
}

0 comments on commit 46f44a1

Please sign in to comment.