renamed shared sample
This commit is contained in:
parent
6a0cfcd6ce
commit
4f5504d1d1
8 changed files with 55 additions and 55 deletions
|
|
@ -43,10 +43,10 @@ import PlutusLedgerApi.V2 (
|
||||||
)
|
)
|
||||||
import Property.Generator (genInput, genOutput)
|
import Property.Generator (genInput, genOutput)
|
||||||
import Sample.Shared (
|
import Sample.Shared (
|
||||||
govAssetClass,
|
|
||||||
govSymbol,
|
|
||||||
govValidatorHash,
|
|
||||||
governor,
|
governor,
|
||||||
|
governorAssetClass,
|
||||||
|
governorSymbol,
|
||||||
|
governorValidatorHash,
|
||||||
gstUTXORef,
|
gstUTXORef,
|
||||||
)
|
)
|
||||||
import Test.Tasty (TestTree)
|
import Test.Tasty (TestTree)
|
||||||
|
|
@ -171,12 +171,12 @@ governorMintingProperty =
|
||||||
{- Note:
|
{- Note:
|
||||||
I don't think it's easily possible to randomize orefs. We can't really pass pass `Governor` type to `actual` function.
|
I don't think it's easily possible to randomize orefs. We can't really pass pass `Governor` type to `actual` function.
|
||||||
-}
|
-}
|
||||||
gst = assetClassValue govAssetClass 1
|
gst = assetClassValue governorAssetClass 1
|
||||||
mintAmount x = mint . mconcat $ replicate x gst
|
mintAmount x = mint . mconcat $ replicate x gst
|
||||||
outputToGov =
|
outputToGov =
|
||||||
output $
|
output $
|
||||||
mconcat
|
mconcat
|
||||||
[ script govValidatorHash
|
[ script governorValidatorHash
|
||||||
, withValue gst
|
, withValue gst
|
||||||
, withDatum govDatum
|
, withDatum govDatum
|
||||||
]
|
]
|
||||||
|
|
@ -205,7 +205,7 @@ governorMintingProperty =
|
||||||
GovernorOutputNotFound -> referencedInput <> mintAmount 1
|
GovernorOutputNotFound -> referencedInput <> mintAmount 1
|
||||||
GovernorPolicyCorrect -> referencedInput <> outputToGov <> mintAmount 1
|
GovernorPolicyCorrect -> referencedInput <> outputToGov <> mintAmount 1
|
||||||
|
|
||||||
return . buildMinting' $ inputs <> outputs <> comp <> withMinting govSymbol
|
return . buildMinting' $ inputs <> outputs <> comp <> withMinting governorSymbol
|
||||||
|
|
||||||
expected :: ScriptContext -> Maybe ()
|
expected :: ScriptContext -> Maybe ()
|
||||||
expected sc =
|
expected sc =
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ import PlutusTx.AssocMap qualified as AssocMap
|
||||||
import Sample.Shared (
|
import Sample.Shared (
|
||||||
agoraScripts,
|
agoraScripts,
|
||||||
authorityTokenSymbol,
|
authorityTokenSymbol,
|
||||||
govAssetClass,
|
governorAssetClass,
|
||||||
govValidatorAddress,
|
governorValidatorAddress,
|
||||||
minAda,
|
minAda,
|
||||||
mkRedeemer,
|
mkRedeemer,
|
||||||
signer,
|
signer,
|
||||||
|
|
@ -99,7 +99,7 @@ mkEffectDatum newGovDatum =
|
||||||
-}
|
-}
|
||||||
mkEffectTxInfo :: GovernorDatum -> TxInfo
|
mkEffectTxInfo :: GovernorDatum -> TxInfo
|
||||||
mkEffectTxInfo newGovDatum =
|
mkEffectTxInfo newGovDatum =
|
||||||
let gst = Value.assetClassValue govAssetClass 1
|
let gst = Value.assetClassValue governorAssetClass 1
|
||||||
at = Value.assetClassValue atAssetClass 1
|
at = Value.assetClassValue atAssetClass 1
|
||||||
|
|
||||||
-- One authority token is burnt in the process.
|
-- One authority token is burnt in the process.
|
||||||
|
|
@ -121,7 +121,7 @@ mkEffectTxInfo newGovDatum =
|
||||||
governorInput :: TxOut
|
governorInput :: TxOut
|
||||||
governorInput =
|
governorInput =
|
||||||
TxOut
|
TxOut
|
||||||
{ txOutAddress = govValidatorAddress
|
{ txOutAddress = governorValidatorAddress
|
||||||
, txOutValue = gst
|
, txOutValue = gst
|
||||||
, txOutDatum = OutputDatumHash $ toDatumHash governorInputDatum
|
, txOutDatum = OutputDatumHash $ toDatumHash governorInputDatum
|
||||||
, txOutReferenceScript = Nothing
|
, txOutReferenceScript = Nothing
|
||||||
|
|
@ -152,7 +152,7 @@ mkEffectTxInfo newGovDatum =
|
||||||
governorOutput :: TxOut
|
governorOutput :: TxOut
|
||||||
governorOutput =
|
governorOutput =
|
||||||
TxOut
|
TxOut
|
||||||
{ txOutAddress = govValidatorAddress
|
{ txOutAddress = governorValidatorAddress
|
||||||
, txOutValue = mconcat [gst, minAda]
|
, txOutValue = mconcat [gst, minAda]
|
||||||
, txOutDatum = OutputDatumHash $ toDatumHash governorOutputDatum
|
, txOutDatum = OutputDatumHash $ toDatumHash governorOutputDatum
|
||||||
, txOutReferenceScript = Nothing
|
, txOutReferenceScript = Nothing
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,9 @@ import PlutusLedgerApi.V2 (
|
||||||
import Sample.Shared (
|
import Sample.Shared (
|
||||||
agoraScripts,
|
agoraScripts,
|
||||||
authorityTokenSymbol,
|
authorityTokenSymbol,
|
||||||
govAssetClass,
|
governorAssetClass,
|
||||||
govValidator,
|
governorValidator,
|
||||||
govValidatorHash,
|
governorValidatorHash,
|
||||||
minAda,
|
minAda,
|
||||||
)
|
)
|
||||||
import Test.Specification (SpecificationTree, testValidator)
|
import Test.Specification (SpecificationTree, testValidator)
|
||||||
|
|
@ -145,19 +145,19 @@ governorRedeemer = MutateGovernor
|
||||||
|
|
||||||
mkGovernorBuilder :: forall b. CombinableBuilder b => GovernorParameters -> b
|
mkGovernorBuilder :: forall b. CombinableBuilder b => GovernorParameters -> b
|
||||||
mkGovernorBuilder ps =
|
mkGovernorBuilder ps =
|
||||||
let gst = Value.assetClassValue govAssetClass 1
|
let gst = Value.assetClassValue governorAssetClass 1
|
||||||
value = sortValue $ gst <> minAda
|
value = sortValue $ gst <> minAda
|
||||||
gstOutput =
|
gstOutput =
|
||||||
if ps.stealGST
|
if ps.stealGST
|
||||||
then pubKey $ head pubKeyHashes
|
then pubKey $ head pubKeyHashes
|
||||||
else script govValidatorHash
|
else script governorValidatorHash
|
||||||
withGSTDatum =
|
withGSTDatum =
|
||||||
maybe mempty withDatum $
|
maybe mempty withDatum $
|
||||||
mkGovernorOutputDatum ps.governorOutputDatumValidity
|
mkGovernorOutputDatum ps.governorOutputDatumValidity
|
||||||
in mconcat
|
in mconcat
|
||||||
[ input $
|
[ input $
|
||||||
mconcat
|
mconcat
|
||||||
[ script govValidatorHash
|
[ script governorValidatorHash
|
||||||
, withDatum governorInputDatum
|
, withDatum governorInputDatum
|
||||||
, withValue value
|
, withValue value
|
||||||
, withRef governorRef
|
, withRef governorRef
|
||||||
|
|
@ -237,7 +237,7 @@ mkTestCase name pb (Validity forGov) =
|
||||||
testValidator
|
testValidator
|
||||||
forGov
|
forGov
|
||||||
name
|
name
|
||||||
govValidator
|
governorValidator
|
||||||
governorInputDatum
|
governorInputDatum
|
||||||
governorRedeemer
|
governorRedeemer
|
||||||
(mkSpending mutate pb governorRef)
|
(mkSpending mutate pb governorRef)
|
||||||
|
|
|
||||||
|
|
@ -108,10 +108,10 @@ import Sample.Proposal.Shared (
|
||||||
import Sample.Shared (
|
import Sample.Shared (
|
||||||
authorityTokenPolicy,
|
authorityTokenPolicy,
|
||||||
authorityTokenSymbol,
|
authorityTokenSymbol,
|
||||||
govAssetClass,
|
|
||||||
govValidator,
|
|
||||||
govValidatorHash,
|
|
||||||
governor,
|
governor,
|
||||||
|
governorAssetClass,
|
||||||
|
governorValidator,
|
||||||
|
governorValidatorHash,
|
||||||
minAda,
|
minAda,
|
||||||
proposalPolicySymbol,
|
proposalPolicySymbol,
|
||||||
proposalValidator,
|
proposalValidator,
|
||||||
|
|
@ -432,19 +432,19 @@ governorRef = TxOutRef governorTxRef 2
|
||||||
-}
|
-}
|
||||||
mkGovernorBuilder :: forall b. CombinableBuilder b => GovernorParameters -> b
|
mkGovernorBuilder :: forall b. CombinableBuilder b => GovernorParameters -> b
|
||||||
mkGovernorBuilder ps =
|
mkGovernorBuilder ps =
|
||||||
let gst = Value.assetClassValue govAssetClass 1
|
let gst = Value.assetClassValue governorAssetClass 1
|
||||||
value = sortValue $ gst <> minAda
|
value = sortValue $ gst <> minAda
|
||||||
in mconcat
|
in mconcat
|
||||||
[ input $
|
[ input $
|
||||||
mconcat
|
mconcat
|
||||||
[ script govValidatorHash
|
[ script governorValidatorHash
|
||||||
, withValue value
|
, withValue value
|
||||||
, withRef governorRef
|
, withRef governorRef
|
||||||
, withDatum governorInputDatum
|
, withDatum governorInputDatum
|
||||||
]
|
]
|
||||||
, output $
|
, output $
|
||||||
mconcat
|
mconcat
|
||||||
[ script govValidatorHash
|
[ script governorValidatorHash
|
||||||
, withValue value
|
, withValue value
|
||||||
, withRef governorRef
|
, withRef governorRef
|
||||||
, withDatum (mkGovernorOutputDatum ps)
|
, withDatum (mkGovernorOutputDatum ps)
|
||||||
|
|
@ -542,7 +542,7 @@ mkTestTree name pb val =
|
||||||
testValidator
|
testValidator
|
||||||
(fromJust val.forGovernorValidator)
|
(fromJust val.forGovernorValidator)
|
||||||
"governor"
|
"governor"
|
||||||
govValidator
|
governorValidator
|
||||||
governorInputDatum
|
governorInputDatum
|
||||||
governorRedeemer
|
governorRedeemer
|
||||||
(spend governorRef)
|
(spend governorRef)
|
||||||
|
|
|
||||||
|
|
@ -72,10 +72,10 @@ import PlutusLedgerApi.V2 (
|
||||||
import Sample.Proposal.Shared (stakeTxRef)
|
import Sample.Proposal.Shared (stakeTxRef)
|
||||||
import Sample.Shared (
|
import Sample.Shared (
|
||||||
fromDiscrete,
|
fromDiscrete,
|
||||||
govAssetClass,
|
|
||||||
govValidator,
|
|
||||||
govValidatorHash,
|
|
||||||
governor,
|
governor,
|
||||||
|
governorAssetClass,
|
||||||
|
governorValidator,
|
||||||
|
governorValidatorHash,
|
||||||
minAda,
|
minAda,
|
||||||
proposalPolicy,
|
proposalPolicy,
|
||||||
proposalPolicySymbol,
|
proposalPolicySymbol,
|
||||||
|
|
@ -284,7 +284,7 @@ createProposal ps = builder
|
||||||
where
|
where
|
||||||
pst = Value.singleton proposalPolicySymbol "" 1
|
pst = Value.singleton proposalPolicySymbol "" 1
|
||||||
sst = Value.assetClassValue stakeAssetClass 1
|
sst = Value.assetClassValue stakeAssetClass 1
|
||||||
gst = Value.assetClassValue govAssetClass 1
|
gst = Value.assetClassValue governorAssetClass 1
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -323,14 +323,14 @@ createProposal ps = builder
|
||||||
timeRange $ mkTimeRange ps
|
timeRange $ mkTimeRange ps
|
||||||
, input $
|
, input $
|
||||||
mconcat
|
mconcat
|
||||||
[ script govValidatorHash
|
[ script governorValidatorHash
|
||||||
, withValue governorValue
|
, withValue governorValue
|
||||||
, withDatum governorInputDatum
|
, withDatum governorInputDatum
|
||||||
, withRef governorRef
|
, withRef governorRef
|
||||||
]
|
]
|
||||||
, output $
|
, output $
|
||||||
mconcat
|
mconcat
|
||||||
[ script govValidatorHash
|
[ script governorValidatorHash
|
||||||
, withValue governorValue
|
, withValue governorValue
|
||||||
, withDatum (mkGovernorOutputDatum ps)
|
, withDatum (mkGovernorOutputDatum ps)
|
||||||
]
|
]
|
||||||
|
|
@ -466,7 +466,7 @@ mkTestTree
|
||||||
testValidator
|
testValidator
|
||||||
validForGovernorValidator
|
validForGovernorValidator
|
||||||
"governor"
|
"governor"
|
||||||
govValidator
|
governorValidator
|
||||||
governorInputDatum
|
governorInputDatum
|
||||||
governorRedeemer
|
governorRedeemer
|
||||||
(spend governorRef)
|
(spend governorRef)
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,12 @@ module Sample.Shared (
|
||||||
|
|
||||||
-- ** Governor
|
-- ** Governor
|
||||||
governor,
|
governor,
|
||||||
govPolicy,
|
governorPolicy,
|
||||||
govValidator,
|
governorValidator,
|
||||||
govSymbol,
|
governorSymbol,
|
||||||
govAssetClass,
|
governorAssetClass,
|
||||||
govValidatorAddress,
|
governorValidatorAddress,
|
||||||
govValidatorHash,
|
governorValidatorHash,
|
||||||
gstUTXORef,
|
gstUTXORef,
|
||||||
|
|
||||||
-- ** Proposal
|
-- ** Proposal
|
||||||
|
|
@ -170,23 +170,23 @@ stakeAddress = Address (ScriptCredential stakeValidatorHash) Nothing
|
||||||
gstUTXORef :: TxOutRef
|
gstUTXORef :: TxOutRef
|
||||||
gstUTXORef = TxOutRef "f28cd7145c24e66fd5bcd2796837aeb19a48a2656e7833c88c62a2d0450bd00d" 0
|
gstUTXORef = TxOutRef "f28cd7145c24e66fd5bcd2796837aeb19a48a2656e7833c88c62a2d0450bd00d" 0
|
||||||
|
|
||||||
govPolicy :: MintingPolicy
|
governorPolicy :: MintingPolicy
|
||||||
govPolicy = MintingPolicy $ agoraScripts ! "agora:governorPolicy"
|
governorPolicy = MintingPolicy $ agoraScripts ! "agora:governorPolicy"
|
||||||
|
|
||||||
govValidator :: Validator
|
governorValidator :: Validator
|
||||||
govValidator = Validator $ agoraScripts ! "agora:governorValidator"
|
governorValidator = Validator $ agoraScripts ! "agora:governorValidator"
|
||||||
|
|
||||||
govSymbol :: CurrencySymbol
|
governorSymbol :: CurrencySymbol
|
||||||
govSymbol = mintingPolicySymbol govPolicy
|
governorSymbol = mintingPolicySymbol governorPolicy
|
||||||
|
|
||||||
govAssetClass :: AssetClass
|
governorAssetClass :: AssetClass
|
||||||
govAssetClass = AssetClass (govSymbol, "")
|
governorAssetClass = AssetClass (governorSymbol, "")
|
||||||
|
|
||||||
govValidatorHash :: ValidatorHash
|
governorValidatorHash :: ValidatorHash
|
||||||
govValidatorHash = validatorHash govValidator
|
governorValidatorHash = validatorHash governorValidator
|
||||||
|
|
||||||
govValidatorAddress :: Address
|
governorValidatorAddress :: Address
|
||||||
govValidatorAddress = scriptHashAddress govValidatorHash
|
governorValidatorAddress = scriptHashAddress governorValidatorHash
|
||||||
|
|
||||||
proposalPolicy :: MintingPolicy
|
proposalPolicy :: MintingPolicy
|
||||||
proposalPolicy = MintingPolicy $ agoraScripts ! "agora:proposalPolicy"
|
proposalPolicy = MintingPolicy $ agoraScripts ! "agora:proposalPolicy"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import Sample.Effect.GovernorMutation (
|
||||||
mkEffectTxInfo,
|
mkEffectTxInfo,
|
||||||
validNewGovernorDatum,
|
validNewGovernorDatum,
|
||||||
)
|
)
|
||||||
import Sample.Shared (govValidator)
|
import Sample.Shared (governorValidator)
|
||||||
import Test.Specification (
|
import Test.Specification (
|
||||||
SpecificationTree,
|
SpecificationTree,
|
||||||
effectFailsWith,
|
effectFailsWith,
|
||||||
|
|
@ -31,7 +31,7 @@ specs =
|
||||||
"valid new governor datum"
|
"valid new governor datum"
|
||||||
[ validatorSucceedsWith
|
[ validatorSucceedsWith
|
||||||
"governor validator should pass"
|
"governor validator should pass"
|
||||||
govValidator
|
governorValidator
|
||||||
( GovernorDatum
|
( GovernorDatum
|
||||||
def
|
def
|
||||||
(ProposalId 0)
|
(ProposalId 0)
|
||||||
|
|
@ -54,7 +54,7 @@ specs =
|
||||||
"invalid new governor datum"
|
"invalid new governor datum"
|
||||||
[ validatorFailsWith
|
[ validatorFailsWith
|
||||||
"governor validator should fail"
|
"governor validator should fail"
|
||||||
govValidator
|
governorValidator
|
||||||
( GovernorDatum
|
( GovernorDatum
|
||||||
def
|
def
|
||||||
(ProposalId 0)
|
(ProposalId 0)
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ mutateGovernorValidator ::
|
||||||
:--> PValidator
|
:--> PValidator
|
||||||
)
|
)
|
||||||
mutateGovernorValidator =
|
mutateGovernorValidator =
|
||||||
plam $ \govValidatorHash gtSymbol -> makeEffect @PMutateGovernorDatum $
|
plam $ \govValidatorHash gstSymbol -> makeEffect @PMutateGovernorDatum $
|
||||||
\_gatCs (effectDatum :: Term _ PMutateGovernorDatum) _ txInfo -> unTermCont $ do
|
\_gatCs (effectDatum :: Term _ PMutateGovernorDatum) _ txInfo -> unTermCont $ do
|
||||||
effectDatumF <- pletAllC effectDatum
|
effectDatumF <- pletAllC effectDatum
|
||||||
txInfoF <- pletFieldsC @'["inputs", "outputs", "datums", "redeemers"] txInfo
|
txInfoF <- pletFieldsC @'["inputs", "outputs", "datums", "redeemers"] txInfo
|
||||||
|
|
@ -188,7 +188,7 @@ mutateGovernorValidator =
|
||||||
inputF.outRef #== effectDatumF.governorRef
|
inputF.outRef #== effectDatumF.governorRef
|
||||||
, ptraceIfFalse "Governor UTxO should carry GST" $
|
, ptraceIfFalse "Governor UTxO should carry GST" $
|
||||||
psymbolValueOf
|
psymbolValueOf
|
||||||
# gtSymbol
|
# gstSymbol
|
||||||
# (pfield @"value" # inputF.resolved)
|
# (pfield @"value" # inputF.resolved)
|
||||||
#== 1
|
#== 1
|
||||||
, ptraceIfFalse "Governor validator run" $
|
, ptraceIfFalse "Governor validator run" $
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue