check minimum stake amount while voting

This commit is contained in:
Hongrui Fang 2022-10-04 22:01:04 +08:00
parent 1b3ec260a3
commit 270c984f8d
10 changed files with 88 additions and 49 deletions

View file

@ -63,6 +63,7 @@ import Test.Tasty.QuickCheck (
data GovernorDatumCases
= ExecuteLE0
| CreateLE0
| ToVotingLE0
| VoteLE0
| Correct
deriving stock (Eq, Show)
@ -88,9 +89,10 @@ governorDatumValidProperty =
classifiedPropertyNative gen (const []) expected classifier pisGovernorDatumValid
where
classifier :: GovernorDatum -> GovernorDatumCases
classifier ((.proposalThresholds) -> ProposalThresholds e c v)
classifier ((.proposalThresholds) -> ProposalThresholds e c tv v)
| e < 0 = ExecuteLE0
| c < 0 = CreateLE0
| tv < 0 = ToVotingLE0
| v < 0 = VoteLE0
| otherwise = Correct
@ -110,24 +112,27 @@ governorDatumValidProperty =
let validGT = taggedInteger (0, 1000000000)
execute <- validGT
create <- validGT
toVoting <- validGT
vote <- validGT
le0 <- taggedInteger (-1000, -1)
case c of
ExecuteLE0 ->
-- execute < 0
return $ ProposalThresholds le0 create vote
return $ ProposalThresholds le0 create toVoting vote
CreateLE0 ->
-- c < 0
return $ ProposalThresholds execute le0 vote
return $ ProposalThresholds execute le0 toVoting vote
ToVotingLE0 ->
return $ ProposalThresholds execute create le0 vote
VoteLE0 ->
-- vote < 0
return $ ProposalThresholds execute create le0
return $ ProposalThresholds execute create toVoting le0
Correct -> do
-- c <= vote < execute
nv <- taggedInteger (0, untag execute - 1)
nc <- taggedInteger (0, untag nv)
return $ ProposalThresholds execute nc nv
return $ ProposalThresholds execute nc toVoting nv
data GovernorPolicyCases
= ReferenceUTXONotSpent

View file

@ -195,7 +195,7 @@ invalidNewGovernorDatum =
GovernorDatum
{ proposalThresholds =
def
{ vote = Tagged (-1)
{ toVoting = Tagged (-1)
}
, nextProposalId = ProposalId 42
, proposalTimings = def

View file

@ -93,7 +93,7 @@ validGovernorOutputDatum =
}
invalidProposalThresholds :: ProposalThresholds
invalidProposalThresholds = ProposalThresholds (-1) (-1) (-1)
invalidProposalThresholds = ProposalThresholds (-1) (-1) (-1) (-1)
invalidMaxTimeRangeWidth :: MaxTimeRangeWidth
invalidMaxTimeRangeWidth = MaxTimeRangeWidth 0

View file

@ -120,6 +120,7 @@ mkGovernorOutputDatum ValueInvalid =
ProposalThresholds
{ execute = -1
, create = -1
, toVoting = -1
, vote = -1
}
in Just $

View file

@ -679,7 +679,7 @@ getNextState = \case
-- | Calculate the number of GTs per stake in order to exceed the minimum limit.
compPerStakeGTsForDraft :: NumStake -> Integer
compPerStakeGTsForDraft nCosigners =
untag (def :: ProposalThresholds).vote
untag (def :: ProposalThresholds).toVoting
`div` fromIntegral nCosigners + 1
dummyDatum :: ()
@ -944,7 +944,7 @@ mkInsufficientCosignsBundle nCosigners nEffects =
}
where
insuffcientPerStakeGTs =
untag (def :: ProposalThresholds).vote
untag (def :: ProposalThresholds).toVoting
`div` fromIntegral nCosigners - 1
template = mkValidToNextStateBundle nCosigners nEffects False Draft

View file

@ -25,6 +25,8 @@ module Sample.Proposal.Vote (
moreThanOneProposals,
invalidLocks,
destroyStakes,
insufficientAmount,
insufficientAmount1,
) where
import Agora.Governor (Governor (..))
@ -526,3 +528,27 @@ destroyStakes =
}
}
}
insufficientAmount :: ParameterBundle
insufficientAmount =
ownerVoteWithSignleStake
{ stakeParameters =
ownerVoteWithSignleStake.stakeParameters
{ stakeInputParameters =
ownerVoteWithSignleStake.stakeParameters.stakeInputParameters
{ perStakeGTs = 1
}
}
}
insufficientAmount1 :: ParameterBundle
insufficientAmount1 =
ownerVoteWithMultipleStakes
{ stakeParameters =
ownerVoteWithMultipleStakes.stakeParameters
{ stakeInputParameters =
ownerVoteWithMultipleStakes.stakeParameters.stakeInputParameters
{ perStakeGTs = 1
}
}
}

View file

@ -189,6 +189,7 @@ instance Default ProposalThresholds where
ProposalThresholds
{ execute = Tagged 1000
, create = Tagged 1
, toVoting = Tagged 100
, vote = Tagged 100
}

View file

@ -176,6 +176,14 @@ specs =
"attempt to burn stakes"
Vote.destroyStakes
(Vote.Validity True False)
, Vote.mkTestTree
"insufficient staked amount"
Vote.insufficientAmount
(Vote.Validity False True)
, Vote.mkTestTree
"insufficient staked amount"
Vote.insufficientAmount1
(Vote.Validity False True)
]
]
, group