2021-05-04 20:20:01 -04:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
#
|
2023-03-06 19:14:00 -05:00
|
|
|
# Smoke tests for haveno-cli running against a live haveno-daemon (on mainnet)
|
2021-05-04 20:20:01 -04:00
|
|
|
#
|
|
|
|
# Prerequisites:
|
|
|
|
#
|
|
|
|
# - bats-core 1.2.0+ must be installed (brew install bats-core on macOS)
|
|
|
|
# see https://github.com/bats-core/bats-core
|
|
|
|
#
|
2023-03-06 19:14:00 -05:00
|
|
|
# - Run `./haveno-daemon --apiPassword=xyz --appDataDir=$TESTDIR` where $TESTDIR
|
2021-05-04 20:20:01 -04:00
|
|
|
# is empty or otherwise contains an unencrypted wallet with a 0 BTC balance
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# This script must be run from the root of the project, e.g.:
|
|
|
|
#
|
|
|
|
# bats apitest/scripts/mainnet-test.sh
|
|
|
|
|
|
|
|
@test "test unsupported method error" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz bogus
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2 # printed only on test failure
|
|
|
|
[ "$output" = "Error: 'bogus' is not a supported method" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test unrecognized option error" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --bogus getversion
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: missing required 'password' option" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test missing required password option error" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli getversion
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: missing required 'password' option" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test incorrect password error" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=bogus getversion
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: incorrect 'password' rpc header value" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getversion call with quoted password" {
|
|
|
|
load 'version-parser'
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password="xyz" getversion
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "$CURRENT_VERSION" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getversion" {
|
|
|
|
# Wait 1 second before calling getversion again.
|
|
|
|
sleep 1
|
|
|
|
load 'version-parser'
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getversion
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "$CURRENT_VERSION" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test setwalletpassword \"a b c\"" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz setwalletpassword --wallet-password="a b c"
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "wallet encrypted" ]
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test unlockwallet without password & timeout args" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz unlockwallet
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: no password specified" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test unlockwallet without timeout arg" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz unlockwallet --wallet-password="a b c"
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: no unlock timeout specified" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@test "test unlockwallet \"a b c\" 8" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz unlockwallet --wallet-password="a b c" --timeout=8
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "wallet unlocked" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getbalance while wallet unlocked for 8s" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getbalance
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
sleep 8
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test unlockwallet \"a b c\" 6" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz unlockwallet --wallet-password="a b c" --timeout=6
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "wallet unlocked" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test lockwallet before unlockwallet timeout=6s expires" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz lockwallet
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "wallet locked" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test setwalletpassword incorrect old pwd error" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz setwalletpassword --wallet-password="z z z" --new-wallet-password="d e f"
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: incorrect old password" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test setwalletpassword oldpwd newpwd" {
|
|
|
|
# Wait 5 seconds before calling setwalletpassword again.
|
|
|
|
sleep 5
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz setwalletpassword --wallet-password="a b c" --new-wallet-password="d e f"
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "wallet encrypted with new password" ]
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getbalance wallet locked error" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getbalance
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: wallet is locked" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test removewalletpassword" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz removewalletpassword --wallet-password="d e f"
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "wallet decrypted" ]
|
|
|
|
sleep 3
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getbalance when wallet available & unlocked with 0 btc balance" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getbalance
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getfundingaddresses" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getfundingaddresses
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getaddressbalance missing address argument" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getaddressbalance
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: no address specified" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getaddressbalance bogus address argument" {
|
|
|
|
# Wait 1 second before calling getaddressbalance again.
|
|
|
|
sleep 1
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getaddressbalance --address=bogus
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: address bogus not found in wallet" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getpaymentmethods" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getpaymentmethods
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getpaymentaccts" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getpaymentaccts
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getoffers missing direction argument" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getoffers
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "actual output: $output" >&2
|
|
|
|
[ "$output" = "Error: no direction (buy|sell) specified" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getoffers sell eur check return status" {
|
|
|
|
# Wait 1 second before calling getoffers again.
|
|
|
|
sleep 1
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getoffers --direction=sell --currency-code=eur
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getoffers buy eur check return status" {
|
|
|
|
# Wait 1 second before calling getoffers again.
|
|
|
|
sleep 1
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getoffers --direction=buy --currency-code=eur
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test getoffers sell gbp check return status" {
|
|
|
|
# Wait 1 second before calling getoffers again.
|
|
|
|
sleep 1
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz getoffers --direction=sell --currency-code=gbp
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test help displayed on stderr if no options or arguments" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 1 ]
|
2023-03-06 19:14:00 -05:00
|
|
|
[ "${lines[0]}" = "Haveno RPC Client" ]
|
|
|
|
[ "${lines[1]}" = "Usage: haveno-cli [options] <method> [params]" ]
|
2021-05-04 20:20:01 -04:00
|
|
|
# TODO add asserts after help text is modified for new endpoints
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test --help option" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --help
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
2023-03-06 19:14:00 -05:00
|
|
|
[ "${lines[0]}" = "Haveno RPC Client" ]
|
|
|
|
[ "${lines[1]}" = "Usage: haveno-cli [options] <method> [params]" ]
|
2021-05-04 20:20:01 -04:00
|
|
|
# TODO add asserts after help text is modified for new endpoints
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "test takeoffer method --help" {
|
2023-03-06 19:14:00 -05:00
|
|
|
run ./haveno-cli --password=xyz takeoffer --help
|
2021-05-04 20:20:01 -04:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "${lines[0]}" = "takeoffer" ]
|
|
|
|
}
|