From a355482feadc5f64b20c69cbf16c679eb4f1bd5b Mon Sep 17 00:00:00 2001 From: Hongrui Fang Date: Mon, 25 Jul 2022 22:18:54 +0800 Subject: [PATCH] tests for delegate voting --- agora-specs/Sample/Proposal/Vote.hs | 27 ++++++++++++++++++++++++--- agora-specs/Spec/Proposal.hs | 8 ++++++-- bench.csv | 6 ++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/agora-specs/Sample/Proposal/Vote.hs b/agora-specs/Sample/Proposal/Vote.hs index 0b28b0a..dd4f661 100644 --- a/agora-specs/Sample/Proposal/Vote.hs +++ b/agora-specs/Sample/Proposal/Vote.hs @@ -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 } --- diff --git a/agora-specs/Spec/Proposal.hs b/agora-specs/Spec/Proposal.hs index 6dd51b0..b49dd60 100644 --- a/agora-specs/Spec/Proposal.hs +++ b/agora-specs/Spec/Proposal.hs @@ -130,8 +130,12 @@ specs = in [legalGroup, illegalGroup] , group "voting" - [ Vote.mkTestTree "legal" Vote.validVoteParameters True - -- TODO: add negative test cases + [ group + "legal" + [ Vote.mkTestTree "ordinary" Vote.validVoteParameters True + , Vote.mkTestTree "delegate" Vote.validVoteAsDelegateParameters True + ] + -- TODO: add negative test cases ] , group "advancing" diff --git a/bench.csv b/bench.csv index cbb095b..64f905b 100644 --- a/bench.csv +++ b/bench.csv @@ -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