|
| 1 | +{-# LANGUAGE BlockArguments #-} |
| 2 | +{-# LANGUAGE DataKinds #-} |
| 3 | +{-# LANGUAGE MultiParamTypeClasses #-} |
| 4 | +{-# LANGUAGE NamedFieldPuns #-} |
| 5 | +{-# LANGUAGE NoImplicitPrelude #-} |
| 6 | +{-# LANGUAGE OverloadedStrings #-} |
| 7 | +{-# LANGUAGE Strict #-} |
| 8 | + |
| 9 | +module CardanoLoans.Test where |
| 10 | + |
| 11 | +import PlutusTx |
| 12 | +import PlutusTx.Prelude |
| 13 | + |
| 14 | +import CardanoLoans.Validator (LoanDatum (..), LoanRedeemer (..), loanValidatorCode) |
| 15 | +import PlutusLedgerApi.V1.Address (pubKeyHashAddress) |
| 16 | +import PlutusLedgerApi.V1.Value qualified as Value |
| 17 | +import PlutusLedgerApi.V2.Tx qualified as Tx |
| 18 | +import PlutusLedgerApi.V3 |
| 19 | +import PlutusTx.AssocMap qualified as Map |
| 20 | + |
| 21 | +validatorCodeFullyApplied :: CompiledCode BuiltinUnit |
| 22 | +validatorCodeFullyApplied = |
| 23 | + loanValidatorCode `unsafeApplyCode` liftCodeDef (toBuiltinData testScriptContext) |
| 24 | + |
| 25 | +testScriptContext :: ScriptContext |
| 26 | +testScriptContext = |
| 27 | + ScriptContext |
| 28 | + { scriptContextTxInfo = txInfo |
| 29 | + , scriptContextRedeemer |
| 30 | + , scriptContextScriptInfo |
| 31 | + } |
| 32 | + where |
| 33 | + txInfo = |
| 34 | + TxInfo |
| 35 | + { txInfoInputs = |
| 36 | + [ |
| 37 | + TxInInfo |
| 38 | + { txInInfoOutRef = txOutRef |
| 39 | + , txInInfoResolved = Tx.pubKeyHashTxOut (Value.lovelaceValue 1000) testBeneficiaryPKH |
| 40 | + } |
| 41 | + ] |
| 42 | + , txInfoReferenceInputs = mempty |
| 43 | + , txInfoOutputs = [ |
| 44 | + TxOut |
| 45 | + { txOutAddress = pubKeyHashAddress testBeneficiaryPKH |
| 46 | + , txOutValue = Value.lovelaceValue 1000 |
| 47 | + , txOutDatum = NoOutputDatum |
| 48 | + , txOutReferenceScript = Nothing |
| 49 | + } |
| 50 | + ] |
| 51 | + , txInfoTxCerts = mempty |
| 52 | + , txInfoRedeemers = Map.empty |
| 53 | + , txInfoVotes = Map.empty |
| 54 | + , txInfoProposalProcedures = mempty |
| 55 | + , txInfoCurrentTreasuryAmount = Nothing |
| 56 | + , txInfoTreasuryDonation = Nothing |
| 57 | + , txInfoFee = 0 |
| 58 | + , txInfoMint = emptyMintValue |
| 59 | + , txInfoWdrl = Map.empty |
| 60 | + , txInfoValidRange = |
| 61 | + Interval |
| 62 | + (LowerBound (Finite 110) True) |
| 63 | + (UpperBound (Finite 1100) True) |
| 64 | + , txInfoSignatories = [testBeneficiaryPKH] |
| 65 | + , txInfoData = Map.empty |
| 66 | + , txInfoId = "058fdca70be67c74151cea3846be7f73342d92c0090b62c1052e6790ad83f145" |
| 67 | + } |
| 68 | + |
| 69 | + scriptContextRedeemer :: Redeemer |
| 70 | + scriptContextRedeemer = Redeemer $ toBuiltinData CloseAsk |
| 71 | + |
| 72 | + txOutRef :: TxOutRef |
| 73 | + txOutRef = TxOutRef txOutRefId txOutRefIdx |
| 74 | + where |
| 75 | + txOutRefId = "058fdca70be67c74151cea3846be7f73342d92c0090b62c1052e6790ad83f145" |
| 76 | + txOutRefIdx = 0 |
| 77 | + |
| 78 | + scriptContextScriptInfo :: ScriptInfo |
| 79 | + scriptContextScriptInfo = SpendingScript txOutRef (Just datum) |
| 80 | + where |
| 81 | + datum :: Datum |
| 82 | + datum = Datum (toBuiltinData testLoanDatum) |
| 83 | + |
| 84 | +testLoanDatum :: LoanDatum |
| 85 | +testLoanDatum = askDatum |
| 86 | + where |
| 87 | + testCurSym :: CurrencySymbol |
| 88 | + testCurSym = CurrencySymbol "mysymbol" |
| 89 | + |
| 90 | + testTokName :: TokenName |
| 91 | + testTokName = TokenName "mytoken" |
| 92 | + |
| 93 | + askDatum :: LoanDatum |
| 94 | + askDatum = AskDatum |
| 95 | + { collateral = [(testCurSym, testTokName)] |
| 96 | + , askBeacon = (testCurSym, testTokName) |
| 97 | + , borrowerId = (testCurSym, testTokName) |
| 98 | + , loanAsset = (testCurSym, testTokName) |
| 99 | + , loanPrinciple = 10 |
| 100 | + , loanTerm = 10 |
| 101 | + } |
| 102 | + |
| 103 | +testBeneficiaryPKH :: PubKeyHash |
| 104 | +testBeneficiaryPKH = PubKeyHash "" |
0 commit comments