2018-07-02 14:14:34 -07:00
|
|
|
#!/bin/bash -e
|
|
|
|
#
|
|
|
|
# Wallet sanity test
|
|
|
|
#
|
|
|
|
|
2018-09-07 09:46:21 -07:00
|
|
|
cd "$(dirname "$0")"/..
|
2018-07-02 14:14:34 -07:00
|
|
|
|
2018-09-16 14:53:24 -06:00
|
|
|
# shellcheck source=multinode-demo/common.sh
|
|
|
|
source multinode-demo/common.sh
|
|
|
|
|
|
|
|
if [[ -z $1 ]]; then # no network argument, use default
|
|
|
|
entrypoint=()
|
2018-07-13 22:10:39 -07:00
|
|
|
else
|
2018-09-16 14:53:24 -06:00
|
|
|
entrypoint=(-n "$1")
|
2018-07-13 22:10:39 -07:00
|
|
|
fi
|
2018-07-02 14:14:34 -07:00
|
|
|
|
|
|
|
# Tokens transferred to this address are lost forever...
|
|
|
|
garbage_address=vS3ngn1TfQmpsW1Z4NkLuqNAQFF3dYQw8UZ6TCx9bmq
|
|
|
|
|
|
|
|
check_balance_output() {
|
2018-08-16 15:11:58 -07:00
|
|
|
declare expected_output="$1"
|
2018-08-16 14:33:14 -07:00
|
|
|
exec 42>&1
|
2018-09-16 14:53:24 -06:00
|
|
|
output=$($solana_wallet "${entrypoint[@]}" balance | tee >(cat - >&42))
|
2018-08-16 15:11:58 -07:00
|
|
|
if [[ ! "$output" =~ $expected_output ]]; then
|
|
|
|
echo "Balance is incorrect. Expected: $expected_output"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-07-02 14:14:34 -07:00
|
|
|
}
|
|
|
|
|
2018-07-02 17:40:17 -07:00
|
|
|
pay_and_confirm() {
|
|
|
|
exec 42>&1
|
2018-09-16 14:53:24 -06:00
|
|
|
signature=$($solana_wallet "${entrypoint[@]}" pay "$@" | tee >(cat - >&42))
|
|
|
|
$solana_wallet "${entrypoint[@]}" confirm "$signature"
|
2018-07-02 17:40:17 -07:00
|
|
|
}
|
|
|
|
|
2018-10-24 22:56:46 -06:00
|
|
|
leader_readiness=false
|
|
|
|
timeout=60
|
2018-10-25 11:20:17 -06:00
|
|
|
while [[ $timeout -gt 0 ]]; do
|
2018-10-24 22:56:46 -06:00
|
|
|
expected_output="Leader ready"
|
|
|
|
exec 42>&1
|
2018-10-25 11:20:17 -06:00
|
|
|
output=$($solana_wallet "${entrypoint[@]}" get-transaction-count | tee >(cat - >&42))
|
|
|
|
if [[ $output -gt 0 ]]; then
|
2018-10-24 22:56:46 -06:00
|
|
|
leader_readiness=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
(( timeout=timeout-2 ))
|
|
|
|
done
|
2018-10-25 11:20:17 -06:00
|
|
|
if ! "$leader_readiness"; then
|
2018-10-24 22:56:46 -06:00
|
|
|
echo "Timed out waiting for leader"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-09-28 08:21:24 -06:00
|
|
|
$solana_keygen
|
2018-09-16 14:53:24 -06:00
|
|
|
$solana_wallet "${entrypoint[@]}" address
|
2018-08-16 14:33:14 -07:00
|
|
|
check_balance_output "No account found" "Your balance is: 0"
|
2018-09-21 19:46:52 -06:00
|
|
|
$solana_wallet "${entrypoint[@]}" airdrop 60
|
2018-07-02 17:40:17 -07:00
|
|
|
check_balance_output "Your balance is: 60"
|
2018-09-21 19:46:52 -06:00
|
|
|
$solana_wallet "${entrypoint[@]}" airdrop 40
|
2018-07-02 17:40:17 -07:00
|
|
|
check_balance_output "Your balance is: 100"
|
2018-09-21 19:46:52 -06:00
|
|
|
pay_and_confirm $garbage_address 99
|
2018-07-02 17:40:17 -07:00
|
|
|
check_balance_output "Your balance is: 1"
|
2018-07-02 14:14:34 -07:00
|
|
|
|
|
|
|
echo PASS
|
|
|
|
exit 0
|