Skip to content

Add test coverage for slashing mechanics (#20)#31

Merged
meshackyaro merged 1 commit into
trustflow-protocol:mainfrom
Godbrand0:feat/slashing-mechanics-tests
Jun 23, 2026
Merged

Add test coverage for slashing mechanics (#20)#31
meshackyaro merged 1 commit into
trustflow-protocol:mainfrom
Godbrand0:feat/slashing-mechanics-tests

Conversation

@Godbrand0

Copy link
Copy Markdown
Contributor

Summary

Closes #20

  • Adds a new contracts/trustflow Soroban contract crate implementing juror staking and a dispute-resolution system with stake slashing
  • Jurors stake tokens before they can vote; minority voters on a resolved dispute are slashed by slash_bps / 10_000 of their current stake (default 10%)
  • Writes 13 unit tests including the core acceptance criterion: three consecutive rounds of malicious voting produce a monotonically decreasing stake that converges to stake * 0.9^3 ≈ 7 290 (verified numerically)

Test plan

  • test_stake_and_unstake – basic staking lifecycle
  • test_stake_zero_rejected – invalid amount guard
  • test_unstake_insufficient_funds – overdraw guard
  • test_cast_vote_requires_stake – voting gate
  • test_cast_vote_duplicate_rejected – double-vote guard
  • test_single_round_malicious_juror_slashed – single-round 10% slash
  • test_honest_jurors_not_slashed – majority voters unaffected
  • test_multiple_rounds_malicious_juror_balance_decreasescore acceptance criterion: 3 rounds, stake decreases each round
  • test_four_rounds_progressive_slashing – 4 rounds at 20% slash rate
  • test_tie_favours_depositor – tie-breaking rule and minority slash
  • test_resolve_dispute_no_votes_fails – edge case: no votes cast
  • test_resolve_already_resolved_fails – double-resolve guard
  • test_slash_cannot_exceed_stake – 100% slash rate floors at zero, not negative

All 13 tests pass. cargo fmt and cargo clippy --workspace --lib both clean.

Implements a new `trustflow` Soroban contract crate that introduces
juror staking and a dispute-resolution system where minority voters
are penalised via stake slashing.  Adds 13 unit tests that simulate
multiple dispute rounds with a malicious juror and verify their balance
decreases monotonically after each round.

@meshackyaro meshackyaro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good job and well done

@meshackyaro meshackyaro merged commit b8a5371 into trustflow-protocol:main Jun 23, 2026
1 check passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Jun 23, 2026
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add test coverage for Slashing mechanics

2 participants