fix broken tests/samples

This commit is contained in:
fanghr 2022-05-25 17:52:05 +08:00
parent 9bc2acb9ca
commit c6c93f587a
8 changed files with 93 additions and 38 deletions

View file

@ -37,7 +37,9 @@ import Plutus.V1.Ledger.Value (AssetClass, assetClass)
import Plutus.V1.Ledger.Value qualified as Value import Plutus.V1.Ledger.Value qualified as Value
import Sample.Shared ( import Sample.Shared (
authorityTokenSymbol, authorityTokenSymbol,
defaultCreateProposalTimeRangeMaxDuration,
defaultProposalThresholds, defaultProposalThresholds,
defaultProposalTimingConfig,
govAssetClass, govAssetClass,
govValidatorAddress, govValidatorAddress,
governor, governor,
@ -101,6 +103,8 @@ mkEffectTxInfo newGovDatum =
GovernorDatum GovernorDatum
{ proposalThresholds = defaultProposalThresholds { proposalThresholds = defaultProposalThresholds
, nextProposalId = ProposalId 0 , nextProposalId = ProposalId 0
, proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }
governorInputDatum :: Datum governorInputDatum :: Datum
governorInputDatum = Datum $ toBuiltinData governorInputDatum' governorInputDatum = Datum $ toBuiltinData governorInputDatum'
@ -161,6 +165,8 @@ validNewGovernorDatum =
GovernorDatum GovernorDatum
{ proposalThresholds = defaultProposalThresholds { proposalThresholds = defaultProposalThresholds
, nextProposalId = ProposalId 42 , nextProposalId = ProposalId 42
, proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }
invalidNewGovernorDatum :: GovernorDatum invalidNewGovernorDatum :: GovernorDatum
@ -171,4 +177,6 @@ invalidNewGovernorDatum =
{ countVoting = Tagged (-1) { countVoting = Tagged (-1)
} }
, nextProposalId = ProposalId 42 , nextProposalId = ProposalId 42
, proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }

View file

@ -64,8 +64,13 @@ import Agora.Stake (
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Agora.Proposal.Time (
ProposalStartingTime (ProposalStartingTime),
ProposalTimingConfig (..),
)
import Sample.Shared ( import Sample.Shared (
authorityTokenSymbol, authorityTokenSymbol,
defaultCreateProposalTimeRangeMaxDuration,
defaultProposalThresholds, defaultProposalThresholds,
defaultProposalTimingConfig, defaultProposalTimingConfig,
govAssetClass, govAssetClass,
@ -74,15 +79,15 @@ import Sample.Shared (
gstUTXORef, gstUTXORef,
minAda, minAda,
proposalPolicySymbol, proposalPolicySymbol,
proposalStartingTimeFromTimeRange,
proposalValidatorAddress, proposalValidatorAddress,
signer, signer,
signer2, signer2,
stake, stake,
stakeAddress, stakeAddress,
stakeAssetClass, stakeAssetClass,
tmpProposalStartingTime,
) )
import Test.Util (datumPair, toDatumHash) import Test.Util (closedBoundedInterval, datumPair, toDatumHash)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -115,6 +120,7 @@ mintGST =
{ proposalThresholds = defaultProposalThresholds { proposalThresholds = defaultProposalThresholds
, nextProposalId = ProposalId 0 , nextProposalId = ProposalId 0
, proposalTimings = defaultProposalTimingConfig , proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }
governorOutputDatum :: Datum governorOutputDatum :: Datum
governorOutputDatum = Datum $ toBuiltinData governorOutputDatum' governorOutputDatum = Datum $ toBuiltinData governorOutputDatum'
@ -209,6 +215,7 @@ createProposal =
{ proposalThresholds = defaultProposalThresholds { proposalThresholds = defaultProposalThresholds
, nextProposalId = thisProposalId , nextProposalId = thisProposalId
, proposalTimings = defaultProposalTimingConfig , proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }
governorInputDatum :: Datum governorInputDatum :: Datum
governorInputDatum = Datum $ toBuiltinData governorInputDatum' governorInputDatum = Datum $ toBuiltinData governorInputDatum'
@ -239,7 +246,7 @@ createProposal =
, thresholds = defaultProposalThresholds , thresholds = defaultProposalThresholds
, votes = emptyVotesFor effects , votes = emptyVotesFor effects
, timingConfig = defaultProposalTimingConfig , timingConfig = defaultProposalTimingConfig
, startingTime = tmpProposalStartingTime , startingTime = proposalStartingTimeFromTimeRange validTimeRange
} }
) )
proposalOutput :: TxOut proposalOutput :: TxOut
@ -300,8 +307,13 @@ createProposal =
} }
--- ---
ownInputRef :: TxOutRef ownInputRef :: TxOutRef
ownInputRef = TxOutRef "4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865" 1 ownInputRef = TxOutRef "4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865" 1
---
validTimeRange = closedBoundedInterval 10 15
in ScriptContext in ScriptContext
{ scriptContextTxInfo = { scriptContextTxInfo =
TxInfo TxInfo
@ -318,7 +330,7 @@ createProposal =
, txInfoMint = pst , txInfoMint = pst
, txInfoDCert = [] , txInfoDCert = []
, txInfoWdrl = [] , txInfoWdrl = []
, txInfoValidRange = Interval.always , txInfoValidRange = validTimeRange
, txInfoSignatories = [signer] , txInfoSignatories = [signer]
, txInfoData = , txInfoData =
datumPair datumPair
@ -381,6 +393,7 @@ mintGATs =
{ proposalThresholds = defaultProposalThresholds { proposalThresholds = defaultProposalThresholds
, nextProposalId = ProposalId 5 , nextProposalId = ProposalId 5
, proposalTimings = defaultProposalTimingConfig , proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }
governorInputDatum :: Datum governorInputDatum :: Datum
governorInputDatum = Datum $ toBuiltinData governorInputDatum' governorInputDatum = Datum $ toBuiltinData governorInputDatum'
@ -416,7 +429,7 @@ mintGATs =
, thresholds = defaultProposalThresholds , thresholds = defaultProposalThresholds
, votes = proposalVotes , votes = proposalVotes
, timingConfig = defaultProposalTimingConfig , timingConfig = defaultProposalTimingConfig
, startingTime = tmpProposalStartingTime , startingTime = ProposalStartingTime 10
} }
proposalInputDatum :: Datum proposalInputDatum :: Datum
proposalInputDatum = Datum $ toBuiltinData proposalInputDatum' proposalInputDatum = Datum $ toBuiltinData proposalInputDatum'
@ -468,6 +481,12 @@ mintGATs =
ownInputRef :: TxOutRef ownInputRef :: TxOutRef
ownInputRef = TxOutRef "4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865" 1 ownInputRef = TxOutRef "4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865" 1
--
validTimeRange =
closedBoundedInterval
(defaultProposalTimingConfig.lockingTime + 11)
(defaultProposalTimingConfig.executingTime - 11)
in ScriptContext in ScriptContext
{ scriptContextTxInfo = { scriptContextTxInfo =
TxInfo TxInfo
@ -486,7 +505,7 @@ mintGATs =
, txInfoMint = gat , txInfoMint = gat
, txInfoDCert = [] , txInfoDCert = []
, txInfoWdrl = [] , txInfoWdrl = []
, txInfoValidRange = Interval.always , txInfoValidRange = validTimeRange
, txInfoSignatories = [signer, signer2] , txInfoSignatories = [signer, signer2]
, txInfoData = , txInfoData =
datumPair datumPair
@ -569,6 +588,7 @@ mutateState =
{ proposalThresholds = defaultProposalThresholds { proposalThresholds = defaultProposalThresholds
, nextProposalId = ProposalId 5 , nextProposalId = ProposalId 5
, proposalTimings = defaultProposalTimingConfig , proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }
governorInputDatum :: Datum governorInputDatum :: Datum
governorInputDatum = Datum $ toBuiltinData governorInputDatum' governorInputDatum = Datum $ toBuiltinData governorInputDatum'

View file

@ -33,7 +33,6 @@ import Plutus.V1.Ledger.Api (
TxOut (TxOut, txOutAddress, txOutDatumHash, txOutValue), TxOut (TxOut, txOutAddress, txOutDatumHash, txOutValue),
TxOutRef (TxOutRef), TxOutRef (TxOutRef),
) )
import Plutus.V1.Ledger.Interval qualified as Interval
import Plutus.V1.Ledger.Value qualified as Value import Plutus.V1.Ledger.Value qualified as Value
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -50,7 +49,7 @@ import Agora.Proposal (
ResultTag (..), ResultTag (..),
emptyVotesFor, emptyVotesFor,
) )
import Agora.Proposal.Time (ProposalTimingConfig (..)) import Agora.Proposal.Time (ProposalStartingTime (ProposalStartingTime), ProposalTimingConfig (..))
import Agora.Stake (ProposalLock (ProposalLock), Stake (..), StakeDatum (..)) import Agora.Stake (ProposalLock (ProposalLock), Stake (..), StakeDatum (..))
import Plutarch.SafeMoney (Tagged (Tagged), untag) import Plutarch.SafeMoney (Tagged (Tagged), untag)
import PlutusTx.AssocMap qualified as AssocMap import PlutusTx.AssocMap qualified as AssocMap
@ -80,7 +79,7 @@ proposalCreation =
, thresholds = defaultProposalThresholds , thresholds = defaultProposalThresholds
, votes = emptyVotesFor effects , votes = emptyVotesFor effects
, timingConfig = defaultProposalTimingConfig , timingConfig = defaultProposalTimingConfig
, startingTime = tmpProposalStartingTime , startingTime = proposalStartingTimeFromTimeRange validTimeRange
} }
) )
@ -92,6 +91,7 @@ proposalCreation =
{ proposalThresholds = defaultProposalThresholds { proposalThresholds = defaultProposalThresholds
, nextProposalId = ProposalId 0 , nextProposalId = ProposalId 0
, proposalTimings = defaultProposalTimingConfig , proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }
) )
govAfter :: Datum govAfter :: Datum
@ -102,8 +102,11 @@ proposalCreation =
{ proposalThresholds = defaultProposalThresholds { proposalThresholds = defaultProposalThresholds
, nextProposalId = ProposalId 1 , nextProposalId = ProposalId 1
, proposalTimings = defaultProposalTimingConfig , proposalTimings = defaultProposalTimingConfig
, createProposalTimeRangeMaxDuration = defaultCreateProposalTimeRangeMaxDuration
} }
) )
validTimeRange = closedBoundedInterval 10 15
in ScriptContext in ScriptContext
{ scriptContextTxInfo = { scriptContextTxInfo =
TxInfo TxInfo
@ -140,7 +143,7 @@ proposalCreation =
, txInfoMint = st , txInfoMint = st
, txInfoDCert = [] , txInfoDCert = []
, txInfoWdrl = [] , txInfoWdrl = []
, txInfoValidRange = Interval.always , txInfoValidRange = validTimeRange
, txInfoSignatories = [signer] , txInfoSignatories = [signer]
, txInfoData = , txInfoData =
[ datumPair proposalDatum [ datumPair proposalDatum
@ -177,7 +180,7 @@ cosignProposal newSigners =
, thresholds = defaultProposalThresholds , thresholds = defaultProposalThresholds
, votes = emptyVotesFor effects , votes = emptyVotesFor effects
, timingConfig = defaultProposalTimingConfig , timingConfig = defaultProposalTimingConfig
, startingTime = tmpProposalStartingTime , startingTime = ProposalStartingTime 0
} }
stakeDatum :: StakeDatum stakeDatum :: StakeDatum
stakeDatum = StakeDatum (Tagged 50_000_000) signer2 [] stakeDatum = StakeDatum (Tagged 50_000_000) signer2 []
@ -298,7 +301,7 @@ voteOnProposal params =
, thresholds = defaultProposalThresholds , thresholds = defaultProposalThresholds
, votes = ProposalVotes initialVotes , votes = ProposalVotes initialVotes
, timingConfig = defaultProposalTimingConfig , timingConfig = defaultProposalTimingConfig
, startingTime = tmpProposalStartingTime , startingTime = ProposalStartingTime 0
} }
proposalInputDatum :: Datum proposalInputDatum :: Datum
proposalInputDatum = Datum $ toBuiltinData proposalInputDatum' proposalInputDatum = Datum $ toBuiltinData proposalInputDatum'

View file

@ -37,7 +37,8 @@ module Sample.Shared (
proposalValidatorHash, proposalValidatorHash,
proposalValidatorAddress, proposalValidatorAddress,
defaultProposalTimingConfig, defaultProposalTimingConfig,
tmpProposalStartingTime, defaultCreateProposalTimeRangeMaxDuration,
proposalStartingTimeFromTimeRange,
-- ** Authority -- ** Authority
authorityToken, authorityToken,
@ -77,7 +78,7 @@ import Agora.Proposal (
ProposalThresholds (..), ProposalThresholds (..),
) )
import Agora.Proposal.Time ( import Agora.Proposal.Time (
ProposalStartingTime (..), ProposalStartingTime (ProposalStartingTime),
ProposalTimingConfig (..), ProposalTimingConfig (..),
) )
import Agora.Stake (Stake (..)) import Agora.Stake (Stake (..))
@ -95,9 +96,15 @@ import Plutus.V1.Ledger.Api (
Address (Address), Address (Address),
Credential (ScriptCredential), Credential (ScriptCredential),
CurrencySymbol, CurrencySymbol,
Extended (..),
Interval (..),
LowerBound (..),
MintingPolicy (..), MintingPolicy (..),
POSIXTime,
POSIXTimeRange,
PubKeyHash, PubKeyHash,
TxOutRef (TxOutRef), TxOutRef (TxOutRef),
UpperBound (..),
Value, Value,
) )
import Plutus.V1.Ledger.Contexts ( import Plutus.V1.Ledger.Contexts (
@ -199,12 +206,14 @@ defaultProposalTimingConfig =
, executingTime = 3000 , executingTime = 3000
} }
{- | Hard coded starting time of every propoal. defaultCreateProposalTimeRangeMaxDuration :: POSIXTime
This will be calculated by the governor in the future. defaultCreateProposalTimeRangeMaxDuration = 10
FIXME: Remove this.
-} proposalStartingTimeFromTimeRange :: POSIXTimeRange -> ProposalStartingTime
tmpProposalStartingTime :: ProposalStartingTime proposalStartingTimeFromTimeRange
tmpProposalStartingTime = ProposalStartingTime 0 (Interval (LowerBound (Finite l) True) (UpperBound (Finite u) True)) =
ProposalStartingTime $ (l + u) `div` 2
proposalStartingTimeFromTimeRange _ = error "Given time range should be finite and closed"
------------------------------------------------------------------ ------------------------------------------------------------------

