Created
July 16, 2020 15:01
-
-
Save dmos62/20981dae799e2fc31b62dd443c44c7ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bats | |
daoSetup_localFile="dao-setup.zip" | |
download-dao-setup-if-needed() { | |
local daoSetup_remoteUrl="https://github.com/bisq-network/bisq/raw/master/docs/dao-setup.zip" | |
test ! -f $daoSetup_localFile \ | |
&& wget -O $daoSetup_localFile $daoSetup_remoteUrl | |
} | |
dataDir="tmp-apitest-datadir" | |
extract-dao-setup () { | |
unzip $daoSetup_localFile -d $dataDir | |
# Get rid of superfluous root folder | |
local superfluousFolder=dao-setup | |
mv $dataDir/$superfluousFolder/* $dataDir/ | |
rm -rf $dataDir/$superfluousFolder/ | |
# Remove unneeded files, to avoid confusion | |
rm $dataDir/Bitcoin-regtest/blocknotify | |
rm $dataDir/Bitcoin-regtest/bitcoin.conf | |
} | |
setup-initial-data-dirs() { | |
# remove dataDir from a previous run | |
rm -rf $dataDir | |
mkdir -p $dataDir | |
extract-dao-setup | |
} | |
bitcoinCore_rpcUser=apitest | |
bitcoinCore_rpcPassword=apitest | |
bitcoinCore_rpcPort=18843 | |
run-bisq () { | |
local executableName=$1 | |
local appName=$2 | |
local dirWithBisqExecutables=.. | |
$dirWithBisqExecutables/$executableName \ | |
--appName=$appName \ | |
--nodePort=$3 \ | |
--rpcBlockNotificationPort=$4 \ | |
--apiPort=$5 \ | |
--apiPassword=xyz \ | |
--appDataDir="$dataDir/$appName" \ | |
--baseCurrencyNetwork=BTC_REGTEST \ | |
--useLocalhostForP2P=true \ | |
--useDevPrivilegeKeys=true \ | |
--seedNodes="localhost:2002" \ | |
--daoActivated=true \ | |
--fullDaoNode=true \ | |
--genesisTxId=30af0050040befd8af25068cc697e418e09c2d8ebd8d411d2240591b9ec203cf \ | |
--genesisBlockHeight=111 \ | |
--rpcUser=$bitcoinCore_rpcUser \ | |
--rpcPassword=$bitcoinCore_rpcPassword \ | |
--rpcPort=$bitcoinCore_rpcPort \ | |
> $dataDir/${appName}-output.txt 2>&1 \ | |
& | |
} | |
seedNode_executableName=bisq-seednode | |
seedNode_appName=bisq-BTC_REGTEST_Seed_2002 | |
seedNode_nodePort=2002 | |
seedNode_blockNotifPort=5120 | |
seedNode_apiPort=-1 | |
arbitrator_executableName=bisq-daemon | |
arbitrator_appName=bisq-BTC_REGTEST_arbitrator | |
arbitrator_nodePort=4444 | |
arbitrator_blockNotifPort=5121 | |
arbitrator_apiPort=9997 | |
alice_executableName=bisq-daemon | |
alice_appName=bisq-BTC_REGTEST_Alice | |
alice_nodePort=7777 | |
alice_blockNotifPort=5122 | |
alice_apiPort=9998 | |
bob_executableName=bisq-daemon | |
bob_appName=bisq-BTC_REGTEST_Bob | |
bob_nodePort=8888 | |
bob_blockNotifPort=5123 | |
bob_apiPort=9999 | |
run-bisq-participants() { | |
# seednode | |
run-bisq \ | |
$seedNode_executableName \ | |
$seedNode_appName \ | |
$seedNode_nodePort \ | |
$seedNode_blockNotifPort \ | |
$seedNode_apiPort | |
SEEDNODE_PID=$! | |
# arbitrator | |
run-bisq \ | |
bisq-daemon \ | |
$arbitrator_executableName \ | |
$arbitrator_appName \ | |
$arbitrator_nodePort \ | |
$arbitrator_blockNotifPort \ | |
$arbitrator_apiPort | |
ARBITRATOR_PID=$! | |
# alice | |
run-bisq \ | |
$alice_executableName \ | |
$alice_appName \ | |
$alice_nodePort \ | |
$alice_blockNotifPort \ | |
$alice_apiPort | |
ALICE_PID=$! | |
# bob | |
run-bisq \ | |
$bob_executableName \ | |
$bob_appName \ | |
$bob_nodePort \ | |
$bob_blockNotifPort \ | |
$bob_apiPort | |
BOB_PID=$! | |
} | |
blockNotifyScript="" | |
blockNotifyScript+=" echo %s | nc -w 1 127.0.0.1 $seedNode_blockNotifPort;" | |
blockNotifyScript+=" echo %s | nc -w 1 127.0.0.1 $arbitrator_blockNotifPort;" | |
blockNotifyScript+=" echo %s | nc -w 1 127.0.0.1 $alice_blockNotifPort;" | |
blockNotifyScript+=" echo %s | nc -w 1 127.0.0.1 $bob_blockNotifPort;" | |
run-bitcoind() { | |
bitcoind \ | |
-daemon \ | |
-datadir= \ | |
-regtest=1 \ | |
-peerbloomfilters=1 \ | |
-server=1 \ | |
-txindex=1 \ | |
-rpcuser=$bitcoinCore_rpcUser \ | |
-rpcpassword=$bitcoinCore_rpcPassword \ | |
-rpcport=$bitcoinCore_rpcPort \ | |
-blocknotify="$blockNotifyScript" \ | |
> $dataDir/bitcoind-output.txt 2>&1 \ | |
& | |
BITCOIND_PID=$! | |
} | |
run-participants() { | |
run-bisq-participants | |
run-bitcoind | |
} | |
setup() { | |
download-dao-setup-if-needed | |
setup-initial-data-dirs | |
run-participants | |
sleep 5s # wait for participants to initialize | |
} | |
kill-participants () { | |
kill $SEEDNODE_PID | |
kill $ARBITRATOR_PID | |
kill $ALICE_PID | |
kill $BOB_PID | |
kill $BITCOIND_PID | |
} | |
teardown() { | |
kill-participants | |
} | |
# TODO implement demo tests | |
@test "invoking 'has' without arguments prints usage" { | |
run $has | |
[ "$status" -eq 0 ] | |
[ "${lines[0]%% *}" = 'has' ] | |
[ "${lines[1]%%:*}" = 'USAGE' ] | |
[ "${lines[2]}" = 'EXAMPLE: has git curl node' ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Untested proof of concept Bisq API e2e testing harness. Superseded by bisq-network/bisq#4366
The single test case (L183) is a placeholder copy-paste from another project.