fix broken tests; utilizing new PCB APIs
This commit is contained in:
parent
3c482cc348
commit
e881f69c99
12 changed files with 150 additions and 204 deletions
|
|
@ -30,6 +30,7 @@ import Plutarch.Context (
|
||||||
output,
|
output,
|
||||||
script,
|
script,
|
||||||
withDatum,
|
withDatum,
|
||||||
|
withMinting,
|
||||||
withOutRef,
|
withOutRef,
|
||||||
withValue,
|
withValue,
|
||||||
)
|
)
|
||||||
|
|
@ -43,6 +44,7 @@ import PlutusLedgerApi.V1.Value (assetClassValue)
|
||||||
import Property.Generator (genInput, genOutput)
|
import Property.Generator (genInput, genOutput)
|
||||||
import Sample.Shared (
|
import Sample.Shared (
|
||||||
govAssetClass,
|
govAssetClass,
|
||||||
|
govSymbol,
|
||||||
govValidatorHash,
|
govValidatorHash,
|
||||||
governor,
|
governor,
|
||||||
gstUTXORef,
|
gstUTXORef,
|
||||||
|
|
@ -181,7 +183,7 @@ governorMintingProperty =
|
||||||
GovernorOutputNotFound -> referencedInput <> mintAmount 1
|
GovernorOutputNotFound -> referencedInput <> mintAmount 1
|
||||||
GovernorPolicyCorrect -> referencedInput <> outputToGov <> mintAmount 1
|
GovernorPolicyCorrect -> referencedInput <> outputToGov <> mintAmount 1
|
||||||
|
|
||||||
return . buildMintingUnsafe $ inputs <> outputs <> comp
|
return . buildMintingUnsafe $ inputs <> outputs <> comp <> withMinting govSymbol
|
||||||
|
|
||||||
expected :: ScriptContext -> Maybe ()
|
expected :: ScriptContext -> Maybe ()
|
||||||
expected sc =
|
expected sc =
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@ import Agora.Proposal.Time (MaxTimeRangeWidth (MaxTimeRangeWidth), ProposalTimin
|
||||||
import Data.Default (Default (..))
|
import Data.Default (Default (..))
|
||||||
import Plutarch.Api.V1 (mintingPolicySymbol, mkMintingPolicy)
|
import Plutarch.Api.V1 (mintingPolicySymbol, mkMintingPolicy)
|
||||||
import Plutarch.Context (
|
import Plutarch.Context (
|
||||||
BaseBuilder,
|
|
||||||
buildTxInfoUnsafe,
|
|
||||||
input,
|
input,
|
||||||
mint,
|
mint,
|
||||||
output,
|
output,
|
||||||
|
|
@ -46,9 +44,6 @@ import Plutarch.Context (
|
||||||
import PlutusLedgerApi.V1 (
|
import PlutusLedgerApi.V1 (
|
||||||
CurrencySymbol,
|
CurrencySymbol,
|
||||||
MintingPolicy,
|
MintingPolicy,
|
||||||
ScriptContext (..),
|
|
||||||
ScriptPurpose (Minting),
|
|
||||||
TxInfo,
|
|
||||||
TxOutRef (TxOutRef),
|
TxOutRef (TxOutRef),
|
||||||
ValidatorHash,
|
ValidatorHash,
|
||||||
)
|
)
|
||||||
|
|
@ -59,7 +54,7 @@ import Sample.Shared (
|
||||||
)
|
)
|
||||||
import Sample.Shared qualified as Shared
|
import Sample.Shared qualified as Shared
|
||||||
import Test.Specification (SpecificationTree, testPolicy)
|
import Test.Specification (SpecificationTree, testPolicy)
|
||||||
import Test.Util (pubKeyHashes, sortValue)
|
import Test.Util (CombinableBuilder, mkMinting, pubKeyHashes, sortValue)
|
||||||
|
|
||||||
data Parameters = Parameters
|
data Parameters = Parameters
|
||||||
{ datumThresholdsValid :: Bool
|
{ datumThresholdsValid :: Bool
|
||||||
|
|
@ -115,8 +110,8 @@ govSymbol = mintingPolicySymbol govPolicy
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
mintGST :: Parameters -> TxInfo
|
mintGST :: forall b. CombinableBuilder b => Parameters -> b
|
||||||
mintGST ps = buildTxInfoUnsafe builder
|
mintGST ps = builder
|
||||||
where
|
where
|
||||||
gstAC =
|
gstAC =
|
||||||
if ps.mintStateTokenWithName
|
if ps.mintStateTokenWithName
|
||||||
|
|
@ -149,7 +144,6 @@ mintGST ps = buildTxInfoUnsafe builder
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
witnessBuilder :: BaseBuilder
|
|
||||||
witnessBuilder =
|
witnessBuilder =
|
||||||
if ps.presentWitness
|
if ps.presentWitness
|
||||||
then
|
then
|
||||||
|
|
@ -166,7 +160,6 @@ mintGST ps = buildTxInfoUnsafe builder
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
govBuilder :: BaseBuilder
|
|
||||||
govBuilder =
|
govBuilder =
|
||||||
let datum =
|
let datum =
|
||||||
if ps.withGovernorDatum
|
if ps.withGovernorDatum
|
||||||
|
|
@ -177,8 +170,6 @@ mintGST ps = buildTxInfoUnsafe builder
|
||||||
. withValue governorValue
|
. withValue governorValue
|
||||||
. datum
|
. datum
|
||||||
--
|
--
|
||||||
|
|
||||||
builder :: BaseBuilder
|
|
||||||
builder =
|
builder =
|
||||||
mconcat
|
mconcat
|
||||||
[ txId "986b756ffb1c9839fc8d0b22a308ac91d5b5d0ebbfa683a47588c8a5cf70b5af"
|
[ txId "986b756ffb1c9839fc8d0b22a308ac91d5b5d0ebbfa683a47588c8a5cf70b5af"
|
||||||
|
|
@ -247,17 +238,10 @@ mintGSTWithNoneEmptyNameParameters =
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
mkTestCase :: String -> Parameters -> Bool -> SpecificationTree
|
mkTestCase :: String -> Parameters -> Bool -> SpecificationTree
|
||||||
mkTestCase
|
mkTestCase name ps valid =
|
||||||
name
|
testPolicy
|
||||||
ps
|
valid
|
||||||
valid = policyTest
|
name
|
||||||
where
|
(governorPolicy governor)
|
||||||
txInfo = mintGST ps
|
()
|
||||||
|
(mkMinting mintGST ps govSymbol)
|
||||||
policyTest =
|
|
||||||
testPolicy
|
|
||||||
valid
|
|
||||||
name
|
|
||||||
(governorPolicy governor)
|
|
||||||
()
|
|
||||||
(ScriptContext txInfo (Minting govSymbol))
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ import Agora.Utils (validatorHashToTokenName)
|
||||||
import Data.Default (def)
|
import Data.Default (def)
|
||||||
import Plutarch.Api.V1 (PValidator, mkValidator, validatorHash)
|
import Plutarch.Api.V1 (PValidator, mkValidator, validatorHash)
|
||||||
import Plutarch.Context (
|
import Plutarch.Context (
|
||||||
BaseBuilder,
|
|
||||||
buildTxInfoUnsafe,
|
|
||||||
input,
|
input,
|
||||||
mint,
|
mint,
|
||||||
output,
|
output,
|
||||||
|
|
@ -37,9 +35,6 @@ import Plutarch.Context (
|
||||||
)
|
)
|
||||||
import PlutusLedgerApi.V1 (
|
import PlutusLedgerApi.V1 (
|
||||||
Data,
|
Data,
|
||||||
ScriptContext (ScriptContext),
|
|
||||||
ScriptPurpose (Spending),
|
|
||||||
TxInfo,
|
|
||||||
TxOutRef (TxOutRef),
|
TxOutRef (TxOutRef),
|
||||||
ValidatorHash,
|
ValidatorHash,
|
||||||
Value,
|
Value,
|
||||||
|
|
@ -54,7 +49,7 @@ import Sample.Shared (
|
||||||
minAda,
|
minAda,
|
||||||
)
|
)
|
||||||
import Test.Specification (SpecificationTree, testValidator)
|
import Test.Specification (SpecificationTree, testValidator)
|
||||||
import Test.Util (pubKeyHashes, sortValue, validatorHashes, withOptional)
|
import Test.Util (CombinableBuilder, mkSpending, pubKeyHashes, sortValue, validatorHashes, withOptional)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -131,13 +126,10 @@ governorRef =
|
||||||
"6cce6dfbb697f9e2c4fe9786bb576eb7bd6cbcf7801a4ba13d596006c2d5b957"
|
"6cce6dfbb697f9e2c4fe9786bb576eb7bd6cbcf7801a4ba13d596006c2d5b957"
|
||||||
1
|
1
|
||||||
|
|
||||||
governorScriptPurpose :: ScriptPurpose
|
|
||||||
governorScriptPurpose = Spending governorRef
|
|
||||||
|
|
||||||
governorRedeemer :: GovernorRedeemer
|
governorRedeemer :: GovernorRedeemer
|
||||||
governorRedeemer = MutateGovernor
|
governorRedeemer = MutateGovernor
|
||||||
|
|
||||||
mkGovernorBuilder :: GovernorParameters -> BaseBuilder
|
mkGovernorBuilder :: forall b. CombinableBuilder b => GovernorParameters -> b
|
||||||
mkGovernorBuilder ps =
|
mkGovernorBuilder ps =
|
||||||
let gst = Value.assetClassValue govAssetClass 1
|
let gst = Value.assetClassValue govAssetClass 1
|
||||||
value = sortValue $ gst <> minAda
|
value = sortValue $ gst <> minAda
|
||||||
|
|
@ -179,7 +171,7 @@ mkGATValue v q =
|
||||||
(validatorHashToTokenName gatOwner)
|
(validatorHashToTokenName gatOwner)
|
||||||
q
|
q
|
||||||
|
|
||||||
mkMockEffectBuilder :: MockEffectParameters -> BaseBuilder
|
mkMockEffectBuilder :: forall b. CombinableBuilder b => MockEffectParameters -> b
|
||||||
mkMockEffectBuilder ps =
|
mkMockEffectBuilder ps =
|
||||||
let mkGATValue' = mkGATValue ps.gatValidity
|
let mkGATValue' = mkGATValue ps.gatValidity
|
||||||
inputValue = mkGATValue' 1
|
inputValue = mkGATValue' 1
|
||||||
|
|
@ -200,13 +192,12 @@ mkMockEffectBuilder ps =
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
mutate :: ParameterBundle -> TxInfo
|
mutate :: forall b. CombinableBuilder b => ParameterBundle -> b
|
||||||
mutate pb =
|
mutate pb =
|
||||||
buildTxInfoUnsafe $
|
mconcat
|
||||||
mconcat
|
[ mkGovernorBuilder pb.governorParameters
|
||||||
[ mkGovernorBuilder pb.governorParameters
|
, mkMockEffectBuilder pb.mockEffectParameters
|
||||||
, mkMockEffectBuilder pb.mockEffectParameters
|
]
|
||||||
]
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -218,10 +209,7 @@ mkTestCase name pb (Validity forGov) =
|
||||||
(governorValidator governor)
|
(governorValidator governor)
|
||||||
governorInputDatum
|
governorInputDatum
|
||||||
governorRedeemer
|
governorRedeemer
|
||||||
( ScriptContext
|
(mkSpending mutate pb governorRef)
|
||||||
(mutate pb)
|
|
||||||
governorScriptPurpose
|
|
||||||
)
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,8 +79,6 @@ import Data.List (sort)
|
||||||
import Data.Maybe (catMaybes, fromJust)
|
import Data.Maybe (catMaybes, fromJust)
|
||||||
import Data.Tagged (Tagged (..), untag)
|
import Data.Tagged (Tagged (..), untag)
|
||||||
import Plutarch.Context (
|
import Plutarch.Context (
|
||||||
BaseBuilder,
|
|
||||||
buildTxInfoUnsafe,
|
|
||||||
input,
|
input,
|
||||||
mint,
|
mint,
|
||||||
output,
|
output,
|
||||||
|
|
@ -97,9 +95,6 @@ import PlutusLedgerApi.V1 (
|
||||||
POSIXTime,
|
POSIXTime,
|
||||||
POSIXTimeRange,
|
POSIXTimeRange,
|
||||||
PubKeyHash,
|
PubKeyHash,
|
||||||
ScriptContext (ScriptContext),
|
|
||||||
ScriptPurpose (Minting, Spending),
|
|
||||||
TxInfo,
|
|
||||||
TxOutRef (TxOutRef),
|
TxOutRef (TxOutRef),
|
||||||
ValidatorHash,
|
ValidatorHash,
|
||||||
)
|
)
|
||||||
|
|
@ -131,9 +126,12 @@ import Test.Specification (
|
||||||
testValidator,
|
testValidator,
|
||||||
)
|
)
|
||||||
import Test.Util (
|
import Test.Util (
|
||||||
|
CombinableBuilder,
|
||||||
closedBoundedInterval,
|
closedBoundedInterval,
|
||||||
datumHash,
|
datumHash,
|
||||||
groupsOfN,
|
groupsOfN,
|
||||||
|
mkMinting,
|
||||||
|
mkSpending,
|
||||||
pubKeyHashes,
|
pubKeyHashes,
|
||||||
sortValue,
|
sortValue,
|
||||||
toDatum,
|
toDatum,
|
||||||
|
|
@ -264,7 +262,7 @@ mkProposalOutputDatum ps =
|
||||||
proposalRef :: TxOutRef
|
proposalRef :: TxOutRef
|
||||||
proposalRef = TxOutRef proposalTxRef 1
|
proposalRef = TxOutRef proposalTxRef 1
|
||||||
|
|
||||||
mkProposalBuilder :: ProposalParameters -> BaseBuilder
|
mkProposalBuilder :: forall b. CombinableBuilder b => ProposalParameters -> b
|
||||||
mkProposalBuilder ps =
|
mkProposalBuilder ps =
|
||||||
let pst = Value.singleton proposalPolicySymbol "" 1
|
let pst = Value.singleton proposalPolicySymbol "" 1
|
||||||
value = sortValue $ minAda <> pst
|
value = sortValue $ minAda <> pst
|
||||||
|
|
@ -280,10 +278,6 @@ mkProposalBuilder ps =
|
||||||
. withValue value
|
. withValue value
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | Script purpose of the proposal validator.
|
|
||||||
proposalScriptPurpose :: ScriptPurpose
|
|
||||||
proposalScriptPurpose = Spending proposalRef
|
|
||||||
|
|
||||||
{- | The proposal redeemer used to spend the proposal UTXO, which is always
|
{- | The proposal redeemer used to spend the proposal UTXO, which is always
|
||||||
'AdvanceProposal' in this case.
|
'AdvanceProposal' in this case.
|
||||||
-}
|
-}
|
||||||
|
|
@ -327,7 +321,7 @@ getStakeInputDatumAt ps = (!!) (mkStakeInputDatums ps)
|
||||||
mkStakeRef :: Index -> TxOutRef
|
mkStakeRef :: Index -> TxOutRef
|
||||||
mkStakeRef = TxOutRef stakeTxRef . (+ 3) . fromIntegral
|
mkStakeRef = TxOutRef stakeTxRef . (+ 3) . fromIntegral
|
||||||
|
|
||||||
mkStakeBuilder :: StakeParameters -> BaseBuilder
|
mkStakeBuilder :: forall b. CombinableBuilder b => StakeParameters -> b
|
||||||
mkStakeBuilder ps =
|
mkStakeBuilder ps =
|
||||||
let perStakeValue =
|
let perStakeValue =
|
||||||
sortValue $
|
sortValue $
|
||||||
|
|
@ -360,10 +354,6 @@ mkStakeBuilder ps =
|
||||||
(mkStakeInputDatums ps)
|
(mkStakeInputDatums ps)
|
||||||
(mkStakeOutputDatums ps)
|
(mkStakeOutputDatums ps)
|
||||||
|
|
||||||
-- | Script purpose of the stake validator, given which stake we want to spend.
|
|
||||||
getStakeScriptPurposeAt :: Index -> ScriptPurpose
|
|
||||||
getStakeScriptPurposeAt = Spending . mkStakeRef
|
|
||||||
|
|
||||||
{- | The proposal redeemer used to spend the stake UTXO, which is always
|
{- | The proposal redeemer used to spend the stake UTXO, which is always
|
||||||
'WitnessStake' in this case.
|
'WitnessStake' in this case.
|
||||||
-}
|
-}
|
||||||
|
|
@ -394,7 +384,7 @@ mkGovernorOutputDatum ps =
|
||||||
governorRef :: TxOutRef
|
governorRef :: TxOutRef
|
||||||
governorRef = TxOutRef governorTxRef 2
|
governorRef = TxOutRef governorTxRef 2
|
||||||
|
|
||||||
mkGovernorBuilder :: GovernorParameters -> BaseBuilder
|
mkGovernorBuilder :: forall b. CombinableBuilder b => GovernorParameters -> b
|
||||||
mkGovernorBuilder ps =
|
mkGovernorBuilder ps =
|
||||||
let gst = Value.assetClassValue govAssetClass 1
|
let gst = Value.assetClassValue govAssetClass 1
|
||||||
value = sortValue $ gst <> minAda
|
value = sortValue $ gst <> minAda
|
||||||
|
|
@ -411,9 +401,6 @@ mkGovernorBuilder ps =
|
||||||
. withDatum (mkGovernorOutputDatum ps)
|
. withDatum (mkGovernorOutputDatum ps)
|
||||||
]
|
]
|
||||||
|
|
||||||
governorScriptPurpose :: ScriptPurpose
|
|
||||||
governorScriptPurpose = Spending governorRef
|
|
||||||
|
|
||||||
{- | The proposal redeemer used to spend the governor UTXO, which is always
|
{- | The proposal redeemer used to spend the governor UTXO, which is always
|
||||||
'MintGATs' in this case.
|
'MintGATs' in this case.
|
||||||
-}
|
-}
|
||||||
|
|
@ -424,11 +411,11 @@ governorRedeemer = MintGATs
|
||||||
|
|
||||||
-- * Authority Token
|
-- * Authority Token
|
||||||
|
|
||||||
mkAuthorityTokenBuilder :: AuthorityTokenParameters -> BaseBuilder
|
mkAuthorityTokenBuilder :: forall b. CombinableBuilder b => AuthorityTokenParameters -> b
|
||||||
mkAuthorityTokenBuilder (AuthorityTokenParameters es mdt invalidTokenName) =
|
mkAuthorityTokenBuilder (AuthorityTokenParameters es mdt invalidTokenName) =
|
||||||
foldMap perEffect es
|
foldMap perEffect es
|
||||||
where
|
where
|
||||||
perEffect :: ValidatorHash -> BaseBuilder
|
perEffect :: ValidatorHash -> b
|
||||||
perEffect vh =
|
perEffect vh =
|
||||||
let tn =
|
let tn =
|
||||||
if invalidTokenName
|
if invalidTokenName
|
||||||
|
|
@ -445,9 +432,6 @@ mkAuthorityTokenBuilder (AuthorityTokenParameters es mdt invalidTokenName) =
|
||||||
. withValue value
|
. withValue value
|
||||||
]
|
]
|
||||||
|
|
||||||
authorityTokenScriptPurepose :: ScriptPurpose
|
|
||||||
authorityTokenScriptPurepose = Minting authorityTokenSymbol
|
|
||||||
|
|
||||||
authorityTokenRedeemer :: ()
|
authorityTokenRedeemer :: ()
|
||||||
authorityTokenRedeemer = ()
|
authorityTokenRedeemer = ()
|
||||||
|
|
||||||
|
|
@ -455,19 +439,20 @@ authorityTokenRedeemer = ()
|
||||||
|
|
||||||
-- | Create a 'TxInfo' that update the status of a proposal.
|
-- | Create a 'TxInfo' that update the status of a proposal.
|
||||||
advance ::
|
advance ::
|
||||||
|
forall b.
|
||||||
|
CombinableBuilder b =>
|
||||||
ParameterBundle ->
|
ParameterBundle ->
|
||||||
TxInfo
|
b
|
||||||
advance pb =
|
advance pb =
|
||||||
let mkBuilderMaybe = maybe mempty
|
let mkBuilderMaybe = maybe mempty
|
||||||
in buildTxInfoUnsafe $
|
in mconcat
|
||||||
mconcat
|
[ mkProposalBuilder pb.proposalParameters
|
||||||
[ mkProposalBuilder pb.proposalParameters
|
, mkStakeBuilder pb.stakeParameters
|
||||||
, mkStakeBuilder pb.stakeParameters
|
, mkBuilderMaybe mkGovernorBuilder pb.governorParameters
|
||||||
, mkBuilderMaybe mkGovernorBuilder pb.governorParameters
|
, mkBuilderMaybe mkAuthorityTokenBuilder pb.authorityTokenParameters
|
||||||
, mkBuilderMaybe mkAuthorityTokenBuilder pb.authorityTokenParameters
|
, timeRange pb.transactionTimeRange
|
||||||
, timeRange pb.transactionTimeRange
|
, maybe mempty signedWith pb.extraSignature
|
||||||
, maybe mempty signedWith pb.extraSignature
|
]
|
||||||
]
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -479,13 +464,14 @@ mkTestTree ::
|
||||||
ParameterBundle ->
|
ParameterBundle ->
|
||||||
Validity ->
|
Validity ->
|
||||||
SpecificationTree
|
SpecificationTree
|
||||||
mkTestTree name params val =
|
mkTestTree name pb val =
|
||||||
group name $ catMaybes [proposal, stake, governor, authority]
|
group name $ catMaybes [proposal, stake, governor, authority]
|
||||||
where
|
where
|
||||||
txInfo = advance params
|
spend = mkSpending advance pb
|
||||||
|
mint = mkMinting advance pb
|
||||||
|
|
||||||
proposal =
|
proposal =
|
||||||
let proposalInputDatum = mkProposalInputDatum params.proposalParameters
|
let proposalInputDatum = mkProposalInputDatum pb.proposalParameters
|
||||||
in Just $
|
in Just $
|
||||||
testValidator
|
testValidator
|
||||||
val.forProposalValidator
|
val.forProposalValidator
|
||||||
|
|
@ -493,10 +479,7 @@ mkTestTree name params val =
|
||||||
(proposalValidator Shared.proposal)
|
(proposalValidator Shared.proposal)
|
||||||
proposalInputDatum
|
proposalInputDatum
|
||||||
proposalRedeemer
|
proposalRedeemer
|
||||||
( ScriptContext
|
(spend proposalRef)
|
||||||
txInfo
|
|
||||||
proposalScriptPurpose
|
|
||||||
)
|
|
||||||
|
|
||||||
stake =
|
stake =
|
||||||
let idx = 0
|
let idx = 0
|
||||||
|
|
@ -505,11 +488,9 @@ mkTestTree name params val =
|
||||||
val.forStakeValidator
|
val.forStakeValidator
|
||||||
"stake"
|
"stake"
|
||||||
(stakeValidator Shared.stake)
|
(stakeValidator Shared.stake)
|
||||||
(getStakeInputDatumAt params.stakeParameters idx)
|
(getStakeInputDatumAt pb.stakeParameters idx)
|
||||||
stakeRedeemer
|
stakeRedeemer
|
||||||
( ScriptContext
|
( spend (mkStakeRef idx)
|
||||||
txInfo
|
|
||||||
(getStakeScriptPurposeAt idx)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
governor =
|
governor =
|
||||||
|
|
@ -519,11 +500,8 @@ mkTestTree name params val =
|
||||||
(governorValidator Shared.governor)
|
(governorValidator Shared.governor)
|
||||||
governorInputDatum
|
governorInputDatum
|
||||||
governorRedeemer
|
governorRedeemer
|
||||||
( ScriptContext
|
(spend governorRef)
|
||||||
txInfo
|
<$ pb.governorParameters
|
||||||
governorScriptPurpose
|
|
||||||
)
|
|
||||||
<$ params.governorParameters
|
|
||||||
|
|
||||||
authority =
|
authority =
|
||||||
testPolicy
|
testPolicy
|
||||||
|
|
@ -531,11 +509,8 @@ mkTestTree name params val =
|
||||||
"authority"
|
"authority"
|
||||||
(authorityTokenPolicy $ AuthorityToken Shared.govAssetClass)
|
(authorityTokenPolicy $ AuthorityToken Shared.govAssetClass)
|
||||||
authorityTokenRedeemer
|
authorityTokenRedeemer
|
||||||
( ScriptContext
|
(mint authorityTokenSymbol)
|
||||||
txInfo
|
<$ (pb.authorityTokenParameters)
|
||||||
authorityTokenScriptPurepose
|
|
||||||
)
|
|
||||||
<$ (params.authorityTokenParameters)
|
|
||||||
|
|
||||||
mkTestTree' ::
|
mkTestTree' ::
|
||||||
String ->
|
String ->
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ import Data.Default (def)
|
||||||
import Data.List (sort)
|
import Data.List (sort)
|
||||||
import Data.Tagged (Tagged, untag)
|
import Data.Tagged (Tagged, untag)
|
||||||
import Plutarch.Context (
|
import Plutarch.Context (
|
||||||
BaseBuilder,
|
|
||||||
buildTxInfoUnsafe,
|
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
script,
|
script,
|
||||||
|
|
@ -49,16 +47,13 @@ import Plutarch.Context (
|
||||||
timeRange,
|
timeRange,
|
||||||
txId,
|
txId,
|
||||||
withDatum,
|
withDatum,
|
||||||
withRefIndex,
|
withOutRef,
|
||||||
withTxId,
|
withTxId,
|
||||||
withValue,
|
withValue,
|
||||||
)
|
)
|
||||||
import PlutusLedgerApi.V1 (
|
import PlutusLedgerApi.V1 (
|
||||||
POSIXTimeRange,
|
POSIXTimeRange,
|
||||||
PubKeyHash,
|
PubKeyHash,
|
||||||
ScriptContext (ScriptContext),
|
|
||||||
ScriptPurpose (Spending),
|
|
||||||
TxInfo,
|
|
||||||
TxOutRef (..),
|
TxOutRef (..),
|
||||||
Value,
|
Value,
|
||||||
)
|
)
|
||||||
|
|
@ -80,7 +75,7 @@ import Test.Specification (
|
||||||
group,
|
group,
|
||||||
testValidator,
|
testValidator,
|
||||||
)
|
)
|
||||||
import Test.Util (closedBoundedInterval, pubKeyHashes, sortValue)
|
import Test.Util (CombinableBuilder, closedBoundedInterval, mkSpending, pubKeyHashes, sortValue)
|
||||||
|
|
||||||
-- | Parameters for cosigning a proposal.
|
-- | Parameters for cosigning a proposal.
|
||||||
data Parameters = Parameters
|
data Parameters = Parameters
|
||||||
|
|
@ -138,8 +133,8 @@ mkStakeInputDatums :: Parameters -> [StakeDatum]
|
||||||
mkStakeInputDatums = fmap (\pk -> StakeDatum perStakedGTs pk []) . newCosigners
|
mkStakeInputDatums = fmap (\pk -> StakeDatum perStakedGTs pk []) . newCosigners
|
||||||
|
|
||||||
-- | Create a 'TxInfo' that tries to cosign a proposal with new cosigners.
|
-- | Create a 'TxInfo' that tries to cosign a proposal with new cosigners.
|
||||||
cosign :: Parameters -> TxInfo
|
cosign :: forall b. CombinableBuilder b => Parameters -> b
|
||||||
cosign ps = buildTxInfoUnsafe builder
|
cosign ps = builder
|
||||||
where
|
where
|
||||||
pst = Value.singleton proposalPolicySymbol "" 1
|
pst = Value.singleton proposalPolicySymbol "" 1
|
||||||
sst = Value.assetClassValue stakeAssetClass 1
|
sst = Value.assetClassValue stakeAssetClass 1
|
||||||
|
|
@ -158,7 +153,6 @@ cosign ps = buildTxInfoUnsafe builder
|
||||||
(untag perStakedGTs)
|
(untag perStakedGTs)
|
||||||
<> sst
|
<> sst
|
||||||
|
|
||||||
stakeBuilder :: BaseBuilder
|
|
||||||
stakeBuilder =
|
stakeBuilder =
|
||||||
foldMap
|
foldMap
|
||||||
( \(stakeDatum, refIdx) ->
|
( \(stakeDatum, refIdx) ->
|
||||||
|
|
@ -166,13 +160,13 @@ cosign ps = buildTxInfoUnsafe builder
|
||||||
if ps.alterOutputStakes
|
if ps.alterOutputStakes
|
||||||
then stakeDatum {stakedAmount = 0}
|
then stakeDatum {stakedAmount = 0}
|
||||||
else stakeDatum
|
else stakeDatum
|
||||||
in mconcat @BaseBuilder
|
in mconcat
|
||||||
[ input $
|
[ input $
|
||||||
script stakeValidatorHash
|
script stakeValidatorHash
|
||||||
. withValue stakeValue
|
. withValue stakeValue
|
||||||
. withDatum stakeDatum
|
. withDatum stakeDatum
|
||||||
. withTxId stakeTxRef
|
. withTxId stakeTxRef
|
||||||
. withRefIndex refIdx
|
. withOutRef (mkStakeRef refIdx)
|
||||||
, output $
|
, output $
|
||||||
script stakeValidatorHash
|
script stakeValidatorHash
|
||||||
. withValue stakeValue
|
. withValue stakeValue
|
||||||
|
|
@ -182,7 +176,7 @@ cosign ps = buildTxInfoUnsafe builder
|
||||||
)
|
)
|
||||||
$ zip
|
$ zip
|
||||||
stakeInputDatums
|
stakeInputDatums
|
||||||
[2 ..]
|
[0 ..]
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -192,7 +186,6 @@ cosign ps = buildTxInfoUnsafe builder
|
||||||
proposalOutputDatum :: ProposalDatum
|
proposalOutputDatum :: ProposalDatum
|
||||||
proposalOutputDatum = mkProposalOutputDatum ps
|
proposalOutputDatum = mkProposalOutputDatum ps
|
||||||
|
|
||||||
proposalBuilder :: BaseBuilder
|
|
||||||
proposalBuilder =
|
proposalBuilder =
|
||||||
mconcat
|
mconcat
|
||||||
[ input $
|
[ input $
|
||||||
|
|
@ -200,7 +193,7 @@ cosign ps = buildTxInfoUnsafe builder
|
||||||
. withValue pst
|
. withValue pst
|
||||||
. withDatum proposalInputDatum
|
. withDatum proposalInputDatum
|
||||||
. withTxId proposalTxRef
|
. withTxId proposalTxRef
|
||||||
. withRefIndex proposalRefIdx
|
. withOutRef proposalRef
|
||||||
, output $
|
, output $
|
||||||
script proposalValidatorHash
|
script proposalValidatorHash
|
||||||
. withValue (sortValue (pst <> minAda))
|
. withValue (sortValue (pst <> minAda))
|
||||||
|
|
@ -217,7 +210,6 @@ cosign ps = buildTxInfoUnsafe builder
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
builder :: BaseBuilder
|
|
||||||
builder =
|
builder =
|
||||||
mconcat
|
mconcat
|
||||||
[ txId "05c67819fc3381a2052b929ab439244b7b5fe3b3bd07f2134055bbbb21bd9e52"
|
[ txId "05c67819fc3381a2052b929ab439244b7b5fe3b3bd07f2134055bbbb21bd9e52"
|
||||||
|
|
@ -231,21 +223,15 @@ proposalRefIdx :: Integer
|
||||||
proposalRefIdx = 1
|
proposalRefIdx = 1
|
||||||
|
|
||||||
-- | Spend the proposal ST.
|
-- | Spend the proposal ST.
|
||||||
proposalScriptPurpose :: ScriptPurpose
|
proposalRef :: TxOutRef
|
||||||
proposalScriptPurpose =
|
proposalRef = TxOutRef proposalTxRef proposalRefIdx
|
||||||
Spending
|
|
||||||
( TxOutRef
|
|
||||||
proposalTxRef
|
|
||||||
proposalRefIdx
|
|
||||||
)
|
|
||||||
|
|
||||||
-- | Consume the given stake.
|
-- | Consume the given stake.
|
||||||
mkStakeScriptPurpose :: Int -> ScriptPurpose
|
mkStakeRef :: Int -> TxOutRef
|
||||||
mkStakeScriptPurpose idx =
|
mkStakeRef idx =
|
||||||
Spending $
|
TxOutRef
|
||||||
TxOutRef
|
stakeTxRef
|
||||||
stakeTxRef
|
$ proposalRefIdx + 1 + fromIntegral idx
|
||||||
$ proposalRefIdx + 1 + fromIntegral idx
|
|
||||||
|
|
||||||
-- | Create a proposal redeemer which cosigns with the new cosginers.
|
-- | Create a proposal redeemer which cosigns with the new cosginers.
|
||||||
mkProposalRedeemer :: Parameters -> ProposalRedeemer
|
mkProposalRedeemer :: Parameters -> ProposalRedeemer
|
||||||
|
|
@ -321,7 +307,7 @@ mkTestTree ::
|
||||||
SpecificationTree
|
SpecificationTree
|
||||||
mkTestTree name ps isValid = group name [proposal, stake]
|
mkTestTree name ps isValid = group name [proposal, stake]
|
||||||
where
|
where
|
||||||
txInfo = cosign ps
|
spend = mkSpending cosign ps
|
||||||
|
|
||||||
proposal =
|
proposal =
|
||||||
let proposalInputDatum = mkProposalInputDatum ps
|
let proposalInputDatum = mkProposalInputDatum ps
|
||||||
|
|
@ -331,10 +317,7 @@ mkTestTree name ps isValid = group name [proposal, stake]
|
||||||
(proposalValidator Shared.proposal)
|
(proposalValidator Shared.proposal)
|
||||||
proposalInputDatum
|
proposalInputDatum
|
||||||
(mkProposalRedeemer ps)
|
(mkProposalRedeemer ps)
|
||||||
( ScriptContext
|
(spend proposalRef)
|
||||||
txInfo
|
|
||||||
proposalScriptPurpose
|
|
||||||
)
|
|
||||||
|
|
||||||
stake =
|
stake =
|
||||||
let idx = 0
|
let idx = 0
|
||||||
|
|
@ -346,7 +329,4 @@ mkTestTree name ps isValid = group name [proposal, stake]
|
||||||
(stakeValidator Shared.stake)
|
(stakeValidator Shared.stake)
|
||||||
stakeInputDatum
|
stakeInputDatum
|
||||||
stakeRedeemer
|
stakeRedeemer
|
||||||
( ScriptContext
|
(spend $ mkStakeRef idx)
|
||||||
txInfo
|
|
||||||
(mkStakeScriptPurpose idx)
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,6 @@ import Data.Coerce (coerce)
|
||||||
import Data.Default (Default (def))
|
import Data.Default (Default (def))
|
||||||
import Data.Tagged (Tagged, untag)
|
import Data.Tagged (Tagged, untag)
|
||||||
import Plutarch.Context (
|
import Plutarch.Context (
|
||||||
BaseBuilder,
|
|
||||||
buildTxInfoUnsafe,
|
|
||||||
input,
|
input,
|
||||||
mint,
|
mint,
|
||||||
output,
|
output,
|
||||||
|
|
@ -63,9 +61,6 @@ import PlutusLedgerApi.V1 (
|
||||||
POSIXTime (POSIXTime),
|
POSIXTime (POSIXTime),
|
||||||
POSIXTimeRange,
|
POSIXTimeRange,
|
||||||
PubKeyHash,
|
PubKeyHash,
|
||||||
ScriptContext (ScriptContext),
|
|
||||||
ScriptPurpose (Minting, Spending),
|
|
||||||
TxInfo,
|
|
||||||
TxOutRef (TxOutRef),
|
TxOutRef (TxOutRef),
|
||||||
ValidatorHash,
|
ValidatorHash,
|
||||||
always,
|
always,
|
||||||
|
|
@ -88,7 +83,7 @@ import Sample.Shared (
|
||||||
)
|
)
|
||||||
import Sample.Shared qualified as Shared
|
import Sample.Shared qualified as Shared
|
||||||
import Test.Specification (SpecificationTree, group, testPolicy, testValidator)
|
import Test.Specification (SpecificationTree, group, testPolicy, testValidator)
|
||||||
import Test.Util (closedBoundedInterval, sortValue)
|
import Test.Util (CombinableBuilder, closedBoundedInterval, mkMinting, mkSpending, sortValue)
|
||||||
|
|
||||||
-- | Parameters for creating a proposal.
|
-- | Parameters for creating a proposal.
|
||||||
data Parameters = Parameters
|
data Parameters = Parameters
|
||||||
|
|
@ -269,8 +264,8 @@ governorRef = TxOutRef "0b2086cbf8b6900f8cb65e012de4516cb66b5cb08a9aaba12a8b88be
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- | Create a 'TxInfo' that spends a stake to create a new proposal.
|
-- | Create a 'TxInfo' that spends a stake to create a new proposal.
|
||||||
createProposal :: Parameters -> TxInfo
|
createProposal :: forall b. CombinableBuilder b => Parameters -> b
|
||||||
createProposal ps = buildTxInfoUnsafe builder
|
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
|
||||||
|
|
@ -296,7 +291,6 @@ createProposal ps = buildTxInfoUnsafe builder
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
builder :: BaseBuilder
|
|
||||||
builder =
|
builder =
|
||||||
mconcat
|
mconcat
|
||||||
[ txId "0b2086cbf8b6900f8cb65e012de4516cb66b5cb08a9aaba12a8b88be"
|
[ txId "0b2086cbf8b6900f8cb65e012de4516cb66b5cb08a9aaba12a8b88be"
|
||||||
|
|
@ -426,7 +420,8 @@ mkTestTree
|
||||||
validForStakeValidator =
|
validForStakeValidator =
|
||||||
group name [proposalTest, governorTest, stakeTest]
|
group name [proposalTest, governorTest, stakeTest]
|
||||||
where
|
where
|
||||||
txInfo = createProposal ps
|
mint = mkMinting createProposal ps
|
||||||
|
spend = mkSpending createProposal ps
|
||||||
|
|
||||||
proposalTest =
|
proposalTest =
|
||||||
testPolicy
|
testPolicy
|
||||||
|
|
@ -434,7 +429,7 @@ mkTestTree
|
||||||
"proposal"
|
"proposal"
|
||||||
(proposalPolicy Shared.proposal.governorSTAssetClass)
|
(proposalPolicy Shared.proposal.governorSTAssetClass)
|
||||||
proposalPolicyRedeemer
|
proposalPolicyRedeemer
|
||||||
(ScriptContext txInfo (Minting proposalPolicySymbol))
|
(mint proposalPolicySymbol)
|
||||||
|
|
||||||
governorTest =
|
governorTest =
|
||||||
testValidator
|
testValidator
|
||||||
|
|
@ -443,11 +438,7 @@ mkTestTree
|
||||||
(governorValidator Shared.governor)
|
(governorValidator Shared.governor)
|
||||||
governorInputDatum
|
governorInputDatum
|
||||||
governorRedeemer
|
governorRedeemer
|
||||||
( ScriptContext
|
(spend governorRef)
|
||||||
txInfo
|
|
||||||
(Spending governorRef)
|
|
||||||
)
|
|
||||||
|
|
||||||
stakeTest =
|
stakeTest =
|
||||||
testValidator
|
testValidator
|
||||||
validForStakeValidator
|
validForStakeValidator
|
||||||
|
|
@ -455,7 +446,4 @@ mkTestTree
|
||||||
(stakeValidator Shared.stake)
|
(stakeValidator Shared.stake)
|
||||||
(mkStakeInputDatum ps)
|
(mkStakeInputDatum ps)
|
||||||
stakeRedeemer
|
stakeRedeemer
|
||||||
( ScriptContext
|
(spend stakeRef)
|
||||||
txInfo
|
|
||||||
(Spending stakeRef)
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ import Agora.Stake.Scripts (stakeValidator)
|
||||||
import Data.Default.Class (Default (def))
|
import Data.Default.Class (Default (def))
|
||||||
import Data.Tagged (Tagged (..), untag)
|
import Data.Tagged (Tagged (..), untag)
|
||||||
import Plutarch.Context (
|
import Plutarch.Context (
|
||||||
BaseBuilder,
|
|
||||||
buildTxInfoUnsafe,
|
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
script,
|
script,
|
||||||
|
|
@ -54,9 +52,6 @@ import Plutarch.Context (
|
||||||
import PlutusLedgerApi.V1 (
|
import PlutusLedgerApi.V1 (
|
||||||
DatumHash,
|
DatumHash,
|
||||||
PubKeyHash,
|
PubKeyHash,
|
||||||
ScriptContext (..),
|
|
||||||
ScriptPurpose (Spending),
|
|
||||||
TxInfo (..),
|
|
||||||
TxOutRef (..),
|
TxOutRef (..),
|
||||||
ValidatorHash,
|
ValidatorHash,
|
||||||
)
|
)
|
||||||
|
|
@ -74,7 +69,7 @@ import Sample.Shared (
|
||||||
)
|
)
|
||||||
import Sample.Shared qualified as Shared
|
import Sample.Shared qualified as Shared
|
||||||
import Test.Specification (SpecificationTree, group, testValidator)
|
import Test.Specification (SpecificationTree, group, testValidator)
|
||||||
import Test.Util (sortValue, updateMap)
|
import Test.Util (CombinableBuilder, mkSpending, sortValue, updateMap)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -249,7 +244,7 @@ mkProposalDatumPair params pid =
|
||||||
getProposalVotes votesTemplate
|
getProposalVotes votesTemplate
|
||||||
|
|
||||||
-- | Create a 'TxInfo' that tries to unlock a stake.
|
-- | Create a 'TxInfo' that tries to unlock a stake.
|
||||||
unlockStake :: Parameters -> TxInfo
|
unlockStake :: forall b. CombinableBuilder b => Parameters -> b
|
||||||
unlockStake ps =
|
unlockStake ps =
|
||||||
let pst = Value.singleton proposalPolicySymbol "" 1
|
let pst = Value.singleton proposalPolicySymbol "" 1
|
||||||
sst = Value.assetClassValue stakeAssetClass 1
|
sst = Value.assetClassValue stakeAssetClass 1
|
||||||
|
|
@ -260,7 +255,6 @@ unlockStake ps =
|
||||||
foldMap
|
foldMap
|
||||||
( \((i, o), idx) ->
|
( \((i, o), idx) ->
|
||||||
mconcat
|
mconcat
|
||||||
@BaseBuilder
|
|
||||||
[ input $
|
[ input $
|
||||||
script proposalValidatorHash
|
script proposalValidatorHash
|
||||||
. withValue pst
|
. withValue pst
|
||||||
|
|
@ -288,7 +282,7 @@ unlockStake ps =
|
||||||
sOutDatum = mkStakeOutputDatum ps
|
sOutDatum = mkStakeOutputDatum ps
|
||||||
|
|
||||||
stakes =
|
stakes =
|
||||||
mconcat @BaseBuilder
|
mconcat
|
||||||
[ input $
|
[ input $
|
||||||
script stakeValidatorHash
|
script stakeValidatorHash
|
||||||
. withValue stakeValue
|
. withValue stakeValue
|
||||||
|
|
@ -301,13 +295,13 @@ unlockStake ps =
|
||||||
]
|
]
|
||||||
|
|
||||||
builder =
|
builder =
|
||||||
mconcat @BaseBuilder
|
mconcat
|
||||||
[ txId "388bc0b897b3dadcd479da4c88291de4113a50b72ddbed001faf7fc03f11bc52"
|
[ txId "388bc0b897b3dadcd479da4c88291de4113a50b72ddbed001faf7fc03f11bc52"
|
||||||
, proposals
|
, proposals
|
||||||
, stakes
|
, stakes
|
||||||
, signedWith defOwner
|
, signedWith defOwner
|
||||||
]
|
]
|
||||||
in buildTxInfoUnsafe builder
|
in builder
|
||||||
|
|
||||||
-- | Reference to the stake UTXO.
|
-- | Reference to the stake UTXO.
|
||||||
stakeRef :: TxOutRef
|
stakeRef :: TxOutRef
|
||||||
|
|
@ -523,7 +517,7 @@ mkAlterStakeParameters nProposals = do
|
||||||
mkTestTree :: String -> Parameters -> Bool -> SpecificationTree
|
mkTestTree :: String -> Parameters -> Bool -> SpecificationTree
|
||||||
mkTestTree name ps isValid = group name [stake, proposal]
|
mkTestTree name ps isValid = group name [stake, proposal]
|
||||||
where
|
where
|
||||||
txInfo = unlockStake ps
|
spend = mkSpending unlockStake ps
|
||||||
|
|
||||||
stake =
|
stake =
|
||||||
testValidator
|
testValidator
|
||||||
|
|
@ -532,7 +526,7 @@ mkTestTree name ps isValid = group name [stake, proposal]
|
||||||
(stakeValidator Shared.stake)
|
(stakeValidator Shared.stake)
|
||||||
(mkStakeInputDatum ps)
|
(mkStakeInputDatum ps)
|
||||||
stakeRedeemer
|
stakeRedeemer
|
||||||
(ScriptContext txInfo (Spending stakeRef))
|
(spend stakeRef)
|
||||||
|
|
||||||
proposal =
|
proposal =
|
||||||
let idx = 0
|
let idx = 0
|
||||||
|
|
@ -544,4 +538,4 @@ mkTestTree name ps isValid = group name [stake, proposal]
|
||||||
(proposalValidator Shared.proposal)
|
(proposalValidator Shared.proposal)
|
||||||
(mkProposalInputDatum ps pid)
|
(mkProposalInputDatum ps pid)
|
||||||
proposalRedeemer
|
proposalRedeemer
|
||||||
(ScriptContext txInfo (Spending ref))
|
(spend ref)
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@ import Agora.Stake.Scripts (stakeValidator)
|
||||||
import Data.Default (Default (def))
|
import Data.Default (Default (def))
|
||||||
import Data.Tagged (Tagged (Tagged), untag)
|
import Data.Tagged (Tagged (Tagged), untag)
|
||||||
import Plutarch.Context (
|
import Plutarch.Context (
|
||||||
BaseBuilder,
|
|
||||||
buildTxInfoUnsafe,
|
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
script,
|
script,
|
||||||
|
|
@ -47,9 +45,6 @@ import Plutarch.Context (
|
||||||
)
|
)
|
||||||
import PlutusLedgerApi.V1 (
|
import PlutusLedgerApi.V1 (
|
||||||
PubKeyHash,
|
PubKeyHash,
|
||||||
ScriptContext (..),
|
|
||||||
ScriptPurpose (Spending),
|
|
||||||
TxInfo,
|
|
||||||
TxOutRef (TxOutRef),
|
TxOutRef (TxOutRef),
|
||||||
)
|
)
|
||||||
import PlutusLedgerApi.V1.Value qualified as Value
|
import PlutusLedgerApi.V1.Value qualified as Value
|
||||||
|
|
@ -71,7 +66,7 @@ import Test.Specification (
|
||||||
testValidator,
|
testValidator,
|
||||||
validatorSucceedsWith,
|
validatorSucceedsWith,
|
||||||
)
|
)
|
||||||
import Test.Util (closedBoundedInterval, sortValue, updateMap)
|
import Test.Util (CombinableBuilder, closedBoundedInterval, mkSpending, sortValue, updateMap)
|
||||||
|
|
||||||
-- | Reference to the proposal UTXO.
|
-- | Reference to the proposal UTXO.
|
||||||
proposalRef :: TxOutRef
|
proposalRef :: TxOutRef
|
||||||
|
|
@ -152,7 +147,7 @@ stakeRedeemer :: StakeRedeemer
|
||||||
stakeRedeemer = PermitVote
|
stakeRedeemer = PermitVote
|
||||||
|
|
||||||
-- | Create a valid transaction that votes on a propsal, given the parameters.
|
-- | Create a valid transaction that votes on a propsal, given the parameters.
|
||||||
vote :: Parameters -> TxInfo
|
vote :: forall b. CombinableBuilder b => Parameters -> b
|
||||||
vote params =
|
vote params =
|
||||||
let pst = Value.singleton proposalPolicySymbol "" 1
|
let pst = Value.singleton proposalPolicySymbol "" 1
|
||||||
sst = Value.assetClassValue stakeAssetClass 1
|
sst = Value.assetClassValue stakeAssetClass 1
|
||||||
|
|
@ -203,7 +198,6 @@ vote params =
|
||||||
<> Value.assetClassValue (untag stake.gtClassRef) params.voteCount
|
<> Value.assetClassValue (untag stake.gtClassRef) params.voteCount
|
||||||
<> minAda
|
<> minAda
|
||||||
|
|
||||||
builder :: BaseBuilder
|
|
||||||
builder =
|
builder =
|
||||||
mconcat
|
mconcat
|
||||||
[ txId "827598fb2d69a896bbd9e645bb14c307df907f422b39eecbe4d6329bc30b428c"
|
[ txId "827598fb2d69a896bbd9e645bb14c307df907f422b39eecbe4d6329bc30b428c"
|
||||||
|
|
@ -228,7 +222,7 @@ vote params =
|
||||||
. withValue stakeValue
|
. withValue stakeValue
|
||||||
. withDatum stakeOutputDatum
|
. withDatum stakeOutputDatum
|
||||||
]
|
]
|
||||||
in buildTxInfoUnsafe builder
|
in builder
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -248,7 +242,7 @@ validVoteParameters =
|
||||||
mkTestTree :: String -> Parameters -> Bool -> SpecificationTree
|
mkTestTree :: String -> Parameters -> Bool -> SpecificationTree
|
||||||
mkTestTree name ps isValid = group name [proposal, stake]
|
mkTestTree name ps isValid = group name [proposal, stake]
|
||||||
where
|
where
|
||||||
txInfo = vote ps
|
spend = mkSpending vote ps
|
||||||
|
|
||||||
proposal =
|
proposal =
|
||||||
testValidator
|
testValidator
|
||||||
|
|
@ -257,10 +251,7 @@ mkTestTree name ps isValid = group name [proposal, stake]
|
||||||
(proposalValidator Shared.proposal)
|
(proposalValidator Shared.proposal)
|
||||||
proposalInputDatum
|
proposalInputDatum
|
||||||
(mkProposalRedeemer ps)
|
(mkProposalRedeemer ps)
|
||||||
( ScriptContext
|
(spend proposalRef)
|
||||||
txInfo
|
|
||||||
(Spending proposalRef)
|
|
||||||
)
|
|
||||||
|
|
||||||
stake =
|
stake =
|
||||||
let stakeInputDatum = mkStakeInputDatum ps
|
let stakeInputDatum = mkStakeInputDatum ps
|
||||||
|
|
@ -269,7 +260,4 @@ mkTestTree name ps isValid = group name [proposal, stake]
|
||||||
(stakeValidator Shared.stake)
|
(stakeValidator Shared.stake)
|
||||||
stakeInputDatum
|
stakeInputDatum
|
||||||
stakeRedeemer
|
stakeRedeemer
|
||||||
( ScriptContext
|
(spend stakeRef)
|
||||||
txInfo
|
|
||||||
(Spending stakeRef)
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,9 @@ import Plutarch.Context (
|
||||||
signedWith,
|
signedWith,
|
||||||
txId,
|
txId,
|
||||||
withDatum,
|
withDatum,
|
||||||
withSpending,
|
withMinting,
|
||||||
withTxId,
|
withOutRef,
|
||||||
|
withSpendingOutRef,
|
||||||
withValue,
|
withValue,
|
||||||
)
|
)
|
||||||
import PlutusLedgerApi.V1 (
|
import PlutusLedgerApi.V1 (
|
||||||
|
|
@ -53,6 +54,7 @@ import PlutusLedgerApi.V1 (
|
||||||
TxInfo (txInfoData, txInfoSignatories),
|
TxInfo (txInfoData, txInfoSignatories),
|
||||||
ValidatorHash (ValidatorHash),
|
ValidatorHash (ValidatorHash),
|
||||||
)
|
)
|
||||||
|
import PlutusLedgerApi.V1.Contexts (TxOutRef (..))
|
||||||
import PlutusLedgerApi.V1.Value qualified as Value (
|
import PlutusLedgerApi.V1.Value qualified as Value (
|
||||||
assetClassValue,
|
assetClassValue,
|
||||||
singleton,
|
singleton,
|
||||||
|
|
@ -86,6 +88,7 @@ stakeCreation =
|
||||||
script stakeValidatorHash
|
script stakeValidatorHash
|
||||||
. withValue (st <> Value.singleton "da8c30857834c6ae7203935b89278c532b3995245295456f993e1d24" "LQ" 424242424242)
|
. withValue (st <> Value.singleton "da8c30857834c6ae7203935b89278c532b3995245295456f993e1d24" "LQ" 424242424242)
|
||||||
. withDatum datum
|
. withDatum datum
|
||||||
|
, withMinting stakeSymbol
|
||||||
]
|
]
|
||||||
in buildMintingUnsafe builder
|
in buildMintingUnsafe builder
|
||||||
|
|
||||||
|
|
@ -130,6 +133,9 @@ stakeDepositWithdraw config =
|
||||||
stakeAfter :: StakeDatum
|
stakeAfter :: StakeDatum
|
||||||
stakeAfter = stakeBefore {stakedAmount = stakeBefore.stakedAmount + config.delta}
|
stakeAfter = stakeBefore {stakedAmount = stakeBefore.stakedAmount + config.delta}
|
||||||
|
|
||||||
|
stakeRef :: TxOutRef
|
||||||
|
stakeRef = TxOutRef "0ffef57e30cc604342c738e31e0451593837b313e7bfb94b0922b142782f98e6" 1
|
||||||
|
|
||||||
builder :: SpendingBuilder
|
builder :: SpendingBuilder
|
||||||
builder =
|
builder =
|
||||||
mconcat
|
mconcat
|
||||||
|
|
@ -140,14 +146,11 @@ stakeDepositWithdraw config =
|
||||||
script stakeValidatorHash
|
script stakeValidatorHash
|
||||||
. withValue (st <> Value.assetClassValue (untag stake.gtClassRef) (untag stakeBefore.stakedAmount))
|
. withValue (st <> Value.assetClassValue (untag stake.gtClassRef) (untag stakeBefore.stakedAmount))
|
||||||
. withDatum stakeAfter
|
. withDatum stakeAfter
|
||||||
. withTxId "0b2086cbf8b6900f8cb65e012de4516cb66b5cb08a9aaba12a8b88be"
|
. withOutRef stakeRef
|
||||||
, output $
|
, output $
|
||||||
script stakeValidatorHash
|
script stakeValidatorHash
|
||||||
. withValue (st <> Value.assetClassValue (untag stake.gtClassRef) (untag stakeAfter.stakedAmount))
|
. withValue (st <> Value.assetClassValue (untag stake.gtClassRef) (untag stakeAfter.stakedAmount))
|
||||||
. withDatum stakeAfter
|
. withDatum stakeAfter
|
||||||
, withSpending $
|
, withSpendingOutRef stakeRef
|
||||||
script stakeValidatorHash
|
|
||||||
. withValue (st <> Value.assetClassValue (untag stake.gtClassRef) (untag stakeBefore.stakedAmount))
|
|
||||||
. withDatum stakeAfter
|
|
||||||
]
|
]
|
||||||
in buildSpendingUnsafe builder
|
in buildSpendingUnsafe builder
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import Plutarch.Context (
|
||||||
script,
|
script,
|
||||||
signedWith,
|
signedWith,
|
||||||
txId,
|
txId,
|
||||||
|
withMinting,
|
||||||
withTxId,
|
withTxId,
|
||||||
withValue,
|
withValue,
|
||||||
)
|
)
|
||||||
|
|
@ -67,6 +68,7 @@ baseCtxBuilder =
|
||||||
, mint (Value.singleton gatCs gatTn (-1))
|
, mint (Value.singleton gatCs gatTn (-1))
|
||||||
, input treasury
|
, input treasury
|
||||||
, output treasury
|
, output treasury
|
||||||
|
, withMinting gatCs
|
||||||
]
|
]
|
||||||
|
|
||||||
{- | A `ScriptContext` that should be compatible with treasury
|
{- | A `ScriptContext` that should be compatible with treasury
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ module Test.Util (
|
||||||
validatorHashes,
|
validatorHashes,
|
||||||
groupsOfN,
|
groupsOfN,
|
||||||
withOptional,
|
withOptional,
|
||||||
|
mkSpending,
|
||||||
|
mkMinting,
|
||||||
|
CombinableBuilder,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -32,9 +35,26 @@ import Data.ByteString qualified as BS
|
||||||
import Data.ByteString.Char8 qualified as C
|
import Data.ByteString.Char8 qualified as C
|
||||||
import Data.ByteString.Lazy qualified as ByteString.Lazy
|
import Data.ByteString.Lazy qualified as ByteString.Lazy
|
||||||
import Data.List (sortOn)
|
import Data.List (sortOn)
|
||||||
import Plutarch.Context (UTXO)
|
import Plutarch.Context (
|
||||||
|
Builder,
|
||||||
|
UTXO,
|
||||||
|
buildMintingUnsafe,
|
||||||
|
buildSpendingUnsafe,
|
||||||
|
withMinting,
|
||||||
|
withSpendingOutRef,
|
||||||
|
)
|
||||||
import Plutarch.Crypto (pblake2b_256)
|
import Plutarch.Crypto (pblake2b_256)
|
||||||
import PlutusLedgerApi.V1 (Credential (PubKeyCredential, ScriptCredential), PubKeyHash (..), ValidatorHash (ValidatorHash))
|
import PlutusLedgerApi.V1 (
|
||||||
|
Credential (
|
||||||
|
PubKeyCredential,
|
||||||
|
ScriptCredential
|
||||||
|
),
|
||||||
|
CurrencySymbol,
|
||||||
|
PubKeyHash (..),
|
||||||
|
ScriptContext,
|
||||||
|
TxOutRef,
|
||||||
|
ValidatorHash (ValidatorHash),
|
||||||
|
)
|
||||||
import PlutusLedgerApi.V1.Interval qualified as PlutusTx
|
import PlutusLedgerApi.V1.Interval qualified as PlutusTx
|
||||||
import PlutusLedgerApi.V1.Scripts (Datum (Datum), DatumHash (DatumHash))
|
import PlutusLedgerApi.V1.Scripts (Datum (Datum), DatumHash (DatumHash))
|
||||||
import PlutusLedgerApi.V1.Value (Value (..))
|
import PlutusLedgerApi.V1.Value (Value (..))
|
||||||
|
|
@ -168,3 +188,25 @@ withOptional ::
|
||||||
UTXO
|
UTXO
|
||||||
withOptional f (Just b) = f b
|
withOptional f (Just b) = f b
|
||||||
withOptional _ _ = id
|
withOptional _ _ = id
|
||||||
|
|
||||||
|
mkSpending ::
|
||||||
|
forall ps.
|
||||||
|
(forall b. (Monoid b, Builder b) => ps -> b) ->
|
||||||
|
ps ->
|
||||||
|
TxOutRef ->
|
||||||
|
ScriptContext
|
||||||
|
mkSpending mkBuilder ps oref =
|
||||||
|
buildSpendingUnsafe $
|
||||||
|
mkBuilder ps <> withSpendingOutRef oref
|
||||||
|
|
||||||
|
mkMinting ::
|
||||||
|
forall ps.
|
||||||
|
(forall b. (Monoid b, Builder b) => ps -> b) ->
|
||||||
|
ps ->
|
||||||
|
CurrencySymbol ->
|
||||||
|
ScriptContext
|
||||||
|
mkMinting mkBuilder ps cs =
|
||||||
|
buildMintingUnsafe $
|
||||||
|
mkBuilder ps <> withMinting cs
|
||||||
|
|
||||||
|
type CombinableBuilder b = (Monoid b, Builder b)
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ Agora/Effects/Treasury Withdrawal Effect/effect/Mixed Assets,455817227,1103968,3
|
||||||
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass,93089688,256879,8290
|
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/governor validator should pass,93089688,256879,8290
|
||||||
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/effect validator should pass,112671240,312571,3751
|
Agora/Effects/Governor Mutation Effect/validator/valid new governor datum/effect validator should pass,112671240,312571,3751
|
||||||
Agora/Stake/policy/stakeCreation,51008580,149029,2522
|
Agora/Stake/policy/stakeCreation,51008580,149029,2522
|
||||||
Agora/Stake/validator/stakeDepositWithdraw deposit,183506412,498838,4745
|
Agora/Stake/validator/stakeDepositWithdraw deposit,183506412,498838,4753
|
||||||
Agora/Stake/validator/stakeDepositWithdraw withdraw,183506412,498838,4733
|
Agora/Stake/validator/stakeDepositWithdraw withdraw,183506412,498838,4741
|
||||||
Agora/Proposal/policy (proposal creation)/legal/proposal,33689644,100286,2005
|
Agora/Proposal/policy (proposal creation)/legal/proposal,33689644,100286,2005
|
||||||
Agora/Proposal/policy (proposal creation)/legal/governor,324511293,861435,8769
|
Agora/Proposal/policy (proposal creation)/legal/governor,324511293,861435,8769
|
||||||
Agora/Proposal/policy (proposal creation)/legal/stake,153960499,403133,5407
|
Agora/Proposal/policy (proposal creation)/legal/stake,153960499,403133,5407
|
||||||
|
|
|
||||||
|
Loading…
Add table
Add a link
Reference in a new issue