Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow longer locks in pilot rounds #177

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Allow longer locks in pilot rounds.
([\#177](https://github.com/informalsystems/hydro/pull/177))
4 changes: 2 additions & 2 deletions artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
64c7901df8a9906223e43bab9aa606579bd61284f91649a2a52d0caf4d697206 hydro.wasm
59a278e98f945a980e4dbd897a3a15cbe54df555515d03ab0f635a2b4ef0e9fa tribute.wasm
6a493be7e950050faa946c87b0c5928907dd9ed2d5e94b1c2d12c844a97cfc4f hydro.wasm
4f9a40da3c48d741112d35f0e4a52111863379d3ac80603c2b361e9b7a927d72 tribute.wasm
Binary file modified artifacts/hydro.wasm
Binary file not shown.
Binary file modified artifacts/tribute.wasm
Binary file not shown.
19 changes: 13 additions & 6 deletions contracts/hydro/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn lock_tokens(
let constants = CONSTANTS.load(deps.storage)?;

validate_contract_is_not_paused(&constants)?;
// if we are in pilot mode, only allow lockups of a single epoch

if constants.is_in_pilot_mode {
pilot_round_validate_lock_duration(constants.lock_epoch_length, lock_duration)?;
} else {
Expand Down Expand Up @@ -488,15 +488,22 @@ fn validate_lock_duration(lock_epoch_length: u64, lock_duration: u64) -> Result<
Ok(())
}
// This is a separate validation function which will be used in the pilot rounds
// of the contract, making sure that only lockups of a single epoch are allowed.
// of the contract, making sure that only lockups of 1, 2 or 3 epochs are allowed.
fn pilot_round_validate_lock_duration(
lock_epoch_length: u64,
lock_duration: u64,
) -> Result<(), ContractError> {
if lock_duration != lock_epoch_length {
return Err(ContractError::Std(StdError::generic_err(
"Lock duration must be 1 epoch",
)));
if lock_duration != lock_epoch_length
&& lock_duration != lock_epoch_length * 2
&& lock_duration != lock_epoch_length * 3
{
return Err(ContractError::Std(StdError::generic_err(format!(
"Lock duration must be 1, 2 or 3 epochs: {}, {} or {}; but was: {}",
lock_epoch_length,
lock_epoch_length * 2,
lock_epoch_length * 3,
lock_duration
))));
}

Ok(())
Expand Down
21 changes: 13 additions & 8 deletions contracts/hydro/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2271,7 +2271,7 @@ fn assert_proposal_voting_power(

// This test verifies that when the contract is in pilot mode,
// the possible lock durations are restricted to the durations allowed during
// pilot rounds (just 1 round in this case).
// pilot rounds (1, 2 or 3 rounds in this case).
#[test]
pub fn pilot_round_lock_duration_test() {
struct TestCase {
Expand All @@ -2286,11 +2286,11 @@ pub fn pilot_round_lock_duration_test() {
},
TestCase {
lock_duration: ONE_MONTH_IN_NANO_SECONDS * 2,
expect_error: true,
expect_error: false,
},
TestCase {
lock_duration: ONE_MONTH_IN_NANO_SECONDS * 3,
expect_error: true,
expect_error: false,
},
TestCase {
lock_duration: ONE_MONTH_IN_NANO_SECONDS * 6,
Expand Down Expand Up @@ -2341,11 +2341,16 @@ pub fn pilot_round_lock_duration_test() {
"Expected error for lock_duration: {}",
case.lock_duration
);
assert!(res
.err()
.unwrap()
.to_string()
.contains("Lock duration must be 1 epoch"),);

let expected_error = format!(
"Lock duration must be 1, 2 or 3 epochs: {}, {} or {}; but was: {}",
msg.lock_epoch_length,
2 * msg.lock_epoch_length,
3 * msg.lock_epoch_length,
case.lock_duration
)
.to_string();
assert!(res.err().unwrap().to_string().contains(&expected_error),);
} else {
assert!(
res.is_ok(),
Expand Down