Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions e2e-tests/test/PlutusScripts/TreasurySpec.hs
Original file line number Diff line number Diff line change
@@ -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