finished morphisms
This commit is contained in:
parent
bd300de832
commit
fdcd725901
1 changed files with 19 additions and 8 deletions
|
|
@ -70,11 +70,11 @@ import Plutus.V1.Ledger.Credential (Credential (PubKeyCredential, ScriptCredenti
|
||||||
import Plutus.V1.Ledger.Scripts (Script, ValidatorHash (ValidatorHash))
|
import Plutus.V1.Ledger.Scripts (Script, ValidatorHash (ValidatorHash))
|
||||||
import Plutus.V1.Ledger.Value (
|
import Plutus.V1.Ledger.Value (
|
||||||
CurrencySymbol (CurrencySymbol),
|
CurrencySymbol (CurrencySymbol),
|
||||||
TokenName (unTokenName),
|
TokenName (TokenName, unTokenName),
|
||||||
Value (Value, getValue),
|
Value (Value, getValue),
|
||||||
)
|
)
|
||||||
import PlutusTx.AssocMap (Map, elems, fromList, keys, singleton, toList, unionWith)
|
import PlutusTx.AssocMap (Map, elems, fromList, keys, singleton, toList, unionWith)
|
||||||
import PlutusTx.AssocMap qualified as AssocMap (lookup)
|
import PlutusTx.AssocMap qualified as AssocMap (insert, lookup)
|
||||||
import Test.Tasty (TestTree, testGroup)
|
import Test.Tasty (TestTree, testGroup)
|
||||||
import Test.Tasty.Hedgehog (fromGroup)
|
import Test.Tasty.Hedgehog (fromGroup)
|
||||||
|
|
||||||
|
|
@ -178,15 +178,26 @@ replaceValue (Value v) cs tn n = Value $ unionWith (\_ x -> x) v v'
|
||||||
kmap :: (k -> k') -> Map k v -> Map k' v
|
kmap :: (k -> k') -> Map k v -> Map k' v
|
||||||
kmap g = fromList . fmap (first g) . toList
|
kmap g = fromList . fmap (first g) . toList
|
||||||
|
|
||||||
fixTokenNames :: TxInInfo -> TxInInfo
|
fixTokenNames :: CurrencySymbol -> TxInInfo -> TxInInfo
|
||||||
fixTokenNames inf =
|
fixTokenNames cs inf =
|
||||||
let cred = inf.txInInfoResolved.txOutAddress.addressCredential
|
let cred = inf.txInInfoResolved.txOutAddress.addressCredential
|
||||||
val = inf.txInInfoResolved.txOutValue
|
Value val = inf.txInInfoResolved.txOutValue
|
||||||
in case cred of
|
in case cred of
|
||||||
PubKeyCredential _ -> inf
|
PubKeyCredential _ -> inf
|
||||||
ScriptCredential (ValidatorHash bs) -> undefined
|
ScriptCredential (ValidatorHash bs) ->
|
||||||
|
case AssocMap.lookup cs val of
|
||||||
|
Nothing -> inf
|
||||||
|
Just m ->
|
||||||
|
let tn :: TokenName = TokenName bs
|
||||||
|
m' = kmap (\_ -> tn) m
|
||||||
|
v' = Value $ AssocMap.insert cs m' val
|
||||||
|
in inf
|
||||||
|
{ txInInfoResolved =
|
||||||
|
inf.txInInfoResolved
|
||||||
|
{ txOutValue = v'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
-- | TODO: Define.
|
|
||||||
instance HasPermutationGenerator TreasuryTxProp TreasuryTxModel where
|
instance HasPermutationGenerator TreasuryTxProp TreasuryTxModel where
|
||||||
generators :: [Morphism TreasuryTxProp TreasuryTxModel]
|
generators :: [Morphism TreasuryTxProp TreasuryTxModel]
|
||||||
generators =
|
generators =
|
||||||
|
|
@ -237,7 +248,7 @@ instance HasPermutationGenerator TreasuryTxProp TreasuryTxModel where
|
||||||
{ scriptContextTxInfo =
|
{ scriptContextTxInfo =
|
||||||
txInfo
|
txInfo
|
||||||
{ txInfoInputs =
|
{ txInfoInputs =
|
||||||
fixTokenNames <$> infoInputs
|
fixTokenNames m.gatCs <$> infoInputs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue