Skip to content

Commit 5d901a9

Browse files
committed
Wallet: add balance subcommand
1 parent 17214fd commit 5d901a9

File tree

8 files changed

+591
-1
lines changed

8 files changed

+591
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Test the wallet balance command with --from key file (text format)
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
9+
cd "$REPO_ROOT"
10+
11+
# Define test parameters
12+
KEY_FILE="tests/files/accounts/test-block-producer"
13+
PASSWORD="test-password"
14+
15+
echo "Test: Verify --from option works with key file (text format)"
16+
export MINA_PRIVKEY_PASS="$PASSWORD"
17+
BALANCE_OUTPUT=$(./target/release/mina wallet balance --from "$KEY_FILE" --endpoint "http://mina-rust-plain-1.gcp.o1test.net/graphql" --format text 2>&1 || true)
18+
19+
echo "Balance command output:"
20+
echo "$BALANCE_OUTPUT"
21+
echo ""
22+
23+
# Command should execute and produce text format output
24+
if echo "$BALANCE_OUTPUT" | grep -q "Account:"; then
25+
echo "✓ Command executed successfully with text format"
26+
# Verify text format structure
27+
if echo "$BALANCE_OUTPUT" | grep -q "Balance:" && \
28+
echo "$BALANCE_OUTPUT" | grep -q "Total:" && \
29+
echo "$BALANCE_OUTPUT" | grep -q "Nonce:"; then
30+
echo "✓ Text output has expected structure"
31+
exit 0
32+
else
33+
echo "✗ Test failed: Text output missing expected fields"
34+
exit 1
35+
fi
36+
elif echo "$BALANCE_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
37+
# Command executed but got an error (e.g., account doesn't exist)
38+
echo "✓ Command executed (account may not exist on network)"
39+
exit 0
40+
else
41+
echo "✗ Test failed: Unexpected output"
42+
exit 1
43+
fi
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Test the wallet balance command JSON format output structure
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
9+
cd "$REPO_ROOT"
10+
11+
# Check for jq
12+
if ! command -v jq &> /dev/null; then
13+
echo "Error: jq is required but not installed"
14+
echo "Install with: apt-get install jq (Ubuntu/Debian) or brew install jq (macOS)"
15+
exit 1
16+
fi
17+
18+
echo "Test: Verify JSON format output structure"
19+
JSON_OUTPUT=$(./target/release/mina wallet balance \
20+
--address "B62qkiqPXFDayJV8JutYvjerERZ35EKrdmdcXh3j1rDUHRs1bJkFFcX" \
21+
--endpoint "http://mina-rust-plain-1.gcp.o1test.net/graphql" \
22+
--format json 2>&1 || true)
23+
24+
echo "JSON format output:"
25+
echo "$JSON_OUTPUT"
26+
echo ""
27+
28+
# Use jq to validate JSON structure
29+
if echo "$JSON_OUTPUT" | jq empty 2>/dev/null; then
30+
# Check for proper JSON structure using jq
31+
if echo "$JSON_OUTPUT" | jq -e '.account and .balance.total and .balance.total_mina and .nonce' > /dev/null 2>&1; then
32+
echo "✓ Test passed: JSON format has proper structure"
33+
exit 0
34+
else
35+
echo "✗ Test failed: JSON structure is incomplete"
36+
echo "Expected fields: account, balance.total, balance.total_mina, nonce"
37+
exit 1
38+
fi
39+
elif echo "$JSON_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
40+
echo "✗ Test failed: Could not retrieve account balance"
41+
echo "The test account may not exist on the network"
42+
exit 1
43+
else
44+
echo "✗ Test failed: Output is not valid JSON"
45+
exit 1
46+
fi
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Test the wallet balance command with --address (JSON format)
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
9+
cd "$REPO_ROOT"
10+
11+
# Check for jq
12+
if ! command -v jq &> /dev/null; then
13+
echo "Error: jq is required but not installed"
14+
echo "Install with: apt-get install jq (Ubuntu/Debian) or brew install jq (macOS)"
15+
exit 1
16+
fi
17+
18+
# Define test parameters
19+
PUBLIC_KEY=$(cat "tests/files/accounts/test-block-producer.pub")
20+
21+
echo "Test: Verify --address option works with public key (JSON format)"
22+
BALANCE_JSON=$(./target/release/mina wallet balance --address "$PUBLIC_KEY" --endpoint "http://mina-rust-plain-1.gcp.o1test.net/graphql" --format json 2>&1 || true)
23+
24+
echo "Balance command output:"
25+
echo "$BALANCE_JSON"
26+
echo ""
27+
28+
# Command should execute and produce JSON output
29+
# Try to parse as JSON using jq
30+
if echo "$BALANCE_JSON" | jq empty 2>/dev/null; then
31+
echo "✓ Command executed successfully with JSON format"
32+
# Verify JSON format structure using jq
33+
if echo "$BALANCE_JSON" | jq -e '.account and .balance and .nonce' > /dev/null 2>&1; then
34+
echo "✓ JSON output has expected structure"
35+
exit 0
36+
else
37+
echo "✗ Test failed: JSON output missing expected fields"
38+
exit 1
39+
fi
40+
elif echo "$BALANCE_JSON" | grep -qE "(Error:|\\[ERROR\\])"; then
41+
# Command executed but got an error (e.g., account doesn't exist)
42+
echo "✓ Command executed (account may not exist on network)"
43+
exit 0
44+
else
45+
echo "✗ Test failed: Unexpected output"
46+
exit 1
47+
fi
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Test the wallet balance command error when no account specified
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
9+
cd "$REPO_ROOT"
10+
11+
echo "Test: Verify error when no account specified"
12+
ERROR_OUTPUT=$(./target/release/mina wallet balance --endpoint "http://mina-rust-plain-1.gcp.o1test.net/graphql" 2>&1 || true)
13+
14+
echo "Command output:"
15+
echo "$ERROR_OUTPUT"
16+
echo ""
17+
18+
if echo "$ERROR_OUTPUT" | grep -qE "(\\[ERROR\\].*Either --address or --from must be provided|Either --address or --from must be provided)"; then
19+
echo "✓ Test passed: Proper error when no account specified"
20+
exit 0
21+
else
22+
echo "✗ Test failed: Expected error message not found"
23+
exit 1
24+
fi
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Test the wallet balance command text format output structure
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
9+
cd "$REPO_ROOT"
10+
11+
echo "Test: Verify text format output structure"
12+
TEXT_OUTPUT=$(./target/release/mina wallet balance \
13+
--address "B62qkiqPXFDayJV8JutYvjerERZ35EKrdmdcXh3j1rDUHRs1bJkFFcX" \
14+
--endpoint "http://mina-rust-plain-1.gcp.o1test.net/graphql" \
15+
--format text 2>&1 || true)
16+
17+
echo "Text format output:"
18+
echo "$TEXT_OUTPUT"
19+
echo ""
20+
21+
if echo "$TEXT_OUTPUT" | grep -q "Account:"; then
22+
# Check for proper text format structure
23+
if echo "$TEXT_OUTPUT" | grep -qE "Balance:" && \
24+
echo "$TEXT_OUTPUT" | grep -qE "Total:.*MINA" && \
25+
echo "$TEXT_OUTPUT" | grep -qE "Nonce:"; then
26+
echo "✓ Test passed: Text format has proper structure"
27+
exit 0
28+
else
29+
echo "✗ Test failed: Text output structure is incomplete"
30+
echo "Expected fields: Balance:, Total: X MINA, Nonce:"
31+
exit 1
32+
fi
33+
elif echo "$TEXT_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
34+
echo "✗ Test failed: Could not retrieve account balance"
35+
echo "The test account may not exist on the network"
36+
exit 1
37+
else
38+
echo "✗ Test failed: Unexpected output format"
39+
exit 1
40+
fi

0 commit comments

Comments
 (0)