diff options
author | Antoine A <> | 2021-12-29 02:41:21 +0100 |
---|---|---|
committer | Antoine A <> | 2021-12-29 02:41:21 +0100 |
commit | 8976614d20acbdd9f88a0e56eb8f9a8886501478 (patch) | |
tree | 660b913bd875faafb773fb7967d93404d507c52f | |
parent | cc87a6e03326de8576e2b0eff3aed5dc1f0ca3b4 (diff) | |
parent | 3949707ed97c982606ba1c068254f7078b50b89b (diff) | |
download | depolymerization-8976614d20acbdd9f88a0e56eb8f9a8886501478.tar.gz depolymerization-8976614d20acbdd9f88a0e56eb8f9a8886501478.tar.bz2 depolymerization-8976614d20acbdd9f88a0e56eb8f9a8886501478.zip |
Merge branch 'presearch' into research
-rw-r--r-- | script/prepare.sh | 8 | ||||
-rw-r--r-- | script/setup.sh | 45 | ||||
-rw-r--r-- | script/test_btc_fail.sh | 18 | ||||
-rw-r--r-- | script/test_btc_stress.sh | 18 | ||||
-rw-r--r-- | script/test_btc_wire.sh | 18 | ||||
-rw-r--r-- | script/test_gateway.sh | 7 | ||||
-rw-r--r-- | script/test_recover_db.sh | 22 | ||||
-rw-r--r-- | test.conf | 2 |
8 files changed, 62 insertions, 76 deletions
diff --git a/script/prepare.sh b/script/prepare.sh index 6a311f9..9340772 100644 --- a/script/prepare.sh +++ b/script/prepare.sh @@ -15,15 +15,17 @@ 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 -tar xvzf btc.tar.gz -C ~/bitcoin +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 -postgresql +cd postgresql ./configure --prefix ~/postgresql make -make check make install echo "III - Config" diff --git a/script/setup.sh b/script/setup.sh index 5ef9d1e..da54e00 100644 --- 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 index c9fa930..849a525 100644 --- 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 index e7ce986..91f8f8b 100644 --- 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 index 442dcf3..3b48bae 100644 --- 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 index 329065a..dd9e59c 100644 --- 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 index d90a541..1e50572 100644 --- 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" @@ -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 |