Skip to content
Open
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
4 changes: 4 additions & 0 deletions contracts/tholos-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ const INSTANCE_LIFETIME_THRESHOLD: u32 = INSTANCE_BUMP_AMOUNT - DAY_IN_LEDGERS;

const MAX_REGISTRATION_DURATION_SECS: u64 = 7 * 24 * 60 * 60;
const MAX_REVEAL_DURATION_SECS: u64 = 7 * 24 * 60 * 60;
pub const MAX_ANTI_SNIPE_HARD_MAX_SECS: u64 = 29 * 24 * 60 * 60; // 29 days
/// Same 7-day cap as v1's `challenge_window_secs`, for the same reason: it
/// must leave real margin within the 30-day persistent-storage TTL bump
/// (`INSTANCE_BUMP_AMOUNT`) for `finalize` to actually get called before the
Expand Down Expand Up @@ -666,6 +667,9 @@ impl TholosV2 {
if anti_snipe_extension_secs > anti_snipe_hard_max_secs {
return Err(Error::InvalidAntiSnipeParams);
}
if anti_snipe_hard_max_secs > MAX_ANTI_SNIPE_HARD_MAX_SECS {
return Err(Error::InvalidAntiSnipeParams);
}
// registration_hard_deadline is registration_opened_at +
// anti_snipe_hard_max_secs (see dispute() below), an absolute
// duration from registration opening, independent of
Expand Down
46 changes: 46 additions & 0 deletions contracts/tholos-v2/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3159,3 +3159,49 @@ mod proptest_settlement {
}
}
}

#[test]
fn test_initialize_rejects_anti_snipe_hard_max_over_max() {
let env = Env::default();
env.mock_all_auths();
let token_id = setup(&env);
let contract_id = env.register(TholosV2, ());
let client = TholosV2Client::new(&env, &contract_id);
let admin = Address::generate(&env);

let result = init_full(
&client,
&admin,
&token_id,
DEFAULT_REGISTRATION_SECS,
DEFAULT_ANTI_SNIPE_EXT_SECS,
MAX_ANTI_SNIPE_HARD_MAX_SECS + 1,
DEFAULT_REVEAL_SECS,
DEFAULT_MAX_POSITION,
DEFAULT_MAX_TOTAL_WEIGHT,
);
assert_eq!(result, Err(Ok(Error::InvalidAntiSnipeParams)));
}

#[test]
fn test_initialize_accepts_anti_snipe_hard_max_at_max() {
let env = Env::default();
env.mock_all_auths();
let token_id = setup(&env);
let contract_id = env.register(TholosV2, ());
let client = TholosV2Client::new(&env, &contract_id);
let admin = Address::generate(&env);

let result = init_full(
&client,
&admin,
&token_id,
DEFAULT_REGISTRATION_SECS,
DEFAULT_ANTI_SNIPE_EXT_SECS,
MAX_ANTI_SNIPE_HARD_MAX_SECS,
DEFAULT_REVEAL_SECS,
DEFAULT_MAX_POSITION,
DEFAULT_MAX_TOTAL_WEIGHT,
);
assert_eq!(result, Ok(Ok(())));
}
2 changes: 1 addition & 1 deletion docs/src/CONTRACT_V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ only affect assertions created after the change.
| `InvalidBondAmount` | `base_bond` isn't positive, or exceeds `MAX_BOND_AMOUNT`. |
| `InvalidRegistrationDuration` | `registration_duration_secs` is zero or exceeds 7 days. |
| `InvalidRevealDuration` | `reveal_duration_secs` is zero or exceeds 7 days. |
| `InvalidAntiSnipeParams` | `anti_snipe_extension_secs` exceeds `anti_snipe_hard_max_secs`, or `anti_snipe_hard_max_secs` is shorter than `registration_duration_secs`. |
| `InvalidAntiSnipeParams` | `anti_snipe_extension_secs` exceeds `anti_snipe_hard_max_secs`, `anti_snipe_hard_max_secs` is shorter than `registration_duration_secs`, or `anti_snipe_hard_max_secs` exceeds `MAX_ANTI_SNIPE_HARD_MAX_SECS` (30 days). |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still says "(30 days)" here, but MAX_ANTI_SNIPE_HARD_MAX_SECS is now 29 days after this PR's own last commit. Please update this to match.

| `InvalidMaxPosition` | `max_position` isn't positive, or exceeds `max_total_weight`. |
| `InvalidMaxTotalWeight` | `max_total_weight` isn't positive, or exceeds `MAX_SETTLEMENT_TOTAL_WEIGHT`. |
| `InvalidChallengeWindow` | `challenge_window_secs` is zero or exceeds 7 days. |
Expand Down