Skip to content

Commit

Permalink
Add test no voters
Browse files Browse the repository at this point in the history
  • Loading branch information
akremstudy committed Dec 4, 2023
1 parent c434669 commit 52321c0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
29 changes: 29 additions & 0 deletions tests/integration/dispute_keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,3 +677,32 @@ func (s *IntegrationTestSuite) TestNoQorumSingleRound() {
// reporter stake should be restored after dispute expires for invalid vote
s.Equal(reporterStakeBefore, reporterStakeAfter)
}

func (s *IntegrationTestSuite) TestDisputeButNoVotes() {
_, msgServer := s.disputeKeeper()
addrs, valAddrs := s.createValidators([]int64{1, 2, 3})
reporter := s.stakingKeeper.Validator(s.ctx, valAddrs[0])
reporterStakeBefore := reporter.GetBondedTokens()
report := types.MicroReport{
Reporter: addrs[0].String(),
Power: reporter.GetConsensusPower(sdk.DefaultPowerReduction),
QueryId: "83a7f3d48786ac2667503a61e8c415438ed2922eb86a2906e4ee66d9a2ce4992",
Value: "000000000000000000000000000000000000000000000058528649cf80ee0000",
Timestamp: 1696516597,
}
disputeFee := s.disputekeeper.GetDisputeFee(s.ctx, report.Reporter, types.Warning)
// Propose dispute pay half of the fee from account
_, err := msgServer.ProposeDispute(s.ctx, &types.MsgProposeDispute{
Creator: addrs[1].String(),
Report: &report,
Fee: sdk.NewCoin(s.denom, disputeFee),
DisputeCategory: types.Warning,
})
s.NoError(err)
s.NotEqual(reporterStakeBefore, s.stakingKeeper.Validator(s.ctx, valAddrs[0]).GetBondedTokens())
// forward time to end vote
s.ctx = s.ctx.WithBlockTime(s.ctx.BlockTime().Add(86400*3 + 1))
header := tmproto.Header{Height: s.app.LastBlockHeight() + 1, Time: s.ctx.BlockTime().Add(1)}
s.app.BeginBlock(abci.RequestBeginBlock{Header: header})
s.Equal(reporterStakeBefore, s.stakingKeeper.Validator(s.ctx, valAddrs[0]).GetBondedTokens())
}
12 changes: 8 additions & 4 deletions x/dispute/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ func (k Keeper) ExecuteVote(ctx sdk.Context, id uint64) {
disputeFeeMinusBurn := dispute.SlashAmount.Sub(dispute.BurnAmount)
// the burnAmount %5 of disputeFee, half of which is burned and the other half is distributed to the voters
burnCoins := dispute.BurnAmount.QuoRaw(2)

voterReward := burnCoins
if len(vote.Voters) == 0 {
burnCoins = dispute.BurnAmount
voterReward = sdk.ZeroInt()
}
switch vote.VoteResult {
case types.VoteResult_INVALID, types.VoteResult_NO_QUORUM_MAJORITY_INVALID:
// burn half the burnAmount
if err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(Denom, burnCoins))); err != nil {
panic(err)
}
// divide the remaining burnAmount equally among the voters and transfer it to their accounts
if err := k.RewardVoters(ctx, vote.Voters, burnCoins); err != nil {
if err := k.RewardVoters(ctx, vote.Voters, voterReward); err != nil {
panic(err)
}
// refund all fees to each dispute fee payer and restore validator bond/power
Expand All @@ -50,7 +54,7 @@ func (k Keeper) ExecuteVote(ctx sdk.Context, id uint64) {
panic(err)
}
// divide the remaining burnAmount equally among the voters and transfer it to their accounts
if err := k.RewardVoters(ctx, vote.Voters, burnCoins); err != nil {
if err := k.RewardVoters(ctx, vote.Voters, voterReward); err != nil {
panic(err)
}
// divide the reporters bond equally amongst the dispute fee payers and add it to the bonded pool
Expand All @@ -66,7 +70,7 @@ func (k Keeper) ExecuteVote(ctx sdk.Context, id uint64) {
panic(err)
}
// divide the remaining burnAmount equally among the voters and transfer it to their accounts
if err := k.RewardVoters(ctx, vote.Voters, burnCoins); err != nil {
if err := k.RewardVoters(ctx, vote.Voters, voterReward); err != nil {
panic(err)
}
// refund the reporters bond to the reporter plus the remaining disputeFee; goes to bonded pool
Expand Down
3 changes: 3 additions & 0 deletions x/dispute/keeper/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func (k Keeper) RefundDisputeFeeToBond(ctx sdk.Context, fromBond []types.PayerIn
}

func (k Keeper) RewardVoters(ctx sdk.Context, voters []string, totalAmount math.Int) error {
if totalAmount.IsZero() {
return nil
}
// multisend to voters
moduleAddress := k.accountKeeper.GetModuleAddress(types.ModuleName)
inputs := []banktypes.Input{banktypes.NewInput(moduleAddress, sdk.NewCoins(sdk.NewCoin(Denom, totalAmount)))}
Expand Down
3 changes: 3 additions & 0 deletions x/dispute/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (k Keeper) TallyVote(ctx sdk.Context, id uint64) {
case scaledInvalid.GT(scaledSupport) && scaledInvalid.GT(scaledAgainst):
k.SetDisputeStatus(ctx, id, disputeStatus)
k.SetVoteResult(ctx, id, types.VoteResult_NO_QUORUM_MAJORITY_INVALID)
case len(vote.Voters) == 0:
k.SetDisputeStatus(ctx, id, disputeStatus)
k.SetVoteResult(ctx, id, types.VoteResult_NO_QUORUM_MAJORITY_INVALID)
default:
}
}
Expand Down

0 comments on commit 52321c0

Please sign in to comment.