Skip to content

Commit d4c0703

Browse files
authored
Merge pull request #1543 from o1-labs/dw/cli-tx-2
CLI: wallet subcommand
2 parents 8b34cb8 + 03eee69 commit d4c0703

29 files changed

+1984
-9
lines changed
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 address command with encrypted key file
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+
PUBKEY_FILE="tests/files/accounts/test-block-producer.pub"
14+
PASSWORD="test-password"
15+
16+
# Read expected public key
17+
EXPECTED_PUBKEY=$(cat "$PUBKEY_FILE")
18+
19+
echo "Testing: mina wallet address"
20+
echo "Key file: $KEY_FILE"
21+
echo "Expected public key: $EXPECTED_PUBKEY"
22+
echo ""
23+
24+
# Run the wallet address command with password from environment variable
25+
export MINA_PRIVKEY_PASS="$PASSWORD"
26+
ACTUAL_PUBKEY=$(./target/release/mina wallet address --from "$KEY_FILE")
27+
28+
echo "Actual public key: $ACTUAL_PUBKEY"
29+
echo ""
30+
31+
# Compare the public keys
32+
if [ "$ACTUAL_PUBKEY" = "$EXPECTED_PUBKEY" ]; then
33+
echo "✓ Test passed: Public key matches expected value"
34+
exit 0
35+
else
36+
echo "✗ Test failed: Public key mismatch"
37+
echo " Expected: $EXPECTED_PUBKEY"
38+
echo " Got: $ACTUAL_PUBKEY"
39+
exit 1
40+
fi
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# Test the wallet balance command with --from key file (text format)
4+
5+
# Check for required environment variables before enabling strict mode
6+
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
7+
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
8+
echo "Please set it to a GraphQL endpoint URL, e.g.:"
9+
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
10+
exit 1
11+
fi
12+
13+
set -euo pipefail
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
17+
cd "$REPO_ROOT"
18+
19+
# Define test parameters
20+
KEY_FILE="tests/files/accounts/test-block-producer"
21+
PASSWORD="test-password"
22+
23+
echo "Test: Verify --from option works with key file (text format)"
24+
export MINA_PRIVKEY_PASS="$PASSWORD"
25+
BALANCE_OUTPUT=$(./target/release/mina wallet balance --from "$KEY_FILE" --endpoint "$MINA_NODE_ENDPOINT" --format text 2>&1 || true)
26+
27+
echo "Balance command output:"
28+
echo "$BALANCE_OUTPUT"
29+
echo ""
30+
31+
# Command should execute and produce text format output
32+
if echo "$BALANCE_OUTPUT" | grep -q "Account:"; then
33+
echo "✓ Command executed successfully with text format"
34+
# Verify text format structure
35+
if echo "$BALANCE_OUTPUT" | grep -q "Balance:" && \
36+
echo "$BALANCE_OUTPUT" | grep -q "Total:" && \
37+
echo "$BALANCE_OUTPUT" | grep -q "Nonce:"; then
38+
echo "✓ Text output has expected structure"
39+
exit 0
40+
else
41+
echo "✗ Test failed: Text output missing expected fields"
42+
exit 1
43+
fi
44+
elif echo "$BALANCE_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
45+
# Command executed but got an error (e.g., account doesn't exist)
46+
echo "✓ Command executed (account may not exist on network)"
47+
exit 0
48+
else
49+
echo "✗ Test failed: Unexpected output"
50+
exit 1
51+
fi
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
# Test the wallet balance command JSON format output structure
4+
5+
# Check for required environment variables before enabling strict mode
6+
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
7+
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
8+
echo "Please set it to a GraphQL endpoint URL, e.g.:"
9+
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
10+
exit 1
11+
fi
12+
13+
set -euo pipefail
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
17+
cd "$REPO_ROOT"
18+
19+
# Check for jq
20+
if ! command -v jq &> /dev/null; then
21+
echo "Error: jq is required but not installed"
22+
echo "Install with: apt-get install jq (Ubuntu/Debian) or brew install jq (macOS)"
23+
exit 1
24+
fi
25+
26+
echo "Test: Verify JSON format output structure"
27+
JSON_OUTPUT=$(./target/release/mina wallet balance \
28+
--address "B62qkiqPXFDayJV8JutYvjerERZ35EKrdmdcXh3j1rDUHRs1bJkFFcX" \
29+
--endpoint "$MINA_NODE_ENDPOINT" \
30+
--format json 2>&1 || true)
31+
32+
echo "JSON format output:"
33+
echo "$JSON_OUTPUT"
34+
echo ""
35+
36+
# Use jq to validate JSON structure
37+
if echo "$JSON_OUTPUT" | jq empty 2>/dev/null; then
38+
# Check for proper JSON structure using jq
39+
if echo "$JSON_OUTPUT" | jq -e '.account and .balance.total and .balance.total_mina and .nonce' > /dev/null 2>&1; then
40+
echo "✓ Test passed: JSON format has proper structure"
41+
exit 0
42+
else
43+
echo "✗ Test failed: JSON structure is incomplete"
44+
echo "Expected fields: account, balance.total, balance.total_mina, nonce"
45+
exit 1
46+
fi
47+
elif echo "$JSON_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
48+
echo "✗ Test failed: Could not retrieve account balance"
49+
echo "The test account may not exist on the network"
50+
exit 1
51+
else
52+
echo "✗ Test failed: Output is not valid JSON"
53+
exit 1
54+
fi
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# Test the wallet balance command with --address (JSON format)
4+
5+
# Check for required environment variables before enabling strict mode
6+
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
7+
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
8+
echo "Please set it to a GraphQL endpoint URL, e.g.:"
9+
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
10+
exit 1
11+
fi
12+
13+
set -euo pipefail
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
17+
cd "$REPO_ROOT"
18+
19+
# Check for jq
20+
if ! command -v jq &> /dev/null; then
21+
echo "Error: jq is required but not installed"
22+
echo "Install with: apt-get install jq (Ubuntu/Debian) or brew install jq (macOS)"
23+
exit 1
24+
fi
25+
26+
# Define test parameters
27+
PUBLIC_KEY=$(cat "tests/files/accounts/test-block-producer.pub")
28+
29+
echo "Test: Verify --address option works with public key (JSON format)"
30+
BALANCE_JSON=$(./target/release/mina wallet balance --address "$PUBLIC_KEY" --endpoint "$MINA_NODE_ENDPOINT" --format json 2>&1 || true)
31+
32+
echo "Balance command output:"
33+
echo "$BALANCE_JSON"
34+
echo ""
35+
36+
# Command should execute and produce JSON output
37+
# Try to parse as JSON using jq
38+
if echo "$BALANCE_JSON" | jq empty 2>/dev/null; then
39+
echo "✓ Command executed successfully with JSON format"
40+
# Verify JSON format structure using jq
41+
if echo "$BALANCE_JSON" | jq -e '.account and .balance and .nonce' > /dev/null 2>&1; then
42+
echo "✓ JSON output has expected structure"
43+
exit 0
44+
else
45+
echo "✗ Test failed: JSON output missing expected fields"
46+
exit 1
47+
fi
48+
elif echo "$BALANCE_JSON" | grep -qE "(Error:|\\[ERROR\\])"; then
49+
# Command executed but got an error (e.g., account doesn't exist)
50+
echo "✓ Command executed (account may not exist on network)"
51+
exit 0
52+
else
53+
echo "✗ Test failed: Unexpected output"
54+
exit 1
55+
fi
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Test the wallet balance command error when no account specified
4+
5+
# Check for required environment variables before enabling strict mode
6+
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
7+
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
8+
echo "Please set it to a GraphQL endpoint URL, e.g.:"
9+
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
10+
exit 1
11+
fi
12+
13+
set -euo pipefail
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
17+
cd "$REPO_ROOT"
18+
19+
echo "Test: Verify error when no account specified"
20+
ERROR_OUTPUT=$(./target/release/mina wallet balance --endpoint "$MINA_NODE_ENDPOINT" 2>&1 || true)
21+
22+
echo "Command output:"
23+
echo "$ERROR_OUTPUT"
24+
echo ""
25+
26+
if echo "$ERROR_OUTPUT" | grep -qE "(\\[ERROR\\].*Either --address or --from must be provided|Either --address or --from must be provided)"; then
27+
echo "✓ Test passed: Proper error when no account specified"
28+
exit 0
29+
else
30+
echo "✗ Test failed: Expected error message not found"
31+
exit 1
32+
fi
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Test the wallet balance command text format output structure
4+
5+
# Check for required environment variables before enabling strict mode
6+
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
7+
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
8+
echo "Please set it to a GraphQL endpoint URL, e.g.:"
9+
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
10+
exit 1
11+
fi
12+
13+
set -euo pipefail
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
17+
cd "$REPO_ROOT"
18+
19+
echo "Test: Verify text format output structure"
20+
TEXT_OUTPUT=$(./target/release/mina wallet balance \
21+
--address "B62qkiqPXFDayJV8JutYvjerERZ35EKrdmdcXh3j1rDUHRs1bJkFFcX" \
22+
--endpoint "$MINA_NODE_ENDPOINT" \
23+
--format text 2>&1 || true)
24+
25+
echo "Text format output:"
26+
echo "$TEXT_OUTPUT"
27+
echo ""
28+
29+
if echo "$TEXT_OUTPUT" | grep -q "Account:"; then
30+
# Check for proper text format structure
31+
if echo "$TEXT_OUTPUT" | grep -qE "Balance:" && \
32+
echo "$TEXT_OUTPUT" | grep -qE "Total:.*MINA" && \
33+
echo "$TEXT_OUTPUT" | grep -qE "Nonce:"; then
34+
echo "✓ Test passed: Text format has proper structure"
35+
exit 0
36+
else
37+
echo "✗ Test failed: Text output structure is incomplete"
38+
echo "Expected fields: Balance:, Total: X MINA, Nonce:"
39+
exit 1
40+
fi
41+
elif echo "$TEXT_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
42+
echo "✗ Test failed: Could not retrieve account balance"
43+
echo "The test account may not exist on the network"
44+
exit 1
45+
else
46+
echo "✗ Test failed: Unexpected output format"
47+
exit 1
48+
fi
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Test the wallet generate command
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+
TEST_KEY="/tmp/mina-test-generated-key-$$"
13+
TEST_PUBKEY="${TEST_KEY}.pub"
14+
PASSWORD="test-password-e2e"
15+
16+
# Cleanup function
17+
cleanup() {
18+
# shellcheck disable=SC2317
19+
rm -f "$TEST_KEY" "$TEST_PUBKEY"
20+
}
21+
22+
# Set trap to cleanup on exit
23+
trap cleanup EXIT
24+
25+
echo "Testing: mina wallet generate"
26+
echo "Output file: $TEST_KEY"
27+
echo ""
28+
29+
# Generate a new key
30+
export MINA_PRIVKEY_PASS="$PASSWORD"
31+
GENERATE_OUTPUT=$(./target/release/mina wallet generate --output "$TEST_KEY")
32+
33+
echo "Generate command output:"
34+
echo "$GENERATE_OUTPUT"
35+
echo ""
36+
37+
# Verify the private key file was created
38+
if [ ! -f "$TEST_KEY" ]; then
39+
echo "✗ Test failed: Private key file was not created"
40+
exit 1
41+
fi
42+
echo "✓ Private key file created"
43+
44+
# Verify the public key file was created
45+
if [ ! -f "$TEST_PUBKEY" ]; then
46+
echo "✗ Test failed: Public key file was not created"
47+
exit 1
48+
fi
49+
echo "✓ Public key file created"
50+
51+
# Extract the public key from the generate output
52+
EXPECTED_PUBKEY=$(cat "$TEST_PUBKEY")
53+
echo "Expected public key: $EXPECTED_PUBKEY"
54+
55+
# Verify the key can be read back with wallet address command
56+
ACTUAL_PUBKEY=$(./target/release/mina wallet address --from "$TEST_KEY")
57+
echo "Actual public key: $ACTUAL_PUBKEY"
58+
echo ""
59+
60+
# Compare the public keys
61+
if [ "$ACTUAL_PUBKEY" = "$EXPECTED_PUBKEY" ]; then
62+
echo "✓ Test passed: Generated key can be read back successfully"
63+
exit 0
64+
else
65+
echo "✗ Test failed: Public key mismatch"
66+
echo " Expected: $EXPECTED_PUBKEY"
67+
echo " Got: $ACTUAL_PUBKEY"
68+
exit 1
69+
fi

0 commit comments

Comments
 (0)