commit 3949707ed97c982606ba1c068254f7078b50b89b
parent af731945c8480a28102c66cf84cf2fb2b8a4f444
Author: Antoine A <>
Date: Wed, 29 Dec 2021 00:04:08 +0100
Test without sudo
Diffstat:
8 files changed, 92 insertions(+), 73 deletions(-)
diff --git a/script/prepare.sh b/script/prepare.sh
@@ -0,0 +1,34 @@
+set -eu
+
+DIR=$(mktemp -d)
+
+function cleanup() {
+ for n in `jobs -p`; do
+ kill $n 2> /dev/null || true
+ done
+ rm -rf $DIR 2> /dev/null
+ wait
+}
+
+trap cleanup EXIT
+
+echo "I - Install bitcoind version 0.22"
+cd $DIR
+curl -L https://bitcoin.org/bin/bitcoin-core-22.0/bitcoin-22.0-x86_64-linux-gnu.tar.gz -o btc.tar.gz
+rm -rfv ~/bitcoin
+mkdir -pv ~/bitcoin
+tar xvzf btc.tar.gz
+mv -v bitcoin-22.0/* ~/bitcoin
+
+echo "II - Install latest postgres from source"
+cd $DIR
+git clone --depth 1 https://git.postgresql.org/git/postgresql.git
+cd postgresql
+./configure --prefix ~/postgresql
+make
+make install
+
+echo "III - Config"
+
+echo "Add ~/bitcoin/bin to your path"
+echo "Add ~/postgresql/bin to your path"
+\ No newline at end of file
diff --git a/script/setup.sh b/script/setup.sh
@@ -2,22 +2,57 @@
## Test utils
+set -eu
+
+# Cleanup to run whenever we exit
+function cleanup() {
+ for n in `jobs -p`; do
+ kill $n &> /dev/null || true
+ done
+ pg_ctl stop -D $DB_DIR -w &> /dev/null
+ rm -rf $DIR &> /dev/null
+ wait
+}
+
+# Install cleanup handler (except for kill -9)
+trap cleanup EXIT
+
+DIR=$(mktemp -d)
+BTC_DIR=$DIR/bitcoin
+DB_DIR=$DIR/db
+mkdir -p $BTC_DIR
+mkdir -p $DB_DIR
+
# Load test.conf as bash variables
function load_config() {
source <(grep = test.conf | sed 's/ *= */=/' | sed 's/=\(.*\)/="\1"/g1')
BANK_ENDPOINT=http://127.0.0.1:$PORT/
}
-# Start postgresql service and reset database schema
+# Create new postgresql cluster and init database schema
+function setup_db() {
+ pg_ctl init -D $DB_DIR &> /dev/null
+ echo "port=5454" >> $DB_DIR/postgresql.conf
+ pg_ctl start -D $DB_DIR > /dev/null
+ echo "CREATE ROLE postgres LOGIN SUPERUSER PASSWORD 'password'" | psql -p 5454 postgres > /dev/null
+ psql $DB_URL < wire-gateway/db/schema.sql &> /dev/null
+}
+
+function stop_db() {
+ pg_ctl stop -D $DB_DIR > /dev/null
+}
+
+function start_db() {
+ pg_ctl start -D $DB_DIR > /dev/null
+}
+
+# Erase database
function reset_db() {
- # TODO sudo alternative ?
- sudo service postgresql start > /dev/null
- sudo -u postgres psql $DB_URL < wire-gateway/db/schema.sql > /dev/null
+ psql $DB_URL < wire-gateway/db/schema.sql > /dev/null
}
# Start a bitcoind regtest server in a temporary directory
function init_btc() {
- BTC_DIR=$(mktemp -d)
echo "regtest=1" > $BTC_DIR/bitcoin.conf
echo "txindex=1" >> $BTC_DIR/bitcoin.conf
echo "fallbackfee=0.00000001" >> $BTC_DIR/bitcoin.conf
diff --git a/script/test_btc_fail.sh b/script/test_btc_fail.sh
@@ -4,28 +4,16 @@
set -eu
-# Cleanup to run whenever we exit
-function cleanup() {
- for n in `jobs -p`; do
- kill $n 2> /dev/null || true
- done
- rm -rf $BTC_DIR 2> /dev/null
- wait
-}
-
-# Install cleanup handler (except for kill -9)
-trap cleanup EXIT
-
source "${BASH_SOURCE%/*}/setup.sh"
echo "----- Setup fail -----"
echo "Load config file"
load_config
-echo "Reset database"
-reset_db
+echo "Start database"
+setup_db
echo "Start bitcoin node"
init_btc
-echo "Init bitcoin regtest"
+echo "Start bitcoin regtest"
setup_btc
echo "Start failing btc-wire"
fail_btc_wire
diff --git a/script/test_btc_stress.sh b/script/test_btc_stress.sh
@@ -4,28 +4,16 @@
set -eu
-# Cleanup to run whenever we exit
-function cleanup() {
- for n in `jobs -p`; do
- kill $n 2> /dev/null || true
- done
- rm -rf $BTC_DIR 2> /dev/null
- wait
-}
-
-# Install cleanup handler (except for kill -9)
-trap cleanup EXIT
-
source "${BASH_SOURCE%/*}/setup.sh"
echo "----- Setup stressed -----"
echo "Load config file"
load_config
-echo "Reset database"
-reset_db
+echo "Start database"
+setup_db
echo "Start bitcoin node"
init_btc
-echo "Init bitcoin regtest"
+echo "Start bitcoin regtest"
setup_btc
echo "Start btc-wire stressed"
stressed_btc_wire
diff --git a/script/test_btc_wire.sh b/script/test_btc_wire.sh
@@ -4,28 +4,16 @@
set -eu
-# Cleanup to run whenever we exit
-function cleanup() {
- for n in `jobs -p`; do
- kill $n 2> /dev/null || true
- done
- rm -rf $BTC_DIR 2> /dev/null
- wait
-}
-
-# Install cleanup handler (except for kill -9)
-trap cleanup EXIT
-
source "${BASH_SOURCE%/*}/setup.sh"
echo "----- Setup -----"
echo "Load config file"
load_config
-echo "Reset database"
-reset_db
+echo "Start database"
+setup_db
echo "Start bitcoin node"
init_btc
-echo "Init bitcoin regtest"
+echo "Start bitcoin regtest"
setup_btc
echo "Start btc-wire"
btc_wire
diff --git a/script/test_gateway.sh b/script/test_gateway.sh
@@ -9,9 +9,6 @@ TEMP_FILE=$(mktemp)
# Cleanup to run whenever we exit
function cleanup() {
- for n in `jobs -p`; do
- kill $n 2> /dev/null || true
- done
rm -f $TEMP_FILE
wait
}
@@ -25,8 +22,8 @@ ADDRESS=mpTJZxWPerz1Gife6mQSdHT8mMuJK6FP85
echo "----- Setup -----"
echo "Load config file"
load_config
-echo "Reset database"
-reset_db
+echo "Start database"
+setup_db
echo "Start gateway"
gateway
echo ""
diff --git a/script/test_recover_db.sh b/script/test_recover_db.sh
@@ -4,28 +4,16 @@
set -eu
-# Cleanup to run whenever we exit
-function cleanup() {
- for n in `jobs -p`; do
- kill $n 2> /dev/null || true
- done
- rm -rf $BTC_DIR 2> /dev/null
- wait
-}
-
-# Install cleanup handler (except for kill -9)
-trap cleanup EXIT
-
source "${BASH_SOURCE%/*}/setup.sh"
echo "----- Setup -----"
echo "Load config file"
load_config
-echo "Reset database"
-reset_db
+echo "Start database"
+setup_db
echo "Start bitcoin node"
init_btc
-echo "Init bitcoin regtest"
+echo "Start bitcoin regtest"
setup_btc
echo "Start btc-wire"
btc_wire
@@ -44,7 +32,7 @@ taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i | grep BTC:0.000042 > /d
echo "----- Without DB -----"
echo "Stop database"
-sudo service postgresql stop > /dev/null
+stop_db
echo "Making incomplete wire transfer to exchange"
$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.00042 &> /dev/null
echo "Making wire transfer to exchange:"
@@ -57,7 +45,7 @@ taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i 2>&1 | grep -q "504" &&
echo "----- Reconnect DB -----"
echo "Start database"
-sudo service postgresql start > /dev/null
+start_db
sleep 6 # Wait for connection to be available
echo -n "Requesting exchange incoming transaction list:"
taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i | grep BTC:0.00004 > /dev/null && echo " OK" || echo " Failed"
diff --git a/test.conf b/test.conf
@@ -2,7 +2,7 @@
BASE_URL = http://test.com
[depolymerizer-bitcoin]
-DB_URL = postgres://localhost/postgres?user=postgres&password=password
+DB_URL = postgres://localhost:5454/postgres?user=postgres&password=password
PORT = 8060
UNIXPATH = TODO
PAYTO = payto://bitcoin/bcrt1qgkgxkjj27g3f7s87mcvjjsghay7gh34cx39prj