Skip to content

Commit

Permalink
Remove build transaction with fee from script
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-iohk committed Oct 25, 2021
1 parent b3f4e50 commit 0280f16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 11 additions & 5 deletions local-cluster/test/Test/LocalClusterSpec.hs
Expand Up @@ -20,6 +20,7 @@ import Cardano.Api (
serialiseToBech32,
serialiseToRawBytesHexText,
shelleyAddressInEra,
writeFileTextEnvelope,
)
import Cardano.Api.Shelley (Lovelace (Lovelace))
import CardanoClient (Sizes (..), buildAddress, buildRaw, calculateMinFee, defaultSizes, queryProtocolParameters, queryTipSlotNo, queryUtxo)
Expand Down Expand Up @@ -72,17 +73,21 @@ assertCanSpendInitialFunds = \case
TxOutValue _ v -> selectLovelace v

nodeDirectory = parentStateDirectory </> "node-" <> show nodeId

rawTx <- buildRaw [txIn] [TxOut (shelleyAddressInEra addr) (TxOutValue MultiAssetInAlonzoEra (lovelaceToValue 100_000_000)) TxOutDatumHashNone] 0 0
paymentOutput = TxOut (shelleyAddressInEra addr) (TxOutValue MultiAssetInAlonzoEra (lovelaceToValue 100_000_000)) TxOutDatumHashNone
rawTx <- buildRaw [txIn] [] 0 0
pparams <- queryProtocolParameters networkId socket
let fee = calculateMinFee networkId rawTx defaultSizes{inputs = 1, outputs = 2, witnesses = 1} pparams
slotNo <- queryTipSlotNo networkId socket
runTestScript nodeDirectory addr txIn amount slotNo fee socket
let changeOutput = TxOut (shelleyAddressInEra addr) (TxOutValue MultiAssetInAlonzoEra (lovelaceToValue $ amount - 100_000_000 - fee)) TxOutDatumHashNone
draftTxPath = nodeDirectory </> "tx.draft"
draftTx <- buildRaw [txIn] [paymentOutput, changeOutput] (slotNo + 100) fee
writeFileTextEnvelope draftTxPath Nothing draftTx >>= either (error . show) pure
runTestScript nodeDirectory addr txIn amount slotNo fee draftTxPath socket
_ ->
error "empty cluster?"

runTestScript :: FilePath -> Address ShelleyAddr -> TxIn -> Lovelace -> SlotNo -> Lovelace -> FilePath -> IO ()
runTestScript nodeDirectory addr (TxIn txId (TxIx txIx)) (Lovelace amount) (SlotNo slot) (Lovelace fee) socket = do
runTestScript :: FilePath -> Address ShelleyAddr -> TxIn -> Lovelace -> SlotNo -> Lovelace -> FilePath -> FilePath -> IO ()
runTestScript nodeDirectory addr (TxIn txId (TxIx txIx)) (Lovelace amount) (SlotNo slot) (Lovelace fee) draftTxPath socket = do
inputScript <- Pkg.getDataFileName "test_submit.sh"
currentEnv <- getEnvironment
let scriptOutput = nodeDirectory </> "test_submit.out"
Expand All @@ -103,6 +108,7 @@ runTestScript nodeDirectory addr (TxIn txId (TxIx txIx)) (Lovelace amount) (Slot
, show amount
, show fee
, show slot
, draftTxPath
]
)
{ env = Just (socketEnv : baseEnv)
Expand Down
8 changes: 2 additions & 6 deletions local-cluster/test_submit.sh
Expand Up @@ -10,15 +10,11 @@ utxo=$2
amount=$3
fees=$4
slot=$5
txDraft=$6

transfer_amount=100000000

cardano-cli transaction build-raw --tx-in $utxo \
--tx-out $utxo_addr+$transfer_amount \
--tx-out $utxo_addr+$(($amount - $transfer_amount - $fees)) \
--invalid-hereafter $((slot + 100)) --fee $fees --out-file tx.draft

cardano-cli transaction sign --tx-body-file tx.draft --signing-key-file ../alice.sk --testnet-magic 42 --out-file tx.signed
cardano-cli transaction sign --tx-body-file $txDraft --signing-key-file ../alice.sk --testnet-magic 42 --out-file tx.signed
cardano-cli transaction submit --tx-file tx.signed --testnet-magic 42

timeout=30
Expand Down

0 comments on commit 0280f16

Please sign in to comment.