Skip to content

Commit 173bd21

Browse files
Enforcing strong typing even across tests
1 parent ae8c5fc commit 173bd21

1 file changed

Lines changed: 35 additions & 23 deletions

File tree

crates/contract/src/api/governance.rs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ mod tests {
143143
contract: &mut MpcContract,
144144
first_participant_id: &AccountId,
145145
participants: Participants,
146-
threshold: GovernanceThreshold,
146+
governance_threshold: GovernanceThreshold,
147147
) -> Result<(), Error> {
148148
let voting_context = VMContextBuilder::new()
149149
.signer_account_id(first_participant_id.clone())
@@ -153,7 +153,7 @@ mod tests {
153153
testing_env!(voting_context);
154154

155155
let proposal = ProposedGovernanceThresholdParameters::new(
156-
GovernanceThresholdParameters::new(participants, threshold).unwrap(),
156+
GovernanceThresholdParameters::new(participants, governance_threshold).unwrap(),
157157
BTreeMap::new(),
158158
);
159159
contract.vote_new_parameters(EpochId::new(1), (&proposal).into_dto_type())
@@ -253,13 +253,13 @@ mod tests {
253253
);
254254
}
255255

256-
/// Builds a Running contract with `num_participants` participants, signing
257-
/// threshold `threshold`, and a single CaitSith [`Sign`] domain whose
258-
/// reconstruction threshold is `reconstruction_threshold`.
256+
/// Builds a Running contract with `num_participants` participants, the given
257+
/// governance threshold, and a single CaitSith [`Sign`] domain with the given
258+
/// reconstruction threshold.
259259
fn setup_running_contract_with_domain(
260260
num_participants: usize,
261-
threshold: u64,
262-
reconstruction_threshold: u64,
261+
governance_threshold: GovernanceThreshold,
262+
reconstruction_threshold: ReconstructionThreshold,
263263
) -> (MpcContract, Participants, AccountId, DomainId) {
264264
let participants = gen_participants(num_participants);
265265
let first_participant_id = participants.participants()[0].0.clone();
@@ -271,16 +271,13 @@ mod tests {
271271
.build()
272272
);
273273

274-
let parameters = GovernanceThresholdParameters::new(
275-
participants.clone(),
276-
GovernanceThreshold::new(threshold),
277-
)
278-
.unwrap();
274+
let parameters =
275+
GovernanceThresholdParameters::new(participants.clone(), governance_threshold).unwrap();
279276
let domain_id = DomainId::default();
280277
let domains = vec![DomainConfig {
281278
id: domain_id,
282279
protocol: Protocol::CaitSith,
283-
reconstruction_threshold: ReconstructionThreshold::new(reconstruction_threshold),
280+
reconstruction_threshold,
284281
purpose: DomainPurpose::Sign,
285282
}];
286283
let (pk, _) = make_public_key_for_curve(Curve::Secp256k1, &mut OsRng);
@@ -317,8 +314,11 @@ mod tests {
317314
#[test]
318315
fn vote_new_parameters__should_reject_when_per_domain_threshold_exceeds_participants() {
319316
// Given: a Running contract with 3 participants and one domain.
320-
let (mut contract, participants, signer, domain_id) =
321-
setup_running_contract_with_domain(3, 2, 2);
317+
let (mut contract, participants, signer, domain_id) = setup_running_contract_with_domain(
318+
3,
319+
GovernanceThreshold::new(2),
320+
ReconstructionThreshold::new(2),
321+
);
322322
// ...and a proposal raising that domain's reconstruction threshold to 4.
323323
let mut per_domain = BTreeMap::new();
324324
per_domain.insert(domain_id, ReconstructionThreshold::new(4));
@@ -343,8 +343,11 @@ mod tests {
343343
#[test]
344344
fn vote_new_parameters__should_reject_when_shrinking_below_governance_threshold() {
345345
// Given: a Running contract with 4 participants and a GovernanceThreshold of 3.
346-
let (mut contract, participants, signer, _domain_id) =
347-
setup_running_contract_with_domain(4, 3, 3);
346+
let (mut contract, participants, signer, _domain_id) = setup_running_contract_with_domain(
347+
4,
348+
GovernanceThreshold::new(3),
349+
ReconstructionThreshold::new(3),
350+
);
348351
// ...and a proposal that shrinks the participant set to 2 without touching
349352
// the per-domain thresholds.
350353
let proposal = ProposedGovernanceThresholdParameters::new(
@@ -372,8 +375,11 @@ mod tests {
372375
#[test]
373376
fn vote_new_parameters__should_reject_when_signing_threshold_exceeds_participants() {
374377
// Given: a Running contract with 3 participants and one domain.
375-
let (mut contract, participants, signer, _domain_id) =
376-
setup_running_contract_with_domain(3, 2, 2);
378+
let (mut contract, participants, signer, _domain_id) = setup_running_contract_with_domain(
379+
3,
380+
GovernanceThreshold::new(2),
381+
ReconstructionThreshold::new(2),
382+
);
377383
// ...and a proposal whose signing threshold (4) exceeds the participant set.
378384
let proposal = ProposedGovernanceThresholdParameters::new(
379385
GovernanceThresholdParameters::new_unvalidated(
@@ -396,8 +402,11 @@ mod tests {
396402
#[test]
397403
fn vote_new_parameters__should_accept_per_domain_threshold_within_participant_count() {
398404
// Given: a Running contract with 5 participants (GovernanceThreshold 4) and one domain.
399-
let (mut contract, participants, signer, domain_id) =
400-
setup_running_contract_with_domain(5, 4, 2);
405+
let (mut contract, participants, signer, domain_id) = setup_running_contract_with_domain(
406+
5,
407+
GovernanceThreshold::new(4),
408+
ReconstructionThreshold::new(2),
409+
);
401410
// ...and a proposal raising the domain's reconstruction threshold to 4,
402411
// which fits the 5 participants and does not exceed the GovernanceThreshold.
403412
let mut per_domain = BTreeMap::new();
@@ -418,8 +427,11 @@ mod tests {
418427
fn vote_new_parameters__should_reject_governance_below_max_reconstruction() {
419428
// Given: a Running contract with 5 participants, GovernanceThreshold 4, and a
420429
// domain whose reconstruction threshold is 4.
421-
let (mut contract, participants, signer, _domain_id) =
422-
setup_running_contract_with_domain(5, 4, 4);
430+
let (mut contract, participants, signer, _domain_id) = setup_running_contract_with_domain(
431+
5,
432+
GovernanceThreshold::new(4),
433+
ReconstructionThreshold::new(4),
434+
);
423435
// ...and a proposal lowering the GovernanceThreshold to 3 (valid on its own)
424436
// while the domain keeps its reconstruction threshold of 4.
425437
let proposal = ProposedGovernanceThresholdParameters::new(

0 commit comments

Comments
 (0)