From 9549fae0df940adb7ec7adf0f7f8a08d4a2d29ca Mon Sep 17 00:00:00 2001 From: fanghr Date: Fri, 20 May 2022 16:02:06 +0800 Subject: [PATCH] fix misleading assert messages && add some comments --- agora-sample/Sample/Proposal.hs | 4 ++++ agora/Agora/Proposal/Scripts.hs | 12 ++++++------ agora/Agora/Stake/Scripts.hs | 2 -- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/agora-sample/Sample/Proposal.hs b/agora-sample/Sample/Proposal.hs index c476ec3..8e00803 100644 --- a/agora-sample/Sample/Proposal.hs +++ b/agora-sample/Sample/Proposal.hs @@ -374,6 +374,10 @@ voteOnProposal params = stakeOutput = stakeInput { txOutDatumHash = Just $ toDatumHash stakeOutputDatum + -- We won't include the minimum Ada in the output value + -- due to how we check the output value in the stake validator. + -- The implementation is correct though, it should work in a + -- real on-chain environment. } --- diff --git a/agora/Agora/Proposal/Scripts.hs b/agora/Agora/Proposal/Scripts.hs index dc85b71..3fe0244 100644 --- a/agora/Agora/Proposal/Scripts.hs +++ b/agora/Agora/Proposal/Scripts.hs @@ -199,14 +199,14 @@ proposalValidator proposal = PProposalVotes voteMap <- tcmatch proposalF.votes voteFor <- tclet $ pfromData $ pfield @"resultTag" # r - tcassert "Invalid vote option" $ + tcassert "Vote option should be valid" $ pisJust #$ plookup # voteFor # voteMap -- Find the input stake, the amount of new votes should be the 'stakedAmount'. let stakeInput = pfield @"resolved" #$ mustBePJust - # "Stake input not found" + # "Stake input should be present" #$ pfind # plam ( \(pfromData . (pfield @"value" #) . (pfield @"resolved" #) -> value) -> @@ -220,7 +220,7 @@ proposalValidator proposal = stakeInF <- tcont $ pletFields @'["stakedAmount", "lockedBy", "owner"] stakeIn -- Ensure that no lock with the current proposal id has been put on the stake. - tcassert "Cannot vote on the a proposal using the same stake twice" $ + tcassert "Same stake shouldn't vote on the same propsoal twice" $ pnot #$ pany # plam ( \((pfield @"proposalTag" #) . pfromData -> pid) -> @@ -231,7 +231,7 @@ proposalValidator proposal = -- TODO: maybe we can move this outside of the pmatch block. -- Filter out own output with own address and PST. let ownOutput = - mustBePJust # "Own output not found" #$ pfind + mustBePJust # "Own output should be present" #$ pfind # plam ( \input -> unTermCont $ do inputF <- tcont $ pletFields @'["address", "value"] input @@ -268,14 +268,14 @@ proposalValidator proposal = .& #startingTime .= proposalF.startingTime ) - tcassert "Invalid output proposal" $ proposalOut #== expectedProposalOut + tcassert "Output proposal should be valid" $ proposalOut #== expectedProposalOut -- We validate the output stake datum here as well: We need the vote option -- to create a valid 'ProposalLock', however the vote option is encoded -- in the proposal redeemer, which is invisible for the stake validator. let stakeOutput = - mustBePJust # "Stake output not found" + mustBePJust # "Stake output should be present" #$ pfind # plam ( \(pfromData . (pfield @"value" #) -> value) -> diff --git a/agora/Agora/Stake/Scripts.hs b/agora/Agora/Stake/Scripts.hs index aaf114b..da9da7f 100644 --- a/agora/Agora/Stake/Scripts.hs +++ b/agora/Agora/Stake/Scripts.hs @@ -327,8 +327,6 @@ stakeValidator stake = $ \value address newStakeDatum' -> let isScriptAddress = pdata address #== ownAddress correctOutputDatum = pdata newStakeDatum' #== expectedDatum - -- TODO: Is this correct? I think We only need to ensure - -- correct amount of GT/SST in the continuing output. valueCorrect = pdata continuingValue #== pdata value in pif isScriptAddress