diff --git a/e2e-tests/test/PlutusScripts/TreasurySpec.hs b/e2e-tests/test/PlutusScripts/TreasurySpec.hs new file mode 100644 index 0000000..f13bb50 --- /dev/null +++ b/e2e-tests/test/PlutusScripts/TreasurySpec.hs @@ -0,0 +1,60 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} + +module PlutusV3.TreasurySpec where + +import Test.Hspec +import Plutus.V3.Ledger.Api +import Plutus.V3.Ledger.Contexts +import PlutusTx.Prelude hiding (pure, (<$>)) +import Ledger.Value (Value, singleton) +import Ledger (TxInfo(..)) + +-- Wrapper to get treasury +txInfoCurrentTreasuryAmount :: TxInfo -> Maybe Value +txInfoCurrentTreasuryAmount = txInfoTreasury + +-- Mock transaction without treasury +mockTxInfoNoTreasury :: TxInfo +mockTxInfoNoTreasury = TxInfo + { txInfoInputs = [] + , txInfoOutputs = [] + , txInfoFee = mempty + , txInfoMint = mempty + , txInfoDCert = [] + , txInfoWdrl = mempty + , txInfoValidRange = always + , txInfoSignatories = [] + , txInfoData = [] + , txInfoId = "dummy" + , txInfoTreasury = Nothing + } + +-- Mock transaction with treasury +mockTxInfoWithTreasury :: Value -> TxInfo +mockTxInfoWithTreasury val = TxInfo + { txInfoInputs = [] + , txInfoOutputs = [] + , txInfoFee = mempty + , txInfoMint = mempty + , txInfoDCert = [] + , txInfoWdrl = mempty + , txInfoValidRange = always + , txInfoSignatories = [] + , txInfoData = [] + , txInfoId = "dummy" + , txInfoTreasury = Just val + } + +-- Tests +spec :: Spec +spec = do + describe "txInfoCurrentTreasuryAmount Tests" $ do + + it "returns Nothing when treasury is not exposed" $ do + txInfoCurrentTreasuryAmount mockTxInfoNoTreasury `shouldBe` Nothing + + it "returns Just Value when treasury is exposed" $ do + let val = singleton "ada" "lovelace" 1000 + txInfoCurrentTreasuryAmount (mockTxInfoWithTreasury val) `shouldBe` Just val \ No newline at end of file