bisq/cli/test.sh
Chris Beams 312ef30b70
Revert marking password as required in JOpt parser
This is a partial reversion of the earlier commit. Marking the password
option as required at the parser level made it impossible to run
./bisq-cli without options or arguments and get the help text. This is a
useful thing to do, and not worth creating a bad user experience to get
the free required option error handling and error messaging.
2020-04-26 21:44:03 +02:00

156 lines
4.5 KiB
Bash
Executable file

#!/bin/bash
#
# References & examples for expect:
#
# - https://pantz.org/software/expect/expect_examples_and_tips.html
# - https://stackoverflow.com/questions/13982310/else-string-matching-in-expect
# - https://gist.github.com/Fluidbyte/6294378
# - https://www.oreilly.com/library/view/exploring-expect/9781565920903/ch04.html
#
# Prior to running this script, run:
#
# ./bisq-daemon --apiPassword=xyz
#
# The data directory used must contain an unencrypted wallet with a 0 BTC balance
# Ensure project root is the current working directory
cd $(dirname $0)/..
OUTPUT=$(expect -c '
# exp_internal 1
puts "TEST unsupported cmd error"
set expected "Error: '\''bogus'\'' is not a supported method"
spawn ./bisq-cli --password=xyz bogus
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
puts "TEST unrecognized option error"
set expected "Error: bogus is not a recognized option"
spawn ./bisq-cli --bogus getversion
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
# exp_internal 1
puts "TEST missing required password option error"
set expected "Error: missing required '\''password'\'' option"
spawn ./bisq-cli getversion
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
# exp_internal 1
puts "TEST getversion (incorrect password error)"
set expected "Error: incorrect '\''password'\'' rpc header value"
spawn ./bisq-cli --password=bogus getversion
expect {
$expected { puts "PASS\n" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
# exp_internal 1
puts "TEST getversion (password value in quotes) COMMIT"
set expected "1.3.2"
# Note: have to define quoted argument in a variable as "''value''"
set pwd_in_quotes "''xyz''"
spawn ./bisq-cli --password=$pwd_in_quotes getversion
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
puts "TEST getversion"
set expected "1.3.2"
spawn ./bisq-cli --password=xyz getversion
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
puts "TEST getbalance"
# exp_internal 1
set expected "0.00000000"
spawn ./bisq-cli --password=xyz getbalance
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
puts "TEST running with no options or arguments prints help text"
# exp_internal 1
set expected "Bisq RPC Client"
spawn ./bisq-cli
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
echo "TEST --help option prints help text"
./bisq-cli --help