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 efca275f29
commit 4b56edb25c
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) import Test.Tasty (defaultMain, testGroup)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -16,39 +17,26 @@ import Spec.Stake qualified as Stake
import Spec.Treasury qualified as Treasury import Spec.Treasury qualified as Treasury
import Spec.Utils qualified as Utils import Spec.Utils qualified as Utils
import Spec.Spec (group, toTestTree)
-- | The Agora test suite. -- | The Agora test suite.
main :: IO () main :: IO ()
main = main = do
setLocaleEncoding utf8
defaultMain $ defaultMain $
testGroup testGroup
"test suite" "test suite"
[ testGroup [ testGroup
"Effects" "Effects"
[ testGroup [ toTestTree $ group "Treasury Withdrawal Effect" TreasuryWithdrawal.specs
"Treasury Withdrawal Effect" , toTestTree $ group "Governor Mutation Effect" GovernorMutation.specs
TreasuryWithdrawal.tests
, testGroup
"Governor Mutation Effect"
GovernorMutation.tests
] ]
, testGroup , toTestTree $ group "Stake tests" Stake.specs
"Stake tests" , toTestTree $ group "Proposal tests" Proposal.specs
Stake.tests , toTestTree $ group "AuthorityToken tests" AuthorityToken.specs
, testGroup , toTestTree $ group "Treasury tests" Treasury.specs
"Proposal tests" , toTestTree $ group "AuthorityToken tests" AuthorityToken.specs
Proposal.tests , toTestTree $ group "Governor tests" Governor.specs
, testGroup
"AuthorityToken tests"
AuthorityToken.tests
, testGroup
"Treasury tests"
Treasury.tests
, testGroup
"AuthorityToken tests"
AuthorityToken.tests
, testGroup
"Governor tests"
Governor.tests
, testGroup , testGroup
"Utility tests" "Utility tests"
Utils.tests Utils.tests

View file

@ -7,13 +7,12 @@ Description: Tests for Authority token functions
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 Agora.AuthorityToken (singleAuthorityTokenBurned)
import Plutarch import Plutarch
import Test.Tasty (TestTree, testGroup)
import Prelude import Prelude
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -33,7 +32,12 @@ import Plutus.V1.Ledger.Api (
import Plutus.V1.Ledger.Interval qualified as Interval import Plutus.V1.Ledger.Interval qualified as Interval
import Plutus.V1.Ledger.Value qualified as Value import Plutus.V1.Ledger.Value qualified as Value
import PlutusTx.AssocMap qualified as AssocMap import PlutusTx.AssocMap qualified as AssocMap
import Test.Util (scriptFails, scriptSucceeds) import Spec.Spec (
SpecificationTree,
group,
scriptFails,
scriptSucceeds,
)
currencySymbol :: CurrencySymbol currencySymbol :: CurrencySymbol
currencySymbol = "deadbeef" currencySymbol = "deadbeef"
@ -65,10 +69,10 @@ singleAuthorityTokenBurnedTest mint outs =
perror perror
in compile s in compile s
tests :: [TestTree] specs :: [SpecificationTree]
tests = specs =
[ -- This is better suited for plutarch-test [ -- This is better suited for plutarch-test
testGroup group
"singleAuthorityTokenBurned" "singleAuthorityTokenBurned"
[ scriptSucceeds [ scriptSucceeds
"Correct simple" "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.Effect.GovernorMutation (mutateGovernorValidator)
import Agora.Governor (GovernorDatum (..), GovernorRedeemer (MutateGovernor)) import Agora.Governor (GovernorDatum (..), GovernorRedeemer (MutateGovernor))
@ -15,14 +15,20 @@ import Sample.Effect.GovernorMutation (
validNewGovernorDatum, validNewGovernorDatum,
) )
import Sample.Shared qualified as Shared import Sample.Shared qualified as Shared
import Test.Tasty (TestTree, testGroup) import Spec.Spec (
import Test.Util (effectFailsWith, effectSucceedsWith, validatorFailsWith, validatorSucceedsWith) SpecificationTree,
effectFailsWith,
effectSucceedsWith,
group,
validatorFailsWith,
validatorSucceedsWith,
)
tests :: [TestTree] specs :: [SpecificationTree]
tests = specs =
[ testGroup [ group
"validator" "validator"
[ testGroup [ group
"valid new governor datum" "valid new governor datum"
[ validatorSucceedsWith [ validatorSucceedsWith
"governor validator should pass" "governor validator should pass"
@ -44,7 +50,7 @@ tests =
(mkEffectDatum validNewGovernorDatum) (mkEffectDatum validNewGovernorDatum)
(ScriptContext (mkEffectTxInfo validNewGovernorDatum) (Spending effectRef)) (ScriptContext (mkEffectTxInfo validNewGovernorDatum) (Spending effectRef))
] ]
, testGroup , group
"invalid new governor datum" "invalid new governor datum"
[ validatorFailsWith [ validatorFailsWith
"governor validator should fail" "governor validator should fail"

View file

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

View file

@ -3,7 +3,7 @@ Module : Spec.Governor
Maintainer : connor@mlabs.city Maintainer : connor@mlabs.city
Description: Tests for Agora governor. 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. that Agora's governor component workds as intended.
Tests should pass when the validator or policy is given one of the 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). 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 (GovernorDatum (..), GovernorRedeemer (..))
import Agora.Governor.Scripts (governorPolicy, governorValidator) import Agora.Governor.Scripts (governorPolicy, governorValidator)
@ -19,14 +19,18 @@ import Agora.Proposal (ProposalId (..))
import Data.Default.Class (Default (def)) import Data.Default.Class (Default (def))
import Sample.Governor (createProposal, mintGATs, mintGST, mutateState) import Sample.Governor (createProposal, mintGATs, mintGST, mutateState)
import Sample.Shared qualified as Shared import Sample.Shared qualified as Shared
import Test.Tasty (TestTree, testGroup) import Spec.Spec (
import Test.Util (policySucceedsWith, validatorSucceedsWith) SpecificationTree,
group,
policySucceedsWith,
validatorSucceedsWith,
)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
tests :: [TestTree] specs :: [SpecificationTree]
tests = specs =
[ testGroup [ group
"policy" "policy"
[ policySucceedsWith [ policySucceedsWith
"GST minting" "GST minting"
@ -34,7 +38,7 @@ tests =
() ()
mintGST mintGST
] ]
, testGroup , group
"validator" "validator"
[ validatorSucceedsWith [ validatorSucceedsWith
"proposal creation" "proposal creation"

View file

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

View file

@ -7,7 +7,7 @@ Description: Tests for Stake policy and validator
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 (Stake (..), StakeDatum (StakeDatum), StakeRedeemer (DepositWithdraw))
import Agora.Stake.Scripts (stakePolicy, stakeValidator) 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 (DepositWithdrawExample (DepositWithdrawExample, delta, startAmount), signer)
import Sample.Stake qualified as Stake 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. specs :: [SpecificationTree]
tests :: [TestTree] specs =
tests = [ group
[ testGroup
"policy" "policy"
[ policySucceedsWith [ policySucceedsWith
"stakeCreation" "stakeCreation"
@ -51,7 +54,7 @@ tests =
() ()
Stake.stakeCreationUnsigned Stake.stakeCreationUnsigned
] ]
, testGroup , group
"validator" "validator"
[ validatorSucceedsWith [ validatorSucceedsWith
"stakeDepositWithdraw deposit" "stakeDepositWithdraw deposit"

View file

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

View file

@ -191,6 +191,7 @@ test-suite agora-test
Spec.Governor Spec.Governor
Spec.Model.MultiSig Spec.Model.MultiSig
Spec.Proposal Spec.Proposal
Spec.Spec
Spec.Stake Spec.Stake
Spec.Treasury Spec.Treasury
Spec.Utils Spec.Utils