Skip to content

Commit

Permalink
Fix discrepencies with CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Niols authored and florentc committed Jan 31, 2023
1 parent e0aa5a5 commit 5f6909e
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 122 deletions.
16 changes: 8 additions & 8 deletions cooked-validators/src/Cooked/MockChain/Direct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -586,16 +586,16 @@ setFeeAndBalance balancePK skel0 = do
Left err -> throwError $ MCECalcFee err
Right newFee
| newFee == fee -> do
-- Debug.Trace.traceM "Reached fixpoint:"
-- Debug.Trace.traceM $ "- fee = " <> show fee
-- Debug.Trace.traceM $ "- skeleton = " <> show (attemptedSkel {_txSkelFee = fee})
pure (attemptedSkel, fee) -- reached fixpoint
-- Debug.Trace.traceM "Reached fixpoint:"
-- Debug.Trace.traceM $ "- fee = " <> show fee
-- Debug.Trace.traceM $ "- skeleton = " <> show (attemptedSkel {_txSkelFee = fee})
pure (attemptedSkel, fee) -- reached fixpoint
| n == 0 -> do
-- Debug.Trace.traceM $ "Max iteration reached: newFee = " <> show newFee
pure (attemptedSkel, max newFee fee) -- maximum number of iterations
-- Debug.Trace.traceM $ "Max iteration reached: newFee = " <> show newFee
pure (attemptedSkel, max newFee fee) -- maximum number of iterations
| otherwise -> do
-- Debug.Trace.traceM $ "New iteration: newfee = " <> show newFee
calcFee (n - 1) newFee cUtxoIndex skel
-- Debug.Trace.traceM $ "New iteration: newfee = " <> show newFee
calcFee (n - 1) newFee cUtxoIndex skel

-- | This funcion is essentially a copy of
-- https://github.com/input-output-hk/plutus-apps/blob/d4255f05477fd8477ee9673e850ebb9ebb8c9657/plutus-ledger/src/Ledger/Fee.hs#L19
Expand Down
6 changes: 3 additions & 3 deletions cooked-validators/src/Cooked/MockChain/GenerateTx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,16 @@ generateTxBodyContent GenTxParams {..} theParams managedData managedTxOuts manag

witnessMap :: Either GenerateTxError (Map C.PolicyId (C.ScriptWitness C.WitCtxMint C.BabbageEra))
witnessMap =
right mconcat
$ mapM
right mconcat $
mapM
( \(policy, redeemer, _tName, _amount) ->
Map.singleton
<$> left
(ToCardanoError "txSkelMintsToTxMintValue, calculating the witness map")
(Pl.toCardanoPolicyId (Pl.mintingPolicyHash policy))
<*> mkMintWitness policy redeemer
)
$ txSkelMintsToList mints
$ txSkelMintsToList mints

