Skip to content

Commit

Permalink
better defaulting to allow to pay integers
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontin committed May 22, 2024
1 parent 8a254e2 commit 17bb134
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
2 changes: 2 additions & 0 deletions cooked-validators.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ library
DataKinds
DerivingStrategies
DerivingVia
ExtendedDefaultRules
FlexibleContexts
FlexibleInstances
GADTs
Expand Down Expand Up @@ -153,6 +154,7 @@ test-suite spec
default-extensions:
ImportQualifiedPost
DataKinds
ExtendedDefaultRules
FlexibleContexts
FlexibleInstances
GADTs
Expand Down
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ library:
- DataKinds
- DerivingStrategies
- DerivingVia
- ExtendedDefaultRules
- FlexibleContexts
- FlexibleInstances
- GADTs
Expand Down Expand Up @@ -88,6 +89,7 @@ tests:
default-extensions:
- ImportQualifiedPost
- DataKinds
- ExtendedDefaultRules
- FlexibleContexts
- FlexibleInstances
- GADTs
Expand Down
4 changes: 2 additions & 2 deletions tests/Cooked/BasicUsageSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ payToAlwaysTrueValidator =
head
<$> ( validateTxSkel' $
txSkelTemplate
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () (10 :: Integer)],
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () 10],
txSkelSigners = [alice]
}
)
Expand All @@ -59,7 +59,7 @@ consumeAlwaysTrueValidator = do
validateTxSkel $
txSkelTemplate
{ txSkelIns = Map.fromList [(outref, TxSkelRedeemerForScript ())],
txSkelOuts = [paysPK alice (10 :: Integer)],
txSkelOuts = [paysPK alice 10],
txSkelSigners = [alice]
}

Expand Down
12 changes: 4 additions & 8 deletions tests/Cooked/InitialDistributionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ bob = wallet 2
-- | An initial distribution where alice owns a UTxO with a datum of
-- type Int and value 10 for each datum kind
initialDistributionWithDatum =
InitialDistribution $
(\f -> f (paysPK alice (2 :: Integer)) 10)
<$> [withDatum @Integer, withInlineDatum, withDatumHash]
InitialDistribution $ [withDatum, withInlineDatum, withDatumHash] <*> [paysPK alice 2] <*> [10]

-- | An initial distribution where alice owns a UTxO with a reference
-- script corresponding to the always succeed validators and bob owns
-- 2 UTxOs with 100 ada
initialDistributionWithReferenceScript =
InitialDistribution $
(paysPK alice (2 :: Integer) `withReferenceScript` alwaysTrueValidator @MockContract)
: replicate 2 (paysPK bob (100 :: Integer))
InitialDistribution $ (paysPK alice 2 `withReferenceScript` alwaysTrueValidator @MockContract) : replicate 2 (paysPK bob 100)

