Skip to content

Commit 809bd6a

Browse files
palasjasagredo
authored andcommitted
Update getTxIx to use getUTxOValues
1 parent 11e2367 commit 809bd6a

File tree

1 file changed

+8
-13
lines changed
  • cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli

1 file changed

+8
-13
lines changed

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ module Cardano.Testnet.Test.Cli.Query
1616
import Cardano.Api
1717
import Cardano.Api.Experimental (Some (..))
1818
import qualified Cardano.Api.Genesis as Api
19-
import Cardano.Api.Ledger (Coin (Coin), EpochInterval (EpochInterval), StandardCrypto,
20-
extractHash, unboundRational)
19+
import Cardano.Api.Ledger (Coin (Coin), EpochInterval (EpochInterval), StandardCrypto, unboundRational)
2120
import qualified Cardano.Api.Ledger as L
2221
import Cardano.Api.Shelley (StakeCredential (StakeCredentialByKey), StakePoolKey)
2322

@@ -26,10 +25,6 @@ import Cardano.CLI.Types.Key (VerificationKeyOrFile (VerificationKeyFi
2625
import Cardano.CLI.Types.Output (QueryTipLocalStateOutput)
2726
import Cardano.Crypto.Hash (hashToStringAsHex)
2827
import qualified Cardano.Ledger.BaseTypes as L
29-
import Cardano.Ledger.Core (valueTxOutL)
30-
import Cardano.Ledger.Shelley.LedgerState (esLStateL, lsUTxOStateL, nesEpochStateL,
31-
utxosUtxoL)
32-
import qualified Cardano.Ledger.UTxO as L
3328
import Cardano.Testnet
3429

3530
import Prelude
@@ -56,7 +51,6 @@ import qualified Data.Vector as Vector
5651
import GHC.Exts (IsList (..))
5752
import GHC.Stack (HasCallStack, withFrozenCallStack)
5853
import qualified GHC.Stack as GHC
59-
import Lens.Micro ((^.))
6054
import System.Directory (makeAbsolute)
6155
import System.FilePath ((</>))
6256

@@ -352,6 +346,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
352346
[(ReferenceScriptAddress plutusV3Script, transferAmount)]
353347
signedTx <- signTx execConfig cEra refScriptSizeWork "signed-tx" txBody [Some $ paymentKeyInfoPair wallet1]
354348
submitTx execConfig cEra signedTx
349+
355350
-- Wait until transaction is on chain and obtain transaction identifier
356351
txId <- retrieveTransactionId execConfig signedTx
357352
txIx <- H.evalMaybeM $ watchEpochStateUpdate epochStateView (EpochInterval 2) (getTxIx sbe txId transferAmount)
@@ -493,15 +488,15 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
493488
makeStakeAddress (fromNetworkMagic $ NetworkMagic $ fromIntegral testnetMagic) (StakeCredentialByKey $ verificationKeyHash delegatorVKey)
494489

495490
getTxIx :: forall m era. HasCallStack => MonadTest m => ShelleyBasedEra era -> String -> Coin -> (AnyNewEpochState, SlotNo, BlockNo) -> m (Maybe Int)
496-
getTxIx sbe txId amount (AnyNewEpochState sbe' newEpochState _, _, _) = do
491+
getTxIx sbe txId amount (AnyNewEpochState sbe' _ tbs, _, _) = do
497492
Refl <- H.leftFail $ assertErasEqual sbe sbe'
498-
shelleyBasedEraConstraints sbe' (do
499-
return $ Map.foldlWithKey (\acc (L.TxIn (L.TxId thisTxId) (L.TxIx thisTxIx)) txOut ->
493+
shelleyBasedEraConstraints sbe' $ do
494+
return $ Map.foldlWithKey (\acc (TxIn (TxId thisTxId) (TxIx thisTxIx)) (TxOut _ txOutValue _ _) ->
500495
case acc of
501-
Nothing | hashToStringAsHex (extractHash thisTxId) == txId &&
502-
valueToLovelace (fromLedgerValue sbe (txOut ^. valueTxOutL)) == Just amount -> Just $ fromIntegral thisTxIx
496+
Nothing | hashToStringAsHex thisTxId == txId &&
497+
txOutValueToLovelace txOutValue == amount -> Just $ fromIntegral thisTxIx
503498
| otherwise -> Nothing
504-
x -> x) Nothing $ L.unUTxO $ newEpochState ^. nesEpochStateL . esLStateL . lsUTxOStateL . utxosUtxoL)
499+
x -> x) Nothing $ getUTxOValues sbe' tbs
505500

506501
-- | @redactJsonStringFieldInFile [(k0, v0), (k1, v1), ..] sourceFilePath targetFilePath@ reads the JSON at @sourceFilePath@, and then
507502
-- replaces the value associated to @k0@ by @v0@, replaces the value associated to @k1@ by @v1@, etc.

0 commit comments

Comments
 (0)