mkMintWitness ::
Pl.Versioned Pl.MintingPolicy ->
Expand Down
46 changes: 23 additions & 23 deletions cooked-validators/src/Cooked/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ prettyMockChainLog opts =
: entries
)
| pcOptPrintTxHashes opts =
go
( "Validated"
<+> PP.parens ("TxId:" <+> prettyCookedOpt opts txId)
<+> prettyTxSkel opts skelContext skel
: acc
)
entries
go
( "Validated"
<+> PP.parens ("TxId:" <+> prettyCookedOpt opts txId)
<+> prettyTxSkel opts skelContext skel :
acc
)
entries
| otherwise = go ("Validated" <+> prettyTxSkel opts skelContext skel : acc) entries
go
acc
Expand Down Expand Up @@ -282,22 +282,22 @@ prettyTxSkelOut opts (Pays output) =
prettyEnum
("Pays to" <+> prettyCookedOpt opts (outputAddress output))
"-"
( prettyCookedOpt opts (outputValue output)
: catMaybes
[ case outputOutputDatum output of
Pl.OutputDatum _datum ->
Just $
"Datum (inlined):"
<+> (PP.align . prettyCookedOpt opts)
(output ^. outputDatumL)
Pl.OutputDatumHash _datum ->
Just $
"Datum (hashed):"
<+> (PP.align . prettyCookedOpt opts)
(output ^. outputDatumL)
Pl.NoOutputDatum -> Nothing,
getReferenceScriptDoc opts output
]
( prettyCookedOpt opts (outputValue output) :
catMaybes
[ case outputOutputDatum output of
Pl.OutputDatum _datum ->
Just $
"Datum (inlined):"
<+> (PP.align . prettyCookedOpt opts)
(output ^. outputDatumL)
Pl.OutputDatumHash _datum ->
Just $
"Datum (hashed):"
<+> (PP.align . prettyCookedOpt opts)
(output ^. outputDatumL)
Pl.NoOutputDatum -> Nothing,
getReferenceScriptDoc opts output
]
)

prettyTxSkelIn :: PrettyCookedOpts -> SkelContext -> (Pl.TxOutRef, TxSkelRedeemer) -> Maybe DocCooked
Expand Down
10 changes: 5 additions & 5 deletions cooked-validators/src/Cooked/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ initialDistribution' = (def <>) . distributionFromList
initialTxFor :: InitialDistribution -> Pl.Tx
initialTxFor initDist
| not $ validInitialDistribution initDist =
error "Not all UTxOs have at least minAda; this initial distribution is unusable"
error "Not all UTxOs have at least minAda; this initial distribution is unusable"
| otherwise =
mempty
{ Pl.txMint = mconcat (map (mconcat . snd) initDist'),
Pl.txOutputs = concatMap (\(w, vs) -> map (initUtxosFor w) vs) initDist'
}
mempty
{ Pl.txMint = mconcat (map (mconcat . snd) initDist'),
Pl.txOutputs = concatMap (\(w, vs) -> map (initUtxosFor w) vs) initDist'
}
where
-- initUtxosFor w v = Pl.TxOut $ Api.TxOut addr val Api.TxOutDatumNone Api.ReferenceScriptNone
initUtxosFor w v = toPlTxOut @() (walletAddress w) v Nothing
Expand Down
48 changes: 24 additions & 24 deletions cooked-validators/tests/Cooked/Attack/DoubleSatSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,32 +180,32 @@ tests =
Just aValue <- valueFromTxOutRef aOref
if
| aValue == Pl.lovelaceValueOf 2_000_000 ->
return
[ toDelta bOref $ TxSkelRedeemerForScript BRedeemer1
| (bOref, bOut) <- bUtxos,
outputValue bOut == Pl.lovelaceValueOf 123 -- not satisfied by any UTxO in 'dsTestMockChain'
]
return
[ toDelta bOref $ TxSkelRedeemerForScript BRedeemer1
| (bOref, bOut) <- bUtxos,
outputValue bOut == Pl.lovelaceValueOf 123 -- not satisfied by any UTxO in 'dsTestMockChain'
]
| aValue == Pl.lovelaceValueOf 3_000_000 ->
return
[ toDelta bOref $ TxSkelRedeemerForScript BRedeemer1
| (bOref, bOut) <- bUtxos,
outputValue bOut == Pl.lovelaceValueOf 6_000_000 -- satisfied by exactly one UTxO in 'dsTestMockChain'
]
return
[ toDelta bOref $ TxSkelRedeemerForScript BRedeemer1
| (bOref, bOut) <- bUtxos,
outputValue bOut == Pl.lovelaceValueOf 6_000_000 -- satisfied by exactly one UTxO in 'dsTestMockChain'
]
| aValue == Pl.lovelaceValueOf 4_000_000 ->
return $
concatMap
( \(bOref, bOut) ->
let bValue = outputValue bOut
in if
| bValue == Pl.lovelaceValueOf 6_000_000 ->
[toDelta bOref $ TxSkelRedeemerForScript BRedeemer1]
| bValue == Pl.lovelaceValueOf 7_000_000 ->
[ toDelta bOref $ TxSkelRedeemerForScript BRedeemer1,
toDelta bOref $ TxSkelRedeemerForScript BRedeemer2
]
| otherwise -> []
)
bUtxos
return $
concatMap
( \(bOref, bOut) ->
let bValue = outputValue bOut
in if
| bValue == Pl.lovelaceValueOf 6_000_000 ->
[toDelta bOref $ TxSkelRedeemerForScript BRedeemer1]
| bValue == Pl.lovelaceValueOf 7_000_000 ->
[ toDelta bOref $ TxSkelRedeemerForScript BRedeemer1,
toDelta bOref $ TxSkelRedeemerForScript BRedeemer2
]
| otherwise -> []
)
bUtxos
| otherwise -> return []
)
(wallet 6)
Expand Down
6 changes: 3 additions & 3 deletions cooked-validators/tests/Cooked/MinAdaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ tests =
testGroup
"automatic minAda adjustment of transaction outputs"
[ testCase "adjusted transaction passes" $ testSucceeds def paymentWithMinAda,
testCase "adjusted transaction contains minimal amount"
$ testFailsFrom'
testCase "adjusted transaction contains minimal amount" $
testFailsFrom'
def
( \case
MCEValidationError (Pl.Phase1, _) -> testSuccess
MCECalcFee (MCEValidationError (Pl.Phase1, _)) -> testSuccess
_ -> testFailure
)
def
$ paymentWithMinAda >>= paymentWithoutMinAda . (+ (-1))
$ paymentWithMinAda >>= paymentWithoutMinAda . (+ (-1))
]
102 changes: 51 additions & 51 deletions cooked-validators/tests/Cooked/ReferenceScriptsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,100 +190,100 @@ tests =
[ testGroup "putting reference scripts on chain and retreiving them" $
let theRefScript = noValidator
theRefScriptHash = toScriptHash theRefScript
in [ testCase "on a public key output"
$ testSucceedsFrom'
in [ testCase "on a public key output" $
testSucceedsFrom'
def
( \mScriptHash _ ->
testCounterexample "the script hash on the retrieved output is wrong" $
Just theRefScriptHash .==. mScriptHash
)
def
$ putRefScriptOnWalletOutput (wallet 3) theRefScript
>>= retrieveRefScriptHash,
testCase "on a script output"
$ testSucceedsFrom'
$ putRefScriptOnWalletOutput (wallet 3) theRefScript
>>= retrieveRefScriptHash,
testCase "on a script output" $
testSucceedsFrom'
def
( \mScriptHash _ ->
testCounterexample "the script hash on the retrieved output is wrong" $
Just theRefScriptHash .==. mScriptHash
)
def
$ putRefScriptOnScriptOutput yesValidator theRefScript
>>= retrieveRefScriptHash
$ putRefScriptOnScriptOutput yesValidator theRefScript
>>= retrieveRefScriptHash
],
testGroup
"checking the presence of reference scripts on the TxInfo"
[ testCase "fail if wrong reference script"
$ testFailsFrom'
[ testCase "fail if wrong reference script" $
testFailsFrom'
def
( isCekEvaluationFailureWithMsg
def
(== "there is no reference input with the correct script hash")
)
def
$ putRefScriptOnWalletOutput (wallet 3) noValidator
>>= checkReferenceScriptOnOref (toScriptHash yesValidator),
$ putRefScriptOnWalletOutput (wallet 3) noValidator
>>= checkReferenceScriptOnOref (toScriptHash yesValidator),
testCase "succeed if correct reference script" $
testSucceeds def $
putRefScriptOnWalletOutput (wallet 3) yesValidator
>>= checkReferenceScriptOnOref (toScriptHash yesValidator)
],
testGroup
"using reference scripts"
[ testCase "fail from transaction generation for missing reference scripts"
$ testFailsFrom'
[ testCase "fail from transaction generation for missing reference scripts" $
testFailsFrom'
def
( \case
MCEGenerationError _ -> testSuccess
MCECalcFee (MCEGenerationError _) -> testSuccess
_ -> testFailure
)
def
$ do
(oref, _) : _ <-
utxosFromCardanoTx
<$> validateTxSkel
$ do
(oref, _) : _ <-
utxosFromCardanoTx
<$> validateTxSkel
txSkelTemplate
{ txSkelOuts =
[ paysScript
yesValidator
()
(Pl.lovelaceValueOf 42_000_000)
]
}
void $
validateTxSkel
txSkelTemplate
{ txSkelOuts =
[ paysScript
yesValidator
()
(Pl.lovelaceValueOf 42_000_000)
]
}
void $
validateTxSkel
txSkelTemplate
{ txSkelIns = Map.singleton oref (TxSkelRedeemerForReferencedScript ())
},
testCase "phase 1 - fail if using a reference script with 'TxSkelRedeemerForScript'"
$ testFailsFrom'
{ txSkelIns = Map.singleton oref (TxSkelRedeemerForReferencedScript ())
},
testCase "phase 1 - fail if using a reference script with 'TxSkelRedeemerForScript'" $
testFailsFrom'
def
( \case
MCEValidationError (Pl.Phase1, _) -> testSuccess
MCECalcFee (MCEValidationError (Pl.Phase1, _)) -> testSuccess
_ -> testFailure
)
def
$ do
scriptOref <- putRefScriptOnWalletOutput (wallet 3) yesValidator
(oref, _) : _ <-
utxosFromCardanoTx
<$> validateTxSkel
$ do
scriptOref <- putRefScriptOnWalletOutput (wallet 3) yesValidator
(oref, _) : _ <-
utxosFromCardanoTx
<$> validateTxSkel
txSkelTemplate
{ txSkelOuts =
[ paysScript
yesValidator
()
(Pl.lovelaceValueOf 42_000_000)
]
}
void $
validateTxSkel
txSkelTemplate
{ txSkelOuts =
[ paysScript
yesValidator
()
(Pl.lovelaceValueOf 42_000_000)
]
}
void $
validateTxSkel
txSkelTemplate
{ txSkelIns = Map.singleton oref (TxSkelRedeemerForScript ()),
txSkelInsReference = Set.singleton scriptOref
},
{ txSkelIns = Map.singleton oref (TxSkelRedeemerForScript ()),
txSkelInsReference = Set.singleton scriptOref
},
testCase
"fail if referenced script's requirement is violated"
$ testFailsFrom'
Expand All @@ -293,7 +293,7 @@ tests =
(== "the required signer is missing")
)
def
$ useReferenceScript (wallet 1) (requireSignerValidator (walletPKHash $ wallet 2)),
$ useReferenceScript (wallet 1) (requireSignerValidator (walletPKHash $ wallet 2)),
testCase "succeed if referenced script's requirement is met" $
testSucceeds def $
useReferenceScript (wallet 1) (requireSignerValidator (walletPKHash $ wallet 1))
Expand Down
2 changes: 1 addition & 1 deletion examples/examples.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4

-- This file has been generated from package.yaml by hpack version 0.34.6.
-- This file has been generated from package.yaml by hpack version 0.34.7.
--
-- see: https://github.com/sol/hpack

Expand Down
8 changes: 4 additions & 4 deletions examples/src/Auction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ PlutusTx.unstableMakeIsData ''Action
mkPolicy :: Pl.TxOutRef -> Pl.ScriptContext -> Bool
mkPolicy offerOref ctx
| amnt == 1 =
traceIfFalse
"Offer UTxO not consumed"
(any (\i -> Pl.txInInfoOutRef i == offerOref) $ Pl.txInfoInputs txi)
traceIfFalse
"Offer UTxO not consumed"
(any (\i -> Pl.txInInfoOutRef i == offerOref) $ Pl.txInfoInputs txi)
-- no further checks here since 'validSetDeadline' checks the remaining conditions
| amnt == -1 =
True -- no further checks here; 'validHammer' checks everything
True -- no further checks here; 'validHammer' checks everything
| otherwise = trace "not minting or burning the right amount" False
where
txi = Pl.scriptContextTxInfo ctx
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
## NOTE: in case of formatting error, check the versions of
## ormolu and try replacing by ${pkgs.ormolu}/bin/ormolu
## https://discourse.nixos.org/t/nix-shell-buildinputs-ordering-issue/12885/8
ormolu --version
ormolu --mode check $(find . -name '*.hs') || exit 1
'';
## The derivation succeeds if the output is created.
Expand Down

0 comments on commit 5f6909e

Please sign in to comment.