diff --git a/agora-test/Spec.hs b/agora-test/Spec.hs index 2d97c1e..3162fd8 100644 --- a/agora-test/Spec.hs +++ b/agora-test/Spec.hs @@ -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 diff --git a/agora-test/Spec/AuthorityToken.hs b/agora-test/Spec/AuthorityToken.hs index fdfda03..1ff3de2 100644 --- a/agora-test/Spec/AuthorityToken.hs +++ b/agora-test/Spec/AuthorityToken.hs @@ -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" diff --git a/agora-test/Spec/Effect/GovernorMutation.hs b/agora-test/Spec/Effect/GovernorMutation.hs index 18ed995..67cf59e 100644 --- a/agora-test/Spec/Effect/GovernorMutation.hs +++ b/agora-test/Spec/Effect/GovernorMutation.hs @@ -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" diff --git a/agora-test/Spec/Effect/TreasuryWithdrawal.hs b/agora-test/Spec/Effect/TreasuryWithdrawal.hs index a380edb..9a6a485 100644 --- a/agora-test/Spec/Effect/TreasuryWithdrawal.hs +++ b/agora-test/Spec/Effect/TreasuryWithdrawal.hs @@ -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" diff --git a/agora-test/Spec/Governor.hs b/agora-test/Spec/Governor.hs index 3ac39a2..3cbcb57 100644 --- a/agora-test/Spec/Governor.hs +++ b/agora-test/Spec/Governor.hs @@ -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" diff --git a/agora-test/Spec/Proposal.hs b/agora-test/Spec/Proposal.hs index c381126..c57fb78 100644 --- a/agora-test/Spec/Proposal.hs +++ b/agora-test/Spec/Proposal.hs @@ -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" diff --git a/agora-test/Spec/Stake.hs b/agora-test/Spec/Stake.hs index 3a3eacd..3b1ac09 100644 --- a/agora-test/Spec/Stake.hs +++ b/agora-test/Spec/Stake.hs @@ -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" diff --git a/agora-test/Spec/Treasury.hs b/agora-test/Spec/Treasury.hs index 0cd139f..03db77d 100644 --- a/agora-test/Spec/Treasury.hs +++ b/agora-test/Spec/Treasury.hs @@ -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" diff --git a/agora.cabal b/agora.cabal index 256e025..8677046 100644 --- a/agora.cabal +++ b/agora.cabal @@ -191,6 +191,7 @@ test-suite agora-test Spec.Governor Spec.Model.MultiSig Spec.Proposal + Spec.Spec Spec.Stake Spec.Treasury Spec.Utils