View file

@ -27,9 +27,10 @@ tests =
"governor validator should pass" "governor validator should pass"
(governorValidator Shared.governor) (governorValidator Shared.governor)
( GovernorDatum ( GovernorDatum
{ proposalThresholds = Shared.defaultProposalThresholds Shared.defaultProposalThresholds
, nextProposalId = ProposalId 0 (ProposalId 0)
} Shared.defaultProposalTimingConfig
Shared.defaultCreateProposalTimeRangeMaxDuration
) )
MutateGovernor MutateGovernor
( ScriptContext ( ScriptContext
@ -48,9 +49,10 @@ tests =
"governor validator should fail" "governor validator should fail"
(governorValidator Shared.governor) (governorValidator Shared.governor)
( GovernorDatum ( GovernorDatum
{ proposalThresholds = Shared.defaultProposalThresholds Shared.defaultProposalThresholds
, nextProposalId = ProposalId 0 (ProposalId 0)
} Shared.defaultProposalTimingConfig
Shared.defaultCreateProposalTimeRangeMaxDuration
) )
MutateGovernor MutateGovernor
( ScriptContext ( ScriptContext

View file

@ -38,19 +38,34 @@ tests =
[ validatorSucceedsWith [ validatorSucceedsWith
"proposal creation" "proposal creation"
(governorValidator Shared.governor) (governorValidator Shared.governor)
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 0) Shared.defaultProposalTimingConfig) ( GovernorDatum
Shared.defaultProposalThresholds
(ProposalId 0)
Shared.defaultProposalTimingConfig
Shared.defaultCreateProposalTimeRangeMaxDuration
)
CreateProposal CreateProposal
createProposal createProposal
, validatorSucceedsWith , validatorSucceedsWith
"GATs minting" "GATs minting"
(governorValidator Shared.governor) (governorValidator Shared.governor)
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 5) Shared.defaultProposalTimingConfig) ( GovernorDatum
Shared.defaultProposalThresholds
(ProposalId 5)
Shared.defaultProposalTimingConfig
Shared.defaultCreateProposalTimeRangeMaxDuration
)
MintGATs MintGATs
mintGATs mintGATs
, validatorSucceedsWith , validatorSucceedsWith
"mutate governor state" "mutate governor state"
(governorValidator Shared.governor) (governorValidator Shared.governor)
(GovernorDatum Shared.defaultProposalThresholds (ProposalId 5) Shared.defaultProposalTimingConfig) ( GovernorDatum
Shared.defaultProposalThresholds
(ProposalId 5)
Shared.defaultProposalTimingConfig
Shared.defaultCreateProposalTimeRangeMaxDuration
)
MutateGovernor MutateGovernor
mutateState mutateState
] ]

View file

@ -31,6 +31,7 @@ import Agora.Proposal.Scripts (
proposalPolicy, proposalPolicy,
proposalValidator, proposalValidator,
) )
import Agora.Proposal.Time (ProposalStartingTime (ProposalStartingTime))
import Agora.Stake ( import Agora.Stake (
ProposalLock (ProposalLock), ProposalLock (ProposalLock),
StakeDatum (StakeDatum), StakeDatum (StakeDatum),
@ -83,7 +84,7 @@ tests =
, (ResultTag 1, AssocMap.empty) , (ResultTag 1, AssocMap.empty)
] ]
, timingConfig = Shared.defaultProposalTimingConfig , timingConfig = Shared.defaultProposalTimingConfig
, startingTime = Shared.tmpProposalStartingTime , startingTime = ProposalStartingTime 0
} }
) )
(Cosign [signer2]) (Cosign [signer2])
@ -118,7 +119,7 @@ tests =
] ]
) )
, timingConfig = Shared.defaultProposalTimingConfig , timingConfig = Shared.defaultProposalTimingConfig
, startingTime = Shared.tmpProposalStartingTime , startingTime = ProposalStartingTime 0
} }
) )
(Vote (ResultTag 0)) (Vote (ResultTag 0))

View file

@ -141,22 +141,20 @@ library
Agora.Proposal.Time Agora.Proposal.Time
Agora.Record Agora.Record
Agora.SafeMoney Agora.SafeMoney
Agora.ScriptInfo
Agora.Stake Agora.Stake
Agora.Stake.Scripts Agora.Stake.Scripts
Agora.Treasury Agora.Treasury
Agora.Utils Agora.Utils
Agora.Utils.Value Agora.Utils.Value
Agora.ScriptInfo
other-modules: other-modules: Agora.Aeson.Orphans
Agora.Aeson.Orphans
hs-source-dirs: agora hs-source-dirs: agora
library pprelude library pprelude
default-language: Haskell2010 default-language: Haskell2010
exposed-modules: PPrelude exposed-modules: PPrelude
hs-source-dirs: agora hs-source-dirs: agora
build-depends: build-depends:
, base , base
, plutarch , plutarch
@ -176,8 +174,8 @@ library agora-sample
Sample.Shared Sample.Shared
Sample.Stake Sample.Stake
Sample.Treasury Sample.Treasury
hs-source-dirs: agora-sample
hs-source-dirs: agora-sample
build-depends: agora-testlib build-depends: agora-testlib
test-suite agora-test test-suite agora-test
@ -214,8 +212,7 @@ executable agora-scripts
import: lang, deps, exe-opts import: lang, deps, exe-opts
main-is: Scripts.hs main-is: Scripts.hs
hs-source-dirs: agora-scripts hs-source-dirs: agora-scripts
other-modules: other-modules: Options
Options
build-depends: build-depends:
, agora , agora
, optparse-applicative , optparse-applicative