fix tests
This commit is contained in:
parent
131fab271f
commit
1f71f30e52
12 changed files with 554 additions and 804 deletions
|
|
@ -74,11 +74,17 @@ atAssetClass = assetClass authorityTokenSymbol tokenName
|
|||
|
||||
-- | The mock reference of the governor state UTXO.
|
||||
govRef :: TxOutRef
|
||||
govRef = TxOutRef "1475e1ee22330dfc55430980e5a6b100ec9d9249bb4b462256a79559" 1
|
||||
govRef =
|
||||
TxOutRef
|
||||
"d63fe09e6ac6e55dea82291149085d0a9b901df65087b83965188ee92fb25aef"
|
||||
1
|
||||
|
||||
-- | The mock reference of the effect UTXO.
|
||||
effectRef :: TxOutRef
|
||||
effectRef = TxOutRef "a302d327d8e5553d50b9d017475369753f723d7e999ac1b68da8ad52" 1
|
||||
effectRef =
|
||||
TxOutRef
|
||||
"3ca6864670aae61a9f3e63064284cec00bd983d77cf4e1ab1e26bef34cafb0a9"
|
||||
1
|
||||
|
||||
-- | The input effect datum in 'mkEffectTransaction'.
|
||||
mkEffectDatum :: GovernorDatum -> MutateGovernorDatum
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ module Sample.Proposal.Advance (
|
|||
mkFromFinishedBundles,
|
||||
mkInsufficientCosignsBundle,
|
||||
mkToNextStateTooLateBundles,
|
||||
mkInvalidOutputStakeBundles,
|
||||
mkMintGATsForWrongEffectsBundle,
|
||||
mkNoGATMintedBundle,
|
||||
mkGATsWithWrongDatumBundle,
|
||||
|
|
@ -46,6 +45,7 @@ import Agora.Governor (
|
|||
import Agora.Proposal (
|
||||
ProposalDatum (..),
|
||||
ProposalEffectGroup,
|
||||
ProposalEffectMetadata (ProposalEffectMetadata),
|
||||
ProposalId (ProposalId),
|
||||
ProposalRedeemer (AdvanceProposal),
|
||||
ProposalStatus (..),
|
||||
|
|
@ -66,7 +66,6 @@ import Agora.Proposal.Time (
|
|||
import Agora.Scripts (AgoraScripts (..))
|
||||
import Agora.Stake (
|
||||
StakeDatum (..),
|
||||
StakeRedeemer (WitnessStake),
|
||||
)
|
||||
import Agora.Utils (scriptHashToTokenName)
|
||||
import Control.Applicative (liftA2)
|
||||
|
|
@ -75,15 +74,17 @@ import Data.Default (def)
|
|||
import Data.List (singleton, sort)
|
||||
import Data.Map.Strict qualified as StrictMap
|
||||
import Data.Maybe (fromJust)
|
||||
import Data.Tagged (Tagged (..), untag)
|
||||
import Data.Tagged (untag)
|
||||
import Plutarch.Context (
|
||||
input,
|
||||
mint,
|
||||
output,
|
||||
referenceInput,
|
||||
script,
|
||||
signedWith,
|
||||
timeRange,
|
||||
withDatum,
|
||||
withInlineDatum,
|
||||
withRef,
|
||||
withValue,
|
||||
)
|
||||
|
|
@ -217,7 +218,6 @@ data StakeParameters = StakeParameters
|
|||
{ numStake :: NumStake
|
||||
, perStakeGTs :: Integer
|
||||
, transactionSignedByOwners :: Bool
|
||||
, invalidStakeOutputDatum :: Bool
|
||||
}
|
||||
|
||||
-- | Represent the number of stakes or the number of the cosigners.
|
||||
|
|
@ -355,7 +355,7 @@ mkStakeInputDatums :: StakeParameters -> [StakeDatum]
|
|||
mkStakeInputDatums ps =
|
||||
let template =
|
||||
StakeDatum
|
||||
{ stakedAmount = Tagged ps.perStakeGTs
|
||||
{ stakedAmount = fromInteger ps.perStakeGTs
|
||||
, owner = PubKeyCredential ""
|
||||
, delegatedTo = Nothing
|
||||
, lockedBy = []
|
||||
|
|
@ -363,24 +363,6 @@ mkStakeInputDatums ps =
|
|||
in (\owner -> template {owner = owner})
|
||||
<$> mkStakeOwners ps.numStake
|
||||
|
||||
-- | Create the output stake datums given the parameters.
|
||||
mkStakeOutputDatums :: StakeParameters -> [StakeDatum]
|
||||
mkStakeOutputDatums ps =
|
||||
let inputDatums = mkStakeInputDatums ps
|
||||
outputStakedAmount =
|
||||
Tagged $
|
||||
if ps.invalidStakeOutputDatum
|
||||
then ps.perStakeGTs * 10
|
||||
else ps.perStakeGTs
|
||||
modify inp = inp {stakedAmount = outputStakedAmount}
|
||||
in modify <$> inputDatums
|
||||
|
||||
{- | Get the input stake datum given the index. The range of the index is
|
||||
@[0, 'StakeParameters.numStake - 1']@
|
||||
-}
|
||||
getStakeInputDatumAt :: StakeParameters -> Index -> StakeDatum
|
||||
getStakeInputDatumAt ps = (!!) (mkStakeInputDatums ps)
|
||||
|
||||
-- | Create the reference to a particular stake UTXO.
|
||||
mkStakeRef :: Index -> TxOutRef
|
||||
mkStakeRef = TxOutRef stakeTxRef . (+ 3) . fromIntegral
|
||||
|
|
@ -397,39 +379,26 @@ mkStakeBuilder ps =
|
|||
<> Value.assetClassValue
|
||||
(untag governor.gtClassRef)
|
||||
ps.perStakeGTs
|
||||
perStake idx i o =
|
||||
perStake idx i =
|
||||
let withSig =
|
||||
case (i.owner, ps.transactionSignedByOwners) of
|
||||
(PubKeyCredential owner, True) -> signedWith owner
|
||||
_ -> mempty
|
||||
in mconcat
|
||||
[ withSig
|
||||
, input $
|
||||
, referenceInput $
|
||||
mconcat
|
||||
[ script stakeValidatorHash
|
||||
, withRef (mkStakeRef idx)
|
||||
, withValue perStakeValue
|
||||
, withDatum i
|
||||
]
|
||||
, output $
|
||||
mconcat
|
||||
[ script stakeValidatorHash
|
||||
, withValue perStakeValue
|
||||
, withDatum o
|
||||
, withInlineDatum i
|
||||
]
|
||||
]
|
||||
in mconcat $
|
||||
zipWith3
|
||||
zipWith
|
||||
perStake
|
||||
[0 :: Index ..]
|
||||
(mkStakeInputDatums ps)
|
||||
(mkStakeOutputDatums ps)
|
||||
|
||||
{- | The proposal redeemer used to spend the stake UTXO, which is always
|
||||
'WitnessStake' in this case.
|
||||
-}
|
||||
stakeRedeemer :: StakeRedeemer
|
||||
stakeRedeemer = WitnessStake
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -553,7 +522,7 @@ mkTestTree ::
|
|||
Validity ->
|
||||
SpecificationTree
|
||||
mkTestTree name pb val =
|
||||
group name $ mconcat [proposal, stake, governor, authority]
|
||||
group name $ mconcat [proposal, governor, authority]
|
||||
where
|
||||
spend = mkSpending advance pb
|
||||
|
||||
|
|
@ -567,22 +536,6 @@ mkTestTree name pb val =
|
|||
proposalInputDatum
|
||||
proposalRedeemer
|
||||
(spend proposalRef)
|
||||
|
||||
stake =
|
||||
if pb.stakeParameters.numStake == 0
|
||||
then mempty
|
||||
else
|
||||
let idx = 0
|
||||
in singleton $
|
||||
testValidator
|
||||
val.forStakeValidator
|
||||
"stake"
|
||||
agoraScripts.compiledStakeValidator
|
||||
(getStakeInputDatumAt pb.stakeParameters idx)
|
||||
stakeRedeemer
|
||||
( spend (mkStakeRef idx)
|
||||
)
|
||||
|
||||
governor =
|
||||
maybe [] singleton $
|
||||
testValidator
|
||||
|
|
@ -747,7 +700,7 @@ mkMockEffects useAuthScript n = effects
|
|||
|
||||
datums = repeat dummyDatumHash
|
||||
|
||||
effectMetadata = zip datums authScripts
|
||||
effectMetadata = zipWith ProposalEffectMetadata datums authScripts
|
||||
effectScripts = validatorHashes
|
||||
|
||||
effects =
|
||||
|
|
@ -822,7 +775,6 @@ mkValidToNextStateBundle nCosigners nEffects authScript from =
|
|||
compPerStakeGTsForDraft $
|
||||
fromIntegral nCosigners
|
||||
, transactionSignedByOwners = False
|
||||
, invalidStakeOutputDatum = False
|
||||
}
|
||||
, governorParameters = Nothing
|
||||
, authorityTokenParameters = []
|
||||
|
|
@ -857,7 +809,7 @@ mkValidToNextStateBundle nCosigners nEffects authScript from =
|
|||
let aut =
|
||||
StrictMap.elems $
|
||||
StrictMap.mapWithKey
|
||||
( \vh (_, authScript) ->
|
||||
( \vh (ProposalEffectMetadata _ authScript) ->
|
||||
AuthorityTokenParameters
|
||||
{ mintGATsFor = vh
|
||||
, carryDatum = Just dummyDatum
|
||||
|
|
@ -920,7 +872,6 @@ mkValidToFailedStateBundles nCosigners nEffects =
|
|||
compPerStakeGTsForDraft $
|
||||
fromIntegral nCosigners
|
||||
, transactionSignedByOwners = False
|
||||
, invalidStakeOutputDatum = False
|
||||
}
|
||||
, governorParameters = Nothing
|
||||
, authorityTokenParameters = []
|
||||
|
|
@ -965,22 +916,6 @@ mkToNextStateTooLateBundles nCosigners nEffects =
|
|||
{ transactionTimeRange = mkTooLateTimeRange from
|
||||
}
|
||||
|
||||
mkInvalidOutputStakeBundles :: Word -> Word -> [ParameterBundle]
|
||||
mkInvalidOutputStakeBundles nCosigners nEffects =
|
||||
liftA2
|
||||
mkBundle
|
||||
[True, False]
|
||||
[Draft]
|
||||
where
|
||||
mkBundle authScript from =
|
||||
let template = mkValidToNextStateBundle nCosigners nEffects authScript from
|
||||
in template
|
||||
{ stakeParameters =
|
||||
template.stakeParameters
|
||||
{ invalidStakeOutputDatum = True
|
||||
}
|
||||
}
|
||||
|
||||
mkUnexpectedOutputStakeBundles :: Word -> Word -> [ParameterBundle]
|
||||
mkUnexpectedOutputStakeBundles nCosigners nEffects =
|
||||
liftA2
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ module Sample.Proposal.Cosign (
|
|||
validCosignNParameters,
|
||||
duplicateCosignersParameters,
|
||||
statusNotDraftCosignNParameters,
|
||||
invalidStakeOutputParameters,
|
||||
mkTestTree,
|
||||
) where
|
||||
|
||||
|
|
@ -31,25 +30,26 @@ import Agora.SafeMoney (GTTag)
|
|||
import Agora.Scripts (AgoraScripts (..))
|
||||
import Agora.Stake (
|
||||
StakeDatum (StakeDatum, owner),
|
||||
StakeRedeemer (WitnessStake),
|
||||
stakedAmount,
|
||||
)
|
||||
import Data.Coerce (coerce)
|
||||
import Data.Default (def)
|
||||
import Data.List (sort)
|
||||
import Data.Map.Strict qualified as StrictMap
|
||||
import Data.Tagged (Tagged, untag)
|
||||
import Data.Tagged (untag)
|
||||
import Plutarch.Context (
|
||||
input,
|
||||
output,
|
||||
referenceInput,
|
||||
script,
|
||||
signedWith,
|
||||
timeRange,
|
||||
txId,
|
||||
withDatum,
|
||||
withInlineDatum,
|
||||
withRef,
|
||||
withValue,
|
||||
)
|
||||
import Plutarch.SafeMoney (Discrete)
|
||||
import PlutusLedgerApi.V1.Value qualified as Value
|
||||
import PlutusLedgerApi.V2 (
|
||||
Credential (PubKeyCredential),
|
||||
|
|
@ -61,6 +61,7 @@ import PlutusLedgerApi.V2 (
|
|||
import Sample.Proposal.Shared (proposalTxRef, stakeTxRef)
|
||||
import Sample.Shared (
|
||||
agoraScripts,
|
||||
fromDiscrete,
|
||||
governor,
|
||||
minAda,
|
||||
proposalPolicySymbol,
|
||||
|
|
@ -71,7 +72,6 @@ import Sample.Shared (
|
|||
)
|
||||
import Test.Specification (
|
||||
SpecificationTree,
|
||||
group,
|
||||
testValidator,
|
||||
)
|
||||
import Test.Util (CombinableBuilder, closedBoundedInterval, mkSpending, pubKeyHashes, sortValue)
|
||||
|
|
@ -82,9 +82,6 @@ data Parameters = Parameters
|
|||
-- ^ New cosigners to be added, and the owners of the generated stakes.
|
||||
, proposalStatus :: ProposalStatus
|
||||
-- ^ Current state of the proposal.
|
||||
, alterOutputStakes :: Bool
|
||||
-- ^ Whether to generate invalid stake outputs.
|
||||
-- In particular, the 'stakedAmount' of all the stake datums will be set to zero.
|
||||
}
|
||||
|
||||
-- | Owner of the creator stake, doesn't really matter in this case.
|
||||
|
|
@ -92,7 +89,7 @@ proposalCreator :: PubKeyHash
|
|||
proposalCreator = signer
|
||||
|
||||
-- | The amount of GTs every generated stake has, doesn't really matter in this case.
|
||||
perStakedGTs :: Tagged GTTag Integer
|
||||
perStakedGTs :: Discrete GTTag
|
||||
perStakedGTs = 5
|
||||
|
||||
{- | Create input proposal datum given the parameters.
|
||||
|
|
@ -151,34 +148,24 @@ cosign ps = builder
|
|||
minAda
|
||||
<> Value.assetClassValue
|
||||
(untag governor.gtClassRef)
|
||||
(untag perStakedGTs)
|
||||
(fromDiscrete perStakedGTs)
|
||||
<> sst
|
||||
|
||||
stakeBuilder =
|
||||
foldMap
|
||||
( \(stakeDatum, refIdx) ->
|
||||
let stakeOutputDatum =
|
||||
if ps.alterOutputStakes
|
||||
then stakeDatum {stakedAmount = 0}
|
||||
else stakeDatum
|
||||
in mconcat
|
||||
[ input $
|
||||
mconcat
|
||||
[ script stakeValidatorHash
|
||||
, withValue stakeValue
|
||||
, withDatum stakeDatum
|
||||
, withRef (mkStakeRef refIdx)
|
||||
]
|
||||
, output $
|
||||
mconcat
|
||||
[ script stakeValidatorHash
|
||||
, withValue stakeValue
|
||||
, withDatum stakeOutputDatum
|
||||
]
|
||||
, case stakeDatum.owner of
|
||||
PubKeyCredential k -> signedWith k
|
||||
_ -> mempty
|
||||
]
|
||||
mconcat
|
||||
[ referenceInput $
|
||||
mconcat
|
||||
[ script stakeValidatorHash
|
||||
, withValue stakeValue
|
||||
, withInlineDatum stakeDatum
|
||||
, withRef (mkStakeRef refIdx)
|
||||
]
|
||||
, case stakeDatum.owner of
|
||||
PubKeyCredential k -> signedWith k
|
||||
_ -> mempty
|
||||
]
|
||||
)
|
||||
$ zip
|
||||
stakeInputDatums
|
||||
|
|
@ -246,10 +233,6 @@ mkStakeRef idx =
|
|||
mkProposalRedeemer :: Parameters -> ProposalRedeemer
|
||||
mkProposalRedeemer = Cosign . sort . newCosigners
|
||||
|
||||
-- | Stake redeemer for cosuming all the stakes generated in the module.
|
||||
stakeRedeemer :: StakeRedeemer
|
||||
stakeRedeemer = WitnessStake
|
||||
|
||||
---
|
||||
|
||||
-- | Create a valid parameters that cosign the proposal with a given number of cosigners.
|
||||
|
|
@ -259,7 +242,6 @@ validCosignNParameters n
|
|||
Parameters
|
||||
{ newCosigners = take n (fmap PubKeyCredential pubKeyHashes)
|
||||
, proposalStatus = Draft
|
||||
, alterOutputStakes = False
|
||||
}
|
||||
| otherwise = error "Number of cosigners should be positive"
|
||||
|
||||
|
|
@ -273,7 +255,6 @@ duplicateCosignersParameters =
|
|||
Parameters
|
||||
{ newCosigners = [PubKeyCredential proposalCreator]
|
||||
, proposalStatus = Draft
|
||||
, alterOutputStakes = False
|
||||
}
|
||||
|
||||
---
|
||||
|
|
@ -288,24 +269,12 @@ statusNotDraftCosignNParameters n =
|
|||
Parameters
|
||||
{ newCosigners = take n (fmap PubKeyCredential pubKeyHashes)
|
||||
, proposalStatus = st
|
||||
, alterOutputStakes = False
|
||||
}
|
||||
)
|
||||
[VotingReady, Locked, Finished]
|
||||
|
||||
---
|
||||
|
||||
{- | Parameters thet change the output stake datums.
|
||||
Invalid for both proposal validator and stake validator.
|
||||
-}
|
||||
invalidStakeOutputParameters :: Parameters
|
||||
invalidStakeOutputParameters =
|
||||
(validCosignNParameters 2)
|
||||
{ alterOutputStakes = True
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
-- | Create a test tree given the parameters. Both the proposal validator and stake validator will be run.
|
||||
mkTestTree ::
|
||||
-- | The name of the test group.
|
||||
|
|
@ -314,7 +283,7 @@ mkTestTree ::
|
|||
-- | Are the parameters valid for the proposal validator?
|
||||
Bool ->
|
||||
SpecificationTree
|
||||
mkTestTree name ps isValid = group name [proposal, stake]
|
||||
mkTestTree name ps isValid = proposal
|
||||
where
|
||||
spend = mkSpending cosign ps
|
||||
|
||||
|
|
@ -322,20 +291,8 @@ mkTestTree name ps isValid = group name [proposal, stake]
|
|||
let proposalInputDatum = mkProposalInputDatum ps
|
||||
in testValidator
|
||||
isValid
|
||||
"proposal"
|
||||
(name <> ": proposal")
|
||||
agoraScripts.compiledProposalValidator
|
||||
proposalInputDatum
|
||||
(mkProposalRedeemer ps)
|
||||
(spend proposalRef)
|
||||
|
||||
stake =
|
||||
let idx = 0
|
||||
stakeInputDatum = mkStakeInputDatums ps !! idx
|
||||
isValid = not ps.alterOutputStakes
|
||||
in testValidator
|
||||
isValid
|
||||
"stake"
|
||||
agoraScripts.compiledStakeValidator
|
||||
stakeInputDatum
|
||||
stakeRedeemer
|
||||
(spend $ mkStakeRef idx)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import Agora.Proposal.Time (
|
|||
),
|
||||
ProposalStartingTime (..),
|
||||
)
|
||||
import Agora.SafeMoney (GTTag)
|
||||
import Agora.Scripts (AgoraScripts (..))
|
||||
import Agora.Stake (
|
||||
ProposalLock (..),
|
||||
|
|
@ -47,7 +48,7 @@ import Agora.Stake (
|
|||
import Data.Coerce (coerce)
|
||||
import Data.Default (Default (def))
|
||||
import Data.Map.Strict qualified as StrictMap
|
||||
import Data.Tagged (Tagged, untag)
|
||||
import Data.Tagged (untag)
|
||||
import Plutarch.Context (
|
||||
input,
|
||||
mint,
|
||||
|
|
@ -60,6 +61,7 @@ import Plutarch.Context (
|
|||
withRef,
|
||||
withValue,
|
||||
)
|
||||
import Plutarch.SafeMoney (Discrete)
|
||||
import PlutusLedgerApi.V1.Value qualified as Value
|
||||
import PlutusLedgerApi.V2 (
|
||||
Credential (PubKeyCredential),
|
||||
|
|
@ -71,6 +73,7 @@ import PlutusLedgerApi.V2 (
|
|||
import Sample.Proposal.Shared (stakeTxRef)
|
||||
import Sample.Shared (
|
||||
agoraScripts,
|
||||
fromDiscrete,
|
||||
govAssetClass,
|
||||
govValidatorHash,
|
||||
governor,
|
||||
|
|
@ -123,7 +126,7 @@ thisProposalId :: ProposalId
|
|||
thisProposalId = ProposalId 25
|
||||
|
||||
-- | The arbitrary staked amount. Doesn;t really matter in this case.
|
||||
stakedGTs :: Tagged _ Integer
|
||||
stakedGTs :: Discrete GTTag
|
||||
stakedGTs = 5
|
||||
|
||||
-- | The owner of the stake.
|
||||
|
|
@ -289,7 +292,7 @@ createProposal ps = builder
|
|||
sortValue $
|
||||
sortValue $
|
||||
sst
|
||||
<> Value.assetClassValue (untag governor.gtClassRef) (untag stakedGTs)
|
||||
<> Value.assetClassValue (untag governor.gtClassRef) (fromDiscrete stakedGTs)
|
||||
<> minAda
|
||||
proposalValue = sortValue $ pst <> minAda
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import Agora.Proposal (
|
|||
ResultTag (..),
|
||||
)
|
||||
import Agora.Proposal.Time (ProposalStartingTime (ProposalStartingTime))
|
||||
import Agora.SafeMoney (GTTag)
|
||||
import Agora.Scripts (AgoraScripts (..))
|
||||
import Agora.Stake (
|
||||
ProposalLock (..),
|
||||
|
|
@ -44,7 +45,7 @@ import Agora.Stake (
|
|||
)
|
||||
import Data.Default.Class (Default (def))
|
||||
import Data.Map.Strict qualified as StrictMap
|
||||
import Data.Tagged (Tagged (..), untag)
|
||||
import Data.Tagged (untag)
|
||||
import Plutarch.Context (
|
||||
input,
|
||||
output,
|
||||
|
|
@ -52,9 +53,11 @@ import Plutarch.Context (
|
|||
signedWith,
|
||||
txId,
|
||||
withDatum,
|
||||
withRedeemer,
|
||||
withRef,
|
||||
withValue,
|
||||
)
|
||||
import Plutarch.SafeMoney (Discrete)
|
||||
import PlutusLedgerApi.V1.Value qualified as Value
|
||||
import PlutusLedgerApi.V2 (
|
||||
Credential (PubKeyCredential),
|
||||
|
|
@ -64,6 +67,7 @@ import PlutusLedgerApi.V2 (
|
|||
import Sample.Proposal.Shared (stakeTxRef)
|
||||
import Sample.Shared (
|
||||
agoraScripts,
|
||||
fromDiscrete,
|
||||
governor,
|
||||
minAda,
|
||||
proposalPolicySymbol,
|
||||
|
|
@ -99,13 +103,13 @@ defVoteFor :: ResultTag
|
|||
defVoteFor = ResultTag 0
|
||||
|
||||
-- | The default number of GTs the stake will have.
|
||||
defStakedGTs :: Tagged _ Integer
|
||||
defStakedGTs :: Discrete GTTag
|
||||
defStakedGTs = 100000
|
||||
|
||||
{- | If 'Parameters.alterOutputStake' is set to true, the
|
||||
'StakeDatum.stakedAmount' will be set to this.
|
||||
-}
|
||||
alteredStakedGTs :: Tagged _ Integer
|
||||
alteredStakedGTs :: Discrete GTTag
|
||||
alteredStakedGTs = 100
|
||||
|
||||
-- | Default owner of the stakes.
|
||||
|
|
@ -212,7 +216,7 @@ mkProposalDatumPair ::
|
|||
ProposalId ->
|
||||
(ProposalDatum, ProposalDatum)
|
||||
mkProposalDatumPair params pid =
|
||||
let inputVotes = mkInputVotes params.stakeRole $ untag defStakedGTs
|
||||
let inputVotes = mkInputVotes params.stakeRole $ fromDiscrete defStakedGTs
|
||||
|
||||
input =
|
||||
ProposalDatum
|
||||
|
|
@ -266,6 +270,7 @@ unlockStake ps =
|
|||
, withValue pst
|
||||
, withDatum i
|
||||
, withRef (mkProposalRef idx)
|
||||
, withRedeemer proposalRedeemer
|
||||
]
|
||||
, output $
|
||||
mconcat
|
||||
|
|
@ -282,7 +287,7 @@ unlockStake ps =
|
|||
mconcat
|
||||
[ Value.assetClassValue
|
||||
(untag governor.gtClassRef)
|
||||
(untag defStakedGTs)
|
||||
(fromDiscrete defStakedGTs)
|
||||
, sst
|
||||
, minAda
|
||||
]
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import Agora.Stake (
|
|||
)
|
||||
import Data.Default (Default (def))
|
||||
import Data.Map.Strict qualified as StrictMap
|
||||
import Data.Tagged (Tagged (Tagged), untag)
|
||||
import Data.Tagged (untag)
|
||||
import Plutarch.Context (
|
||||
input,
|
||||
output,
|
||||
|
|
@ -41,6 +41,7 @@ import Plutarch.Context (
|
|||
timeRange,
|
||||
txId,
|
||||
withDatum,
|
||||
withRedeemer,
|
||||
withRef,
|
||||
withValue,
|
||||
)
|
||||
|
|
@ -139,7 +140,7 @@ delegate = head pubKeyHashes
|
|||
mkStakeInputDatum :: Parameters -> StakeDatum
|
||||
mkStakeInputDatum params =
|
||||
StakeDatum
|
||||
{ stakedAmount = Tagged params.voteCount
|
||||
{ stakedAmount = fromInteger params.voteCount
|
||||
, owner = PubKeyCredential stakeOwner
|
||||
, delegatedTo =
|
||||
if params.voteAsDelegate
|
||||
|
|
@ -230,6 +231,7 @@ vote params =
|
|||
, withValue pst
|
||||
, withDatum proposalInputDatum
|
||||
, withRef proposalRef
|
||||
, withRedeemer $ mkProposalRedeemer params
|
||||
]
|
||||
, input $
|
||||
mconcat
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ module Sample.Shared (
|
|||
deterministicTracingConfing,
|
||||
mkEffect,
|
||||
mkRedeemer,
|
||||
fromDiscrete,
|
||||
|
||||
-- * Agora Scripts
|
||||
agoraScripts,
|
||||
|
|
@ -73,6 +74,7 @@ import Agora.Utils (
|
|||
CompiledValidator (getCompiledValidator),
|
||||
validatorHashToTokenName,
|
||||
)
|
||||
import Data.Coerce (coerce)
|
||||
import Data.Default.Class (Default (..))
|
||||
import Data.Tagged (Tagged (..))
|
||||
import Plutarch (Config (..), TracingMode (DetTracing))
|
||||
|
|
@ -82,6 +84,7 @@ import Plutarch.Api.V2 (
|
|||
mkValidator,
|
||||
validatorHash,
|
||||
)
|
||||
import Plutarch.SafeMoney (Discrete (Discrete))
|
||||
import PlutusLedgerApi.V1.Address (scriptHashAddress)
|
||||
import PlutusLedgerApi.V1.Contexts (TxOut (..))
|
||||
import PlutusLedgerApi.V1.Scripts (Validator, ValidatorHash (..))
|
||||
|
|
@ -225,6 +228,9 @@ mkEffect v = CompiledEffect $ mkValidator deterministicTracingConfing v
|
|||
mkRedeemer :: forall redeemer. PlutusTx.ToData redeemer => redeemer -> Redeemer
|
||||
mkRedeemer = Redeemer . toBuiltinData
|
||||
|
||||
fromDiscrete :: forall tag. Discrete tag -> Integer
|
||||
fromDiscrete = coerce
|
||||
|
||||
------------------------------------------------------------------
|
||||
|
||||
treasuryOut :: TxOut
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import Agora.SafeMoney (GTTag)
|
|||
import Agora.Stake (
|
||||
StakeDatum (StakeDatum, stakedAmount),
|
||||
)
|
||||
import Data.Tagged (Tagged, untag)
|
||||
import Data.Tagged (untag)
|
||||
import Plutarch.Context (
|
||||
MintingBuilder,
|
||||
SpendingBuilder,
|
||||
|
|
@ -41,6 +41,7 @@ import Plutarch.Context (
|
|||
withSpendingOutRef,
|
||||
withValue,
|
||||
)
|
||||
import Plutarch.SafeMoney (Discrete)
|
||||
import PlutusLedgerApi.V1.Contexts (TxOutRef (..))
|
||||
import PlutusLedgerApi.V1.Value qualified as Value (
|
||||
assetClassValue,
|
||||
|
|
@ -56,6 +57,7 @@ import PlutusLedgerApi.V2 (
|
|||
)
|
||||
import PlutusTx.AssocMap qualified as AssocMap
|
||||
import Sample.Shared (
|
||||
fromDiscrete,
|
||||
governor,
|
||||
signer,
|
||||
stakeAssetClass,
|
||||
|
|
@ -112,9 +114,9 @@ stakeCreationUnsigned =
|
|||
|
||||
-- | Config for creating a ScriptContext that deposits or withdraws.
|
||||
data DepositWithdrawExample = DepositWithdrawExample
|
||||
{ startAmount :: Tagged GTTag Integer
|
||||
{ startAmount :: Discrete GTTag
|
||||
-- ^ The amount of GT stored before the transaction.
|
||||
, delta :: Tagged GTTag Integer
|
||||
, delta :: Discrete GTTag
|
||||
-- ^ The amount of GT deposited or withdrawn from the Stake.
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +145,7 @@ stakeDepositWithdraw config =
|
|||
, withValue
|
||||
( sortValue $
|
||||
st
|
||||
<> Value.assetClassValue (untag governor.gtClassRef) (untag stakeBefore.stakedAmount)
|
||||
<> Value.assetClassValue (untag governor.gtClassRef) (fromDiscrete stakeBefore.stakedAmount)
|
||||
)
|
||||
, withDatum stakeAfter
|
||||
, withRef stakeRef
|
||||
|
|
@ -154,7 +156,7 @@ stakeDepositWithdraw config =
|
|||
, withValue
|
||||
( sortValue $
|
||||
st
|
||||
<> Value.assetClassValue (untag governor.gtClassRef) (untag stakeAfter.stakedAmount)
|
||||
<> Value.assetClassValue (untag governor.gtClassRef) (fromDiscrete stakeAfter.stakedAmount)
|
||||
)
|
||||
, withDatum stakeAfter
|
||||
]
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ import PlutusLedgerApi.V2 (
|
|||
)
|
||||
import Sample.Shared (
|
||||
agoraScripts,
|
||||
fromDiscrete,
|
||||
governor,
|
||||
minAda,
|
||||
signer,
|
||||
|
|
@ -123,7 +124,7 @@ setDelegate ps = buildSpending' builder
|
|||
[ st
|
||||
, Value.assetClassValue
|
||||
(untag governor.gtClassRef)
|
||||
(untag stakeInput.stakedAmount)
|
||||
(fromDiscrete stakeInput.stakedAmount)
|
||||
, minAda
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -121,10 +121,6 @@ specs =
|
|||
"duplicate cosigners"
|
||||
Cosign.duplicateCosignersParameters
|
||||
False
|
||||
, Cosign.mkTestTree
|
||||
"altered output stake"
|
||||
Cosign.invalidStakeOutputParameters
|
||||
False
|
||||
, illegalStatusNotDraftGroup
|
||||
]
|
||||
in [legalGroup, illegalGroup]
|
||||
|
|
@ -234,26 +230,6 @@ specs =
|
|||
, forGovernorValidator = Just True
|
||||
, forAuthorityTokenPolicy = Just True
|
||||
}
|
||||
, Advance.mkTestTree'
|
||||
"altered output stake datum"
|
||||
(\b -> unwords ["from", show b.proposalParameters.fromStatus])
|
||||
(Advance.mkInvalidOutputStakeBundles cs es)
|
||||
Advance.Validity
|
||||
{ forProposalValidator = False
|
||||
, forStakeValidator = False
|
||||
, forGovernorValidator = Just True
|
||||
, forAuthorityTokenPolicy = Just True
|
||||
}
|
||||
, Advance.mkTestTree'
|
||||
"unexpected stake datum"
|
||||
(\b -> unwords ["from", show b.proposalParameters.fromStatus])
|
||||
(Advance.mkUnexpectedOutputStakeBundles cs es)
|
||||
Advance.Validity
|
||||
{ forProposalValidator = False
|
||||
, forStakeValidator = True
|
||||
, forGovernorValidator = Just True
|
||||
, forAuthorityTokenPolicy = Just True
|
||||
}
|
||||
, Advance.mkTestTree
|
||||
"forget to mint GATs"
|
||||
(Advance.mkNoGATMintedBundle cs es)
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ import Agora.Utils (
|
|||
)
|
||||
import Control.Composition ((.**), (.***))
|
||||
import Data.Coerce (coerce)
|
||||
import Data.Text qualified as Text
|
||||
import Plutarch.Evaluate (evalScript)
|
||||
import PlutusLedgerApi.V1.Scripts (
|
||||
Context (..),
|
||||
|
|
@ -137,8 +138,12 @@ toTestTree (Terminal (Specification name expectation script)) =
|
|||
Failure -> onFailure
|
||||
FailureWith s -> onFailureWith s
|
||||
where
|
||||
beautifyTraces =
|
||||
Text.unpack
|
||||
. Text.intercalate "\n"
|
||||
. map (" " <>)
|
||||
(res, _budget, traces) = evalScript script
|
||||
ts = " Traces: " <> show traces
|
||||
ts = " Traces:\n" <> beautifyTraces traces
|
||||
onSuccess = case res of
|
||||
Left e ->
|
||||
assertFailure $
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue