Skip to content

Commit f0e295f

Browse files
committed
Fix after the rebase
1 parent 1e57965 commit f0e295f

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

hydra-cluster/src/Hydra/Cluster/Scenarios.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,14 +1342,15 @@ canDepositPartially tracer workDir blockTime backend hydraScriptsTxId =
13421342
(walletVk, walletSk) <- generate genKeyPair
13431343

13441344
tokensUTxO <- generate (genUTxOWithAssetsSized 2 (Just $ PolicyId $ CAPI.hashScript $ CAPI.PlutusScript dummyMintingScript))
1345-
let tokenValue = UTxO.totalValue tokensUTxO
1346-
let tokenAssets = valueToPolicyAssets tokenValue
1345+
let totalTokenValue = UTxO.totalValue tokensUTxO
1346+
let tokenAssets = valueToPolicyAssets totalTokenValue
1347+
let tokenAssetValue = foldMap ((mempty <>) . uncurry policyAssetsToValue) (Map.toList tokenAssets)
13471348
let seedAmount = 5_000_000
13481349
-- NOTE: We (and also the users) need to make sure we give enough ADA when committing. If deposit tx ADA amount is too low
13491350
-- and some ADA is added to it after balancing in the wallet, then we have problems matching on the 'CommitApproved' etc.
13501351
let commitAmount = 3_000_000
13511352
commitUTxOWithoutTokens <- seedFromFaucet backend walletVk (lovelaceToValue seedAmount) (contramap FromFaucet tracer)
1352-
commitUTxOWithTokens <- seedFromFaucet backend walletVk (lovelaceToValue seedAmount <> tokenValue) (contramap FromFaucet tracer)
1353+
commitUTxOWithTokens <- seedFromFaucet backend walletVk (lovelaceToValue seedAmount <> totalTokenValue) (contramap FromFaucet tracer)
13531354
-- This one is expected to fail since there is 5 ADA at the wallet address but we specified 6 ADA to commit
13541355
(requestCommitTx' n1 commitUTxOWithoutTokens (Just 8_000_000) Nothing <&> toJSON)
13551356
`shouldThrow` expectErrorStatus 400 (Just "AmountTooLow")
@@ -1383,7 +1384,7 @@ canDepositPartially tracer workDir blockTime backend hydraScriptsTxId =
13831384
getSnapshotUTxO n1 `shouldReturn` expectedDeposit
13841385
-- check that user balance contains the change from the commit tx + commitAmount in the UTxO we didn't commit
13851386
(balance <$> Backend.queryUTxOFor backend QueryTip walletVk)
1386-
`shouldReturn` lovelaceToValue commitAmount
1387+
`shouldReturn` lovelaceToValue seedAmount
13871388

13881389
send n2 $ input "Close" []
13891390

@@ -1401,7 +1402,8 @@ canDepositPartially tracer workDir blockTime backend hydraScriptsTxId =
14011402

14021403
-- Assert final wallet balance
14031404
(balance <$> Backend.queryUTxOFor backend QueryTip walletVk)
1404-
`shouldReturn` balance (commitUTxOWithoutTokens <> commitUTxOWithTokens)
1405+
`shouldReturn` lovelaceToValue (seedAmount + commitAmount)
1406+
<> tokenAssetValue
14051407
where
14061408
hydraTracer = contramap FromHydraNode tracer
14071409

@@ -1573,9 +1575,9 @@ canRecoverDepositInAnyState tracer workDir backend hydraScriptsTxId =
15731575
-- Get some L1 funds
15741576
(walletVk, walletSk) <- generate genKeyPair
15751577
let commitAmount = 5_000_000
1576-
commitUTxO1 <- seedFromFaucet backend walletVk commitAmount (contramap FromFaucet tracer)
1577-
commitUTxO2 <- seedFromFaucet backend walletVk commitAmount (contramap FromFaucet tracer)
1578-
commitUTxO3 <- seedFromFaucet backend walletVk commitAmount (contramap FromFaucet tracer)
1578+
commitUTxO1 <- seedFromFaucet backend walletVk (lovelaceToValue commitAmount) (contramap FromFaucet tracer)
1579+
commitUTxO2 <- seedFromFaucet backend walletVk (lovelaceToValue commitAmount) (contramap FromFaucet tracer)
1580+
commitUTxO3 <- seedFromFaucet backend walletVk (lovelaceToValue commitAmount) (contramap FromFaucet tracer)
15791581

15801582
queryWalletBalance walletVk `shouldReturn` lovelaceToValue (commitAmount * 3)
15811583

hydra-plutus/src/Hydra/Contract/Head.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ checkIncrement ctx@ScriptContext{scriptContextTxInfo = txInfo} openBefore redeem
298298

299299
mustIncreaseValue =
300300
traceIfFalse $(errorCode HeadValueIsNotPreserved) $
301-
headInValue <> depositValue === headOutValue
301+
-- NOTE: Strict equality (===) in presence of non ADA assets here
302+
-- seem to make this check not work. Since we don't want to sort on-chain (inefficient)
303+
-- and it is hard/impossible to sort in the off-chain code we just use PlutusTx equality which should
304+
-- be enough in this case.
305+
headInValue <> depositValue == headOutValue
302306

303307
OpenDatum
304308
{ parties = prevParties

hydra-tx/src/Hydra/Tx/Deposit.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ depositTx networkId headId commitBlueprintTx upperSlot deadline amount tokens =
7474

7575
-- | Merges the two 'UTxO' favoring data coming from the first argument 'UTxO'.
7676
-- In case the same 'TxIn' was found in the first 'UTxO' - second 'UTxO' value
77-
-- will be apended to the input.
78-
-- NOTE: We need this since mappend on 'UTxO' is happy to accept the first 'Value' it encounteres
77+
-- will be appended to the input.
78+
-- NOTE: We need this since mappend on 'UTxO' is happy to accept the first 'Value' it encounters
7979
-- in case 'TxId'/s are the same.
8080
mergeUTxO :: UTxO -> UTxO -> UTxO
8181
mergeUTxO utxo utxoToMerge =
@@ -126,9 +126,6 @@ pickTokensToDeposit leftoverUTxO depositTokens
126126
Just availQty | reqQty <= availQty -> Map.insert name reqQty matched
127127
_ -> matched
128128

129-
bumpIndices :: UTxO -> UTxO
130-
bumpIndices utxo = UTxO.fromList $ (\(TxIn hash (TxIx n), txOut) -> (TxIn hash (TxIx $ n + 1), txOut)) <$> UTxO.toList utxo
131-
132129
-- Helper to create TxOut with original lovelace + new value (unchanged from original).
133130
mkTxOutValueNotKeepingLovelace :: TxOut ctx -> Value -> TxOut ctx
134131
mkTxOutValueNotKeepingLovelace (TxOut addr _ datum refScript) newValue =

0 commit comments

Comments
 (0)