tests for delegate voting

This commit is contained in:
Hongrui Fang 2022-07-25 22:18:54 +08:00
parent 11757be255
commit 791b1fe291
3 changed files with 34 additions and 7 deletions

View file

@ -8,6 +8,7 @@ Sample and utilities for testing the functionalities of voting on proposals.
module Sample.Proposal.Vote ( module Sample.Proposal.Vote (
validVoteParameters, validVoteParameters,
mkTestTree, mkTestTree,
validVoteAsDelegateParameters,
) where ) where
import Agora.Proposal ( import Agora.Proposal (
@ -66,7 +67,7 @@ import Test.Specification (
testValidator, testValidator,
validatorSucceedsWith, validatorSucceedsWith,
) )
import Test.Util (CombinableBuilder, closedBoundedInterval, mkSpending, sortValue, updateMap) import Test.Util (CombinableBuilder, closedBoundedInterval, mkSpending, pubKeyHashes, sortValue, updateMap)
-- | Reference to the proposal UTXO. -- | Reference to the proposal UTXO.
proposalRef :: TxOutRef proposalRef :: TxOutRef
@ -82,6 +83,8 @@ data Parameters = Parameters
-- ^ The outcome the transaction is voting for. -- ^ The outcome the transaction is voting for.
, voteCount :: Integer , voteCount :: Integer
-- ^ The count of votes. -- ^ The count of votes.
, voteAsDelegate :: Bool
-- ^ Delegate the stake and use it to vote.
} }
-- | The public key hash of the stake owner. -- | The public key hash of the stake owner.
@ -121,6 +124,9 @@ existingLocks =
, Voted (ProposalId 1) (ResultTag 2) , Voted (ProposalId 1) (ResultTag 2)
] ]
delegate :: PubKeyHash
delegate = head pubKeyHashes
{- | Set the 'StakeDatum.stakedAmount' according to the number of votes being {- | Set the 'StakeDatum.stakedAmount' according to the number of votes being
casted. casted.
-} -}
@ -129,7 +135,10 @@ mkStakeInputDatum params =
StakeDatum StakeDatum
{ stakedAmount = Tagged params.voteCount { stakedAmount = Tagged params.voteCount
, owner = stakeOwner , owner = stakeOwner
, delegatedTo = Nothing , delegatedTo =
if params.voteAsDelegate
then Just delegate
else Nothing
, lockedBy = existingLocks , lockedBy = existingLocks
} }
@ -199,10 +208,15 @@ vote params =
<> Value.assetClassValue (untag stake.gtClassRef) params.voteCount <> Value.assetClassValue (untag stake.gtClassRef) params.voteCount
<> minAda <> minAda
signer =
if params.voteAsDelegate
then delegate
else stakeOwner
builder = builder =
mconcat mconcat
[ txId "827598fb2d69a896bbd9e645bb14c307df907f422b39eecbe4d6329bc30b428c" [ txId "827598fb2d69a896bbd9e645bb14c307df907f422b39eecbe4d6329bc30b428c"
, signedWith stakeOwner , signedWith signer
, timeRange validTimeRange , timeRange validTimeRange
, input $ , input $
script proposalValidatorHash script proposalValidatorHash
@ -233,6 +247,13 @@ validVoteParameters =
Parameters Parameters
{ voteFor = ResultTag 0 { voteFor = ResultTag 0
, voteCount = 27 , voteCount = 27
, voteAsDelegate = False
}
validVoteAsDelegateParameters :: Parameters
validVoteAsDelegateParameters =
validVoteParameters
{ voteAsDelegate = True
} }
--- ---

View file

@ -130,8 +130,12 @@ specs =
in [legalGroup, illegalGroup] in [legalGroup, illegalGroup]
, group , group
"voting" "voting"
[ Vote.mkTestTree "legal" Vote.validVoteParameters True [ group
-- TODO: add negative test cases "legal"
[ Vote.mkTestTree "ordinary" Vote.validVoteParameters True
, Vote.mkTestTree "delegate" Vote.validVoteAsDelegateParameters True
]
-- TODO: add negative test cases
] ]
, group , group
"advancing" "advancing"

View file

@ -48,8 +48,10 @@ Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 5 co
Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: VotingReady/stake,1157564197,3077623,11488 Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: VotingReady/stake,1157564197,3077623,11488
Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: Locked/stake,1157564197,3077623,11488 Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: Locked/stake,1157564197,3077623,11488
Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: Finished/stake,1157564197,3077623,11488 Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: Finished/stake,1157564197,3077623,11488
Agora/Proposal/validator/voting/legal/proposal,254761960,715291,8396 Agora/Proposal/validator/voting/legal/ordinary/proposal,254761960,715291,8396
Agora/Proposal/validator/voting/legal/stake,144453449,381134,5812 Agora/Proposal/validator/voting/legal/ordinary/stake,144453449,381134,5812
Agora/Proposal/validator/voting/legal/delegate/proposal,254862648,715291,8459
Agora/Proposal/validator/voting/legal/delegate/stake,147870356,388160,5906
Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from Draft to VotingReady/proposal,249151017,693538,8909 Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from Draft to VotingReady/proposal,249151017,693538,8909
Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from Draft to VotingReady/stake,136455095,355188,6122 Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from Draft to VotingReady/stake,136455095,355188,6122
Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from VotingReady to Locked/proposal,293313747,804549,8918 Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from VotingReady to Locked/proposal,293313747,804549,8918

1 name cpu mem size
48 Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: VotingReady/stake 1157564197 3077623 11488
49 Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: Locked/stake 1157564197 3077623 11488
50 Agora/Proposal/validator/cosignature/illegal/proposal status not Draft/with 10 cosigners/status: Finished/stake 1157564197 3077623 11488
51 Agora/Proposal/validator/voting/legal/proposal Agora/Proposal/validator/voting/legal/ordinary/proposal 254761960 715291 8396
52 Agora/Proposal/validator/voting/legal/stake Agora/Proposal/validator/voting/legal/ordinary/stake 144453449 381134 5812
53 Agora/Proposal/validator/voting/legal/delegate/proposal 254862648 715291 8459
54 Agora/Proposal/validator/voting/legal/delegate/stake 147870356 388160 5906
55 Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from Draft to VotingReady/proposal 249151017 693538 8909
56 Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from Draft to VotingReady/stake 136455095 355188 6122
57 Agora/Proposal/validator/advancing/with 1 cosigners and 1 effects/legal/to next state/from VotingReady to Locked/proposal 293313747 804549 8918