getValueFromInitialDatum :: (MonadBlockChain m) => m [Integer]
getValueFromInitialDatum = do
Expand All @@ -38,13 +34,13 @@ spendReferenceAlwaysTrueValidator = do
(scriptTxOutRef : _) <-
validateTxSkel' $
txSkelTemplate
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () (2 :: Integer)],
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () 2],
txSkelSigners = [bob]
}
void $
validateTxSkel $
txSkelTemplate
{ txSkelOuts = [paysPK alice (2 :: Integer)],
{ txSkelOuts = [paysPK alice 2],
txSkelIns = Map.singleton scriptTxOutRef (TxSkelRedeemerForReferencedScript referenceScriptTxOutRef ()),
txSkelSigners = [bob]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Cooked/InlineDatumsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ listUtxosTestTrace useInlineDatum validator =
<$> validateTxSkel
txSkelTemplate
{ txSkelOpts = def {txOptEnsureMinAda = True},
txSkelOuts = [(if useInlineDatum then paysScriptInlineDatum validator else paysScript validator) FirstPaymentDatum (3 :: Integer)],
txSkelOuts = [(if useInlineDatum then paysScriptInlineDatum validator else paysScript validator) FirstPaymentDatum 3],
txSkelSigners = [wallet 1]
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Cooked/MinAdaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ paymentWithMinAda = do
<$> validateTxSkel
txSkelTemplate
{ txSkelOpts = def {txOptEnsureMinAda = True},
txSkelOuts = [paysPK (wallet 2) (0 :: Integer) `withDatum` heavyDatum],
txSkelOuts = [paysPK (wallet 2) 0 `withDatum` heavyDatum],
txSkelSigners = [wallet 1]
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Cooked/ReferenceInputsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ trace1 = do
validateTxSkel'
txSkelTemplate
{ txSkelOuts =
[ paysScriptInlineDatum fooTypedValidator (FooDatum (walletPKHash (wallet 3))) (4 :: Integer),
paysScript barTypedValidator () (5 :: Integer)
[ paysScriptInlineDatum fooTypedValidator (FooDatum (walletPKHash (wallet 3))) 4,
paysScript barTypedValidator () 5
],
txSkelSigners = [wallet 2]
}
Expand All @@ -105,7 +105,7 @@ trace1 = do
txSkelTemplate
{ txSkelIns = Map.singleton txOutRefBar $ TxSkelRedeemerForScript (),
txSkelInsReference = Set.singleton txOutRefFoo,
txSkelOuts = [paysPK (wallet 4) (5 :: Integer)],
txSkelOuts = [paysPK (wallet 4) 5],
txSkelSigners = [wallet 3]
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Cooked/ReferenceScriptsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ checkReferenceScriptOnOref expectedScriptHash refScriptOref = do
oref : _ <-
validateTxSkel'
txSkelTemplate
{ txSkelOuts = [paysScript (requireRefScriptValidator (expectedScriptHash, "there is no reference input with the correct script hash")) () (42 :: Integer)],
{ txSkelOuts = [paysScript (requireRefScriptValidator (expectedScriptHash, "there is no reference input with the correct script hash")) () 42],
txSkelSigners = [wallet 1]
}
void $
Expand All @@ -115,7 +115,7 @@ useReferenceScript spendingSubmitter theScript = do
oref : _ <-
validateTxSkel'
txSkelTemplate
{ txSkelOuts = [paysScript theScript () (42 :: Integer)],
{ txSkelOuts = [paysScript theScript () 42],
txSkelSigners = [wallet 1]
}
void $
Expand Down Expand Up @@ -192,11 +192,11 @@ tests =
)
def
$ do
(consumedOref, _) : _ <- runUtxoSearch $ utxosAtSearch (wallet 1) *+* pureBoolFilter ((`Script.geq` toValue (42 :: Integer)) . outputValue)
(consumedOref, _) : _ <- runUtxoSearch $ utxosAtSearch (wallet 1) *+* pureBoolFilter ((`Script.geq` toValue 42) . outputValue)
oref : _ <-
validateTxSkel'
txSkelTemplate
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () (42 :: Integer)],
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () 42],
txSkelIns = Map.singleton consumedOref TxSkelNoRedeemerForPK,
txSkelSigners = [wallet 1]
}
Expand All @@ -221,7 +221,7 @@ tests =
oref : _ <-
validateTxSkel'
txSkelTemplate
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () (42 :: Integer)],
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () 42],
txSkelSigners = [wallet 1]
}
void $
Expand All @@ -244,7 +244,7 @@ tests =
oref : _ <-
validateTxSkel'
txSkelTemplate
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () (42 :: Integer)],
{ txSkelOuts = [paysScript (alwaysTrueValidator @MockContract) () 42],
txSkelSigners = [wallet 1]
}
void $
Expand Down
2 changes: 1 addition & 1 deletion tests/Cooked/ShowBSSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ printTrace = do
validateTxSkel'
txSkelTemplate
{ txSkelSigners = [wallet 1],
txSkelOuts = [paysScriptInlineDatum printValidator () (30 :: Integer)]
txSkelOuts = [paysScriptInlineDatum printValidator () 30]
}
void $
validateTxSkel
Expand Down
30 changes: 15 additions & 15 deletions tests/Cooked/Tweak/TamperDatumSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ tamperDatumTweakTest =
txSkelTemplate
{ txSkelLabel = Set.singleton $ TxLabel TamperDatumLbl,
txSkelOuts =
[ paysPK alice (Script.Lovelace 789) `withDatum` (52 :: Integer, 54 :: Integer),
[ paysPK alice (Script.Lovelace 789) `withDatum` (52, 54),
paysPK alice (Script.Lovelace 234) `withDatum` (),
paysPK alice (Script.Lovelace 567) `withDatum` (76 :: Integer, 77 :: Integer)
paysPK alice (Script.Lovelace 567) `withDatum` (76, 77)
]
}
)
Expand All @@ -36,9 +36,9 @@ tamperDatumTweakTest =
)
( txSkelTemplate
{ txSkelOuts =
[ paysPK alice (Script.Lovelace 789) `withDatum` (52 :: Integer, 53 :: Integer),
[ paysPK alice (Script.Lovelace 789) `withDatum` (52, 53),
paysPK alice (Script.Lovelace 234) `withDatum` (),
paysPK alice (Script.Lovelace 567) `withDatum` (76 :: Integer, 77 :: Integer)
paysPK alice (Script.Lovelace 567) `withDatum` (76, 77)
]
}
)
Expand All @@ -54,20 +54,20 @@ malformDatumTweakTest =
txSkelOuts =
[ paysPK alice (Script.Lovelace 789) `withDatum` PlutusTx.toBuiltinData datum1,
paysPK alice (Script.Lovelace 234) `withDatum` (),
paysPK alice (Script.Lovelace 567) `withDatum` (76 :: Integer, 77 :: Integer),
paysPK alice (Script.Lovelace 567) `withDatum` (76, 77),
paysPK alice (Script.Lovelace 567) `withDatum` PlutusTx.toBuiltinData datum4
]
}
)
in assertSameSets
[ txSkelWithDatums1And4 (52 :: Integer, ()) (84 :: Integer, 85 :: Integer), -- datum1 changed, datum4 untouched
txSkelWithDatums1And4 False (84 :: Integer, 85 :: Integer), -- datum1 changed, datum4 untouched
txSkelWithDatums1And4 (52 :: Integer, ()) (84 :: Integer, ()), -- datum1 changed, datum4 as well
[ txSkelWithDatums1And4 (52, ()) (84, 85), -- datum1 changed, datum4 untouched
txSkelWithDatums1And4 False (84, 85), -- datum1 changed, datum4 untouched
txSkelWithDatums1And4 (52, ()) (84, ()), -- datum1 changed, datum4 as well
txSkelWithDatums1And4 False False, -- datum1 changed, datum4 as well
txSkelWithDatums1And4 (52 :: Integer, ()) False, -- datum1 changed, datum4 as well
txSkelWithDatums1And4 False (84 :: Integer, ()), -- datum1 changed, datum4 as well
txSkelWithDatums1And4 (52 :: Integer, 53 :: Integer) (84 :: Integer, ()), -- datum1 untouched, datum4 changed
txSkelWithDatums1And4 (52 :: Integer, 53 :: Integer) False -- datum1 untouched, datum4 changed
txSkelWithDatums1And4 (52, ()) False, -- datum1 changed, datum4 as well
txSkelWithDatums1And4 False (84, ()), -- datum1 changed, datum4 as well
txSkelWithDatums1And4 (52, 53) (84, ()), -- datum1 untouched, datum4 changed
txSkelWithDatums1And4 (52, 53) False -- datum1 untouched, datum4 changed
]
( runTweak
( malformDatumTweak @(Integer, Integer)
Expand All @@ -82,10 +82,10 @@ malformDatumTweakTest =
)
( txSkelTemplate
{ txSkelOuts =
[ paysPK alice (Script.Lovelace 789) `withDatum` (52 :: Integer, 53 :: Integer),
[ paysPK alice (Script.Lovelace 789) `withDatum` (52, 53),
paysPK alice (Script.Lovelace 234) `withDatum` (),
paysPK alice (Script.Lovelace 567) `withDatum` (76 :: Integer, 77 :: Integer),
paysPK alice (Script.Lovelace 567) `withDatum` (84 :: Integer, 85 :: Integer)
paysPK alice (Script.Lovelace 567) `withDatum` (76, 77),
paysPK alice (Script.Lovelace 567) `withDatum` (84, 85)
]
}
)
Expand Down

0 comments on commit 17bb134

Please sign in to comment.