From 01b7d1cf9e40e5dfb613f8cfab53c77720bd0f9e Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Mon, 22 Nov 2021 16:02:39 +0000 Subject: [PATCH] Remove some undefined values to generate payment Also added lovelaceToTxOutValue which is not exported from Cardano.Api --- local-cluster/src/CardanoClient.hs | 3 +++ local-cluster/test/Test/DirectChainSpec.hs | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/local-cluster/src/CardanoClient.hs b/local-cluster/src/CardanoClient.hs index e04a7b5eb40..a3027b76346 100644 --- a/local-cluster/src/CardanoClient.hs +++ b/local-cluster/src/CardanoClient.hs @@ -73,6 +73,9 @@ txOutLovelace (TxOut _ val _) = TxOutAdaOnly _ l -> l TxOutValue _ v -> selectLovelace v +lovelaceToTxOutValue :: Lovelace -> TxOutValue AlonzoEra +lovelaceToTxOutValue lovelace = TxOutValue MultiAssetInAlonzoEra (lovelaceToValue lovelace) + -- |Query current protocol parameters. -- -- Throws 'CardanoClientException' if query fails. diff --git a/local-cluster/test/Test/DirectChainSpec.hs b/local-cluster/test/Test/DirectChainSpec.hs index 3204d081fb0..df71a56e583 100644 --- a/local-cluster/test/Test/DirectChainSpec.hs +++ b/local-cluster/test/Test/DirectChainSpec.hs @@ -7,9 +7,10 @@ module Test.DirectChainSpec where import Hydra.Prelude import Test.Hydra.Prelude -import Cardano.Api (Lovelace (Lovelace), NetworkId (Testnet), UTxO (UTxO)) +import Cardano.Api (Key (getVerificationKey), Lovelace (Lovelace), NetworkId (Testnet), SigningKey (PaymentSigningKey), UTxO (UTxO)) +import Cardano.Api.Shelley (VerificationKey (PaymentVerificationKey)) import Cardano.Ledger.Keys (VKey (VKey)) -import CardanoClient (build, queryUtxo, sign, submit, waitForPayment) +import CardanoClient (build, buildAddress, queryUtxo, sign, submit, waitForPayment) import CardanoCluster ( ClusterLog, keysFor, @@ -169,27 +170,27 @@ generatePaymentToCommit :: Cardano.VerificationKey -> Natural -> IO (Utxo CardanoTx) -generatePaymentToCommit (RunningNode _ nodeSocket) _sk _vk lovelace = do +generatePaymentToCommit (RunningNode _ nodeSocket) sk vk lovelace = do UTxO availableUtxo <- queryUtxo networkId nodeSocket [spendingAddress] let inputs = (,Nothing) <$> Map.keys availableUtxo build networkId nodeSocket spendingAddress inputs [] theOutput >>= \case Left e -> error (show e) Right body -> do - let tx = sign cardanoSigningKey body + let tx = sign sk body submit networkId nodeSocket tx convertUtxo <$> waitForPayment networkId nodeSocket amountLovelace receivingAddress where networkId = Testnet magic - cardanoSigningKey = error "convert from sk" + spendingSigningKey = PaymentSigningKey sk - cardanoVerificationKey = error "convert from vk" + receivingVerificationKey = PaymentVerificationKey $ VKey vk - spendingAddress = error "create from sk" + spendingAddress = buildAddress (getVerificationKey spendingSigningKey) networkId - receivingAddress = error "create from vk" + receivingAddress = buildAddress receivingVerificationKey networkId - theOutput = error "should pay lovelace to vk" + theOutput = TxOut receivingAddress (lovelaceToTxOutValue lovelace) TxOutDatumNone convertUtxo = error "convert utxo"