From 30a0f99861a861ee3e96c23a8a09043473fed25b Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 25 Jan 2021 12:30:59 -0300 Subject: [PATCH 1/3] Fix bash syntax inconsistencies Many unnecesary braces around ${VARIABLE} references were removed. --- apitest/scripts/limit-order-simulation.sh | 87 +++++++------ apitest/scripts/trade-simulation-env.sh | 32 ++--- apitest/scripts/trade-simulation-utils.sh | 42 +++--- apitest/scripts/trade-simulation.sh | 151 +++++++++++----------- 4 files changed, 157 insertions(+), 155 deletions(-) diff --git a/apitest/scripts/limit-order-simulation.sh b/apitest/scripts/limit-order-simulation.sh index 253deec1a8a..9715da3f715 100755 --- a/apitest/scripts/limit-order-simulation.sh +++ b/apitest/scripts/limit-order-simulation.sh @@ -34,57 +34,58 @@ # # `$ apitest/scripts/limit-order-simulation.sh -l 40000 -d sell -c fr -m 0.00 -a 0.125` +APP_BASE_NAME=$(basename "$0") APP_HOME=$(pwd -P) -APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts" +APITEST_SCRIPTS_HOME="$APP_HOME/apitest/scripts" -source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" -source "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh" +source "$APITEST_SCRIPTS_HOME/trade-simulation-env.sh" +source "$APITEST_SCRIPTS_HOME/trade-simulation-utils.sh" checksetup parselimitorderopts "$@" -printdate "Started ${APP_BASE_NAME} with parameters:" +printdate "Started $APP_BASE_NAME with parameters:" printscriptparams printbreak editpaymentaccountform "$COUNTRY_CODE" exitoncommandalert $? -cat "${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" +cat "$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" printbreak # Create F2F payment accounts for $COUNTRY_CODE, and get the $CURRENCY_CODE. -printdate "Creating Alice's face to face ${COUNTRY_CODE} payment account." -CMD="${CLI_BASE} --port=${ALICE_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" -printdate "ALICE CLI: ${CMD}" -CMD_OUTPUT=$(createpaymentacct "${CMD}") +printdate "Creating Alice's face to face $COUNTRY_CODE payment account." +CMD="$CLI_BASE --port=$ALICE_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" +printdate "ALICE CLI: $CMD" +CMD_OUTPUT=$(createpaymentacct "$CMD") exitoncommandalert $? -echo "${CMD_OUTPUT}" -ALICE_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}") +echo "$CMD_OUTPUT" +ALICE_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT") exitoncommandalert $? -CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}") +CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT") exitoncommandalert $? -printdate "ALICE F2F payment-account-id = ${ALICE_ACCT_ID}, currency-code = ${CURRENCY_CODE}." +printdate "ALICE F2F payment-account-id = $ALICE_ACCT_ID, currency-code = $CURRENCY_CODE." printbreak -printdate "Creating Bob's face to face ${COUNTRY_CODE} payment account." -CMD="${CLI_BASE} --port=${BOB_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" -printdate "BOB CLI: ${CMD}" -CMD_OUTPUT=$(createpaymentacct "${CMD}") +printdate "Creating Bob's face to face $COUNTRY_CODE payment account." +CMD="$CLI_BASE --port=$BOB_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" +printdate "BOB CLI: $CMD" +CMD_OUTPUT=$(createpaymentacct "$CMD") exitoncommandalert $? -echo "${CMD_OUTPUT}" -BOB_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}") +echo "$CMD_OUTPUT" +BOB_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT") exitoncommandalert $? -CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}") +CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT") exitoncommandalert $? -printdate "BOB F2F payment-account-id = ${BOB_ACCT_ID}, currency-code = ${CURRENCY_CODE}." +printdate "BOB F2F payment-account-id = $BOB_ACCT_ID, currency-code = $CURRENCY_CODE." printbreak # Bob & Alice now have matching payment accounts, now loop until the price limit is reached, then create an offer. if [ "$DIRECTION" = "BUY" ] then - printdate "Create a BUY / ${CURRENCY_CODE} offer when the market price falls to or below ${LIMIT_PRICE} ${CURRENCY_CODE}." + printdate "Create a BUY / $CURRENCY_CODE offer when the market price falls to or below $LIMIT_PRICE $CURRENCY_CODE." else - printdate "Create a SELL / ${CURRENCY_CODE} offer when the market price rises to or above ${LIMIT_PRICE} ${CURRENCY_CODE}." + printdate "Create a SELL / $CURRENCY_CODE offer when the market price rises to or above $LIMIT_PRICE $CURRENCY_CODE." fi DONE=0 @@ -112,33 +113,33 @@ while : ; do sleep "$WAIT" done -printdate "ALICE: Creating ${DIRECTION} ${CURRENCY_CODE} offer with payment acct ${ALICE_ACCT_ID}." -CMD="$CLI_BASE --port=${ALICE_PORT} createoffer" -CMD+=" --payment-account=${ALICE_ACCT_ID}" -CMD+=" --direction=${DIRECTION}" -CMD+=" --currency-code=${CURRENCY_CODE}" -CMD+=" --amount=${AMOUNT}" -if [ -z "${MKT_PRICE_MARGIN}" ]; then - CMD+=" --fixed-price=${FIXED_PRICE}" +printdate "ALICE: Creating $DIRECTION $CURRENCY_CODE offer with payment acct $ALICE_ACCT_ID." +CMD="$CLI_BASE --port=$ALICE_PORT createoffer" +CMD+=" --payment-account=$ALICE_ACCT_ID" +CMD+=" --direction=$DIRECTION" +CMD+=" --currency-code=$CURRENCY_CODE" +CMD+=" --amount=$AMOUNT" +if [ -z "$MKT_PRICE_MARGIN" ]; then + CMD+=" --fixed-price=$FIXED_PRICE" else - CMD+=" --market-price-margin=${MKT_PRICE_MARGIN}" + CMD+=" --market-price-margin=$MKT_PRICE_MARGIN" fi CMD+=" --security-deposit=50.0" CMD+=" --fee-currency=BSQ" -printdate "ALICE CLI: ${CMD}" -OFFER_ID=$(createoffer "${CMD}") +printdate "ALICE CLI: $CMD" +OFFER_ID=$(createoffer "$CMD") exitoncommandalert $? -printdate "ALICE: Created offer with id: ${OFFER_ID}." +printdate "ALICE: Created offer with id: $OFFER_ID." printbreak sleeptraced 3 # Show Alice's new offer. -printdate "ALICE: Looking at her new ${DIRECTION} ${CURRENCY_CODE} offer." -CMD="$CLI_BASE --port=${ALICE_PORT} getmyoffer --offer-id=${OFFER_ID}" -printdate "ALICE CLI: ${CMD}" +printdate "ALICE: Looking at her new $DIRECTION $CURRENCY_CODE offer." +CMD="$CLI_BASE --port=$ALICE_PORT getmyoffer --offer-id=$OFFER_ID" +printdate "ALICE CLI: $CMD" OFFER=$($CMD) exitoncommandalert $? -echo "${OFFER}" +echo "$OFFER" printbreak sleeptraced 7 @@ -149,11 +150,11 @@ printbreak sleeptraced 5 # Show Alice's offer in Bob's CLI. -printdate "BOB: Looking at ${DIRECTION} ${CURRENCY_CODE} offers." -CMD="$CLI_BASE --port=${BOB_PORT} getoffers --direction=${DIRECTION} --currency-code=${CURRENCY_CODE}" -printdate "BOB CLI: ${CMD}" +printdate "BOB: Looking at $DIRECTION $CURRENCY_CODE offers." +CMD="$CLI_BASE --port=$BOB_PORT getoffers --direction=$DIRECTION --currency-code=$CURRENCY_CODE" +printdate "BOB CLI: $CMD" OFFERS=$($CMD) exitoncommandalert $? -echo "${OFFERS}" +echo "$OFFERS" exit 0 diff --git a/apitest/scripts/trade-simulation-env.sh b/apitest/scripts/trade-simulation-env.sh index 64be81029a8..78d9d6dee10 100755 --- a/apitest/scripts/trade-simulation-env.sh +++ b/apitest/scripts/trade-simulation-env.sh @@ -22,14 +22,14 @@ checksetup() { --registration-key=6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a" exit 1; } - printdate "Checking ${APP_HOME} for some expected directories and files." - if [ -d "${APP_HOME}/apitest" ]; then + printdate "Checking $APP_HOME for some expected directories and files." + if [ -d "$APP_HOME/apitest" ]; then printdate "Subproject apitest exists."; else printdate "Error: Subproject apitest not found, maybe because you are not running the script from the project root dir." exit 1 fi - if [ -f "${APP_HOME}/bisq-cli" ]; then + if [ -f "$APP_HOME/bisq-cli" ]; then printdate "The bisq-cli script exists."; else printdate "Error: The bisq-cli script not found, maybe because you are not running the script from the project root dir." @@ -181,12 +181,12 @@ parselimitorderopts() { checkbitcoindrunning() { # There may be a '+' char in the path and we have to escape it for pgrep. - if [[ ${APP_HOME} == *"+"* ]]; then - ESCAPED_APP_HOME=$(escapepluschar "${APP_HOME}") + if [[ $APP_HOME == *"+"* ]]; then + ESCAPED_APP_HOME=$(escapepluschar "$APP_HOME") else - ESCAPED_APP_HOME="${APP_HOME}" + ESCAPED_APP_HOME="$APP_HOME" fi - if pgrep -f "bitcoind -datadir=${ESCAPED_APP_HOME}/apitest/build/resources/main/Bitcoin-regtest" > /dev/null ; then + if pgrep -f "bitcoind -datadir=$ESCAPED_APP_HOME/apitest/build/resources/main/Bitcoin-regtest" > /dev/null ; then printdate "The regtest bitcoind node is running on host." else printdate "Error: regtest bitcoind node is not running on host, exiting." @@ -196,24 +196,24 @@ checkbitcoindrunning() { printscriptparams() { if [ -n "${LIMIT_PRICE+1}" ]; then - echo " LIMIT_PRICE = ${LIMIT_PRICE}" + echo " LIMIT_PRICE = $LIMIT_PRICE" fi - echo " DIRECTION = ${DIRECTION}" - echo " COUNTRY_CODE = ${COUNTRY_CODE}" - echo " FIXED_PRICE = ${FIXED_PRICE}" - echo " MKT_PRICE_MARGIN = ${MKT_PRICE_MARGIN}" - echo " AMOUNT = ${AMOUNT}" + echo " DIRECTION = $DIRECTION" + echo " COUNTRY_CODE = $COUNTRY_CODE" + echo " FIXED_PRICE = $FIXED_PRICE" + echo " MKT_PRICE_MARGIN = $MKT_PRICE_MARGIN" + echo " AMOUNT = $AMOUNT" if [ -n "${BOB_ROLE+1}" ]; then - echo " BOB_ROLE = ${BOB_ROLE}" + echo " BOB_ROLE = $BOB_ROLE" fi if [ -n "${ALICE_ROLE+1}" ]; then - echo " ALICE_ROLE = ${ALICE_ROLE}" + echo " ALICE_ROLE = $ALICE_ROLE" fi if [ -n "${WAIT+1}" ]; then - echo " WAIT = ${WAIT}" + echo " WAIT = $WAIT" fi } diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index d41ef2b80d2..2c7f93138ab 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -2,7 +2,7 @@ # This file must be sourced by the main driver. -source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" +source "$APITEST_SCRIPTS_HOME/trade-simulation-env.sh" printdate() { echo "[$(date)] $@" @@ -46,10 +46,10 @@ exitoncommandalert() { registerdisputeagents() { # Silently register dev dispute agents. It's easy to forget. REG_KEY="6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a" - CMD="${CLI_BASE} --port=${ARBITRATOR_PORT} registerdisputeagent --dispute-agent-type=mediator --registration-key=${REG_KEY}" + CMD="$CLI_BASE --port=$ARBITRATOR_PORT registerdisputeagent --dispute-agent-type=mediator --registration-key=$REG_KEY" SILENT=$($CMD) commandalert $? "Could not register dev/test mediator." - CMD="${CLI_BASE} --port=${ARBITRATOR_PORT} registerdisputeagent --dispute-agent-type=refundagent --registration-key=${REG_KEY}" + CMD="$CLI_BASE --port=$ARBITRATOR_PORT registerdisputeagent --dispute-agent-type=refundagent --registration-key=$REG_KEY" SILENT=$($CMD) commandalert $? "Could not register dev/test refundagent." # Do something with $SILENT to keep codacy happy. @@ -59,7 +59,7 @@ registerdisputeagents() { getbtcoreaddress() { CMD="bitcoin-cli -regtest -rpcport=19443 -rpcuser=apitest -rpcpassword=apitest getnewaddress" NEW_ADDRESS=$($CMD) - echo "${NEW_ADDRESS}" + echo "$NEW_ADDRESS" } genbtcblocks() { @@ -74,7 +74,7 @@ genbtcblocks() { for i in $(seq -f "%02g" 1 "$NUM_BLOCKS") do NEW_BLOCK_HASH=$(genbtcblock "$CMD") - printdate "Block Hash #$i:${NEW_BLOCK_HASH}" + printdate "Block Hash #$i:$NEW_BLOCK_HASH" sleep "$SECONDS_BETWEEN_BLOCKS" done } @@ -88,12 +88,12 @@ genbtcblock() { escapepluschar() { STRING="$1" NEW_STRING=$(echo "${STRING//+/\\+}") - echo "${NEW_STRING}" + echo "$NEW_STRING" } printbalances() { PORT="$1" - printcmd "${CLI_BASE} --port=${PORT} getbalance" + printcmd "$CLI_BASE --port=$PORT getbalance" $CLI_BASE --port="$PORT" getbalance } @@ -102,54 +102,54 @@ getpaymentaccountmethods() { CMD_OUTPUT=$($CMD) commandalert $? "Could not get payment method ids." printdate "Payment Method IDs:" - echo "${CMD_OUTPUT}" + echo "$CMD_OUTPUT" } getpaymentaccountform() { CMD="$1" CMD_OUTPUT=$($CMD) commandalert $? "Could not get new payment account form." - echo "${CMD_OUTPUT}" + echo "$CMD_OUTPUT" } editpaymentaccountform() { COUNTRY_CODE="$1" - CMD="python3 ${APITEST_SCRIPTS_HOME}/editf2faccountform.py $COUNTRY_CODE" + CMD="python3 $APITEST_SCRIPTS_HOME/editf2faccountform.py $COUNTRY_CODE" CMD_OUTPUT=$($CMD) commandalert $? "Could not edit payment account form." - printdate "Saved payment account form as ${F2F_ACCT_FORM}." + printdate "Saved payment account form as $F2F_ACCT_FORM." } getnewpaymentacctid() { CREATE_PAYMENT_ACCT_OUTPUT="$1" - PAYMENT_ACCT_DETAIL=$(echo -e "${CREATE_PAYMENT_ACCT_OUTPUT}" | sed -n '3p') + PAYMENT_ACCT_DETAIL=$(echo -e "$CREATE_PAYMENT_ACCT_OUTPUT" | sed -n '3p') ACCT_ID=$(echo -e "$PAYMENT_ACCT_DETAIL" | awk '{print $NF}') - echo "${ACCT_ID}" + echo "$ACCT_ID" } getnewpaymentacctcurrency() { CREATE_PAYMENT_ACCT_OUTPUT="$1" - PAYMENT_ACCT_DETAIL=$(echo -e "${CREATE_PAYMENT_ACCT_OUTPUT}" | sed -n '3p') + PAYMENT_ACCT_DETAIL=$(echo -e "$CREATE_PAYMENT_ACCT_OUTPUT" | sed -n '3p') # This is brittle; it requires the account name field to have N words, # e.g, "Face to Face Payment Account" as defined in editf2faccountform.py. CURRENCY_CODE=$(echo -e "$PAYMENT_ACCT_DETAIL" | awk '{print $6}') - echo "${CURRENCY_CODE}" + echo "$CURRENCY_CODE" } createpaymentacct() { CMD="$1" CMD_OUTPUT=$($CMD) commandalert $? "Could not create new payment account." - echo "${CMD_OUTPUT}" + echo "$CMD_OUTPUT" } getpaymentaccounts() { PORT="$1" - printcmd "${CLI_BASE} --port=${PORT} getpaymentaccts" + printcmd "$CLI_BASE --port=$PORT getpaymentaccts" CMD="$CLI_BASE --port=$PORT getpaymentaccts" CMD_OUTPUT=$($CMD) commandalert $? "Could not get payment accounts." - echo "${CMD_OUTPUT}" + echo "$CMD_OUTPUT" } createoffer() { @@ -160,9 +160,9 @@ createoffer() { # return from this function now, passing the error status code to the caller. commandalert $? "Could not create offer." - OFFER_DETAIL=$(echo -e "${OFFER_DESC}" | sed -n '2p') - NEW_OFFER_ID=$(echo -e "${OFFER_DETAIL}" | awk '{print $NF}') - echo "${NEW_OFFER_ID}" + OFFER_DETAIL=$(echo -e "$OFFER_DESC" | sed -n '2p') + NEW_OFFER_ID=$(echo -e "$OFFER_DETAIL" | awk '{print $NF}') + echo "$NEW_OFFER_ID" } getcurrentprice() { diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index 3928cbf4471..477703d8ec1 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -41,91 +41,91 @@ export APP_BASE_NAME=$(basename "$0") export APP_HOME=$(pwd -P) -export APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts" +export APITEST_SCRIPTS_HOME="$APP_HOME/apitest/scripts" -source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" -source "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh" +source "$APITEST_SCRIPTS_HOME/trade-simulation-env.sh" +source "$APITEST_SCRIPTS_HOME/trade-simulation-utils.sh" checksetup parseopts "$@" -printdate "Started ${APP_BASE_NAME} with parameters:" +printdate "Started $APP_BASE_NAME with parameters:" printscriptparams printbreak registerdisputeagents printdate "Alice looks for the ID of the face to face payment account method (Bob will use same payment method)." -CMD="${CLI_BASE} --port=${ALICE_PORT} getpaymentmethods" -printdate "ALICE CLI: ${CMD}" +CMD="$CLI_BASE --port=$ALICE_PORT getpaymentmethods" +printdate "ALICE CLI: $CMD" getpaymentaccountmethods "$CMD" printbreak -printdate "Alice uses the F2F payment method id to create a face to face payment account in country ${COUNTRY_CODE}." -CMD="${CLI_BASE} --port=${ALICE_PORT} getpaymentacctform --payment-method-id=F2F" -printdate "ALICE CLI: ${CMD}" +printdate "Alice uses the F2F payment method id to create a face to face payment account in country $COUNTRY_CODE." +CMD="$CLI_BASE --port=$ALICE_PORT getpaymentacctform --payment-method-id=F2F" +printdate "ALICE CLI: $CMD" getpaymentaccountform "$CMD" printbreak -printdate "Bob & Alice edit their ${COUNTRY_CODE} payment account forms, and renames them to ${F2F_ACCT_FORM}" +printdate "Bob & Alice edit their $COUNTRY_CODE payment account forms, and renames them to $F2F_ACCT_FORM" editpaymentaccountform "$COUNTRY_CODE" -cat "${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" +cat "$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" # Remove the autogenerated json template because we are going to use one created by a python script in the next step. -CMD="rm -v ${APP_HOME}/f2f_*.json" +CMD="rm -v $APP_HOME/f2f_*.json" DELETE_JSON_TEMPLATE=$($CMD) printdate "$DELETE_JSON_TEMPLATE" printbreak -printdate "Bob and Alice create their face to face ${COUNTRY_CODE} payment accounts." -CMD="${CLI_BASE} --port=${BOB_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" -printdate "BOB CLI: ${CMD}" -CMD_OUTPUT=$(createpaymentacct "${CMD}") -echo "${CMD_OUTPUT}" -BOB_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}") -BOB_ACCT_CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}") -printdate "BOB F2F payment-account-id = ${BOB_ACCT_ID}, currency-code = ${BOB_ACCT_CURRENCY_CODE}." +printdate "Bob and Alice create their face to face $COUNTRY_CODE payment accounts." +CMD="$CLI_BASE --port=$BOB_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" +printdate "BOB CLI: $CMD" +CMD_OUTPUT=$(createpaymentacct "$CMD") +echo "$CMD_OUTPUT" +BOB_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT") +BOB_ACCT_CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT") +printdate "BOB F2F payment-account-id = $BOB_ACCT_ID, currency-code = $BOB_ACCT_CURRENCY_CODE." printbreak -CMD="${CLI_BASE} --port=${ALICE_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" -printdate "ALICE CLI: ${CMD}" -CMD_OUTPUT=$(createpaymentacct "${CMD}") -echo "${CMD_OUTPUT}" -ALICE_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}") -ALICE_ACCT_CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}") -printdate "ALICE F2F payment-account-id = ${ALICE_ACCT_ID}, currency-code = ${ALICE_ACCT_CURRENCY_CODE}." +CMD="$CLI_BASE --port=$ALICE_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" +printdate "ALICE CLI: $CMD" +CMD_OUTPUT=$(createpaymentacct "$CMD") +echo "$CMD_OUTPUT" +ALICE_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT") +ALICE_ACCT_CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT") +printdate "ALICE F2F payment-account-id = $ALICE_ACCT_ID, currency-code = $ALICE_ACCT_CURRENCY_CODE." printbreak -printdate "ALICE ${ALICE_ROLE}: Creating ${DIRECTION} ${ALICE_ACCT_CURRENCY_CODE} offer with payment acct ${ALICE_ACCT_ID}." +printdate "ALICE $ALICE_ROLE: Creating $DIRECTION $ALICE_ACCT_CURRENCY_CODE offer with payment acct $ALICE_ACCT_ID." CURRENT_PRICE=$(getcurrentprice "$ALICE_PORT" "$ALICE_ACCT_CURRENCY_CODE") exitoncommandalert $? printdate "Current Market Price: $CURRENT_PRICE" -CMD="$CLI_BASE --port=${ALICE_PORT} createoffer" -CMD+=" --payment-account=${ALICE_ACCT_ID}" -CMD+=" --direction=${DIRECTION}" -CMD+=" --currency-code=${ALICE_ACCT_CURRENCY_CODE}" -CMD+=" --amount=${AMOUNT}" -if [ -z "${MKT_PRICE_MARGIN}" ]; then - CMD+=" --fixed-price=${FIXED_PRICE}" +CMD="$CLI_BASE --port=$ALICE_PORT createoffer" +CMD+=" --payment-account=$ALICE_ACCT_ID" +CMD+=" --direction=$DIRECTION" +CMD+=" --currency-code=$ALICE_ACCT_CURRENCY_CODE" +CMD+=" --amount=$AMOUNT" +if [ -z "$MKT_PRICE_MARGIN" ]; then + CMD+=" --fixed-price=$FIXED_PRICE" else - CMD+=" --market-price-margin=${MKT_PRICE_MARGIN}" + CMD+=" --market-price-margin=$MKT_PRICE_MARGIN" fi CMD+=" --security-deposit=15.0" CMD+=" --fee-currency=BSQ" -printdate "ALICE CLI: ${CMD}" -OFFER_ID=$(createoffer "${CMD}") +printdate "ALICE CLI: $CMD" +OFFER_ID=$(createoffer "$CMD") exitoncommandalert $? -printdate "ALICE ${ALICE_ROLE}: Created offer with id: ${OFFER_ID}." +printdate "ALICE $ALICE_ROLE: Created offer with id: $OFFER_ID." printbreak sleeptraced 3 # Show Alice's new offer. -printdate "ALICE ${ALICE_ROLE}: Looking at her new ${DIRECTION} ${CURRENCY_CODE} offer." -CMD="$CLI_BASE --port=${ALICE_PORT} getmyoffer --offer-id=${OFFER_ID}" -printdate "ALICE CLI: ${CMD}" +printdate "ALICE $ALICE_ROLE: Looking at her new $DIRECTION $CURRENCY_CODE offer." +CMD="$CLI_BASE --port=$ALICE_PORT getmyoffer --offer-id=$OFFER_ID" +printdate "ALICE CLI: $CMD" OFFER=$($CMD) exitoncommandalert $? -echo "${OFFER}" +echo "$OFFER" printbreak sleeptraced 7 @@ -136,23 +136,23 @@ printbreak sleeptraced 10 # List offers. -printdate "BOB ${BOB_ROLE}: Looking at ${DIRECTION} ${BOB_ACCT_CURRENCY_CODE} offers." -CMD="$CLI_BASE --port=${BOB_PORT} getoffers --direction=${DIRECTION} --currency-code=${BOB_ACCT_CURRENCY_CODE}" -printdate "BOB CLI: ${CMD}" +printdate "BOB $BOB_ROLE: Looking at $DIRECTION $BOB_ACCT_CURRENCY_CODE offers." +CMD="$CLI_BASE --port=$BOB_PORT getoffers --direction=$DIRECTION --currency-code=$BOB_ACCT_CURRENCY_CODE" +printdate "BOB CLI: $CMD" OFFERS=$($CMD) exitoncommandalert $? -echo "${OFFERS}" +echo "$OFFERS" printbreak sleeptraced 3 # Take offer. -printdate "BOB ${BOB_ROLE}: Taking offer ${OFFER_ID} with payment acct ${BOB_ACCT_ID}." -CMD="$CLI_BASE --port=${BOB_PORT} takeoffer --offer-id=${OFFER_ID} --payment-account=${BOB_ACCT_ID} --fee-currency=bsq" -printdate "BOB CLI: ${CMD}" +printdate "BOB $BOB_ROLE: Taking offer $OFFER_ID with payment acct $BOB_ACCT_ID." +CMD="$CLI_BASE --port=$BOB_PORT takeoffer --offer-id=$OFFER_ID --payment-account=$BOB_ACCT_ID --fee-currency=bsq" +printdate "BOB CLI: $CMD" TRADE=$($CMD) commandalert $? "Could not take offer." -echo "${TRADE}" +echo "$TRADE" printbreak sleeptraced 10 @@ -163,45 +163,46 @@ printbreak sleeptraced 6 # Send payment sent and received messages. -if [ "${DIRECTION}" = "BUY" ] +if [ "$DIRECTION" = "BUY" ] then - PAYER="ALICE ${ALICE_ROLE}" - PAYER_PORT=${ALICE_PORT} + PAYER="ALICE $ALICE_ROLE" + PAYER_PORT=$ALICE_PORT PAYER_CLI="ALICE CLI" - PAYEE="BOB ${BOB_ROLE}" - PAYEE_PORT=${BOB_PORT} + PAYEE="BOB $BOB_ROLE" + PAYEE_PORT=$BOB_PORT PAYEE_CLI="BOB CLI" else - PAYER="BOB ${BOB_ROLE}" - PAYER_PORT=${BOB_PORT} + PAYER="BOB $BOB_ROLE" + PAYER_PORT=$BOB_PORT PAYER_CLI="BOB CLI" - PAYEE="ALICE ${ALICE_ROLE}" - PAYEE_PORT=${ALICE_PORT} + PAYEE="ALICE $ALICE_ROLE" + PAYEE_PORT=$ALICE_PORT PAYEE_CLI="ALICE CLI" fi # Confirm payment started. -printdate "${PAYER}: Sending fiat payment sent msg." -CMD="$CLI_BASE --port=${PAYER_PORT} confirmpaymentstarted --trade-id=${OFFER_ID}" -printdate "${PAYER_CLI}: ${CMD}" +printdate "$PAYER: Sending fiat payment sent msg." +CMD="$CLI_BASE --port=$PAYER_PORT confirmpaymentstarted --trade-id=$OFFER_ID" +printdate "$PAYER_CLI: $CMD" SENT_MSG=$($CMD) commandalert $? "Could not send confirmpaymentstarted message." -printdate "${SENT_MSG}" +printdate "$SENT_MSG" printbreak sleeptraced 2 printdate "Generating btc blocks after fiat payment sent msg." genbtcblocks 3 5 sleeptraced 2 +printbreak # Confirm payment received. -printdate "${PAYEE}: Sending fiat payment received msg." -CMD="$CLI_BASE --port=${PAYEE_PORT} confirmpaymentreceived --trade-id=${OFFER_ID}" -printdate "${PAYEE_CLI}: ${CMD}" +printdate "$PAYEE: Sending fiat payment received msg." +CMD="$CLI_BASE --port=$PAYEE_PORT confirmpaymentreceived --trade-id=$OFFER_ID" +printdate "$PAYEE_CLI: $CMD" RCVD_MSG=$($CMD) commandalert $? "Could not send confirmpaymentreceived message." -printdate "${RCVD_MSG}" +printdate "$RCVD_MSG" printbreak sleeptraced 4 @@ -212,19 +213,19 @@ printbreak sleeptraced 3 # Complete the trade on the seller side. -if [ "${DIRECTION}" = "BUY" ] +if [ "$DIRECTION" = "BUY" ] then - printdate "BOB ${BOB_ROLE}: Closing trade by keeping funds in Bisq wallet." - CMD="$CLI_BASE --port=${BOB_PORT} keepfunds --trade-id=${OFFER_ID}" - printdate "BOB CLI: ${CMD}" + printdate "BOB $BOB_ROLE: Closing trade by keeping funds in Bisq wallet." + CMD="$CLI_BASE --port=$BOB_PORT keepfunds --trade-id=$OFFER_ID" + printdate "BOB CLI: $CMD" else printdate "ALICE (taker): Closing trade by keeping funds in Bisq wallet." - CMD="$CLI_BASE --port=${ALICE_PORT} keepfunds --trade-id=${OFFER_ID}" - printdate "ALICE CLI: ${CMD}" + CMD="$CLI_BASE --port=$ALICE_PORT keepfunds --trade-id=$OFFER_ID" + printdate "ALICE CLI: $CMD" fi KEEP_FUNDS_MSG=$($CMD) commandalert $? "Could close trade with keepfunds command." -printdate "${KEEP_FUNDS_MSG}" +printdate "$KEEP_FUNDS_MSG" sleeptraced 5 printbreak From 5a78d181036e597112b6677b821ba0ab62f0dc93 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Thu, 28 Jan 2021 19:33:21 -0300 Subject: [PATCH 2/3] Refactor createpaymentacct and trade protocol functions Code duplication needs to be reduced as new scripts are added. - Refactor the createpaymentacct functions. The steps required to create a payment account are still displayed, but only for Alice, not Bob. - Treat the trade protocol simulation as an atomic function. This will reduce 'main' simulation script size as new ones are added. --- apitest/scripts/trade-simulation-utils.sh | 145 ++++++++++++++++++++++ apitest/scripts/trade-simulation.sh | 143 +++------------------ 2 files changed, 165 insertions(+), 123 deletions(-) diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index 2c7f93138ab..412d759ac19 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -152,6 +152,33 @@ getpaymentaccounts() { echo "$CMD_OUTPUT" } +showcreatepaymentacctsteps() { + USER="$1" + PORT="$2" + printdate "$USER looks for the ID of the face to face payment account method (Bob will use same payment method)." + CMD="$CLI_BASE --port=$PORT getpaymentmethods" + printdate "$USER CLI: $CMD" + PAYMENT_ACCT_METHODS=$(getpaymentaccountmethods "$CMD") + echo "$PAYMENT_ACCT_METHODS" + printbreak + + printdate "$USER uses the F2F payment method id to create a face to face payment account in country $COUNTRY_CODE." + CMD="$CLI_BASE --port=$PORT getpaymentacctform --payment-method-id=F2F" + printdate "$USER CLI: $CMD" + getpaymentaccountform "$CMD" + printbreak + + printdate "$USER edits the $COUNTRY_CODE payment account form, and (optionally) renames it as $F2F_ACCT_FORM" + editpaymentaccountform "$COUNTRY_CODE" + cat "$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" + + # Remove the autogenerated json template because we are going to use one created by a python script in the next step. + CMD="rm -v $APP_HOME/f2f_*.json" + DELETE_JSON_TEMPLATE=$($CMD) + printdate "$DELETE_JSON_TEMPLATE" + printbreak +} + createoffer() { CREATE_OFFER_CMD="$1" OFFER_DESC=$($CREATE_OFFER_CMD) @@ -165,6 +192,124 @@ createoffer() { echo "$NEW_OFFER_ID" } +getfirstofferid() { + PORT="$1" + CMD="$CLI_BASE --port=$PORT getoffers --direction=$DIRECTION --currency-code=$CURRENCY_CODE" + CMD_OUTPUT=$($CMD) + commandalert $? "Could not get current $DIRECTION / $CURRENCY_CODE offers." + FIRST_OFFER_DETAIL=$(echo -e "$CMD_OUTPUT" | sed -n '2p') + FIRST_OFFER_ID=$(echo -e "$FIRST_OFFER_DETAIL" | awk '{print $NF}') + commandalert $? "Could parse the offer-id from the first listed offer." + echo "$FIRST_OFFER_ID" +} + +# This is a large function that should be broken up if it ever makes sense to not treat a trade +# execution simulation as an atomic operation. But we are not testing api methods here, just +# demonstrating how to use them to get through the trade protocol. It should work for any trade +# between Bob & Alice, as long as Alice is maker, Bob is taker, and the offer to be taken is the +# first displayed in Bob's getoffers command output. +executetrade() { + # Bob list available offers. + printdate "BOB $BOB_ROLE: Looking at $DIRECTION $CURRENCY_CODE offers." + CMD="$CLI_BASE --port=$BOB_PORT getoffers --direction=$DIRECTION --currency-code=$CURRENCY_CODE" + printdate "BOB CLI: $CMD" + OFFERS=$($CMD) + exitoncommandalert $? + echo "$OFFERS" + printbreak + + OFFER_ID=$(getfirstofferid "$BOB_PORT") + exitoncommandalert $? + printdate "First offer found: $OFFER_ID" + + # Take Alice's offer. + CMD="$CLI_BASE --port=$BOB_PORT takeoffer --offer-id=$OFFER_ID --payment-account=$BOB_ACCT_ID --fee-currency=bsq" + printdate "BOB CLI: $CMD" + TRADE=$($CMD) + commandalert $? "Could not take offer." + # Print the takeoffer command's console output. + printdate "$TRADE" + printbreak + sleeptraced 10 + + # Generate some btc blocks + printdate "Generating btc blocks after Bob takes Alice's offer." + genbtcblocks 3 3 + printbreak + sleeptraced 5 + + # Send payment sent and received messages. + if [ "$DIRECTION" = "BUY" ] + then + PAYER="ALICE $ALICE_ROLE" + PAYER_PORT=$ALICE_PORT + PAYER_CLI="ALICE CLI" + PAYEE="BOB $BOB_ROLE" + PAYEE_PORT=$BOB_PORT + PAYEE_CLI="BOB CLI" + else + PAYER="BOB $BOB_ROLE" + PAYER_PORT=$BOB_PORT + PAYER_CLI="BOB CLI" + PAYEE="ALICE $ALICE_ROLE" + PAYEE_PORT=$ALICE_PORT + PAYEE_CLI="ALICE CLI" + fi + + # Confirm payment started. + printdate "$PAYER: Sending fiat payment sent msg." + CMD="$CLI_BASE --port=$PAYER_PORT confirmpaymentstarted --trade-id=$OFFER_ID" + printdate "$PAYER_CLI: $CMD" + SENT_MSG=$($CMD) + commandalert $? "Could not send confirmpaymentstarted message." + # Print the confirmpaymentstarted command's console output. + printdate "$SENT_MSG" + printbreak + + sleeptraced 2 + printdate "Generating btc blocks after fiat payment sent msg." + genbtcblocks 3 5 + sleeptraced 2 + printbreak + + # Confirm payment received. + printdate "$PAYEE: Sending fiat payment received msg." + CMD="$CLI_BASE --port=$PAYEE_PORT confirmpaymentreceived --trade-id=$OFFER_ID" + printdate "$PAYEE_CLI: $CMD" + RCVD_MSG=$($CMD) + commandalert $? "Could not send confirmpaymentreceived message." + # Print the confirmpaymentreceived command's console output. + printdate "$RCVD_MSG" + printbreak + sleeptraced 4 + + # Generate some btc blocks + printdate "Generating btc blocks after fiat transfer." + genbtcblocks 3 5 + printbreak + sleeptraced 3 + + # Complete the trade on the seller side. + if [ "$DIRECTION" = "BUY" ] + then + printdate "BOB $BOB_ROLE: Closing trade by keeping funds in Bisq wallet." + CMD="$CLI_BASE --port=$BOB_PORT keepfunds --trade-id=$OFFER_ID" + printdate "BOB CLI: $CMD" + else + printdate "ALICE (taker): Closing trade by keeping funds in Bisq wallet." + CMD="$CLI_BASE --port=$ALICE_PORT keepfunds --trade-id=$OFFER_ID" + printdate "ALICE CLI: $CMD" + fi + KEEP_FUNDS_MSG=$($CMD) + commandalert $? "Could close trade with keepfunds command." + # Print the keepfunds command's console output. + printdate "$KEEP_FUNDS_MSG" + sleeptraced 5 + printbreak + + printdate "Trade $OFFER_ID complete." +} + getcurrentprice() { PORT="$1" CURRENCY_CODE="$2" diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index 477703d8ec1..bb2a93293a4 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -55,55 +55,41 @@ printbreak registerdisputeagents -printdate "Alice looks for the ID of the face to face payment account method (Bob will use same payment method)." -CMD="$CLI_BASE --port=$ALICE_PORT getpaymentmethods" -printdate "ALICE CLI: $CMD" -getpaymentaccountmethods "$CMD" -printbreak +# Demonstrate how to create a country based, face to face account. +showcreatepaymentacctsteps "Alice" "$ALICE_PORT" -printdate "Alice uses the F2F payment method id to create a face to face payment account in country $COUNTRY_CODE." -CMD="$CLI_BASE --port=$ALICE_PORT getpaymentacctform --payment-method-id=F2F" +CMD="$CLI_BASE --port=$ALICE_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" printdate "ALICE CLI: $CMD" -getpaymentaccountform "$CMD" +CMD_OUTPUT=$(createpaymentacct "$CMD") +echo "$CMD_OUTPUT" printbreak - -printdate "Bob & Alice edit their $COUNTRY_CODE payment account forms, and renames them to $F2F_ACCT_FORM" -editpaymentaccountform "$COUNTRY_CODE" -cat "$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" - -# Remove the autogenerated json template because we are going to use one created by a python script in the next step. -CMD="rm -v $APP_HOME/f2f_*.json" -DELETE_JSON_TEMPLATE=$($CMD) -printdate "$DELETE_JSON_TEMPLATE" +export ALICE_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT") +export CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT") +printdate "Alice's F2F payment-account-id: $ALICE_ACCT_ID, currency-code: $CURRENCY_CODE" +exitoncommandalert $? printbreak -printdate "Bob and Alice create their face to face $COUNTRY_CODE payment accounts." +printdate "Bob creates his F2F payment account." CMD="$CLI_BASE --port=$BOB_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" printdate "BOB CLI: $CMD" CMD_OUTPUT=$(createpaymentacct "$CMD") echo "$CMD_OUTPUT" -BOB_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT") -BOB_ACCT_CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT") -printdate "BOB F2F payment-account-id = $BOB_ACCT_ID, currency-code = $BOB_ACCT_CURRENCY_CODE." printbreak - -CMD="$CLI_BASE --port=$ALICE_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM" -printdate "ALICE CLI: $CMD" -CMD_OUTPUT=$(createpaymentacct "$CMD") -echo "$CMD_OUTPUT" -ALICE_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT") -ALICE_ACCT_CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT") -printdate "ALICE F2F payment-account-id = $ALICE_ACCT_ID, currency-code = $ALICE_ACCT_CURRENCY_CODE." +export BOB_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT") +export CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT") +printdate "Bob's F2F payment-account-id: $BOB_ACCT_ID, currency-code: $CURRENCY_CODE" +exitoncommandalert $? printbreak -printdate "ALICE $ALICE_ROLE: Creating $DIRECTION $ALICE_ACCT_CURRENCY_CODE offer with payment acct $ALICE_ACCT_ID." -CURRENT_PRICE=$(getcurrentprice "$ALICE_PORT" "$ALICE_ACCT_CURRENCY_CODE") +# Alice creates an offer. +printdate "ALICE $ALICE_ROLE: Creating $DIRECTION $CURRENCY_CODE offer with payment acct $ALICE_ACCT_ID." +CURRENT_PRICE=$(getcurrentprice "$ALICE_PORT" "$CURRENCY_CODE") exitoncommandalert $? printdate "Current Market Price: $CURRENT_PRICE" CMD="$CLI_BASE --port=$ALICE_PORT createoffer" CMD+=" --payment-account=$ALICE_ACCT_ID" CMD+=" --direction=$DIRECTION" -CMD+=" --currency-code=$ALICE_ACCT_CURRENCY_CODE" +CMD+=" --currency-code=$CURRENCY_CODE" CMD+=" --amount=$AMOUNT" if [ -z "$MKT_PRICE_MARGIN" ]; then CMD+=" --fixed-price=$FIXED_PRICE" @@ -135,98 +121,9 @@ genbtcblocks 3 5 printbreak sleeptraced 10 -# List offers. -printdate "BOB $BOB_ROLE: Looking at $DIRECTION $BOB_ACCT_CURRENCY_CODE offers." -CMD="$CLI_BASE --port=$BOB_PORT getoffers --direction=$DIRECTION --currency-code=$BOB_ACCT_CURRENCY_CODE" -printdate "BOB CLI: $CMD" -OFFERS=$($CMD) +# Go through the trade protocol. +executetrade exitoncommandalert $? -echo "$OFFERS" -printbreak -sleeptraced 3 - -# Take offer. -printdate "BOB $BOB_ROLE: Taking offer $OFFER_ID with payment acct $BOB_ACCT_ID." -CMD="$CLI_BASE --port=$BOB_PORT takeoffer --offer-id=$OFFER_ID --payment-account=$BOB_ACCT_ID --fee-currency=bsq" -printdate "BOB CLI: $CMD" -TRADE=$($CMD) -commandalert $? "Could not take offer." - -echo "$TRADE" -printbreak -sleeptraced 10 - -# Generating some btc blocks -printdate "Generating btc blocks after Bob takes Alice's offer." -genbtcblocks 3 3 -printbreak -sleeptraced 6 - -# Send payment sent and received messages. -if [ "$DIRECTION" = "BUY" ] -then - PAYER="ALICE $ALICE_ROLE" - PAYER_PORT=$ALICE_PORT - PAYER_CLI="ALICE CLI" - PAYEE="BOB $BOB_ROLE" - PAYEE_PORT=$BOB_PORT - PAYEE_CLI="BOB CLI" -else - PAYER="BOB $BOB_ROLE" - PAYER_PORT=$BOB_PORT - PAYER_CLI="BOB CLI" - PAYEE="ALICE $ALICE_ROLE" - PAYEE_PORT=$ALICE_PORT - PAYEE_CLI="ALICE CLI" -fi - -# Confirm payment started. -printdate "$PAYER: Sending fiat payment sent msg." -CMD="$CLI_BASE --port=$PAYER_PORT confirmpaymentstarted --trade-id=$OFFER_ID" -printdate "$PAYER_CLI: $CMD" -SENT_MSG=$($CMD) -commandalert $? "Could not send confirmpaymentstarted message." - -printdate "$SENT_MSG" -printbreak - -sleeptraced 2 -printdate "Generating btc blocks after fiat payment sent msg." -genbtcblocks 3 5 -sleeptraced 2 -printbreak - -# Confirm payment received. -printdate "$PAYEE: Sending fiat payment received msg." -CMD="$CLI_BASE --port=$PAYEE_PORT confirmpaymentreceived --trade-id=$OFFER_ID" -printdate "$PAYEE_CLI: $CMD" -RCVD_MSG=$($CMD) -commandalert $? "Could not send confirmpaymentreceived message." -printdate "$RCVD_MSG" -printbreak -sleeptraced 4 - -# Generate some btc blocks -printdate "Generating btc blocks after fiat transfer." -genbtcblocks 3 5 -printbreak -sleeptraced 3 - -# Complete the trade on the seller side. -if [ "$DIRECTION" = "BUY" ] -then - printdate "BOB $BOB_ROLE: Closing trade by keeping funds in Bisq wallet." - CMD="$CLI_BASE --port=$BOB_PORT keepfunds --trade-id=$OFFER_ID" - printdate "BOB CLI: $CMD" -else - printdate "ALICE (taker): Closing trade by keeping funds in Bisq wallet." - CMD="$CLI_BASE --port=$ALICE_PORT keepfunds --trade-id=$OFFER_ID" - printdate "ALICE CLI: $CMD" -fi -KEEP_FUNDS_MSG=$($CMD) -commandalert $? "Could close trade with keepfunds command." -printdate "$KEEP_FUNDS_MSG" -sleeptraced 5 printbreak # Get balances after trade completion. From 74008e938568ff556a6481e4f6720f4e1ab8d6a1 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Thu, 28 Jan 2021 19:56:15 -0300 Subject: [PATCH 3/3] Move createoffer command generation to its own function --- apitest/scripts/trade-simulation-utils.sh | 18 ++++++++++++++++++ apitest/scripts/trade-simulation.sh | 13 +------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index 412d759ac19..180e1894dfd 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -179,6 +179,24 @@ showcreatepaymentacctsteps() { printbreak } +gencreateoffercommand() { + PORT="$1" + ACCT_ID="$2" + CMD="$CLI_BASE --port=$PORT createoffer" + CMD+=" --payment-account=$ACCT_ID" + CMD+=" --direction=$DIRECTION" + CMD+=" --currency-code=$CURRENCY_CODE" + CMD+=" --amount=$AMOUNT" + if [ -z "$MKT_PRICE_MARGIN" ]; then + CMD+=" --fixed-price=$FIXED_PRICE" + else + CMD+=" --market-price-margin=$MKT_PRICE_MARGIN" + fi + CMD+=" --security-deposit=15.0" + CMD+=" --fee-currency=BSQ" + echo "$CMD" +} + createoffer() { CREATE_OFFER_CMD="$1" OFFER_DESC=$($CREATE_OFFER_CMD) diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index bb2a93293a4..cf8bda74102 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -86,18 +86,7 @@ printdate "ALICE $ALICE_ROLE: Creating $DIRECTION $CURRENCY_CODE offer with pay CURRENT_PRICE=$(getcurrentprice "$ALICE_PORT" "$CURRENCY_CODE") exitoncommandalert $? printdate "Current Market Price: $CURRENT_PRICE" -CMD="$CLI_BASE --port=$ALICE_PORT createoffer" -CMD+=" --payment-account=$ALICE_ACCT_ID" -CMD+=" --direction=$DIRECTION" -CMD+=" --currency-code=$CURRENCY_CODE" -CMD+=" --amount=$AMOUNT" -if [ -z "$MKT_PRICE_MARGIN" ]; then - CMD+=" --fixed-price=$FIXED_PRICE" -else - CMD+=" --market-price-margin=$MKT_PRICE_MARGIN" -fi -CMD+=" --security-deposit=15.0" -CMD+=" --fee-currency=BSQ" +CMD=$(gencreateoffercommand "$ALICE_PORT" "$ALICE_ACCT_ID") printdate "ALICE CLI: $CMD" OFFER_ID=$(createoffer "$CMD") exitoncommandalert $?