diff --git a/dist/setup.sh b/dist/setup.sh index eec7c0b..b287a7d 100755 --- a/dist/setup.sh +++ b/dist/setup.sh @@ -855,7 +855,7 @@ SUDO_REQUIRED=0 AUTOSTART=0 # CYPHERNODE VERSION "v0.7.0-dev" -SETUP_VERSION="v0.7.0-dev" +SETUP_VERSION="dev-on-v0.7.0" CONF_VERSION="v0.7.0-dev" GATEKEEPER_VERSION="v0.7.0-dev" TOR_VERSION="v0.7.0-dev" @@ -865,8 +865,8 @@ PROXYCRON_VERSION="v0.7.0-dev" OTSCLIENT_VERSION="v0.7.0-dev" PYCOIN_VERSION="v0.7.0-dev" CYPHERAPPS_VERSION="dev" -BITCOIN_VERSION="v0.21.1" -LIGHTNING_VERSION="v0.10.1" +BITCOIN_VERSION="v22.0" +LIGHTNING_VERSION="v0.10.2" TRAEFIK_VERSION="v1.7.9-alpine" MOSQUITTO_VERSION="1.6-openssl" POSTGRES_VERSION="14.0-alpine" diff --git a/proxy_docker/Dockerfile b/proxy_docker/Dockerfile index 21d460b..bfdb13b 100644 --- a/proxy_docker/Dockerfile +++ b/proxy_docker/Dockerfile @@ -16,7 +16,7 @@ WORKDIR ${HOME} COPY app/data/* ./ COPY app/script/* ./ COPY app/tests/* ./tests/ -COPY --from=cyphernode/clightning:v0.10.1 /usr/local/bin/lightning-cli ./ +COPY --from=cyphernode/clightning:v0.10.2 /usr/local/bin/lightning-cli ./ COPY --from=eclipse-mosquitto:1.6-openssl /usr/bin/mosquitto_rr /usr/bin/mosquitto_sub /usr/bin/mosquitto_pub /usr/bin/ COPY --from=eclipse-mosquitto:1.6-openssl /usr/lib/libmosquitto* /usr/lib/ COPY --from=eclipse-mosquitto:1.6-openssl /usr/lib/libcrypto* /usr/lib/ diff --git a/proxy_docker/app/script/computefees.sh b/proxy_docker/app/script/computefees.sh index 57a3484..cd18cfd 100644 --- a/proxy_docker/app/script/computefees.sh +++ b/proxy_docker/app/script/computefees.sh @@ -88,9 +88,7 @@ compute_vin_total_amount() sql "INSERT INTO tx (txid, hash, confirmations, timereceived, size, vsize, blockhash, blockheight, blocktime)"\ " VALUES ('${vin_txid}', '${vin_hash}', ${vin_confirmations}, ${vin_timereceived}, ${vin_size}, ${vin_vsize}, '${vin_blockhash}', ${vin_blockheight}, ${vin_blocktime})"\ " ON CONFLICT (txid) DO"\ -" UPDATE SET blockhash='${vin_blockhash}', blockheight=${vin_blockheight}, blocktime=${vin_blocktime}, confirmations=${vin_confirmations}"\ -" RETURNING id" \ - "SELECT id FROM tx WHERE txid='${vin_txid}'" +" UPDATE SET blockhash='${vin_blockhash}', blockheight=${vin_blockheight}, blocktime=${vin_blocktime}, confirmations=${vin_confirmations}" trace_rc $? done diff --git a/proxy_docker/app/tests/test-batching.sh b/proxy_docker/app/tests/test-batching.sh index 63b79a1..d62d6fc 100755 --- a/proxy_docker/app/tests/test-batching.sh +++ b/proxy_docker/app/tests/test-batching.sh @@ -1,8 +1,9 @@ #!/bin/sh -# docker exec -it $(docker ps -q -f "name=proxy\.") ./tests/test-batching.sh +. ./colors.sh # This needs to be run in regtest +# You need jq installed for these tests to run correctly # This will test: # @@ -22,23 +23,48 @@ # Notes: -# 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 proxy:8888/listbatchers | jq +# curl -d '{}' proxy:8888/getbatcher | jq +# curl -d '{}' proxy:8888/getbatchdetails | jq +# curl -d '{"outputLabel":"test002","address":"1abd","amount":0.0002}' proxy:8888/addtobatch | jq +# curl -d '{}' proxy:8888/batchspend | jq +# curl -d '{"outputId":1}' proxy:8888/removefrombatch | jq -# curl -d '{"batcherLabel":"lowfees","confTarget":32}' localhost:8888/createbatcher | jq -# curl localhost:8888/listbatchers | jq +# curl -d '{"batcherLabel":"lowfees","confTarget":32}' proxy:8888/createbatcher | jq +# curl proxy:8888/listbatchers | jq + +# curl -d '{"batcherLabel":"lowfees"}' proxy:8888/getbatcher | jq +# curl -d '{"batcherLabel":"lowfees"}' proxy:8888/getbatchdetails | jq +# curl -d '{"batcherLabel":"lowfees","outputLabel":"test002","address":"1abd","amount":0.0002}' proxy:8888/addtobatch | jq +# curl -d '{"batcherLabel":"lowfees"}' proxy:8888/batchspend | jq +# curl -d '{"batcherLabel":"lowfees","outputId":9}' proxy:8888/removefrombatch | jq + + +trace() { + if [ "${1}" -le "${TRACING}" ]; then + echo "$(date -u +%FT%TZ) ${2}" 1>&2 + fi +} + +start_test_container() { + docker run -d --rm -it --name tests-batching --network=cyphernodenet alpine +} + +stop_test_container() { + trace 1 "\n\n[stop_test_container] ${BCyan}Stopping existing containers if they are running...${Color_Off}\n" + + docker stop tests-batching + docker stop tests-batching-cb +} + +exec_in_test_container() { + docker exec -it tests-batching "$@" +} -# 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() { + trace 1 "\n\n[testbatching] ${BCyan}Let's test batching features!...${Color_Off}\n" + local response local id local id2 @@ -55,41 +81,41 @@ testbatching() { echo "url2=${url2}" # List batchers (should show at least empty default batcher) - echo "Testing listbatchers..." - response=$(curl -s proxy:8888/listbatchers) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing listbatchers...${Color_Off}\n" + response=$(exec_in_test_container curl -s proxy:8888/listbatchers) + trace 3 "[testbatching] response=${response}" id=$(echo "${response}" | jq ".result[0].batcherId") - echo "batcherId=${id}" + trace 3 "[testbatching] batcherId=${id}" if [ "${id}" -ne "1" ]; then exit 10 fi - echo "Tested listbatchers." + trace 2 "\n\n[testbatching] ${BCyan}Tested listbatchers.${Color_Off}\n" # getbatcher the default batcher - echo "Testing getbatcher..." - response=$(curl -sd '{}' localhost:8888/getbatcher) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing getbatcher...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{}' proxy:8888/getbatcher) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq -r ".result.batcherLabel") - echo "batcherLabel=${data}" + trace 3 "[testbatching] batcherLabel=${data}" if [ "${data}" != "default" ]; then exit 20 fi - response=$(curl -sd '{"batcherId":1}' localhost:8888/getbatcher) - echo "response=${response}" + response=$(exec_in_test_container curl -sd '{"batcherId":1}' proxy:8888/getbatcher) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq -r ".result.batcherLabel") - echo "batcherLabel=${data}" + trace 3 "[testbatching] batcherLabel=${data}" if [ "${data}" != "default" ]; then exit 25 fi - echo "Tested getbatcher." + trace 2 "\n\n[testbatching] ${BCyan}Tested getbatcher.${Color_Off}\n" # getbatchdetails the default batcher - echo "Testing getbatchdetails..." - response=$(curl -sd '{}' localhost:8888/getbatchdetails) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing getbatchdetails...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{}' proxy:8888/getbatchdetails) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq -r ".result.batcherLabel") - echo "batcherLabel=${data}" + trace 3 "[testbatching] batcherLabel=${data}" if [ "${data}" != "default" ]; then exit 30 fi @@ -98,10 +124,10 @@ testbatching() { exit 32 fi - response=$(curl -sd '{"batcherId":1}' localhost:8888/getbatchdetails) - echo "response=${response}" + response=$(exec_in_test_container curl -sd '{"batcherId":1}' proxy:8888/getbatchdetails) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq -r ".result.batcherLabel") - echo "batcherLabel=${data}" + trace 3 "[testbatching] batcherLabel=${data}" if [ "${data}" != "default" ]; then exit 35 fi @@ -109,16 +135,16 @@ testbatching() { if [ "$?" -ne 0 ]; then exit 37 fi - echo "Tested getbatchdetails." + trace 2 "\n\n[testbatching] ${BCyan}Tested getbatchdetails.${Color_Off}\n" # 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}" + trace 2 "\n\n[testbatching] ${BCyan}Testing addtobatch...${Color_Off}\n" + address1=$(exec_in_test_container curl -s proxy:8888/getnewaddress | jq -r ".address") + trace 3 "[testbatching] address1=${address1}" + response=$(exec_in_test_container curl -sd '{"outputLabel":"test001","address":"'${address1}'","amount":0.001}' proxy:8888/addtobatch) + trace 3 "[testbatching] response=${response}" id=$(echo "${response}" | jq ".result.batcherId") - echo "batcherId=${id}" + trace 3 "[testbatching] batcherId=${id}" if [ "${id}" -ne "1" ]; then exit 40 fi @@ -126,14 +152,14 @@ testbatching() { if [ "$?" -ne 0 ]; then exit 42 fi - echo "outputId=${id}" + trace 3 "[testbatching] 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}" + address2=$(exec_in_test_container curl -s proxy:8888/getnewaddress | jq -r ".address") + trace 3 "[testbatching] address2=${address2}" + response=$(exec_in_test_container curl -sd '{"batcherId":1,"outputLabel":"test002","address":"'${address2}'","amount":22000000}' proxy:8888/addtobatch) + trace 3 "[testbatching] response=${response}" id2=$(echo "${response}" | jq ".result.batcherId") - echo "batcherId=${id2}" + trace 3 "[testbatching] batcherId=${id2}" if [ "${id2}" -ne "1" ]; then exit 47 fi @@ -141,115 +167,104 @@ testbatching() { if [ "$?" -ne 0 ]; then exit 50 fi - echo "outputId=${id2}" - echo "Tested addtobatch." + trace 3 "[testbatching] outputId=${id2}" + trace 2 "\n\n[testbatching] ${BCyan}Tested addtobatch.${Color_Off}\n" # batchspend default batcher - echo "Testing batchspend..." - response=$(curl -sd '{}' localhost:8888/batchspend) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing batchspend...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{}' proxy:8888/batchspend) + trace 3 "[testbatching] response=${response}" echo "${response}" | jq -e ".error" if [ "$?" -ne 0 ]; then exit 55 fi - echo "Tested batchspend." + trace 2 "\n\n[testbatching] ${BCyan}Tested batchspend.${Color_Off}\n" # getbatchdetails the default batcher - echo "Testing getbatchdetails..." - response=$(curl -sd '{}' localhost:8888/getbatchdetails) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing getbatchdetails...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{}' proxy:8888/getbatchdetails) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq ".result.nbOutputs") - echo "nbOutputs=${data}" - echo "Tested getbatchdetails." + trace 3 "[testbatching] nbOutputs=${data}" + trace 2 "\n\n[testbatching] ${BCyan}Tested getbatchdetails.${Color_Off}\n" # removefrombatch from default batcher - echo "Testing removefrombatch..." - response=$(curl -sd '{"outputId":'${id}'}' localhost:8888/removefrombatch) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing removefrombatch...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{"outputId":'${id}'}' proxy:8888/removefrombatch) + trace 3 "[testbatching] response=${response}" id=$(echo "${response}" | jq ".result.batcherId") - echo "batcherId=${id}" + trace 3 "[testbatching] batcherId=${id}" if [ "${id}" -ne "1" ]; then exit 60 fi - response=$(curl -sd '{"outputId":'${id2}'}' localhost:8888/removefrombatch) - echo "response=${response}" + response=$(exec_in_test_container curl -sd '{"outputId":'${id2}'}' proxy:8888/removefrombatch) + trace 3 "[testbatching] response=${response}" id=$(echo "${response}" | jq ".result.batcherId") - echo "batcherId=${id}" + trace 3 "[testbatching] batcherId=${id}" if [ "${id}" -ne "1" ]; then exit 64 fi - echo "Tested removefrombatch." + trace 2 "\n\n[testbatching] ${BCyan}Tested removefrombatch.${Color_Off}\n" # getbatchdetails the default batcher - echo "Testing getbatchdetails..." - response=$(curl -sd '{"batcherId":1}' localhost:8888/getbatchdetails) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing getbatchdetails...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{"batcherId":1}' proxy:8888/getbatchdetails) + trace 3 "[testbatching] response=${response}" data2=$(echo "${response}" | jq ".result.nbOutputs") - echo "nbOutputs=${data2}" + trace 3 "[testbatching] nbOutputs=${data2}" if [ "${data2}" -ne "$((${data}-2))" ]; then exit 68 fi - echo "Tested getbatchdetails." - - - - - - - - - - - + trace 2 "\n\n[testbatching] ${BCyan}Tested getbatchdetails.${Color_Off}\n" # 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}" + trace 2 "\n\n[testbatching] ${BCyan}Testing createbatcher...${Color_Off}\n" + response=$(exec_in_test_container curl -s -H 'Content-Type: application/json' -d '{"batcherLabel":"testbatcher","confTarget":32}' proxy:8888/createbatcher) + trace 3 "[testbatching] 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}" + trace 2 "\n\n[testbatching] ${BCyan}Testing listbatches...${Color_Off}\n" + response=$(exec_in_test_container curl -s proxy:8888/listbatchers) + trace 3 "[testbatching] response=${response}" id=$(echo "${response}" | jq '.result[] | select(.batcherLabel == "testbatcher") | .batcherId') - echo "batcherId=${id}" + trace 3 "[testbatching] batcherId=${id}" if [ -z "${id}" ]; then exit 75 fi - echo "Tested listbatchers." + trace 2 "\n\n[testbatching] ${BCyan}Tested listbatchers.${Color_Off}\n" # getbatcher the testbatcher batcher - echo "Testing getbatcher..." - response=$(curl -sd '{"batcherId":'${id}'}' localhost:8888/getbatcher) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing getbatcher...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{"batcherId":'${id}'}' proxy:8888/getbatcher) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq -r ".result.batcherLabel") - echo "batcherLabel=${data}" + trace 3 "[testbatching] batcherLabel=${data}" if [ "${data}" != "testbatcher" ]; then exit 80 fi - response=$(curl -sd '{"batcherLabel":"testbatcher"}' localhost:8888/getbatcher) - echo "response=${response}" + response=$(exec_in_test_container curl -sd '{"batcherLabel":"testbatcher"}' proxy:8888/getbatcher) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq -r ".result.batcherId") - echo "batcherId=${data}" + trace 3 "[testbatching] batcherId=${data}" if [ "${data}" != "${id}" ]; then exit 90 fi - echo "Tested getbatcher." + trace 2 "\n\n[testbatching] ${BCyan}Tested getbatcher.${Color_Off}\n" # getbatchdetails the testbatcher batcher - echo "Testing getbatchdetails..." - response=$(curl -sd '{"batcherLabel":"testbatcher"}' localhost:8888/getbatchdetails) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing getbatchdetails...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{"batcherLabel":"testbatcher"}' proxy:8888/getbatchdetails) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq -r ".result.batcherId") - echo "batcherId=${data}" + trace 3 "[testbatching] batcherId=${data}" if [ "${data}" != "${id}" ]; then exit 100 fi @@ -258,10 +273,10 @@ testbatching() { exit 110 fi - response=$(curl -sd '{"batcherId":'${id}'}' localhost:8888/getbatchdetails) - echo "response=${response}" + response=$(exec_in_test_container curl -sd '{"batcherId":'${id}'}' proxy:8888/getbatchdetails) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq -r ".result.batcherLabel") - echo "batcherLabel=${data}" + trace 3 "[testbatching] batcherLabel=${data}" if [ "${data}" != "testbatcher" ]; then exit 120 fi @@ -269,16 +284,16 @@ testbatching() { if [ "$?" -ne 0 ]; then exit 130 fi - echo "Tested getbatchdetails." + trace 2 "\n\n[testbatching] ${BCyan}Tested getbatchdetails.${Color_Off}\n" # 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}" + trace 2 "\n\n[testbatching] ${BCyan}Testing addtobatch...${Color_Off}\n" + address1=$(exec_in_test_container curl -s proxy:8888/getnewaddress | jq -r ".address") + trace 3 "[testbatching] address1=${address1}" + response=$(exec_in_test_container curl -sd '{"batcherId":'${id}',"outputLabel":"test001","address":"'${address1}'","amount":0.001,"webhookUrl":"'${url1}'/'${address1}'"}' proxy:8888/addtobatch) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq ".result.batcherId") - echo "batcherId=${data}" + trace 3 "[testbatching] batcherId=${data}" if [ "${data}" -ne "${id}" ]; then exit 140 fi @@ -286,14 +301,14 @@ testbatching() { if [ "$?" -ne 0 ]; then exit 142 fi - echo "outputId=${id2}" + trace 3 "[testbatching] 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}" + address2=$(exec_in_test_container curl -s proxy:8888/getnewaddress | jq -r ".address") + trace 3 "[testbatching] address2=${address2}" + response=$(exec_in_test_container curl -sd '{"batcherLabel":"testbatcher","outputLabel":"test002","address":"'${address2}'","amount":0.002,"webhookUrl":"'${url2}'/'${address2}'"}' proxy:8888/addtobatch) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq ".result.batcherId") - echo "batcherId=${data}" + trace 3 "[testbatching] batcherId=${data}" if [ "${data}" -ne "${id}" ]; then exit 150 fi @@ -301,35 +316,35 @@ testbatching() { if [ "$?" -ne 0 ]; then exit 152 fi - echo "outputId=${id2}" - echo "Tested addtobatch." + trace 3 "[testbatching] outputId=${id2}" + trace 2 "\n\n[testbatching] ${BCyan}Tested addtobatch.${Color_Off}\n" # batchspend testbatcher batcher - echo "Testing batchspend..." - response=$(curl -sd '{"batcherLabel":"testbatcher"}' localhost:8888/batchspend) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing batchspend...${Color_Off}\n" + response=$(exec_in_test_container curl -sd '{"batcherLabel":"testbatcher"}' proxy:8888/batchspend) + trace 3 "[testbatching] response=${response}" data2=$(echo "${response}" | jq -e ".result.txid") if [ "$?" -ne 0 ]; then exit 160 fi - echo "txid=${data2}" + trace 3 "[testbatching] txid=${data2}" data=$(echo "${response}" | jq ".result.outputs | length") if [ "${data}" -ne "2" ]; then exit 162 fi - echo "Tested batchspend." + trace 2 "\n\n[testbatching] ${BCyan}Tested batchspend.${Color_Off}\n" # getbatchdetails the testbatcher batcher - echo "Testing getbatchdetails..." - echo "txid=${data2}" - response=$(curl -sd '{"batcherLabel":"testbatcher","txid":'${data2}'}' localhost:8888/getbatchdetails) - echo "response=${response}" + trace 2 "\n\n[testbatching] ${BCyan}Testing getbatchdetails...${Color_Off}\n" + trace 3 "[testbatching] txid=${data2}" + response=$(exec_in_test_container curl -sd '{"batcherLabel":"testbatcher","txid":'${data2}'}' proxy:8888/getbatchdetails) + trace 3 "[testbatching] response=${response}" data=$(echo "${response}" | jq ".result.nbOutputs") - echo "nbOutputs=${data}" + trace 3 "[testbatching] nbOutputs=${data}" if [ "${data}" -ne "2" ]; then exit 170 fi - echo "Tested getbatchdetails." + trace 2 "\n\n[testbatching] ${BCyan}Tested getbatchdetails.${Color_Off}\n" # List batchers # Add to batch @@ -337,16 +352,33 @@ testbatching() { # Remove from batch # List batchers - echo - echo "Tests successful!" + trace 1 "\n\n[testbatching] ${On_IGreen}${BBlack} ALL GOOD! Yayyyy! ${Color_Off}\n" } -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' & +start_callback_server() { + trace 1 "\n\n[start_callback_server] ${BCyan}Let's start a callback server!...${Color_Off}\n" + + port=${1:-${callbackserverport}} + docker run --rm -t --name tests-batching-cb --network=cyphernodenet alpine sh -c "nc -vlp${port} -e sh -c 'echo -en \"HTTP/1.1 200 OK\\\\r\\\\n\\\\r\\\\n\" ; echo -en \"\\033[40m\\033[0;37m\" >&2 ; date >&2 ; timeout 1 tee /dev/tty | cat ; echo -e \"\033[0m\" >&2'" & } -wait_for_callbacks +TRACING=3 + +stop_test_container +start_test_container + +callbackserverport="1111" +callbackservername="tests-batching-cb" + +trace 1 "\n\n[test-batching] ${BCyan}Installing needed packages...${Color_Off}\n" +exec_in_test_container apk add --update curl + testbatching + +trace 1 "\n\n[test-batching] ${BCyan}Tearing down...${Color_Off}\n" wait + +stop_test_container + +trace 1 "\n\n[test-batching] ${BCyan}See ya!${Color_Off}\n" diff --git a/proxy_docker/app/tests/test-derive.sh b/proxy_docker/app/tests/test-derive.sh index 1e1e669..07d9173 100755 --- a/proxy_docker/app/tests/test-derive.sh +++ b/proxy_docker/app/tests/test-derive.sh @@ -1,6 +1,8 @@ #!/bin/sh -# docker run -it --rm -it --name test-derive --network=cyphernodenet -v "$PWD/test-derive.sh:/test-derive.sh" alpine /test-derive.sh +. ./colors.sh + +# You need jq installed for these tests to run correctly # This will test: # @@ -12,7 +14,27 @@ # ...and it will compare performance between Pycoin et Bitcoin Core's address derivations... # -test_derive() { +trace() { + if [ "${1}" -le "${TRACING}" ]; then + echo "$(date -u +%FT%TZ) ${2}" 1>&2 + fi +} + +start_test_container() { + docker run -d --rm -it --name test-derive --network=cyphernodenet alpine +} + +stop_test_container() { + trace 1 "\n\n[stop_test_container] ${BCyan}Stopping existing containers if they are running...${Color_Off}\n" + + docker stop test-derive +} + +exec_in_test_container() { + docker exec -it test-derive "$@" +} + +tests_derive() { local address local address1 local address2 @@ -20,14 +42,17 @@ test_derive() { local response local transaction + trace 1 "\n\n[tests_derive] ${BCyan}Let's test the derivation features!...${Color_Off}\n" + # 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 -s proxy:8888/deriveindex/25-30) - echo "response=${response}" + trace 2 "\n\n[tests_derive] ${BCyan}Testing deriveindex...${Color_Off}\n" + response=$(exec_in_test_container curl -s proxy:8888/deriveindex/25-30) + trace 3 "[tests_derive] response=${response}" local nbaddr=$(echo "${response}" | jq ".addresses | length") + trace 3 "[tests_derive] nbaddr=${nbaddr}" if [ "${nbaddr}" -ne "6" ]; then exit 130 fi @@ -35,16 +60,16 @@ test_derive() { if [ "${address}" != "2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP" ]; then exit 140 fi - echo "Tested deriveindex." + trace 2 "\n\n[tests_derive] ${BCyan}Tested deriveindex.${Color_Off}\n" # 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 -s -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/25-30\"}" proxy:8888/derivepubpath) - echo "response=${response}" + trace 2 "\n\n[tests_derive] ${BCyan}Testing derivepubpath...${Color_Off}\n" + response=$(exec_in_test_container curl -s -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/25-30\"}" proxy:8888/derivepubpath) + trace 3 "[tests_derive] response=${response}" local nbaddr=$(echo "${response}" | jq ".addresses | length") if [ "${nbaddr}" -ne "6" ]; then exit 150 @@ -53,15 +78,15 @@ test_derive() { if [ "${address}" != "2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP" ]; then exit 160 fi - echo "Tested derivepubpath." + trace 2 "\n\n[tests_derive] ${BCyan}Tested derivepubpath.${Color_Off}\n" # deriveindex_bitcoind # (GET) http://proxy:8888/deriveindex_bitcoind/25-30 # ["2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8","2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV","2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP","2Mth8XDZpXkY9d95tort8HYEAuEesow2tF6","2MwqEmAXhUw6H7bJwMhD13HGWVEj2HgFiNH","2N2Y4BVRdrRFhweub2ehHXveGZC3nryMEJw"] - echo "Testing deriveindex_bitcoind..." - response=$(curl -s proxy:8888/deriveindex_bitcoind/25-30) - echo "response=${response}" + trace 2 "\n\n[tests_derive] ${BCyan}Testing deriveindex_bitcoind...${Color_Off}\n" + response=$(exec_in_test_container curl -s proxy:8888/deriveindex_bitcoind/25-30) + trace 3 "[tests_derive] response=${response}" local nbaddr=$(echo "${response}" | jq ". | length") if [ "${nbaddr}" -ne "6" ]; then exit 130 @@ -70,16 +95,16 @@ test_derive() { if [ "${address}" != "2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP" ]; then exit 140 fi - echo "Tested deriveindex_bitcoind." + trace 2 "\n\n[tests_derive] ${BCyan}Tested deriveindex_bitcoind.${Color_Off}\n" # derivepubpath_bitcoind # (GET) http://proxy:8888/derivepubpath_bitcoind # BODY {"pub32":"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb","path":"0/25-30"} # ["2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8","2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV","2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP","2Mth8XDZpXkY9d95tort8HYEAuEesow2tF6","2MwqEmAXhUw6H7bJwMhD13HGWVEj2HgFiNH","2N2Y4BVRdrRFhweub2ehHXveGZC3nryMEJw"] - echo "Testing derivepubpath_bitcoind..." - response=$(curl -s -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/25-30\"}" proxy:8888/derivepubpath_bitcoind) - echo "response=${response}" + trace 2 "\n\n[tests_derive] ${BCyan}Testing derivepubpath_bitcoind...${Color_Off}\n" + response=$(exec_in_test_container curl -s -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/25-30\"}" proxy:8888/derivepubpath_bitcoind) + trace 3 "[tests_derive] response=${response}" local nbaddr=$(echo "${response}" | jq ". | length") if [ "${nbaddr}" -ne "6" ]; then exit 150 @@ -88,14 +113,14 @@ test_derive() { if [ "${address}" != "2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP" ]; then exit 160 fi - echo "Tested derivepubpath_bitcoind." + trace 2 "\n\n[tests_derive] ${BCyan}Tested derivepubpath_bitcoind.${Color_Off}\n" # deriveindex_bitcoind and derivepubpath_bitcoind faster derivation? - echo -e "\nDeriving 500 addresses with derivepubpath (Pycoin)..." - time curl -s -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/0-499\"}" proxy:8888/derivepubpath > /dev/null + trace 2 "\n\n[tests_derive] ${BCyan}Deriving 500 addresses with derivepubpath (Pycoin)...${Color_Off}\n" + exec_in_test_container sh -c 'time curl -s -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/0-499\"}" proxy:8888/derivepubpath > /dev/null' - echo -e "\nDeriving 500 addresses with derivepubpath_bitcoind (Bitcoin Core)..." - time curl -s -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/0-499\"}" proxy:8888/derivepubpath_bitcoind > /dev/null + trace 2 "\n\n[tests_derive] ${BCyan}Deriving 500 addresses with derivepubpath_bitcoind (Bitcoin Core)...${Color_Off}\n" + exec_in_test_container sh -c 'time curl -s -H "Content-Type: application/json" -d "{\"pub32\":\"upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb\",\"path\":\"0/0-499\"}" proxy:8888/derivepubpath_bitcoind > /dev/null' # Deriving 500 addresses with derivepubpath (pycoin)... # real 0m 18.15s @@ -107,8 +132,23 @@ test_derive() { # user 0m 0.00s # sys 0m 0.00s + trace 1 "\n\n[tests_derive] ${On_IGreen}${BBlack} ALL GOOD! Yayyyy! ${Color_Off}\n" + } -apk add curl jq +TRACING=3 -test_derive +stop_test_container +start_test_container + +trace 1 "\n\n[test-derive] ${BCyan}Installing needed packages...${Color_Off}\n" +exec_in_test_container apk add --update curl + +tests_derive + +trace 1 "\n\n[test-derive] ${BCyan}Tearing down...${Color_Off}\n" +wait + +stop_test_container + +trace 1 "\n\n[test-derive] ${BCyan}See ya!${Color_Off}\n" diff --git a/proxy_docker/app/tests/test-manage-missed.sh b/proxy_docker/app/tests/test-manage-missed.sh index 5f8167c..9b5ba6a 100755 --- a/proxy_docker/app/tests/test-manage-missed.sh +++ b/proxy_docker/app/tests/test-manage-missed.sh @@ -4,6 +4,7 @@ . ./mine.sh # This needs to be run in regtest +# You need jq installed for these tests to run correctly # This will test the missed watched transactions mechanisms by broadcasting # transactions on watched addresses while the proxy is shut down... @@ -141,7 +142,7 @@ trace 2 "url2=${url2}" trace 2 "url3=${url3}" trace 2 "url4=${url4}" -exec_in_test_container apk add curl +exec_in_test_container apk add --update curl # exec_in_test_container ping -c 5 tests-manage-missed # exec_in_test_container curl -vd 'toto' ${url1}/allo test_manage_missed_0_conf diff --git a/proxy_docker/app/tests/test-watchpub32.sh b/proxy_docker/app/tests/test-watchpub32.sh index cb4725a..98fa3b4 100755 --- a/proxy_docker/app/tests/test-watchpub32.sh +++ b/proxy_docker/app/tests/test-watchpub32.sh @@ -4,6 +4,7 @@ . ./mine.sh # This needs to be run in regtest +# You need jq installed for these tests to run correctly # This will test: # @@ -30,7 +31,7 @@ start_test_container() { } stop_test_container() { - trace 1 "\n\n[test_watch_pub32] ${BCyan}Stopping existing containers if they are running...${Color_Off}\n" + trace 1 "\n\n[stop_test_container] ${BCyan}Stopping existing containers if they are running...${Color_Off}\n" docker stop tests-watch-pub32 docker stop tests-watch-pub32-cb @@ -433,7 +434,7 @@ callbackserverport="1111" callbackservername="tests-watch-pub32-cb" trace 1 "\n\n[test_watch_pub32] ${BCyan}Installing needed packages...${Color_Off}\n" -exec_in_test_container apk add curl +exec_in_test_container apk add --update curl test_watch_pub32