Better missed-conf-management, better tests

This commit is contained in:
kexkey
2021-08-20 17:24:38 -04:00
parent 2e60b91a6a
commit 659147c71d
12 changed files with 620 additions and 350 deletions

View File

@@ -11,7 +11,7 @@ do_callbacks() {
trace "Entering do_callbacks()..."
# Let's fetch all the watching addresses still being watched but not called back
local callbacks=$(sql 'SELECT DISTINCT w.callback0conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime, w.id, is_replaceable, pub32_index, pub32, label, derivation_path, event_message, hash FROM watching w LEFT JOIN watching_tx ON w.id = watching_id LEFT JOIN tx ON tx.id = tx_id LEFT JOIN watching_by_pub32 w32 ON watching_by_pub32_id = w32.id WHERE NOT calledback0conf AND watching_id NOT NULL AND w.callback0conf NOT NULL AND w.watching')
local callbacks=$(sql 'SELECT DISTINCT w.callback0conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime, w.id, is_replaceable, pub32_index, pub32, w32.label, derivation_path, event_message, hash FROM watching w LEFT JOIN watching_tx ON w.id = watching_id LEFT JOIN tx ON tx.id = tx_id LEFT JOIN watching_by_pub32 w32 ON watching_by_pub32_id = w32.id WHERE NOT calledback0conf AND watching_id NOT NULL AND w.callback0conf NOT NULL AND w.watching')
trace "[do_callbacks] callbacks0conf=${callbacks}"
local returncode
@@ -30,7 +30,7 @@ do_callbacks() {
fi
done
callbacks=$(sql 'SELECT DISTINCT w.callback1conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime, w.id, is_replaceable, pub32_index, pub32, label, derivation_path, event_message, hash FROM watching w, watching_tx wt, tx t LEFT JOIN watching_by_pub32 w32 ON watching_by_pub32_id = w32.id WHERE w.id = watching_id AND tx_id = t.id AND NOT calledback1conf AND confirmations>0 AND w.callback1conf NOT NULL AND w.watching')
callbacks=$(sql 'SELECT DISTINCT w.callback1conf, address, txid, vout, amount, confirmations, timereceived, fee, size, vsize, blockhash, blockheight, blocktime, w.id, is_replaceable, pub32_index, pub32, w32.label, derivation_path, event_message, hash FROM watching w, watching_tx wt, tx t LEFT JOIN watching_by_pub32 w32 ON watching_by_pub32_id = w32.id WHERE w.id = watching_id AND tx_id = t.id AND NOT calledback1conf AND confirmations>0 AND w.callback1conf NOT NULL AND w.watching')
trace "[do_callbacks] callbacks1conf=${callbacks}"
for row in ${callbacks}

View File

@@ -29,6 +29,8 @@ confirmation() {
local returncode
local txid=${1}
local bypass_callbacks=${2}
trace "[confirmation] bypass_callbacks=${bypass_callbacks}"
local tx_details
tx_details="$(get_transaction ${txid})"
returncode=$?
@@ -196,7 +198,13 @@ confirmation() {
) 201>./.confirmation.lock
# There's a lock in callbacks, let's get out of the confirmation lock before entering another one
do_callbacks
# If this was called by missed_conf algo, we don't want to process all the callbacks now. We wait
# for next cron.
if [ -z "${bypass_callbacks}" ]; then
trace "[confirmation] Let's do the callbacks!"
do_callbacks
fi
echo '{"result":"confirmed"}'
return 0

View File

@@ -38,46 +38,63 @@ manage_missed_conf() {
trace "[Entering manage_missed_conf()]"
local watches=$(sql 'SELECT DISTINCT address FROM watching w LEFT JOIN watching_tx ON w.id = watching_id LEFT JOIN tx t ON t.id = tx_id WHERE watching AND imported AND (tx_id IS NULL OR t.confirmations=0)')
local watches=$(sql 'SELECT DISTINCT address, w.inserted_ts FROM watching w LEFT JOIN watching_tx ON w.id = watching_id LEFT JOIN tx t ON t.id = tx_id WHERE watching AND imported AND (tx_id IS NULL OR t.confirmations=0)')
trace "[manage_missed_conf] watches=${watches}"
if [ ${#watches} -eq 0 ]; then
trace "[manage_missed_conf] Nothing missed!"
return 0
fi
local addresses
local received
local latesttxid
local tx
local blocktime
local data
local result
local returncode
local row
local address
local inserted_ts
local txid
local txids
local IFS=$'\n'
for address in ${watches}
for row in ${watches}
do
if [ -z ${addresses} ]; then
addresses="[\"${address}\""
# Let's get confirmed received txs for the address
address=$(echo "${row}" | cut -d '|' -f1)
inserted_ts=$(date -d "$(echo "${row}" | cut -d '|' -f2)" +"%s")
trace "[manage_missed_conf] address=${address}"
data='{"method":"listreceivedbyaddress","params":[0, false, true, "'${address}'"]}'
received=$(send_to_watcher_node ${data} | jq '.result[0]')
if [ "${received}" = "null" ]; then
# Not confirmed while we were away...
trace "[manage_missed_conf] Nothing missed here"
else
addresses="${addresses},\"${address}\""
# We got something confirmed
# Let's find out if it was confirmed after being watched
trace "[manage_missed_conf] We got something confirmed"
latesttxid=$(echo "${received}" | jq -r ".txids | last")
data='{"method":"gettransaction","params":["'${latesttxid}'"]}'
tx=$(send_to_watcher_node ${data})
blocktime=$(echo "${tx}" | jq '.result.blocktime')
txtime=$(echo "${tx}" | jq '.result.time')
confirmations=$(echo "${tx}" | jq '.result.confirmations')
trace "[manage_missed_conf] blocktime=${blocktime}"
trace "[manage_missed_conf] txtime=${txtime}"
trace "[manage_missed_conf] inserted_ts=${inserted_ts}"
trace "[manage_missed_conf] confirmations=${confirmations}"
if [ "${txtime}" -gt "${inserted_ts}" ]; then
# Mined after watch, we missed it!
trace "[manage_missed_conf] Mined after watch, we missed it!"
confirmation "${latesttxid}" "true"
fi
fi
done
addresses="${addresses}]"
# Watching addresses with UTXO are transactions being watched that went through without us knowing it, we missed the conf
data="{\"method\":\"listunspent\",\"params\":[0, 9999999, ${addresses}]}"
local unspents
unspents=$(send_to_watcher_node ${data})
returncode=$?
trace_rc ${returncode}
if [ "${returncode}" -ne 0 ]; then
return ${returncode}
fi
local txids=$(echo "${unspents}" | jq -r ".result[].txid")
for txid in ${txids}
do
confirmation "${txid}"
done
return 0
}
case "${0}" in *manage_missed_conf.sh) manage_not_imported $@; manage_missed_conf $@;; esac

View File

@@ -1,326 +0,0 @@
#!/bin/sh
# curl localhost:8888/listbatchers | jq
# curl -d '{}' localhost:8888/getbatcher | jq
# curl -d '{}' localhost:8888/getbatchdetails | jq
# curl -d '{"outputLabel":"test002","address":"1abd","amount":0.0002}' localhost:8888/addtobatch | jq
# curl -d '{}' localhost:8888/batchspend | jq
# curl -d '{"outputId":1}' localhost:8888/removefrombatch | jq
# curl -d '{"batcherLabel":"lowfees","confTarget":32}' localhost:8888/createbatcher | jq
# curl localhost:8888/listbatchers | jq
# curl -d '{"batcherLabel":"lowfees"}' localhost:8888/getbatcher | jq
# curl -d '{"batcherLabel":"lowfees"}' localhost:8888/getbatchdetails | jq
# curl -d '{"batcherLabel":"lowfees","outputLabel":"test002","address":"1abd","amount":0.0002}' localhost:8888/addtobatch | jq
# curl -d '{"batcherLabel":"lowfees"}' localhost:8888/batchspend | jq
# curl -d '{"batcherLabel":"lowfees","outputId":9}' localhost:8888/removefrombatch | jq
testbatching() {
local response
local id
local id2
local data
local data2
local address1
local address2
local amount1
local amount2
local url1="$(hostname):1111/callback"
echo "url1=${url1}"
local url2="$(hostname):1112/callback"
echo "url2=${url2}"
# List batchers (should show at least empty default batcher)
echo "Testing listbatchers..."
response=$(curl -s proxy:8888/listbatchers)
echo "response=${response}"
id=$(echo "${response}" | jq ".result[0].batcherId")
echo "batcherId=${id}"
if [ "${id}" -ne "1" ]; then
exit 10
fi
echo "Tested listbatchers."
# getbatcher the default batcher
echo "Testing getbatcher..."
response=$(curl -sd '{}' localhost:8888/getbatcher)
echo "response=${response}"
data=$(echo "${response}" | jq -r ".result.batcherLabel")
echo "batcherLabel=${data}"
if [ "${data}" != "default" ]; then
exit 20
fi
response=$(curl -sd '{"batcherId":1}' localhost:8888/getbatcher)
echo "response=${response}"
data=$(echo "${response}" | jq -r ".result.batcherLabel")
echo "batcherLabel=${data}"
if [ "${data}" != "default" ]; then
exit 25
fi
echo "Tested getbatcher."
# getbatchdetails the default batcher
echo "Testing getbatchdetails..."
response=$(curl -sd '{}' localhost:8888/getbatchdetails)
echo "response=${response}"
data=$(echo "${response}" | jq -r ".result.batcherLabel")
echo "batcherLabel=${data}"
if [ "${data}" != "default" ]; then
exit 30
fi
echo "${response}" | jq -e ".result.outputs"
if [ "$?" -ne 0 ]; then
exit 32
fi
response=$(curl -sd '{"batcherId":1}' localhost:8888/getbatchdetails)
echo "response=${response}"
data=$(echo "${response}" | jq -r ".result.batcherLabel")
echo "batcherLabel=${data}"
if [ "${data}" != "default" ]; then
exit 35
fi
echo "${response}" | jq -e ".result.outputs"
if [ "$?" -ne 0 ]; then
exit 37
fi
echo "Tested getbatchdetails."
# addtobatch to default batcher
echo "Testing addtobatch..."
address1=$(curl -s localhost:8888/getnewaddress | jq -r ".address")
echo "address1=${address1}"
response=$(curl -sd '{"outputLabel":"test001","address":"'${address1}'","amount":0.001}' localhost:8888/addtobatch)
echo "response=${response}"
id=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${id}"
if [ "${id}" -ne "1" ]; then
exit 40
fi
id=$(echo "${response}" | jq -e ".result.outputId")
if [ "$?" -ne 0 ]; then
exit 42
fi
echo "outputId=${id}"
address2=$(curl -s localhost:8888/getnewaddress | jq -r ".address")
echo "address2=${address2}"
response=$(curl -sd '{"batcherId":1,"outputLabel":"test002","address":"'${address2}'","amount":22000000}' localhost:8888/addtobatch)
echo "response=${response}"
id2=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${id2}"
if [ "${id2}" -ne "1" ]; then
exit 47
fi
id2=$(echo "${response}" | jq -e ".result.outputId")
if [ "$?" -ne 0 ]; then
exit 50
fi
echo "outputId=${id2}"
echo "Tested addtobatch."
# batchspend default batcher
echo "Testing batchspend..."
response=$(curl -sd '{}' localhost:8888/batchspend)
echo "response=${response}"
echo "${response}" | jq -e ".error"
if [ "$?" -ne 0 ]; then
exit 55
fi
echo "Tested batchspend."
# getbatchdetails the default batcher
echo "Testing getbatchdetails..."
response=$(curl -sd '{}' localhost:8888/getbatchdetails)
echo "response=${response}"
data=$(echo "${response}" | jq ".result.nbOutputs")
echo "nbOutputs=${data}"
echo "Tested getbatchdetails."
# removefrombatch from default batcher
echo "Testing removefrombatch..."
response=$(curl -sd '{"outputId":'${id}'}' localhost:8888/removefrombatch)
echo "response=${response}"
id=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${id}"
if [ "${id}" -ne "1" ]; then
exit 60
fi
response=$(curl -sd '{"outputId":'${id2}'}' localhost:8888/removefrombatch)
echo "response=${response}"
id=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${id}"
if [ "${id}" -ne "1" ]; then
exit 64
fi
echo "Tested removefrombatch."
# getbatchdetails the default batcher
echo "Testing getbatchdetails..."
response=$(curl -sd '{"batcherId":1}' localhost:8888/getbatchdetails)
echo "response=${response}"
data2=$(echo "${response}" | jq ".result.nbOutputs")
echo "nbOutputs=${data2}"
if [ "${data2}" -ne "$((${data}-2))" ]; then
exit 68
fi
echo "Tested getbatchdetails."
# Create a batcher
echo "Testing createbatcher..."
response=$(curl -s -H 'Content-Type: application/json' -d '{"batcherLabel":"testbatcher","confTarget":32}' proxy:8888/createbatcher)
echo "response=${response}"
id=$(echo "${response}" | jq -e ".result.batcherId")
if [ "$?" -ne "0" ]; then
exit 70
fi
# List batchers (should show at least default and testbatcher batchers)
echo "Testing listbatches..."
response=$(curl -s proxy:8888/listbatchers)
echo "response=${response}"
id=$(echo "${response}" | jq '.result[] | select(.batcherLabel == "testbatcher") | .batcherId')
echo "batcherId=${id}"
if [ -z "${id}" ]; then
exit 75
fi
echo "Tested listbatchers."
# getbatcher the testbatcher batcher
echo "Testing getbatcher..."
response=$(curl -sd '{"batcherId":'${id}'}' localhost:8888/getbatcher)
echo "response=${response}"
data=$(echo "${response}" | jq -r ".result.batcherLabel")
echo "batcherLabel=${data}"
if [ "${data}" != "testbatcher" ]; then
exit 80
fi
response=$(curl -sd '{"batcherLabel":"testbatcher"}' localhost:8888/getbatcher)
echo "response=${response}"
data=$(echo "${response}" | jq -r ".result.batcherId")
echo "batcherId=${data}"
if [ "${data}" != "${id}" ]; then
exit 90
fi
echo "Tested getbatcher."
# getbatchdetails the testbatcher batcher
echo "Testing getbatchdetails..."
response=$(curl -sd '{"batcherLabel":"testbatcher"}' localhost:8888/getbatchdetails)
echo "response=${response}"
data=$(echo "${response}" | jq -r ".result.batcherId")
echo "batcherId=${data}"
if [ "${data}" != "${id}" ]; then
exit 100
fi
echo "${response}" | jq -e ".result.outputs"
if [ "$?" -ne 0 ]; then
exit 110
fi
response=$(curl -sd '{"batcherId":'${id}'}' localhost:8888/getbatchdetails)
echo "response=${response}"
data=$(echo "${response}" | jq -r ".result.batcherLabel")
echo "batcherLabel=${data}"
if [ "${data}" != "testbatcher" ]; then
exit 120
fi
echo "${response}" | jq -e ".result.outputs"
if [ "$?" -ne 0 ]; then
exit 130
fi
echo "Tested getbatchdetails."
# addtobatch to testbatcher batcher
echo "Testing addtobatch..."
address1=$(curl -s localhost:8888/getnewaddress | jq -r ".address")
echo "address1=${address1}"
response=$(curl -sd '{"batcherId":'${id}',"outputLabel":"test001","address":"'${address1}'","amount":0.001,"webhookUrl":"'${url1}'/'${address1}'"}' localhost:8888/addtobatch)
echo "response=${response}"
data=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${data}"
if [ "${data}" -ne "${id}" ]; then
exit 140
fi
id2=$(echo "${response}" | jq -e ".result.outputId")
if [ "$?" -ne 0 ]; then
exit 142
fi
echo "outputId=${id2}"
address2=$(curl -s localhost:8888/getnewaddress | jq -r ".address")
echo "address2=${address2}"
response=$(curl -sd '{"batcherLabel":"testbatcher","outputLabel":"test002","address":"'${address2}'","amount":0.002,"webhookUrl":"'${url2}'/'${address2}'"}' localhost:8888/addtobatch)
echo "response=${response}"
data=$(echo "${response}" | jq ".result.batcherId")
echo "batcherId=${data}"
if [ "${data}" -ne "${id}" ]; then
exit 150
fi
id2=$(echo "${response}" | jq -e ".result.outputId")
if [ "$?" -ne 0 ]; then
exit 152
fi
echo "outputId=${id2}"
echo "Tested addtobatch."
# batchspend testbatcher batcher
echo "Testing batchspend..."
response=$(curl -sd '{"batcherLabel":"testbatcher"}' localhost:8888/batchspend)
echo "response=${response}"
data2=$(echo "${response}" | jq -e ".result.txid")
if [ "$?" -ne 0 ]; then
exit 160
fi
echo "txid=${data2}"
data=$(echo "${response}" | jq ".result.outputs | length")
if [ "${data}" -ne "2" ]; then
exit 162
fi
echo "Tested batchspend."
# getbatchdetails the testbatcher batcher
echo "Testing getbatchdetails..."
echo "txid=${data2}"
response=$(curl -sd '{"batcherLabel":"testbatcher","txid":'${data2}'}' localhost:8888/getbatchdetails)
echo "response=${response}"
data=$(echo "${response}" | jq ".result.nbOutputs")
echo "nbOutputs=${data}"
if [ "${data}" -ne "2" ]; then
exit 170
fi
echo "Tested getbatchdetails."
# List batchers
# Add to batch
# List batchers
# Remove from batch
# List batchers
}
wait_for_callbacks() {
nc -vlp1111 -e sh -c 'echo -en "HTTP/1.1 200 OK\r\n\r\n" ; timeout 1 tee /dev/tty | cat ; echo 1>&2' &
nc -vlp1112 -e sh -c 'echo -en "HTTP/1.1 200 OK\r\n\r\n" ; timeout 1 tee /dev/tty | cat ; echo 1>&2' &
}
wait_for_callbacks
testbatching
wait

View File

@@ -1,9 +0,0 @@
#!/bin/sh
read line
echo "${line}" 1>&2
echo -ne "HTTP/1.1 200 OK\r\n"
echo -e "Content-Type: application/json\r\nContent-Length: 0\r\n\r\n"
# Small delay needed for the data to be processed correctly by peer
sleep 0.5s

View File

@@ -1,322 +0,0 @@
#!/bin/sh
tests()
{
local address
local address1
local address2
local address3
local response
# getbestblockhash
# (GET) http://proxy:8888/getbestblockhash
echo "Testing getbestblockhash..."
response=$(curl -s proxy:8888/getbestblockhash)
echo "response=${response}"
local blockhash=$(echo ${response} | jq ".result" | tr -d '\"')
echo "blockhash=${blockhash}"
if [ -z "${blockhash}" ]; then
exit 2
fi
echo "Tested getbestblockhash."
# getbestblockinfo
# curl (GET) http://proxy:8888/getbestblockinfo
echo "Testing getbestblockinfo..."
response=$(curl -s proxy:8888/getbestblockinfo)
echo "response=${response}"
local blockhash2=$(echo ${response} | jq ".result.hash" | tr -d '\"')
echo "blockhash2=${blockhash2}"
if [ "${blockhash2}" != "${blockhash}" ]; then
exit 4
fi
echo "Tested getbestblockinfo."
# getblockinfo
# (GET) http://proxy:8888/getblockinfo/000000006f82a384c208ecfa04d05beea02d420f3f398ddda5c7f900de5718ea
echo "Testing getblockinfo..."
response=$(curl -s proxy:8888/getblockinfo/${blockhash})
echo "response=${response}"
blockhash2=$(echo ${response} | jq ".result.hash" | tr -d '\"')
echo "blockhash2=${blockhash2}"
if [ "${blockhash2}" != "${blockhash}" ]; then
exit 6
fi
echo "Tested getblockinfo."
# gettransaction
# (GET) http://proxy:8888/gettransaction/af867c86000da76df7ddb1054b273ca9e034e8c89d049b5b2795f9f590f67648
echo "Testing gettransaction..."
response=$(curl -s proxy:8888/gettransaction/af867c86000da76df7ddb1054b273ca9e034e8c89d049b5b2795f9f590f67648)
echo "response=${response}"
local txid=$(echo ${response} | jq ".result.txid" | tr -d '\"')
echo "txid=${txid}"
if [ "${txid}" != "af867c86000da76df7ddb1054b273ca9e034e8c89d049b5b2795f9f590f67648" ]; then
exit 8
fi
echo "Tested gettransaction."
# getnewaddress
# (GET) http://proxy:8888/getnewaddress
# returns {"address":"2MuiUu8AyuByAGYRDAqqhdYxt8gXcsQ1Ymw"}
echo "Testing getnewaddress..."
response=$(curl -s proxy:8888/getnewaddress)
echo "response=${response}"
address1=$(echo ${response} | jq ".address" | tr -d '\"')
echo "address1=${address1}"
if [ -z "${address1}" ]; then
exit 10
fi
address2=$(curl -s proxy:8888/getnewaddress | jq ".address" | tr -d '\"')
echo "address2=${address2}"
echo "Tested getnewaddress."
# getbalance
# (GET) http://proxy:8888/getbalance
echo "Testing getbalance..."
response=$(curl -s proxy:8888/getbalance)
echo "response=${response}"
local balance=$(echo ${response} | jq ".balance")
echo "balance=${balance}"
if [ -z "${balance}" ]; then
exit 12
fi
echo "Tested getbalance."
# watch
# POST http://proxy:8888/watch
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","unconfirmedCallbackURL":"192.168.122.233:1111/callback0conf","confirmedCallbackURL":"192.168.122.233:1111/callback1conf"}
echo "Testing watch..."
local url1="$(hostname):1111/callback0conf"
local url2="$(hostname):1111/callback1conf"
echo "url1=${url1}"
echo "url2=${url2}"
response=$(curl -s -H "Content-Type: application/json" -d "{\"address\":\"${address1}\",\"unconfirmedCallbackURL\":\"${url1}\",\"confirmedCallbackURL\":\"${url2}\"}" proxy:8888/watch)
echo "response=${response}"
local id=$(echo "${response}" | jq ".id" | tr -d '\"')
echo "id=${id}"
local event=$(echo "${response}" | jq ".event" | tr -d '\"')
echo "event=${event}"
if [ "${event}" != "watch" ]; then
exit 15
fi
address=$(echo "${response}" | jq ".address" | tr -d '\"')
echo "address=${address}"
if [ "${address}" != "${address1}" ]; then
exit 20
fi
local imported=$(echo "${response}" | jq ".imported" | tr -d '\"')
echo "imported=${imported}"
if [ "${imported}" != "1" ]; then
exit 30
fi
local inserted=$(echo "${response}" | jq ".inserted" | tr -d '\"')
echo "inserted=${inserted}"
if [ "${inserted}" != "1" ]; then
exit 40
fi
local unconfirmedCallbackURL=$(echo "${response}" | jq ".unconfirmedCallbackURL" | tr -d '\"')
echo "unconfirmedCallbackURL=${unconfirmedCallbackURL}"
if [ "${unconfirmedCallbackURL}" != "${url1}" ]; then
exit 60
fi
local confirmedCallbackURL=$(echo "${response}" | jq ".confirmedCallbackURL" | tr -d '\"')
echo "confirmedCallbackURL=${confirmedCallbackURL}"
if [ "${confirmedCallbackURL}" != "${url2}" ]; then
exit 70
fi
# Let's watch another address just to be able to test unwatch later and test if found in getactivewatches
response=$(curl -s -H "Content-Type: application/json" -d "{\"address\":\"${address2}\",\"unconfirmedCallbackURL\":\"${url1}2\",\"confirmedCallbackURL\":\"${url2}2\"}" proxy:8888/watch)
echo "response=${response}"
echo "Tested watch."
# getactivewatches
# (GET) http://proxy:8888/getactivewatches
echo "Testing getactivewatches..."
response=$(curl -s proxy:8888/getactivewatches)
echo "response=${response}"
response=$(echo ${response} | jq ".watches[]")
echo "response=${response}"
local id2=$(echo ${response} | jq "select(.address == \"${address1}\") | .id" | tr -d '\"')
echo "id2=${id2}"
if [ "${id2}" != "${id}" ]; then
exit 80
fi
id2=$(echo ${response} | jq "select(.address == \"${address2}\") | .id" | tr -d '\"')
echo "id2=${id2}"
if [ -z "${id2}" ]; then
exit 90
fi
echo "Tested getactivewatches."
# unwatch
# (GET) http://proxy:8888/unwatch/2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp
echo "Testing unwatch..."
response=$(curl -s proxy:8888/unwatch/${address2})
echo "response=${response}"
event=$(echo "${response}" | jq ".event" | tr -d '\"')
echo "event=${event}"
if [ "${event}" != "unwatch" ]; then
exit 100
fi
address=$(echo "${response}" | jq ".address" | tr -d '\"')
echo "address=${address}"
if [ "${address}" != "${address2}" ]; then
exit 110
fi
response=$(curl -s proxy:8888/getactivewatches)
echo "response=${response}"
response=$(echo "${response}" | jq ".watches[]")
echo "response=${response}"
id2=$(echo ${response} | jq "select(.address == \"${address2}\") | .id" | tr -d '\"')
echo "id2=${id2}"
if [ -n "${id2}" ]; then
exit 120
fi
echo "Tested unwatch."
# deriveindex
# (GET) http://proxy:8888/deriveindex/25-30
# {"addresses":[{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},{"address":"2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV"},{"address":"2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP"},{"address":"2Mth8XDZpXkY9d95tort8HYEAuEesow2tF6"},{"address":"2MwqEmAXhUw6H7bJwMhD13HGWVEj2HgFiNH"},{"address":"2N2Y4BVRdrRFhweub2ehHXveGZC3nryMEJw"}]}
echo "Testing deriveindex..."
response=$(curl -v proxy:8888/deriveindex/25-30)
echo "response=${response}"
local nbaddr=$(echo "${response}" | jq ".addresses | length")
if [ "${nbaddr}" -ne "6" ]; then
exit 130
fi
address=$(echo "${response}" | jq ".addresses[2].address" | tr -d '\"')
if [ "${address}" != "2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP" ]; then
exit 140
fi
echo "Tested deriveindex."
# derivepubpath
# (GET) http://proxy:8888/derivepubpath
# BODY {"pub32":"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb","path":"0/25-30"}
# {"addresses":[{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},{"address":"2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV"},{"address":"2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP"},{"address":"2Mth8XDZpXkY9d95tort8HYEAuEesow2tF6"},{"address":"2MwqEmAXhUw6H7bJwMhD13HGWVEj2HgFiNH"},{"address":"2N2Y4BVRdrRFhweub2ehHXveGZC3nryMEJw"}]}
echo "Testing derivepubpath..."
response=$(curl -v -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/25-30\"}" proxy:8888/derivepubpath)
echo "response=${response}"
local nbaddr=$(echo "${response}" | jq ".addresses | length")
if [ "${nbaddr}" -ne "6" ]; then
exit 150
fi
address=$(echo "${response}" | jq ".addresses[2].address" | tr -d '\"')
if [ "${address}" != "2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP" ]; then
exit 160
fi
echo "Tested derivepubpath."
# spend
# POST http://proxy:8888/spend
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233}
# By spending to a watched address, we will test the spending feature and trigger the confirmation to test
# confirmations of watched addresses... Cleva!!!
echo "Testing spend, conf and callbacks..."
response=$(curl -v -H "Content-Type: application/json" -d "{\"address\":\"${address1}\",\"amount\":0.00001}" proxy:8888/spend)
echo "response=${response}"
wait_for_callbacks
echo "Tested spend, conf and callbacks."
# addtobatch
# POST http://proxy:8888/addtobatch
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233}
# By spending to a watched address, we will test the spending feature and trigger the confirmation to test
# confirmations of watched addresses... Cleva!!!
# echo "Testing addtobatch..."
# response=$(curl -v -H "Content-Type: application/json" -d "{\"address\":\"${address1}\",\"amount\":0.00001}" proxy:8888/spend)
# echo "response=${response}"
# wait_for_callbacks
# echo "Tested addtobatch ."
# conf
# (GET) http://proxy:8888/conf/b081ca7724386f549cf0c16f71db6affeb52ff7a0d9b606fb2e5c43faffd3387
# Let's trigger tx confirmation even if not confirmed. Will be funny. Should take care of
# multiple confirmations of the same state.
# executecallbacks
# (GET) http://cyphernode::8080/executecallbacks
#echo "GET /getbestblockinfo" | nc proxy:8888 - | sed -En "s/^(\{.*)/\1/p" | jq
# spend
# POST http://proxy:8888/spend
# BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233}
#curl -v -H "Content-Type: application/json" -d '{"address":"2MsWyaQ8APbnqasFpWopqUKqsdpiVY3EwLE","amount":0.0001}' proxy:8888/spend
# ln_getinfo
# (GET) http://proxy:8888/ln_getinfo
echo "Testing ln_getinfo..."
response=$(curl -s proxy:8888/ln_getinfo)
echo "response=${response}"
local port=$(echo ${response} | jq ".binding[] | select(.type == \"ipv4\") | .port")
echo "port=${port}"
if [ "${port}" != "9735" ]; then
exit 170
fi
echo "Tested ln_getinfo."
# ln_newaddr
# (GET) http://proxy:8888/ln_newaddr
echo "Testing ln_newaddr..."
response=$(curl -s proxy:8888/ln_newaddr)
echo "response=${response}"
address=$(echo ${response} | jq ".address")
echo "address=${address}"
if [ -z "${address}" ]; then
exit 180
fi
echo "Tested ln_newaddr."
# ln_create_invoice
# POST http://proxy:8888/ln_create_invoice
# BODY {"msatoshi":"10000","label":"koNCcrSvhX3dmyFhW","description":"Bylls order #10649","expiry":"10"}
#echo "Testing ln_create_invoice..."
#response=$(curl -v -H "Content-Type: application/json" -d "{\"msatoshi\":10000,\"label\":\"koNCcrSvhX3dmyFhW\",\"description\":\"Bylls order #10649\",\"expiry\":10}" proxy:8888/ln_create_invoice)
#echo "response=${response}"
#echo "Tested ln_create_invoice."
# ln_pay
}
wait_for_callbacks()
{
nc -vlp1111 -e ./tests-cb.sh
nc -vlp1111 -e ./tests-cb.sh
}
tests