Skip to content

Commit

Permalink
Update getTxIx to use getUTxOValues
Browse files Browse the repository at this point in the history
  • Loading branch information
palas authored and jasagredo committed Jan 27, 2025
1 parent 11e2367 commit 809bd6a
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module Cardano.Testnet.Test.Cli.Query
import Cardano.Api
import Cardano.Api.Experimental (Some (..))
import qualified Cardano.Api.Genesis as Api
import Cardano.Api.Ledger (Coin (Coin), EpochInterval (EpochInterval), StandardCrypto,
extractHash, unboundRational)
import Cardano.Api.Ledger (Coin (Coin), EpochInterval (EpochInterval), StandardCrypto, unboundRational)
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (StakeCredential (StakeCredentialByKey), StakePoolKey)

Expand All @@ -26,10 +25,6 @@ import Cardano.CLI.Types.Key (VerificationKeyOrFile (VerificationKeyFi
import Cardano.CLI.Types.Output (QueryTipLocalStateOutput)
import Cardano.Crypto.Hash (hashToStringAsHex)
import qualified Cardano.Ledger.BaseTypes as L
import Cardano.Ledger.Core (valueTxOutL)
import Cardano.Ledger.Shelley.LedgerState (esLStateL, lsUTxOStateL, nesEpochStateL,
utxosUtxoL)
import qualified Cardano.Ledger.UTxO as L
import Cardano.Testnet

import Prelude
Expand All @@ -56,7 +51,6 @@ import qualified Data.Vector as Vector
import GHC.Exts (IsList (..))
import GHC.Stack (HasCallStack, withFrozenCallStack)
import qualified GHC.Stack as GHC
import Lens.Micro ((^.))
import System.Directory (makeAbsolute)
import System.FilePath ((</>))

Expand Down Expand Up @@ -352,6 +346,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
[(ReferenceScriptAddress plutusV3Script, transferAmount)]
signedTx <- signTx execConfig cEra refScriptSizeWork "signed-tx" txBody [Some $ paymentKeyInfoPair wallet1]
submitTx execConfig cEra signedTx

-- Wait until transaction is on chain and obtain transaction identifier
txId <- retrieveTransactionId execConfig signedTx
txIx <- H.evalMaybeM $ watchEpochStateUpdate epochStateView (EpochInterval 2) (getTxIx sbe txId transferAmount)
Expand Down Expand Up @@ -493,15 +488,15 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
makeStakeAddress (fromNetworkMagic $ NetworkMagic $ fromIntegral testnetMagic) (StakeCredentialByKey $ verificationKeyHash delegatorVKey)

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

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

0 comments on commit 809bd6a

Please sign in to comment.