Skip to content

Commit

Permalink
cap num unique validators to 50
Browse files Browse the repository at this point in the history
  • Loading branch information
0xripleys committed Oct 15, 2024
1 parent 259b00d commit 2a72f3a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions contracts/sources/storage.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ module liquid_staking::storage {
use sui::bag::{Self, Bag};

/* Errors */
const ETooManyValidators: u64 = 0;

/* Constants */
const MIN_STAKE_THRESHOLD: u64 = 1_000_000_000;
const MAX_VALIDATORS: u64 = 50;

/// The Storage struct holds all stake for the LST.
public struct Storage has store {
Expand Down Expand Up @@ -518,6 +520,8 @@ module liquid_staking::storage {
extra_fields: bag::new(ctx)
});

assert!(self.validator_infos.length() <= MAX_VALIDATORS, ETooManyValidators);

i
}

Expand Down
32 changes: 31 additions & 1 deletion contracts/tests/storage_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module liquid_staking::storage_tests {
use sui::balance::{Self};
use liquid_staking::storage::{new};
use sui::sui::SUI;
use std::macros::do;

#[test_only]
fun setup_sui_system(scenario: &mut Scenario, stakes: vector<u64>) {
Expand Down Expand Up @@ -1127,4 +1128,33 @@ module liquid_staking::storage_tests {

scenario.end();
}
}

#[test]
#[expected_failure(abort_code = 0, location = liquid_staking::storage)]
fun test_too_many_validators() {
let mut scenario = test_scenario::begin(@0x0);

let mut storage = new(scenario.ctx());

let mut validator_initial_stakes = vector::empty();
51u64.do!(|_| {
validator_initial_stakes.push_back(100);
});

setup_sui_system(&mut scenario, validator_initial_stakes);
scenario.next_tx(@0x0);

51u64.do!(|i| {
let stake = stake_with(i, 100, &mut scenario);

let mut system_state = scenario.take_shared<SuiSystemState>();
storage.join_stake(&mut system_state, stake, scenario.ctx());
test_scenario::return_shared(system_state);

scenario.next_tx(@0x0);
});

sui::test_utils::destroy(storage);
scenario.end();
}
}

0 comments on commit 2a72f3a

Please sign in to comment.