tests for delegate voting

This commit is contained in:
Hongrui Fang 2022-07-25 22:18:54 +08:00
parent be1eabc261
commit a355482fea
No known key found for this signature in database
GPG key ID: 1E0454204FC7D755
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 (
validVoteParameters,
mkTestTree,
validVoteAsDelegateParameters,
) where
import Agora.Proposal (
@ -66,7 +67,7 @@ import Test.Specification (
testValidator,
validatorSucceedsWith,
)
import Test.Util (CombinableBuilder, closedBoundedInterval, mkSpending, sortValue, updateMap)
import Test.Util (CombinableBuilder, closedBoundedInterval, mkSpending, pubKeyHashes, sortValue, updateMap)
-- | Reference to the proposal UTXO.
proposalRef :: TxOutRef
@ -82,6 +83,8 @@ data Parameters = Parameters
-- ^ The outcome the transaction is voting for.
, voteCount :: Integer
-- ^ The count of votes.
, voteAsDelegate :: Bool
-- ^ Delegate the stake and use it to vote.
}
-- | The public key hash of the stake owner.
@ -121,6 +124,9 @@ existingLocks =
, Voted (ProposalId 1) (ResultTag 2)
]
delegate :: PubKeyHash
delegate = head pubKeyHashes
{- | Set the 'StakeDatum.stakedAmount' according to the number of votes being
casted.
-}
@ -129,7 +135,10 @@ mkStakeInputDatum params =
StakeDatum
{ stakedAmount = Tagged params.voteCount
, owner = stakeOwner
, delegatedTo = Nothing
, delegatedTo =
if params.voteAsDelegate
then Just delegate
else Nothing
, lockedBy = existingLocks
}
@ -199,10 +208,15 @@ vote params =
<> Value.assetClassValue (untag stake.gtClassRef) params.voteCount
<> minAda
signer =
if params.voteAsDelegate
then delegate
else stakeOwner
builder =
mconcat
[ txId "827598fb2d69a896bbd9e645bb14c307df907f422b39eecbe4d6329bc30b428c"
, signedWith stakeOwner
, signedWith signer
, timeRange validTimeRange
, input $
script proposalValidatorHash
@ -233,6 +247,13 @@ validVoteParameters =
Parameters
{ voteFor = ResultTag 0
, voteCount = 27
, voteAsDelegate = False
}
validVoteAsDelegateParameters :: Parameters
validVoteAsDelegateParameters =
validVoteParameters
{ voteAsDelegate = True
}
---

View file

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

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: 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/voting/legal/proposal,254761960,715291,8396
Agora/Proposal/validator/voting/legal/stake,144453449,381134,5812
Agora/Proposal/validator/voting/legal/ordinary/proposal,254761960,715291,8396
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/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

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