Skip to content
Open
74 changes: 43 additions & 31 deletions crates/contract/src/api/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mod tests {
contract: &mut MpcContract,
first_participant_id: &AccountId,
participants: Participants,
threshold: GovernanceThreshold,
governance_threshold: GovernanceThreshold,
) -> Result<(), Error> {
let voting_context = VMContextBuilder::new()
.signer_account_id(first_participant_id.clone())
Expand All @@ -153,7 +153,7 @@ mod tests {
testing_env!(voting_context);

let proposal = ProposedGovernanceThresholdParameters::new(
GovernanceThresholdParameters::new(participants, threshold).unwrap(),
GovernanceThresholdParameters::new(participants, governance_threshold).unwrap(),
BTreeMap::new(),
);
contract.vote_new_parameters(EpochId::new(1), (&proposal).into_dto_type())
Expand All @@ -166,14 +166,14 @@ mod tests {
#[test]
fn test_vote_new_parameters_succeeds_with_default_tee_status() {
let (mut contract, participants, first_participant_id) = setup_tee_test_contract(3, 2);
let threshold = GovernanceThreshold::new(2);
let governance_threshold = GovernanceThreshold::new(2);

// No attestations submitted - all participants have default TEE status None
let result = setup_voting_context_and_vote(
&mut contract,
&first_participant_id,
participants,
threshold,
governance_threshold,
);
assert!(
result.is_ok(),
Expand All @@ -188,7 +188,7 @@ mod tests {
#[test]
fn test_vote_new_parameters_succeeds_when_all_participants_have_valid_tee() {
let (mut contract, participants, first_participant_id) = setup_tee_test_contract(3, 2);
let threshold = GovernanceThreshold::new(2);
let governance_threshold = GovernanceThreshold::new(2);

// Submit valid attestations for all participants
submit_valid_attestations(&mut contract, &participants, &[0, 1, 2]);
Expand All @@ -198,7 +198,7 @@ mod tests {
&mut contract,
&first_participant_id,
participants,
threshold,
governance_threshold,
);
assert!(
result.is_ok(),
Expand All @@ -215,7 +215,7 @@ mod tests {
#[test]
fn test_vote_new_parameters_succeeds_after_invalid_attestation_rejected() {
let (mut contract, participants, first_participant_id) = setup_tee_test_contract(4, 3);
let threshold = GovernanceThreshold::new(3);
let governance_threshold = GovernanceThreshold::new(3);

// Submit valid attestations for first 3 participants
submit_valid_attestations(&mut contract, &participants, &[0, 1, 2]);
Expand Down Expand Up @@ -245,21 +245,21 @@ mod tests {
&mut contract,
&first_participant_id,
participants,
threshold,
governance_threshold,
);
assert!(
result.is_ok(),
"Should succeed when participants have Valid or None TEE status (invalid attestations rejected)"
);
}

/// Builds a Running contract with `num_participants` participants, signing
/// threshold `threshold`, and a single CaitSith [`Sign`] domain whose
/// reconstruction threshold is `reconstruction_threshold`.
/// Builds a Running contract with `num_participants` participants, the given
/// governance threshold, and a single CaitSith [`Sign`] domain with the given
/// reconstruction threshold.
fn setup_running_contract_with_domain(
num_participants: usize,
threshold: u64,
reconstruction_threshold: u64,
governance_threshold: GovernanceThreshold,
reconstruction_threshold: ReconstructionThreshold,
) -> (MpcContract, Participants, AccountId, DomainId) {
let participants = gen_participants(num_participants);
let first_participant_id = participants.participants()[0].0.clone();
Expand All @@ -271,16 +271,13 @@ mod tests {
.build()
);

let parameters = GovernanceThresholdParameters::new(
participants.clone(),
GovernanceThreshold::new(threshold),
)
.unwrap();
let parameters =
GovernanceThresholdParameters::new(participants.clone(), governance_threshold).unwrap();
let domain_id = DomainId::default();
let domains = vec![DomainConfig {
id: domain_id,
protocol: Protocol::CaitSith,
reconstruction_threshold: ReconstructionThreshold::new(reconstruction_threshold),
reconstruction_threshold,
purpose: DomainPurpose::Sign,
}];
let (pk, _) = make_public_key_for_curve(Curve::Secp256k1, &mut OsRng);
Expand Down Expand Up @@ -317,8 +314,11 @@ mod tests {
#[test]
fn vote_new_parameters__should_reject_when_per_domain_threshold_exceeds_participants() {
// Given: a Running contract with 3 participants and one domain.
let (mut contract, participants, signer, domain_id) =
setup_running_contract_with_domain(3, 2, 2);
let (mut contract, participants, signer, domain_id) = setup_running_contract_with_domain(
3,
GovernanceThreshold::new(2),
ReconstructionThreshold::new(2),
);
// ...and a proposal raising that domain's reconstruction threshold to 4.
let mut per_domain = BTreeMap::new();
per_domain.insert(domain_id, ReconstructionThreshold::new(4));
Expand All @@ -343,8 +343,11 @@ mod tests {
#[test]
fn vote_new_parameters__should_reject_when_shrinking_below_governance_threshold() {
// Given: a Running contract with 4 participants and a GovernanceThreshold of 3.
let (mut contract, participants, signer, _domain_id) =
setup_running_contract_with_domain(4, 3, 3);
let (mut contract, participants, signer, _domain_id) = setup_running_contract_with_domain(
4,
GovernanceThreshold::new(3),
ReconstructionThreshold::new(3),
);
// ...and a proposal that shrinks the participant set to 2 without touching
// the per-domain thresholds.
let proposal = ProposedGovernanceThresholdParameters::new(
Expand Down Expand Up @@ -372,8 +375,11 @@ mod tests {
#[test]
fn vote_new_parameters__should_reject_when_signing_threshold_exceeds_participants() {
// Given: a Running contract with 3 participants and one domain.
let (mut contract, participants, signer, _domain_id) =
setup_running_contract_with_domain(3, 2, 2);
let (mut contract, participants, signer, _domain_id) = setup_running_contract_with_domain(
3,
GovernanceThreshold::new(2),
ReconstructionThreshold::new(2),
);
// ...and a proposal whose signing threshold (4) exceeds the participant set.
let proposal = ProposedGovernanceThresholdParameters::new(
GovernanceThresholdParameters::new_unvalidated(
Expand All @@ -396,8 +402,11 @@ mod tests {
#[test]
fn vote_new_parameters__should_accept_per_domain_threshold_within_participant_count() {
// Given: a Running contract with 5 participants (GovernanceThreshold 4) and one domain.
let (mut contract, participants, signer, domain_id) =
setup_running_contract_with_domain(5, 4, 2);
let (mut contract, participants, signer, domain_id) = setup_running_contract_with_domain(
5,
GovernanceThreshold::new(4),
ReconstructionThreshold::new(2),
);
// ...and a proposal raising the domain's reconstruction threshold to 4,
// which fits the 5 participants and does not exceed the GovernanceThreshold.
let mut per_domain = BTreeMap::new();
Expand All @@ -418,8 +427,11 @@ mod tests {
fn vote_new_parameters__should_reject_governance_below_max_reconstruction() {
// Given: a Running contract with 5 participants, GovernanceThreshold 4, and a
// domain whose reconstruction threshold is 4.
let (mut contract, participants, signer, _domain_id) =
setup_running_contract_with_domain(5, 4, 4);
let (mut contract, participants, signer, _domain_id) = setup_running_contract_with_domain(
5,
GovernanceThreshold::new(4),
ReconstructionThreshold::new(4),
);
// ...and a proposal lowering the GovernanceThreshold to 3 (valid on its own)
// while the domain keeps its reconstruction threshold of 4.
let proposal = ProposedGovernanceThresholdParameters::new(
Expand Down Expand Up @@ -447,9 +459,9 @@ mod tests {
// Given: a participant whose vote is forwarded through another contract,
// so signer_account_id (the participant) != predecessor_account_id (the forwarder).
let (mut contract, participants, first_participant_id) = setup_tee_test_contract(3, 2);
let threshold = GovernanceThreshold::new(2);
let governance_threshold = GovernanceThreshold::new(2);
let proposal = ProposedGovernanceThresholdParameters::new(
GovernanceThresholdParameters::new(participants, threshold).unwrap(),
GovernanceThresholdParameters::new(participants, governance_threshold).unwrap(),
BTreeMap::new(),
);

Expand Down
6 changes: 3 additions & 3 deletions crates/contract/src/api/tee_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::{BTreeMap, BTreeSet};
impl MpcContract {
/// Vote for a candidate account to become the trusted verifier contract
/// account, committing to the code hash the voter audited. When the proposal
/// crosses the signing threshold, the trusted verifier account is updated
/// crosses the governance threshold, the trusted verifier account is updated
/// and all pending verifier-change votes are cleared.
#[handle_result]
pub fn vote_tee_verifier_change(
Expand Down Expand Up @@ -131,7 +131,7 @@ mod tests {

#[test]
fn vote_tee_verifier_change__should_apply_candidate_when_threshold_reached() {
// Given a running contract with 3 participants, signing threshold 2,
// Given a running contract with 3 participants, governance threshold 2,
// starting unconfigured.
let (mut contract, participants, _) = setup_tee_test_contract(3, 2);
assert_eq!(contract.tee_verifier_account_id, None);
Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {

#[test]
fn remove_non_participant_tee_verifier_votes__should_drop_votes_from_dropped_participants() {
// Given a running contract with 3 participants, signing threshold 3, where
// Given a running contract with 3 participants, governance threshold 3, where
// two participants have cast votes for distinct candidates (neither crosses
// threshold, so both stay pending).
let (mut contract, participants, _) = setup_tee_test_contract(3, 3);
Expand Down
Loading