Added review changes
This commit is contained in:
parent
6aa4ed732a
commit
7572bb4da2
5 changed files with 85 additions and 115 deletions
|
|
@ -1,14 +1,3 @@
|
||||||
{- |
|
|
||||||
Module: Main
|
|
||||||
Description: Agora test suite.
|
|
||||||
Maintainer: emi@haskell.fyi
|
|
||||||
|
|
||||||
This module is the root of Agora's test suite.
|
|
||||||
-}
|
|
||||||
module Main (main) where
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -42,6 +31,12 @@ main =
|
||||||
, testGroup
|
, testGroup
|
||||||
"Proposal tests"
|
"Proposal tests"
|
||||||
Proposal.tests
|
Proposal.tests
|
||||||
|
, testGroup
|
||||||
|
"AuthorityToken tests"
|
||||||
|
AuthorityToken.tests
|
||||||
|
, testGroup
|
||||||
|
"Treasury tests"
|
||||||
|
Treasury.tests
|
||||||
, testGroup
|
, testGroup
|
||||||
"Multisig tests"
|
"Multisig tests"
|
||||||
[ testGroup
|
[ testGroup
|
||||||
|
|
@ -50,10 +45,4 @@ main =
|
||||||
, MultiSig.genTests
|
, MultiSig.genTests
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
, testGroup
|
|
||||||
"AuthorityToken tests"
|
|
||||||
AuthorityToken.tests
|
|
||||||
, testGroup
|
|
||||||
"Treasury tests"
|
|
||||||
Treasury.tests
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ module Spec.Sample.Shared (
|
||||||
-- * Misc
|
-- * Misc
|
||||||
signer,
|
signer,
|
||||||
signer2,
|
signer2,
|
||||||
|
minAda,
|
||||||
|
withMinAda,
|
||||||
|
|
||||||
-- * Components
|
-- * Components
|
||||||
|
|
||||||
|
|
@ -30,8 +32,16 @@ module Spec.Sample.Shared (
|
||||||
proposalPolicySymbol,
|
proposalPolicySymbol,
|
||||||
proposalValidatorHash,
|
proposalValidatorHash,
|
||||||
proposalValidatorAddress,
|
proposalValidatorAddress,
|
||||||
|
|
||||||
|
-- ** Treasury
|
||||||
|
treasuryOut,
|
||||||
|
gatTn,
|
||||||
|
gatCs,
|
||||||
|
mockTrEffect,
|
||||||
|
trCredential,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Agora.Effect.NoOp (noOpValidator)
|
||||||
import Agora.Governor (
|
import Agora.Governor (
|
||||||
Governor (Governor),
|
Governor (Governor),
|
||||||
governorPolicy,
|
governorPolicy,
|
||||||
|
|
@ -47,6 +57,8 @@ import Agora.Proposal.Scripts (
|
||||||
)
|
)
|
||||||
import Agora.Stake (Stake (..))
|
import Agora.Stake (Stake (..))
|
||||||
import Agora.Stake.Scripts (stakePolicy, stakeValidator)
|
import Agora.Stake.Scripts (stakePolicy, stakeValidator)
|
||||||
|
import Agora.Treasury (treasuryValidator)
|
||||||
|
import Agora.Utils (validatorHashToTokenName)
|
||||||
import Plutarch.Api.V1 (
|
import Plutarch.Api.V1 (
|
||||||
mintingPolicySymbol,
|
mintingPolicySymbol,
|
||||||
mkMintingPolicy,
|
mkMintingPolicy,
|
||||||
|
|
@ -62,7 +74,11 @@ import Plutus.V1.Ledger.Api (
|
||||||
MintingPolicy (..),
|
MintingPolicy (..),
|
||||||
PubKeyHash,
|
PubKeyHash,
|
||||||
)
|
)
|
||||||
|
import Plutus.V1.Ledger.Contexts (
|
||||||
|
TxOut (..),
|
||||||
|
)
|
||||||
import Plutus.V1.Ledger.Scripts (Validator, ValidatorHash)
|
import Plutus.V1.Ledger.Scripts (Validator, ValidatorHash)
|
||||||
|
import Plutus.V1.Ledger.Value (TokenName, Value)
|
||||||
import Plutus.V1.Ledger.Value qualified as Value
|
import Plutus.V1.Ledger.Value qualified as Value
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -131,3 +147,42 @@ defaultProposalThresholds =
|
||||||
, create = Tagged 1
|
, create = Tagged 1
|
||||||
, startVoting = Tagged 10
|
, startVoting = Tagged 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
|
||||||
|
treasuryOut :: TxOut
|
||||||
|
treasuryOut =
|
||||||
|
TxOut
|
||||||
|
{ txOutAddress = Address trCredential Nothing
|
||||||
|
, txOutValue = minAda
|
||||||
|
, txOutDatumHash = Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
{- | Arbitrary 'CurrencySymbol', representing the 'CurrencySymbol'
|
||||||
|
of a valid governance authority token (GAT).
|
||||||
|
-}
|
||||||
|
gatCs :: CurrencySymbol
|
||||||
|
gatCs = "73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049"
|
||||||
|
|
||||||
|
trValidator :: Validator
|
||||||
|
trValidator = mkValidator (treasuryValidator gatCs)
|
||||||
|
|
||||||
|
-- | `ScriptCredential` used for the dummy treasury validator.
|
||||||
|
trCredential :: Credential
|
||||||
|
trCredential = ScriptCredential $ validatorHash trValidator
|
||||||
|
|
||||||
|
-- | `TokenName` for GAT generated from address of `mockTrEffect`.
|
||||||
|
gatTn :: TokenName
|
||||||
|
gatTn = validatorHashToTokenName $ validatorHash mockTrEffect
|
||||||
|
|
||||||
|
-- | Mock treasury effect script, used for testing.
|
||||||
|
mockTrEffect :: Validator
|
||||||
|
mockTrEffect = mkValidator $ noOpValidator gatCs
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
|
||||||
|
minAda :: Value
|
||||||
|
minAda = Value.singleton "" "" 10_000_000
|
||||||
|
|
||||||
|
withMinAda :: Value -> Value
|
||||||
|
withMinAda v = v <> minAda
|
||||||
|
|
|
||||||
|
|
@ -9,27 +9,14 @@ This module contains sample data, used in the tests written in
|
||||||
`Spec.Treasury`.
|
`Spec.Treasury`.
|
||||||
-}
|
-}
|
||||||
module Spec.Sample.Treasury (
|
module Spec.Sample.Treasury (
|
||||||
BadTreasuryRedeemer (NukeTheSystem),
|
|
||||||
gatCs,
|
gatCs,
|
||||||
validCtx,
|
validCtx,
|
||||||
treasuryRef,
|
treasuryRef,
|
||||||
gatTn,
|
gatTn,
|
||||||
walletIn,
|
walletIn,
|
||||||
trCredential,
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Agora.Effect.NoOp (noOpValidator)
|
import Plutarch.Api.V1 (validatorHash)
|
||||||
import Agora.Treasury (
|
|
||||||
treasuryValidator,
|
|
||||||
)
|
|
||||||
import GHC.Generics qualified as GHC
|
|
||||||
import Generics.SOP (Generic, I (I))
|
|
||||||
import Plutarch.Api.V1 (mkValidator, validatorHash)
|
|
||||||
import Plutarch.DataRepr (
|
|
||||||
DerivePConstantViaData (..),
|
|
||||||
PIsDataReprInstances (..),
|
|
||||||
)
|
|
||||||
import Plutarch.Lift (PConstantDecl, PUnsafeLiftDecl (PLifted))
|
|
||||||
import Plutus.V1.Ledger.Address (Address (..))
|
import Plutus.V1.Ledger.Address (Address (..))
|
||||||
import Plutus.V1.Ledger.Api (
|
import Plutus.V1.Ledger.Api (
|
||||||
BuiltinByteString,
|
BuiltinByteString,
|
||||||
|
|
@ -47,26 +34,18 @@ import Plutus.V1.Ledger.Contexts (
|
||||||
import Plutus.V1.Ledger.Credential (Credential (ScriptCredential))
|
import Plutus.V1.Ledger.Credential (Credential (ScriptCredential))
|
||||||
import Plutus.V1.Ledger.Interval qualified as Interval
|
import Plutus.V1.Ledger.Interval qualified as Interval
|
||||||
import Plutus.V1.Ledger.Scripts (
|
import Plutus.V1.Ledger.Scripts (
|
||||||
Validator,
|
|
||||||
ValidatorHash (ValidatorHash),
|
ValidatorHash (ValidatorHash),
|
||||||
)
|
)
|
||||||
import Plutus.V1.Ledger.Value (
|
|
||||||
CurrencySymbol,
|
|
||||||
TokenName (TokenName),
|
|
||||||
)
|
|
||||||
import Plutus.V1.Ledger.Value qualified as Value
|
import Plutus.V1.Ledger.Value qualified as Value
|
||||||
import PlutusTx qualified
|
import Spec.Sample.Shared (
|
||||||
import Spec.Sample.Shared (signer)
|
gatCs,
|
||||||
import Spec.Util (datumPair, toDatumHash)
|
gatTn,
|
||||||
|
mockTrEffect,
|
||||||
{- | Arbitrary 'CurrencySymbol', representing the 'CurrencySymbol'
|
signer,
|
||||||
of a valid governance authority token (GAT).
|
treasuryOut,
|
||||||
-}
|
withMinAda,
|
||||||
gatCs :: CurrencySymbol
|
)
|
||||||
gatCs = "73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049"
|
import Spec.Util (datumPair)
|
||||||
|
|
||||||
trValidator :: Validator
|
|
||||||
trValidator = mkValidator (treasuryValidator gatCs)
|
|
||||||
|
|
||||||
{- | A `ScriptContext` that should be compatible with treasury
|
{- | A `ScriptContext` that should be compatible with treasury
|
||||||
transactions.
|
transactions.
|
||||||
|
|
@ -113,17 +92,11 @@ validCtx =
|
||||||
, txInInfoResolved =
|
, txInInfoResolved =
|
||||||
TxOut
|
TxOut
|
||||||
{ txOutAddress =
|
{ txOutAddress =
|
||||||
Address (ScriptCredential $ validatorHash mockEffect) Nothing
|
Address (ScriptCredential $ validatorHash mockTrEffect) Nothing
|
||||||
, txOutValue = Value.singleton gatCs gatTn 1
|
, txOutValue = withMinAda $ Value.singleton gatCs gatTn 1
|
||||||
, txOutDatumHash = Just (toDatumHash ())
|
, txOutDatumHash = Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
treasuryOut :: TxOut =
|
|
||||||
TxOut
|
|
||||||
{ txOutAddress = Address trCredential Nothing
|
|
||||||
, txOutValue = Value.singleton "" "" 0
|
|
||||||
, txOutDatumHash = Just (toDatumHash ())
|
|
||||||
}
|
|
||||||
|
|
||||||
-- | Reference to treasury output.
|
-- | Reference to treasury output.
|
||||||
treasuryRef :: TxOutRef
|
treasuryRef :: TxOutRef
|
||||||
|
|
@ -139,22 +112,6 @@ effectRef =
|
||||||
"52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3"
|
"52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3"
|
||||||
0
|
0
|
||||||
|
|
||||||
-- | `ScriptCredential` used for the dummy treasury validator.
|
|
||||||
trCredential :: Credential
|
|
||||||
trCredential = ScriptCredential $ validatorHash trValidator
|
|
||||||
|
|
||||||
-- | Mock effect script, used for testing.
|
|
||||||
mockEffect :: Validator
|
|
||||||
mockEffect = mkValidator $ noOpValidator gatCs
|
|
||||||
|
|
||||||
-- | The hash of the mock effect script.
|
|
||||||
addressBs :: BuiltinByteString
|
|
||||||
(ValidatorHash addressBs) = validatorHash mockEffect
|
|
||||||
|
|
||||||
-- | `TokenName` for GAT generated from address of `mockEffect`.
|
|
||||||
gatTn :: TokenName
|
|
||||||
gatTn = TokenName addressBs
|
|
||||||
|
|
||||||
-- | Input representing a user wallet with a valid GAT.
|
-- | Input representing a user wallet with a valid GAT.
|
||||||
walletIn :: TxInInfo
|
walletIn :: TxInInfo
|
||||||
walletIn =
|
walletIn =
|
||||||
|
|
@ -174,33 +131,5 @@ walletIn =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Unsupported treasury redeemer.
|
addressBs :: BuiltinByteString
|
||||||
newtype BadTreasuryRedeemer
|
(ValidatorHash addressBs) = validatorHash mockTrEffect
|
||||||
= -- | Unsupported treasury redeemer.
|
|
||||||
NukeTheSystem Integer
|
|
||||||
deriving stock (Eq, Show, GHC.Generic)
|
|
||||||
|
|
||||||
PlutusTx.makeIsDataIndexed
|
|
||||||
''BadTreasuryRedeemer
|
|
||||||
[ ('NukeTheSystem, 0)
|
|
||||||
]
|
|
||||||
|
|
||||||
-- | Plutarch implementation of `BadTreasuryRedeemer`.
|
|
||||||
newtype PBadTreasuryRedeemer (s :: S)
|
|
||||||
= PNukeTheSystem (Term s (PDataRecord '["_0" ':= PInteger]))
|
|
||||||
deriving stock (GHC.Generic)
|
|
||||||
deriving anyclass (Generic)
|
|
||||||
deriving anyclass (PIsDataRepr)
|
|
||||||
deriving
|
|
||||||
(PlutusType, PIsData)
|
|
||||||
via PIsDataReprInstances PBadTreasuryRedeemer
|
|
||||||
|
|
||||||
instance PUnsafeLiftDecl PBadTreasuryRedeemer where
|
|
||||||
type PLifted PBadTreasuryRedeemer = BadTreasuryRedeemer
|
|
||||||
deriving via
|
|
||||||
( DerivePConstantViaData
|
|
||||||
BadTreasuryRedeemer
|
|
||||||
PBadTreasuryRedeemer
|
|
||||||
)
|
|
||||||
instance
|
|
||||||
(PConstantDecl BadTreasuryRedeemer)
|
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,15 @@ import Plutus.V1.Ledger.Scripts (
|
||||||
ValidatorHash (ValidatorHash),
|
ValidatorHash (ValidatorHash),
|
||||||
)
|
)
|
||||||
import Plutus.V1.Ledger.Value qualified as Value
|
import Plutus.V1.Ledger.Value qualified as Value
|
||||||
|
|
||||||
|
-- BadTreasuryRedeemer (NukeTheSystem),
|
||||||
|
|
||||||
|
import Spec.Sample.Shared (
|
||||||
|
trCredential,
|
||||||
|
)
|
||||||
import Spec.Sample.Treasury (
|
import Spec.Sample.Treasury (
|
||||||
-- BadTreasuryRedeemer (NukeTheSystem),
|
|
||||||
gatCs,
|
gatCs,
|
||||||
gatTn,
|
gatTn,
|
||||||
trCredential,
|
|
||||||
treasuryRef,
|
treasuryRef,
|
||||||
validCtx,
|
validCtx,
|
||||||
walletIn,
|
walletIn,
|
||||||
|
|
@ -104,14 +108,7 @@ tests =
|
||||||
StakingHash trCredential
|
StakingHash trCredential
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
, -- , validatorFailsWith -- TODO: Check.
|
, validatorFailsWith -- TODO: Use QuickCheck.
|
||||||
-- "Fails with invalid redeemer"
|
|
||||||
-- (treasuryValidator gatCs)
|
|
||||||
-- ()
|
|
||||||
-- (NukeTheSystem 72)
|
|
||||||
-- validCtx
|
|
||||||
|
|
||||||
validatorFailsWith -- TODO: Use QuickCheck.
|
|
||||||
"Fails when multiple GATs burned"
|
"Fails when multiple GATs burned"
|
||||||
(treasuryValidator gatCs)
|
(treasuryValidator gatCs)
|
||||||
()
|
()
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@ common deps
|
||||||
|
|
||||||
common test-deps
|
common test-deps
|
||||||
build-depends:
|
build-depends:
|
||||||
|
, agora
|
||||||
, apropos
|
, apropos
|
||||||
, apropos-tx
|
, apropos-tx
|
||||||
, lens
|
, lens
|
||||||
|
|
@ -137,11 +138,10 @@ library
|
||||||
Agora.Stake
|
Agora.Stake
|
||||||
Agora.Stake.Scripts
|
Agora.Stake.Scripts
|
||||||
Agora.Treasury
|
Agora.Treasury
|
||||||
|
|
||||||
other-modules:
|
|
||||||
Agora.Utils
|
Agora.Utils
|
||||||
Agora.Utils.Value
|
Agora.Utils.Value
|
||||||
|
|
||||||
|
other-modules:
|
||||||
hs-source-dirs: agora
|
hs-source-dirs: agora
|
||||||
|
|
||||||
library pprelude
|
library pprelude
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue