Lib
{-# OPTIONS --safe #-}
open import Ledger.Prelude hiding (fromList; ε; _/_)
open import Test.LedgerImplementation using (SVTransactionStructure)
import Ledger.Conway.Specification.Script.ScriptPurpose as SP
module Test.Lib
{T D : Set}{{DecEq-Data : DecEq D}}{{Show-Data : Show D}}
(open SP (SVTransactionStructure T D) using (TxInfo; ScriptPurpose))
(valContext' : TxInfo → ScriptPurpose → D)
where
open import Test.AbstractImplementation valContext'
open import Test.LedgerImplementation T D
renaming (SVTransactionStructure to SVTransactionStructure')
open import Ledger.Conway.Specification.Utxo SVTransactionStructure' SVAbstractFunctions
open import Ledger.Conway.Specification.Transaction using (TransactionStructure)
open TransactionStructure SVTransactionStructure'
open import Ledger.Prelude.Numeric using (mkUnitInterval; mkℕ⁺)
open import Data.Integer using (ℤ; +_)
open import Data.Rational using (½; 1ℚ ; mkℚ+ ; _/_)
open import Data.Nat.Coprimality using (Coprime; gcd≡1⇒coprime)
createEnv : ℕ → UTxOEnv
createEnv s = record { slot = s ; treasury = 0 ;
pparams = record
{ maxBlockSize = 90112
; maxTxSize = 16384
; maxHeaderSize = 1100
; maxValSize = 5000
; maxCollateralInputs = 3
; pv = 8 , 0
; maxTxExUnits = 10000000000 , 14000000
; maxBlockExUnits = 40000000000 , 62000000
; a = 44
; b = 155381
; minUTxOValue = 0
; poolDeposit = 500000000
; keyDeposit = 500000000
; monetaryExpansion = mkUnitInterval (+ 3 / 1000)
; treasuryCut = mkUnitInterval (+ 2 / 10)
; coinsPerUTxOByte = 0
; minFeeRefScriptCoinsPerByte = mkℚ+ 15 1 (gcd≡1⇒coprime refl)
; prices = tt
; maxRefScriptSizePerTx = 200 * 1024
; maxRefScriptSizePerBlock = 1024 * 1024
; refScriptCostStride = mkℕ⁺ 25
; refScriptCostMultiplier = mkℚ+ 6 5 (gcd≡1⇒coprime refl)
; a0 = 1ℚ
; Emax = 18
; nopt = 0
; collateralPercentage = 150
; costmdls = tt
; drepThresholds = record
{ P1 = ½
; P2a = ½
; P2b = ½
; P3 = ½
; P4 = ½
; P5a = ½
; P5b = ½
; P5c = ½
; P5d = ½
; P6 = ½
}
; poolThresholds = record
{ Q1 = ½
; Q2a = ½
; Q2b = ½
; Q4 = ½
; Q5 = ½
}
; govActionLifetime = 10
; govActionDeposit = 1000000
; drepDeposit = 1000000
; drepActivity = 13
; ccMinSize = 10
; ccMaxTermLength = 73
} }
createUTxO : (index : ℕ)
→ (wallet : ℕ)
→ (value : Value)
→ Maybe (D ⊎ DataHash)
→ TxIn × TxOut
createUTxO index wallet value d = (index , index)
, (inj₁ (record { net = 0 ; pay = KeyHashObj wallet ; stake = just (KeyHashObj wallet) })
, value , d , nothing)
createInitUtxoState : (wallets : ℕ)
→ (value : Value)
→ List (TxIn × TxOut)
createInitUtxoState zero value = []
createInitUtxoState (suc wallet) value = createUTxO (suc wallet) (suc wallet) value nothing
∷ createInitUtxoState wallet value
fromList' : List (TxIn × TxOut) → UTxO
fromList' = fromListᵐ
fromListIx : List (Implementation.Ix × TxOut) → Implementation.Ix ⇀ TxOut
fromListIx = fromListᵐ
applyScript : (Maybe D → Maybe D → Bool) → List D → Bool
applyScript f [] = f nothing nothing
applyScript f (_ ∷ []) = f nothing nothing
applyScript f (redeemer ∷ valcontext ∷ []) = f nothing (just redeemer)
applyScript f (datum ∷ redeemer ∷ valcontext ∷ _) = f (just datum) (just redeemer)
notEmpty : ∀ {A : Type} → List A → Type
notEmpty [] = ⊥
notEmpty (x ∷ xs) = ⊤
isSuccess : ComputationResult String UTxOState → Bool
isSuccess (success x) = true
isSuccess (failure x) = false
applyScriptWithContext : (Maybe D → Maybe D → List D → Bool) → List D → Bool
applyScriptWithContext f [] = f nothing nothing []
applyScriptWithContext f (_ ∷ []) = f nothing nothing []
applyScriptWithContext f (redeemer ∷ valcontext ∷ []) = f nothing (just redeemer) []
applyScriptWithContext f (datum ∷ redeemer ∷ valcontext ∷ vs) = f (just datum) (just redeemer) (valcontext ∷ vs)