Skip to content

Commit

Permalink
Make it possible to choose socket file and other parameters when runn…
Browse files Browse the repository at this point in the history
…ing plutus test script. Such configuration will make it possible to run them from automated tests in CI.
  • Loading branch information
newhoggy committed Jun 23, 2021
1 parent b76de42 commit fbc7193
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
50 changes: 26 additions & 24 deletions scripts/plutus/example-txin-locking-plutus-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
set -e
set -o pipefail

export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}"
export UTXO_VKEY="${UTXO_VKEY:-example/shelley/utxo-keys/utxo1.vkey}"
export UTXO_SKEY="${UTXO_SKEY:-example/shelley/utxo-keys/utxo1.skey}"
export WORK="${WORK:-example/work}"

if [ "$1" == "guessinggame" ]; then
# NB: This plutus script uses a "typed" redeemer and "typed" datum.
plutusscriptinuse=scripts/plutus/scripts/typed-guessing-game-redeemer-42-datum-42.plutus
Expand Down Expand Up @@ -38,17 +43,14 @@ fi

plutusscriptaddr=$(cardano-cli address build --payment-script-file $plutusscriptinuse --testnet-magic 42)

mkdir -p example/work

utxovkey=example/shelley/utxo-keys/utxo1.vkey
utxoskey=example/shelley/utxo-keys/utxo1.skey
mkdir -p $WORK

utxoaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $utxovkey)
utxoaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $UTXO_VKEY)

cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file example/work/utxo.json
cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file $WORK/utxo.json

txin=$(jq -r 'keys[]' example/work/utxo.json)
lovelaceattxin=$(jq -r ".[\"$txin\"].value.lovelace" example/work/utxo.json)
txin=$(jq -r 'keys[]' $WORK/utxo.json)
lovelaceattxin=$(jq -r ".[\"$txin\"].value.lovelace" $WORK/utxo.json)
lovelaceattxindiv2=$(expr $lovelaceattxin / 2)

cardano-cli transaction build-raw \
Expand All @@ -58,34 +60,34 @@ cardano-cli transaction build-raw \
--tx-out "$plutusscriptaddr+$lovelaceattxindiv2" \
--tx-out-datum-hash "$scriptdatumhash" \
--tx-out "$utxoaddr+$lovelaceattxindiv2" \
--out-file example/work/create-datum-output.body
--out-file $WORK/create-datum-output.body

cardano-cli transaction sign \
--tx-body-file example/work/create-datum-output.body \
--tx-body-file $WORK/create-datum-output.body \
--testnet-magic 42 \
--signing-key-file $utxoskey\
--out-file example/work/create-datum-output.tx
--signing-key-file $UTXO_SKEY \
--out-file $WORK/create-datum-output.tx

# SUBMIT
cardano-cli transaction submit --tx-file example/work/create-datum-output.tx --testnet-magic 42
cardano-cli transaction submit --tx-file $WORK/create-datum-output.tx --testnet-magic 42
echo "Pausing for 5 seconds..."
sleep 5

# Step 2
# After "locking" the tx output at the script address, we can now can attempt to spend
# the "locked" tx output below.

cardano-cli query utxo --address $plutusscriptaddr --testnet-magic 42 --out-file example/work/plutusutxo.json
plutusutxotxin=$(jq -r 'keys[]' example/work/plutusutxo.json)
cardano-cli query utxo --address $plutusscriptaddr --testnet-magic 42 --out-file $WORK/plutusutxo.json
plutusutxotxin=$(jq -r 'keys[]' $WORK/plutusutxo.json)

cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file example/work/utxo.json
txinCollateral=$(jq -r 'keys[]' example/work/utxo.json)
cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file $WORK/utxo.json
txinCollateral=$(jq -r 'keys[]' $WORK/utxo.json)

cardano-cli query protocol-parameters --testnet-magic 42 --out-file example/pparams.json

dummyaddress=addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4

lovelaceatplutusscriptaddr=$(jq -r ".[\"$plutusutxotxin\"].value.lovelace" example/work/plutusutxo.json)
lovelaceatplutusscriptaddr=$(jq -r ".[\"$plutusutxotxin\"].value.lovelace" $WORK/plutusutxo.json)

txfee=$(expr $plutusrequiredtime + $plutusrequiredtime)
spendable=$(expr $lovelaceatplutusscriptaddr - $plutusrequiredtime - $plutusrequiredtime)
Expand All @@ -101,17 +103,17 @@ cardano-cli transaction build-raw \
--protocol-params-file example/pparams.json\
--tx-in-redeemer-file "$redeemerfilepath" \
--tx-in-execution-units "($plutusrequiredtime, $plutusrequiredspace)" \
--out-file example/work/test-alonzo.body
--out-file $WORK/test-alonzo.body

cardano-cli transaction sign \
--tx-body-file example/work/test-alonzo.body \
--tx-body-file $WORK/test-alonzo.body \
--testnet-magic 42 \
--signing-key-file example/shelley/utxo-keys/utxo1.skey \
--out-file example/work/alonzo.tx
--signing-key-file "${UTXO_SKEY}" \
--out-file $WORK/alonzo.tx

# SUBMIT example/work/alonzo.tx
# SUBMIT $WORK/alonzo.tx
echo "Submit the tx with plutus script and wait 5 seconds..."
cardano-cli transaction submit --tx-file example/work/alonzo.tx --testnet-magic 42
cardano-cli transaction submit --tx-file $WORK/alonzo.tx --testnet-magic 42
sleep 5
echo ""
echo "Querying UTxO at $dummyaddress. If there is ADA at the address the Plutus script successfully executed!"
Expand Down
2 changes: 1 addition & 1 deletion scripts/plutus/simple-minting-policy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set -o pipefail

# Step 1 - Send ADA to token script owner

export CARDANO_NODE_SOCKET_PATH=example/node-bft1/node.sock
export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}"

utxovkey=example/shelley/utxo-keys/utxo1.vkey
utxoskey=example/shelley/utxo-keys/utxo1.skey
Expand Down

0 comments on commit fbc7193

Please sign in to comment.