From 0464a03989e7025d43bf64154afdbd1cd8c4a0b6 Mon Sep 17 00:00:00 2001 From: Seungheon Oh Date: Tue, 19 Apr 2022 23:02:51 -0400 Subject: [PATCH] now proper a proper script context.. and some formatting fixes --- .../Spec/Effect/TreasuryWithdrawalEffect.hs | 56 ++++++++++++++----- agora/Agora/Effect/TreasuryWithdrawal.hs | 6 +- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/agora-test/Spec/Effect/TreasuryWithdrawalEffect.hs b/agora-test/Spec/Effect/TreasuryWithdrawalEffect.hs index e8e3476..751a3bc 100644 --- a/agora-test/Spec/Effect/TreasuryWithdrawalEffect.hs +++ b/agora-test/Spec/Effect/TreasuryWithdrawalEffect.hs @@ -5,25 +5,21 @@ Description: Sample based testing for Treasury Withdrawal Effect This module tests the Treasury Withdrawal Effect. -} -module Spec.Effect.TreasuryWithdrawalEffect (currSymbol, signer, validator, validatorHashTN, withdrawalEffect) where +module Spec.Effect.TreasuryWithdrawalEffect (currSymbol, signer, validator, validatorHashTN, scriptContext1) where import Plutarch.Api.V1 import Plutus.V1.Ledger.Api import Plutus.V1.Ledger.Interval qualified as Interval import Plutus.V1.Ledger.Value qualified as Value +import Data.ByteString.Hash + import Agora.Effect.TreasuryWithdrawal ---receiverList :: TreasuryWithdrawalDatum ---receiverList = TreasuryWithdrawalDatum [(mempty, mempty)] +-- receiverList :: TreasuryWithdrawalDatum +-- receiverList = TreasuryWithdrawalDatum [(mempty, mempty)] -_datum :: TreasuryWithdrawalDatum -_datum = - TreasuryWithdrawalDatum - [ (PubKeyCredential signer, Value.singleton currSymbol validatorHashTN 1) - ] - --- | A sample Currency Symbol +-- | A sample Currency Symbol. currSymbol :: CurrencySymbol currSymbol = CurrencySymbol "Orangebottle19721121" @@ -31,6 +27,24 @@ currSymbol = CurrencySymbol "Orangebottle19721121" signer :: PubKeyHash signer = "8a30896c4fd5e79843e4ca1bd2cdbaa36f8c0bc3be7401214142019c" +-- | List of users who the effect will pay to. +users :: [Credential] +users = + PubKeyCredential . PubKeyHash . toBuiltin . sha2 + <$> [ "Hello world" + , "Hello Agora" + , "Hello Plutarch" + ] + +-- | Datum for Treasury Withdrawal Effect Validator. +_datum :: TreasuryWithdrawalDatum +_datum = + TreasuryWithdrawalDatum + [ (users !! 0, Value.singleton currSymbol validatorHashTN 1) + , (users !! 1, Value.singleton currSymbol validatorHashTN 1) + , (users !! 2, Value.singleton currSymbol validatorHashTN 1) + ] + -- | Effect validator instance. validator :: Validator validator = mkValidator $ treasuryWithdrawalValidator currSymbol @@ -39,8 +53,8 @@ validator = mkValidator $ treasuryWithdrawalValidator currSymbol validatorHashTN :: TokenName validatorHashTN = let ValidatorHash vh = validatorHash validator in TokenName vh -withdrawalEffect :: ScriptContext -withdrawalEffect = +scriptContext1 :: ScriptContext +scriptContext1 = ScriptContext { scriptContextTxInfo = TxInfo @@ -67,7 +81,23 @@ withdrawalEffect = , txOutDatumHash = Nothing } ] - , txInfoOutputs = [] + , txInfoOutputs = + [ TxOut + { txOutAddress = Address (users !! 0) Nothing + , txOutValue = Value.singleton currSymbol validatorHashTN 1 + , txOutDatumHash = Nothing + } + , TxOut + { txOutAddress = Address (users !! 1) Nothing + , txOutValue = Value.singleton currSymbol validatorHashTN 1 + , txOutDatumHash = Nothing + } + , TxOut + { txOutAddress = Address (users !! 2) Nothing + , txOutValue = Value.singleton currSymbol validatorHashTN 1 + , txOutDatumHash = Nothing + } + ] , txInfoFee = Value.singleton "" "" 2 , txInfoMint = mempty , txInfoDCert = [] diff --git a/agora/Agora/Effect/TreasuryWithdrawal.hs b/agora/Agora/Effect/TreasuryWithdrawal.hs index 536c0e3..1156a3c 100644 --- a/agora/Agora/Effect/TreasuryWithdrawal.hs +++ b/agora/Agora/Effect/TreasuryWithdrawal.hs @@ -8,10 +8,10 @@ Description: An Effect that withdraws treasury deposit An Effect that withdraws treasury deposit -} module Agora.Effect.TreasuryWithdrawal ( - TreasuryWithdrawalDatum(..), - PTreasuryWithdrawalDatum(..), + TreasuryWithdrawalDatum (..), + PTreasuryWithdrawalDatum (..), treasuryWithdrawalValidator, - ) where +) where import GHC.Generics qualified as GHC import Generics.SOP (Generic, I (I))