fix broken tests/samples
This commit is contained in:
parent
355f838417
commit
55435d601f
8 changed files with 93 additions and 38 deletions
|
|
@ -37,7 +37,9 @@ import Plutus.V1.Ledger.Value (AssetClass, assetClass)
|
|||
import Plutus.V1.Ledger.Value qualified as Value
|
||||
import Sample.Shared (
|
||||
authorityTokenSymbol,
|
||||
defaultCreateProposalTimeRangeMaxDuration,
|
||||
defaultProposalThresholds,
|
||||
defaultProposalTimingConfig,
|
||||
govAssetClass,
|
||||
govValidatorAddress,
|
||||
governor,
|
||||
|
|
@ -101,6 +103,8 @@ mkEffectTxInfo newGovDatum =
|
|||
GovernorDatum
|
||||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 0
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
governorInputDatum :: Datum
|
||||
governorInputDatum = Datum $ toBuiltinData governorInputDatum'
|
||||
|
|
@ -161,6 +165,8 @@ validNewGovernorDatum =
|
|||
GovernorDatum
|
||||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 42
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
|
||||
invalidNewGovernorDatum :: GovernorDatum
|
||||
|
|
@ -171,4 +177,6 @@ invalidNewGovernorDatum =
|
|||
{ countVoting = Tagged (-1)
|
||||
}
|
||||
, nextProposalId = ProposalId 42
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,13 @@ import Agora.Stake (
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
import Agora.Proposal.Time (
|
||||
ProposalStartingTime (ProposalStartingTime),
|
||||
ProposalTimingConfig (..),
|
||||
)
|
||||
import Sample.Shared (
|
||||
authorityTokenSymbol,
|
||||
defaultCreateProposalTimeRangeMaxDuration,
|
||||
defaultProposalThresholds,
|
||||
defaultProposalTimingConfig,
|
||||
govAssetClass,
|
||||
|
|
@ -74,15 +79,15 @@ import Sample.Shared (
|
|||
gstUTXORef,
|
||||
minAda,
|
||||
proposalPolicySymbol,
|
||||
proposalStartingTimeFromTimeRange,
|
||||
proposalValidatorAddress,
|
||||
signer,
|
||||
signer2,
|
||||
stake,
|
||||
stakeAddress,
|
||||
stakeAssetClass,
|
||||
tmpProposalStartingTime,
|
||||
)
|
||||
import Test.Util (datumPair, toDatumHash)
|
||||
import Test.Util (closedBoundedInterval, datumPair, toDatumHash)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -115,6 +120,7 @@ mintGST =
|
|||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 0
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
governorOutputDatum :: Datum
|
||||
governorOutputDatum = Datum $ toBuiltinData governorOutputDatum'
|
||||
|
|
@ -209,6 +215,7 @@ createProposal =
|
|||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = thisProposalId
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
governorInputDatum :: Datum
|
||||
governorInputDatum = Datum $ toBuiltinData governorInputDatum'
|
||||
|
|
@ -239,7 +246,7 @@ createProposal =
|
|||
, thresholds = defaultProposalThresholds
|
||||
, votes = emptyVotesFor effects
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
, startingTime = proposalStartingTimeFromTimeRange validTimeRange
|
||||
}
|
||||
)
|
||||
proposalOutput :: TxOut
|
||||
|
|
@ -300,8 +307,13 @@ createProposal =
|
|||
}
|
||||
|
||||
---
|
||||
|
||||
ownInputRef :: TxOutRef
|
||||
ownInputRef = TxOutRef "4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865" 1
|
||||
|
||||
---
|
||||
|
||||
validTimeRange = closedBoundedInterval 10 15
|
||||
in ScriptContext
|
||||
{ scriptContextTxInfo =
|
||||
TxInfo
|
||||
|
|
@ -318,7 +330,7 @@ createProposal =
|
|||
, txInfoMint = pst
|
||||
, txInfoDCert = []
|
||||
, txInfoWdrl = []
|
||||
, txInfoValidRange = Interval.always
|
||||
, txInfoValidRange = validTimeRange
|
||||
, txInfoSignatories = [signer]
|
||||
, txInfoData =
|
||||
datumPair
|
||||
|
|
@ -381,6 +393,7 @@ mintGATs =
|
|||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 5
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
governorInputDatum :: Datum
|
||||
governorInputDatum = Datum $ toBuiltinData governorInputDatum'
|
||||
|
|
@ -416,7 +429,7 @@ mintGATs =
|
|||
, thresholds = defaultProposalThresholds
|
||||
, votes = proposalVotes
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
, startingTime = ProposalStartingTime 10
|
||||
}
|
||||
proposalInputDatum :: Datum
|
||||
proposalInputDatum = Datum $ toBuiltinData proposalInputDatum'
|
||||
|
|
@ -468,6 +481,12 @@ mintGATs =
|
|||
|
||||
ownInputRef :: TxOutRef
|
||||
ownInputRef = TxOutRef "4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865" 1
|
||||
|
||||
--
|
||||
validTimeRange =
|
||||
closedBoundedInterval
|
||||
(defaultProposalTimingConfig.lockingTime + 11)
|
||||
(defaultProposalTimingConfig.executingTime - 11)
|
||||
in ScriptContext
|
||||
{ scriptContextTxInfo =
|
||||
TxInfo
|
||||
|
|
@ -486,7 +505,7 @@ mintGATs =
|
|||
, txInfoMint = gat
|
||||
, txInfoDCert = []
|
||||
, txInfoWdrl = []
|
||||
, txInfoValidRange = Interval.always
|
||||
, txInfoValidRange = validTimeRange
|
||||
, txInfoSignatories = [signer, signer2]
|
||||
, txInfoData =
|
||||
datumPair
|
||||
|
|
@ -569,6 +588,7 @@ mutateState =
|
|||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 5
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
governorInputDatum :: Datum
|
||||
governorInputDatum = Datum $ toBuiltinData governorInputDatum'
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import Plutus.V1.Ledger.Api (
|
|||
TxOut (TxOut, txOutAddress, txOutDatumHash, txOutValue),
|
||||
TxOutRef (TxOutRef),
|
||||
)
|
||||
import Plutus.V1.Ledger.Interval qualified as Interval
|
||||
import Plutus.V1.Ledger.Value qualified as Value
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
|
@ -50,7 +49,7 @@ import Agora.Proposal (
|
|||
ResultTag (..),
|
||||
emptyVotesFor,
|
||||
)
|
||||
import Agora.Proposal.Time (ProposalTimingConfig (..))
|
||||
import Agora.Proposal.Time (ProposalStartingTime (ProposalStartingTime), ProposalTimingConfig (..))
|
||||
import Agora.Stake (ProposalLock (ProposalLock), Stake (..), StakeDatum (..))
|
||||
import Plutarch.SafeMoney (Tagged (Tagged), untag)
|
||||
import PlutusTx.AssocMap qualified as AssocMap
|
||||
|
|
@ -80,7 +79,7 @@ proposalCreation =
|
|||
, thresholds = defaultProposalThresholds
|
||||
, votes = emptyVotesFor effects
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
, startingTime = proposalStartingTimeFromTimeRange validTimeRange
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -92,6 +91,7 @@ proposalCreation =
|
|||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 0
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
)
|
||||
govAfter :: Datum
|
||||
|
|
@ -102,8 +102,11 @@ proposalCreation =
|
|||
{ proposalThresholds = defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 1
|
||||
, proposalTimings = defaultProposalTimingConfig
|
||||
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
|
||||
}
|
||||
)
|
||||
|
||||
validTimeRange = closedBoundedInterval 10 15
|
||||
in ScriptContext
|
||||
{ scriptContextTxInfo =
|
||||
TxInfo
|
||||
|
|
@ -140,7 +143,7 @@ proposalCreation =
|
|||
, txInfoMint = st
|
||||
, txInfoDCert = []
|
||||
, txInfoWdrl = []
|
||||
, txInfoValidRange = Interval.always
|
||||
, txInfoValidRange = validTimeRange
|
||||
, txInfoSignatories = [signer]
|
||||
, txInfoData =
|
||||
[ datumPair proposalDatum
|
||||
|
|
@ -177,7 +180,7 @@ cosignProposal newSigners =
|
|||
, thresholds = defaultProposalThresholds
|
||||
, votes = emptyVotesFor effects
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
, startingTime = ProposalStartingTime 0
|
||||
}
|
||||
stakeDatum :: StakeDatum
|
||||
stakeDatum = StakeDatum (Tagged 50_000_000) signer2 []
|
||||
|
|
@ -298,7 +301,7 @@ voteOnProposal params =
|
|||
, thresholds = defaultProposalThresholds
|
||||
, votes = ProposalVotes initialVotes
|
||||
, timingConfig = defaultProposalTimingConfig
|
||||
, startingTime = tmpProposalStartingTime
|
||||
, startingTime = ProposalStartingTime 0
|
||||
}
|
||||
proposalInputDatum :: Datum
|
||||
proposalInputDatum = Datum $ toBuiltinData proposalInputDatum'
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ module Sample.Shared (
|
|||
proposalValidatorHash,
|
||||
proposalValidatorAddress,
|
||||
defaultProposalTimingConfig,
|
||||
tmpProposalStartingTime,
|
||||
defaultCreateProposalTimeRangeMaxDuration,
|
||||
proposalStartingTimeFromTimeRange,
|
||||
|
||||
-- ** Authority
|
||||
authorityToken,
|
||||
|
|
@ -77,7 +78,7 @@ import Agora.Proposal (
|
|||
ProposalThresholds (..),
|
||||
)
|
||||
import Agora.Proposal.Time (
|
||||
ProposalStartingTime (..),
|
||||
ProposalStartingTime (ProposalStartingTime),
|
||||
ProposalTimingConfig (..),
|
||||
)
|
||||
import Agora.Stake (Stake (..))
|
||||
|
|
@ -95,9 +96,15 @@ import Plutus.V1.Ledger.Api (
|
|||
Address (Address),
|
||||
Credential (ScriptCredential),
|
||||
CurrencySymbol,
|
||||
Extended (..),
|
||||
Interval (..),
|
||||
LowerBound (..),
|
||||
MintingPolicy (..),
|
||||
POSIXTime,
|
||||
POSIXTimeRange,
|
||||
PubKeyHash,
|
||||
TxOutRef (TxOutRef),
|
||||
UpperBound (..),
|
||||
Value,
|
||||
)
|
||||
import Plutus.V1.Ledger.Contexts (
|
||||
|
|
@ -199,12 +206,14 @@ defaultProposalTimingConfig =
|
|||
, executingTime = 3000
|
||||
}
|
||||
|
||||
{- | Hard coded starting time of every propoal.
|
||||
This will be calculated by the governor in the future.
|
||||
FIXME: Remove this.
|
||||
-}
|
||||
tmpProposalStartingTime :: ProposalStartingTime
|
||||
tmpProposalStartingTime = ProposalStartingTime 0
|
||||
defaultCreateProposalTimeRangeMaxDuration :: POSIXTime
|
||||
defaultCreateProposalTimeRangeMaxDuration = 10
|
||||
|
||||
proposalStartingTimeFromTimeRange :: POSIXTimeRange -> ProposalStartingTime
|
||||
proposalStartingTimeFromTimeRange
|
||||
(Interval (LowerBound (Finite l) True) (UpperBound (Finite u) True)) =
|
||||
ProposalStartingTime $ (l + u) `div` 2
|
||||
proposalStartingTimeFromTimeRange _ = error "Given time range should be finite and closed"
|
||||
|
||||
------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,10 @@ tests =
|
|||
"governor validator should pass"
|
||||
(governorValidator Shared.governor)
|
||||
( GovernorDatum
|
||||
{ proposalThresholds = Shared.defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 0
|
||||
}
|
||||
Shared.defaultProposalThresholds
|
||||
(ProposalId 0)
|
||||
Shared.defaultProposalTimingConfig
|
||||
Shared.defaultCreateProposalTimeRangeMaxDuration
|
||||
)
|
||||
MutateGovernor
|
||||
( ScriptContext
|
||||
|
|
@ -48,9 +49,10 @@ tests =
|
|||
"governor validator should fail"
|
||||
(governorValidator Shared.governor)
|
||||
( GovernorDatum
|
||||
{ proposalThresholds = Shared.defaultProposalThresholds
|
||||
, nextProposalId = ProposalId 0
|
||||
}
|
||||
Shared.defaultProposalThresholds
|
||||
(ProposalId 0)
|
||||
Shared.defaultProposalTimingConfig
|
||||
Shared.defaultCreateProposalTimeRangeMaxDuration
|
||||
)
|
||||
MutateGovernor
|
||||
( ScriptContext
|
||||
|
|
|
|||
|
|
@ -38,19 +38,34 @@ tests =
|
|||
[ validatorSucceedsWith
|
||||
"proposal creation"
|
||||
(governorValidator Shared.governor)
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 0) Shared.defaultProposalTimingConfig)
|
||||
( GovernorDatum
|
||||
Shared.defaultProposalThresholds
|
||||
(ProposalId 0)
|
||||
Shared.defaultProposalTimingConfig
|
||||
Shared.defaultCreateProposalTimeRangeMaxDuration
|
||||
)
|
||||
CreateProposal
|
||||
createProposal
|
||||
, validatorSucceedsWith
|
||||
"GATs minting"
|
||||
(governorValidator Shared.governor)
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 5) Shared.defaultProposalTimingConfig)
|
||||
( GovernorDatum
|
||||
Shared.defaultProposalThresholds
|
||||
(ProposalId 5)
|
||||
Shared.defaultProposalTimingConfig
|
||||
Shared.defaultCreateProposalTimeRangeMaxDuration
|
||||
)
|
||||
MintGATs
|
||||
mintGATs
|
||||
, validatorSucceedsWith
|
||||
"mutate governor state"
|
||||
(governorValidator Shared.governor)
|
||||
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 5) Shared.defaultProposalTimingConfig)
|
||||
( GovernorDatum
|
||||
Shared.defaultProposalThresholds
|
||||
(ProposalId 5)
|
||||
Shared.defaultProposalTimingConfig
|
||||
Shared.defaultCreateProposalTimeRangeMaxDuration
|
||||
)
|
||||
MutateGovernor
|
||||
mutateState
|
||||
]
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import Agora.Proposal.Scripts (
|
|||
proposalPolicy,
|
||||
proposalValidator,
|
||||
)
|
||||
import Agora.Proposal.Time (ProposalStartingTime (ProposalStartingTime))
|
||||
import Agora.Stake (
|
||||
ProposalLock (ProposalLock),
|
||||
StakeDatum (StakeDatum),
|
||||
|
|
@ -83,7 +84,7 @@ tests =
|
|||
, (ResultTag 1, AssocMap.empty)
|
||||
]
|
||||
, timingConfig = Shared.defaultProposalTimingConfig
|
||||
, startingTime = Shared.tmpProposalStartingTime
|
||||
, startingTime = ProposalStartingTime 0
|
||||
}
|
||||
)
|
||||
(Cosign [signer2])
|
||||
|
|
@ -118,7 +119,7 @@ tests =
|
|||
]
|
||||
)
|
||||
, timingConfig = Shared.defaultProposalTimingConfig
|
||||
, startingTime = Shared.tmpProposalStartingTime
|
||||
, startingTime = ProposalStartingTime 0
|
||||
}
|
||||
)
|
||||
(Vote (ResultTag 0))
|
||||
|
|
|
|||
11
agora.cabal
11
agora.cabal
|
|
@ -141,22 +141,20 @@ library
|
|||
Agora.Proposal.Time
|
||||
Agora.Record
|
||||
Agora.SafeMoney
|
||||
Agora.ScriptInfo
|
||||
Agora.Stake
|
||||
Agora.Stake.Scripts
|
||||
Agora.Treasury
|
||||
Agora.Utils
|
||||
Agora.Utils.Value
|
||||
Agora.ScriptInfo
|
||||
|
||||
other-modules:
|
||||
Agora.Aeson.Orphans
|
||||
other-modules: Agora.Aeson.Orphans
|
||||
hs-source-dirs: agora
|
||||
|
||||
library pprelude
|
||||
default-language: Haskell2010
|
||||
exposed-modules: PPrelude
|
||||
hs-source-dirs: agora
|
||||
|
||||
build-depends:
|
||||
, base
|
||||
, plutarch
|
||||
|
|
@ -176,8 +174,8 @@ library agora-sample
|
|||
Sample.Shared
|
||||
Sample.Stake
|
||||
Sample.Treasury
|
||||
hs-source-dirs: agora-sample
|
||||
|
||||
hs-source-dirs: agora-sample
|
||||
build-depends: agora-testlib
|
||||
|
||||
test-suite agora-test
|
||||
|
|
@ -214,8 +212,7 @@ executable agora-scripts
|
|||
import: lang, deps, exe-opts
|
||||
main-is: Scripts.hs
|
||||
hs-source-dirs: agora-scripts
|
||||
other-modules:
|
||||
Options
|
||||
other-modules: Options
|
||||
build-depends:
|
||||
, agora
|
||||
, optparse-applicative
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue