Specs use generalized format so that it can be used for benchmarking

This commit is contained in:
Seungheon Oh 2022-05-24 13:09:58 -05:00
parent c51b8fa9de
commit ff91432a68
No known key found for this signature in database
GPG key ID: 9B0E12D357369B66
9 changed files with 103 additions and 85 deletions

View file

@ -2,6 +2,7 @@ import Prelude
--------------------------------------------------------------------------------
import GHC.IO.Encoding (setLocaleEncoding, utf8)
import Test.Tasty (defaultMain, testGroup)
--------------------------------------------------------------------------------
@ -16,39 +17,26 @@ import Spec.Stake qualified as Stake
import Spec.Treasury qualified as Treasury
import Spec.Utils qualified as Utils
import Spec.Spec (group, toTestTree)
-- | The Agora test suite.
main :: IO ()
main =
main = do
setLocaleEncoding utf8
defaultMain $
testGroup
"test suite"
[ testGroup
"Effects"
[ testGroup
"Treasury Withdrawal Effect"
TreasuryWithdrawal.tests
, testGroup
"Governor Mutation Effect"
GovernorMutation.tests
[ toTestTree $ group "Treasury Withdrawal Effect" TreasuryWithdrawal.specs
, toTestTree $ group "Governor Mutation Effect" GovernorMutation.specs
]
, testGroup
"Stake tests"
Stake.tests
, testGroup
"Proposal tests"
Proposal.tests
, testGroup
"AuthorityToken tests"
AuthorityToken.tests
, testGroup
"Treasury tests"
Treasury.tests
, testGroup
"AuthorityToken tests"
AuthorityToken.tests
, testGroup
"Governor tests"
Governor.tests
, toTestTree $ group "Stake tests" Stake.specs
, toTestTree $ group "Proposal tests" Proposal.specs
, toTestTree $ group "AuthorityToken tests" AuthorityToken.specs
, toTestTree $ group "Treasury tests" Treasury.specs
, toTestTree $ group "AuthorityToken tests" AuthorityToken.specs
, toTestTree $ group "Governor tests" Governor.specs
, testGroup
"Utility tests"
Utils.tests

View file

@ -7,13 +7,12 @@ Description: Tests for Authority token functions
Tests for Authority token functions
-}
module Spec.AuthorityToken (tests) where
module Spec.AuthorityToken (specs) where
--------------------------------------------------------------------------------
import Agora.AuthorityToken (singleAuthorityTokenBurned)
import Plutarch
import Test.Tasty (TestTree, testGroup)
import Prelude
--------------------------------------------------------------------------------
@ -33,7 +32,12 @@ import Plutus.V1.Ledger.Api (
import Plutus.V1.Ledger.Interval qualified as Interval
import Plutus.V1.Ledger.Value qualified as Value
import PlutusTx.AssocMap qualified as AssocMap
import Test.Util (scriptFails, scriptSucceeds)
import Spec.Spec (
SpecificationTree,
group,
scriptFails,
scriptSucceeds,
)
currencySymbol :: CurrencySymbol
currencySymbol = "deadbeef"
@ -65,10 +69,10 @@ singleAuthorityTokenBurnedTest mint outs =
perror
in compile s
tests :: [TestTree]
tests =
specs :: [SpecificationTree]
specs =
[ -- This is better suited for plutarch-test
testGroup
group
"singleAuthorityTokenBurned"
[ scriptSucceeds
"Correct simple"

View file

@ -1,4 +1,4 @@
module Spec.Effect.GovernorMutation (tests) where
module Spec.Effect.GovernorMutation (specs) where
import Agora.Effect.GovernorMutation (mutateGovernorValidator)
import Agora.Governor (GovernorDatum (..), GovernorRedeemer (MutateGovernor))
@ -15,14 +15,20 @@ import Sample.Effect.GovernorMutation (
validNewGovernorDatum,
)
import Sample.Shared qualified as Shared
import Test.Tasty (TestTree, testGroup)
import Test.Util (effectFailsWith, effectSucceedsWith, validatorFailsWith, validatorSucceedsWith)
import Spec.Spec (
SpecificationTree,
effectFailsWith,
effectSucceedsWith,
group,
validatorFailsWith,
validatorSucceedsWith,
)
tests :: [TestTree]
tests =
[ testGroup
specs :: [SpecificationTree]
specs =
[ group
"validator"
[ testGroup
[ group
"valid new governor datum"
[ validatorSucceedsWith
"governor validator should pass"
@ -44,7 +50,7 @@ tests =
(mkEffectDatum validNewGovernorDatum)
(ScriptContext (mkEffectTxInfo validNewGovernorDatum) (Spending effectRef))
]
, testGroup
, group
"invalid new governor datum"
[ validatorFailsWith
"governor validator should fail"

View file

@ -3,9 +3,9 @@ Module : Spec.Effect.TreasuryWithdrawalEffect
Maintainer : seungheon.ooh@gmail.com
Description: Sample based testing for Treasury Withdrawal Effect
This module tests the Treasury Withdrawal Effect.
This module specs the Treasury Withdrawal Effect.
-}
module Spec.Effect.TreasuryWithdrawal (tests) where
module Spec.Effect.TreasuryWithdrawal (specs) where
import Agora.Effect.TreasuryWithdrawal (
TreasuryWithdrawalDatum (TreasuryWithdrawalDatum),
@ -25,12 +25,16 @@ import Sample.Effect.TreasuryWithdrawal (
treasuries,
users,
)
import Test.Tasty (TestTree, testGroup)
import Test.Util (effectFailsWith, effectSucceedsWith)
import Spec.Spec (
SpecificationTree,
effectFailsWith,
effectSucceedsWith,
group,
)
tests :: [TestTree]
tests =
[ testGroup
specs :: [SpecificationTree]
specs =
[ group
"effect"
[ effectSucceedsWith
"Simple"

View file

@ -3,7 +3,7 @@ Module : Spec.Governor
Maintainer : connor@mlabs.city
Description: Tests for Agora governor.
Thie module exports `tests`, a list of `TestTree`s, which ensure
Thie module exports `specs`, a list of `TestTree`s, which ensure
that Agora's governor component workds as intended.
Tests should pass when the validator or policy is given one of the
@ -11,7 +11,7 @@ valid script contexts, which are defined in 'Agora.Sample.Governor'.
TODO: Add negative test cases, see [#76](https://github.com/Liqwid-Labs/agora/issues/76).
-}
module Spec.Governor (tests) where
module Spec.Governor (specs) where
import Agora.Governor (GovernorDatum (..), GovernorRedeemer (..))
import Agora.Governor.Scripts (governorPolicy, governorValidator)
@ -19,14 +19,18 @@ import Agora.Proposal (ProposalId (..))
import Data.Default.Class (Default (def))
import Sample.Governor (createProposal, mintGATs, mintGST, mutateState)
import Sample.Shared qualified as Shared
import Test.Tasty (TestTree, testGroup)
import Test.Util (policySucceedsWith, validatorSucceedsWith)
import Spec.Spec (
SpecificationTree,
group,
policySucceedsWith,
validatorSucceedsWith,
)
--------------------------------------------------------------------------------
tests :: [TestTree]
tests =
[ testGroup
specs :: [SpecificationTree]
specs =
[ group
"policy"
[ policySucceedsWith
"GST minting"
@ -34,7 +38,7 @@ tests =
()
mintGST
]
, testGroup
, group
"validator"
[ validatorSucceedsWith
"proposal creation"

View file

@ -7,7 +7,7 @@ Description: Tests for Proposal policy and validator
Tests for Proposal policy and validator
-}
module Spec.Proposal (tests) where
module Spec.Proposal (specs) where
--------------------------------------------------------------------------------
@ -45,15 +45,19 @@ import PlutusTx.AssocMap qualified as AssocMap
import Sample.Proposal qualified as Proposal
import Sample.Shared (signer, signer2)
import Sample.Shared qualified as Shared
import Test.Tasty (TestTree, testGroup)
import Test.Util (policySucceedsWith, validatorSucceedsWith)
import Spec.Spec (
SpecificationTree,
group,
policySucceedsWith,
validatorSucceedsWith,
)
--------------------------------------------------------------------------------
-- | Stake tests.
tests :: [TestTree]
tests =
[ testGroup
-- | Stake specs.
specs :: [SpecificationTree]
specs =
[ group
"policy"
[ policySucceedsWith
"proposalCreation"
@ -61,9 +65,9 @@ tests =
()
Proposal.proposalCreation
]
, testGroup
, group
"validator"
[ testGroup
[ group
"cosignature"
[ validatorSucceedsWith
"proposal"
@ -97,7 +101,7 @@ tests =
WitnessStake
(ScriptContext (Proposal.cosignProposal [signer2]) (Spending Proposal.stakeRef))
]
, testGroup
, group
"voting"
[ validatorSucceedsWith
"proposal"

View file

@ -7,7 +7,7 @@ Description: Tests for Stake policy and validator
Tests for Stake policy and validator
-}
module Spec.Stake (tests) where
module Spec.Stake (specs) where
--------------------------------------------------------------------------------
@ -15,10 +15,6 @@ import Prelude
--------------------------------------------------------------------------------
import Test.Tasty (TestTree, testGroup)
--------------------------------------------------------------------------------
import Agora.Stake (Stake (..), StakeDatum (StakeDatum), StakeRedeemer (DepositWithdraw))
import Agora.Stake.Scripts (stakePolicy, stakeValidator)
@ -26,14 +22,21 @@ import Agora.Stake.Scripts (stakePolicy, stakeValidator)
import Sample.Stake (DepositWithdrawExample (DepositWithdrawExample, delta, startAmount), signer)
import Sample.Stake qualified as Stake
import Test.Util (policyFailsWith, policySucceedsWith, toDatum, validatorFailsWith, validatorSucceedsWith)
import Spec.Spec (
SpecificationTree,
group,
policyFailsWith,
policySucceedsWith,
validatorFailsWith,
validatorSucceedsWith,
)
import Test.Util (toDatum)
--------------------------------------------------------------------------------
-- | Stake tests.
tests :: [TestTree]
tests =
[ testGroup
specs :: [SpecificationTree]
specs =
[ group
"policy"
[ policySucceedsWith
"stakeCreation"
@ -51,7 +54,7 @@ tests =
()
Stake.stakeCreationUnsigned
]
, testGroup
, group
"validator"
[ validatorSucceedsWith
"stakeDepositWithdraw deposit"

View file

@ -5,7 +5,7 @@ Module: Spec.Treasury
Description: Tests for Agora treasury.
Maintainer: jack@mlabs.city
This module exports `tests`, a list of `TestTree`s, which ensure
This module exports `specs`, a list of `TestTree`s, which ensure
that Agora's treasury component works as desired.
Tests need to fail when:
@ -19,7 +19,7 @@ Tests need to fail when:
ii. A script has a GAT, the token name for which does /not/
match the script's validator hash.
-}
module Spec.Treasury (tests) where
module Spec.Treasury (specs) where
import Agora.Treasury (
TreasuryRedeemer (SpendTreasuryGAT),
@ -48,14 +48,18 @@ import Sample.Treasury (
validCtx,
walletIn,
)
import Test.Tasty (TestTree, testGroup)
import Test.Util (validatorFailsWith, validatorSucceedsWith)
import Spec.Spec (
SpecificationTree,
group,
validatorFailsWith,
validatorSucceedsWith,
)
tests :: [TestTree]
tests =
[ testGroup
specs :: [SpecificationTree]
specs =
[ group
"Validator"
[ testGroup
[ group
"Positive"
[ validatorSucceedsWith
"Allows for effect changes"
@ -64,9 +68,9 @@ tests =
SpendTreasuryGAT
validCtx
]
, testGroup
, group
"Negative"
[ testGroup
[ group
"Fails with ScriptPurpose not Minting"
[ validatorFailsWith
"Spending"