properly check state datum when creat a proposal
This commit is contained in:
parent
a4d55f221a
commit
15414aeda4
1 changed files with 32 additions and 20 deletions
|
|
@ -43,7 +43,7 @@ import Agora.AuthorityToken (
|
||||||
singleAuthorityTokenBurned,
|
singleAuthorityTokenBurned,
|
||||||
)
|
)
|
||||||
import Agora.Proposal (
|
import Agora.Proposal (
|
||||||
PProposalDatum,
|
PProposalDatum (..),
|
||||||
PProposalId,
|
PProposalId,
|
||||||
PProposalStatus (PDraft, PExecutable, PFinished),
|
PProposalStatus (PDraft, PExecutable, PFinished),
|
||||||
PProposalThresholds,
|
PProposalThresholds,
|
||||||
|
|
@ -64,6 +64,7 @@ import Agora.Utils (
|
||||||
passert,
|
passert,
|
||||||
passetClassValueOf,
|
passetClassValueOf,
|
||||||
passetClassValueOf',
|
passetClassValueOf',
|
||||||
|
pfindDatum,
|
||||||
pfindTxInByTxOutRef,
|
pfindTxInByTxOutRef,
|
||||||
pisDJust,
|
pisDJust,
|
||||||
pisJust,
|
pisJust,
|
||||||
|
|
@ -358,16 +359,28 @@ governorValidator gov =
|
||||||
passert "Output utxo to governor should have datum" $
|
passert "Output utxo to governor should have datum" $
|
||||||
pisDJust # ownOutput.datumHash
|
pisDJust # ownOutput.datumHash
|
||||||
|
|
||||||
-- TODO: use `PTryFrom` and reject bad datum
|
let outputGovernorStateDatumHash = mustBePDJust # "Output governor state datum hash not found" # ownOutput.datumHash
|
||||||
newDatum' <- plet $ mustFindDatum' @PGovernorDatum # ownOutput.datumHash # ctx.txInfo
|
|
||||||
newParams <- pletFields @'["proposalThresholds", "nextProposalId"] newDatum'
|
newDatumData <-
|
||||||
|
plet $
|
||||||
|
pforgetData $
|
||||||
|
pdata $
|
||||||
|
mustBePJust # "Ouput governor state datum not found"
|
||||||
|
#$ pfindDatum # outputGovernorStateDatumHash # txInfo'
|
||||||
|
|
||||||
case redeemer of
|
case redeemer of
|
||||||
PCreateProposal _ -> P.do
|
PCreateProposal _ -> P.do
|
||||||
passert "Proposal id should be advanced by 1" $
|
let expectedNextProposalId = pnextProposalId # oldParams.nextProposalId
|
||||||
pnextProposalId # oldParams.nextProposalId #== newParams.nextProposalId
|
|
||||||
|
|
||||||
-- TODO: check other fields of the state datum
|
expectedNewDatum :: Term _ PGovernorDatum
|
||||||
|
expectedNewDatum =
|
||||||
|
pcon $
|
||||||
|
PGovernorDatum $
|
||||||
|
pdcons @"proposalThresholds" # oldParams.proposalThresholds
|
||||||
|
#$ pdcons @"nextProposalId" # pdata expectedNextProposalId # pdnil
|
||||||
|
|
||||||
|
passert "Unexpected governor state datum" $
|
||||||
|
newDatumData #== (pforgetData $ pdata $ expectedNewDatum)
|
||||||
|
|
||||||
passert "Exactly one proposal token must be minted" $
|
passert "Exactly one proposal token must be minted" $
|
||||||
hasOnlyOneTokenOfCurrencySymbol # pproposalSymbol # txInfo.mint
|
hasOnlyOneTokenOfCurrencySymbol # pproposalSymbol # txInfo.mint
|
||||||
|
|
@ -416,9 +429,7 @@ governorValidator gov =
|
||||||
|
|
||||||
popaque $ pconstant ()
|
popaque $ pconstant ()
|
||||||
PMintGATs _ -> P.do
|
PMintGATs _ -> P.do
|
||||||
passert "Governor state should not be changed" $
|
passert "Governor state should not be changed" $ newDatumData #== datum'
|
||||||
-- FIXME: There should be a better way to do this
|
|
||||||
(pforgetData $ pdata newDatum') #== datum'
|
|
||||||
|
|
||||||
inputsWithProposalStateToken <-
|
inputsWithProposalStateToken <-
|
||||||
plet $
|
plet $
|
||||||
|
|
@ -477,16 +488,17 @@ governorValidator gov =
|
||||||
|
|
||||||
passert "Proposal must be in executable state in order to execute effects" isProposalExecutable
|
passert "Proposal must be in executable state in order to execute effects" isProposalExecutable
|
||||||
|
|
||||||
-- TODO: not sure if I did the right thing, can't use haskell level constructor here
|
let expectedOutputDatum =
|
||||||
let fields =
|
pforgetData $
|
||||||
pdcons @"id" # inputProposalDatum.id
|
pdata $
|
||||||
#$ pdcons @"effects" # inputProposalDatum.effects
|
pcon $
|
||||||
#$ pdcons @"status" # pdata (pcon $ PFinished pdnil)
|
PProposalDatum $
|
||||||
#$ pdcons @"cosigners" # inputProposalDatum.cosigners
|
pdcons @"id" # inputProposalDatum.id
|
||||||
#$ pdcons @"thresholds" # inputProposalDatum.thresholds
|
#$ pdcons @"effects" # inputProposalDatum.effects
|
||||||
#$ pdcons @"votes" # inputProposalDatum.votes # pdnil
|
#$ pdcons @"status" # pdata (pcon $ PFinished pdnil)
|
||||||
|
#$ pdcons @"cosigners" # inputProposalDatum.cosigners
|
||||||
expectedOutputDatum = pforgetData $ pdata fields
|
#$ pdcons @"thresholds" # inputProposalDatum.thresholds
|
||||||
|
#$ pdcons @"votes" # inputProposalDatum.votes # pdnil
|
||||||
|
|
||||||
passert "Unexpected output proposal datum" $
|
passert "Unexpected output proposal datum" $
|
||||||
pforgetData (pdata outputProposalDatum') #== expectedOutputDatum
|
pforgetData (pdata outputProposalDatum') #== expectedOutputDatum
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue