Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/scripts/wallet/test-address.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -euo pipefail

# Test the wallet address command with encrypted key file

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"

# Define test parameters
KEY_FILE="tests/files/accounts/test-block-producer"
PUBKEY_FILE="tests/files/accounts/test-block-producer.pub"
PASSWORD="test-password"

# Read expected public key
EXPECTED_PUBKEY=$(cat "$PUBKEY_FILE")

echo "Testing: mina wallet address"
echo "Key file: $KEY_FILE"
echo "Expected public key: $EXPECTED_PUBKEY"
echo ""

# Run the wallet address command with password from environment variable
export MINA_PRIVKEY_PASS="$PASSWORD"
ACTUAL_PUBKEY=$(./target/release/mina wallet address --from "$KEY_FILE")

echo "Actual public key: $ACTUAL_PUBKEY"
echo ""

# Compare the public keys
if [ "$ACTUAL_PUBKEY" = "$EXPECTED_PUBKEY" ]; then
echo "✓ Test passed: Public key matches expected value"
exit 0
else
echo "✗ Test failed: Public key mismatch"
echo " Expected: $EXPECTED_PUBKEY"
echo " Got: $ACTUAL_PUBKEY"
exit 1
fi
51 changes: 51 additions & 0 deletions .github/scripts/wallet/test-balance-from-key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Test the wallet balance command with --from key file (text format)

# Check for required environment variables before enabling strict mode
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
echo "Please set it to a GraphQL endpoint URL, e.g.:"
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
exit 1
fi

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"

# Define test parameters
KEY_FILE="tests/files/accounts/test-block-producer"
PASSWORD="test-password"

echo "Test: Verify --from option works with key file (text format)"
export MINA_PRIVKEY_PASS="$PASSWORD"
BALANCE_OUTPUT=$(./target/release/mina wallet balance --from "$KEY_FILE" --endpoint "$MINA_NODE_ENDPOINT" --format text 2>&1 || true)

echo "Balance command output:"
echo "$BALANCE_OUTPUT"
echo ""

# Command should execute and produce text format output
if echo "$BALANCE_OUTPUT" | grep -q "Account:"; then
echo "✓ Command executed successfully with text format"
# Verify text format structure
if echo "$BALANCE_OUTPUT" | grep -q "Balance:" && \
echo "$BALANCE_OUTPUT" | grep -q "Total:" && \
echo "$BALANCE_OUTPUT" | grep -q "Nonce:"; then
echo "✓ Text output has expected structure"
exit 0
else
echo "✗ Test failed: Text output missing expected fields"
exit 1
fi
elif echo "$BALANCE_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
# Command executed but got an error (e.g., account doesn't exist)
echo "✓ Command executed (account may not exist on network)"
exit 0
else
echo "✗ Test failed: Unexpected output"
exit 1
fi
54 changes: 54 additions & 0 deletions .github/scripts/wallet/test-balance-json-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Test the wallet balance command JSON format output structure

# Check for required environment variables before enabling strict mode
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
echo "Please set it to a GraphQL endpoint URL, e.g.:"
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
exit 1
fi

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"

# Check for jq
if ! command -v jq &> /dev/null; then
echo "Error: jq is required but not installed"
echo "Install with: apt-get install jq (Ubuntu/Debian) or brew install jq (macOS)"
exit 1
fi

echo "Test: Verify JSON format output structure"
JSON_OUTPUT=$(./target/release/mina wallet balance \
--address "B62qkiqPXFDayJV8JutYvjerERZ35EKrdmdcXh3j1rDUHRs1bJkFFcX" \
--endpoint "$MINA_NODE_ENDPOINT" \
--format json 2>&1 || true)

echo "JSON format output:"
echo "$JSON_OUTPUT"
echo ""

# Use jq to validate JSON structure
if echo "$JSON_OUTPUT" | jq empty 2>/dev/null; then
# Check for proper JSON structure using jq
if echo "$JSON_OUTPUT" | jq -e '.account and .balance.total and .balance.total_mina and .nonce' > /dev/null 2>&1; then
echo "✓ Test passed: JSON format has proper structure"
exit 0
else
echo "✗ Test failed: JSON structure is incomplete"
echo "Expected fields: account, balance.total, balance.total_mina, nonce"
exit 1
fi
elif echo "$JSON_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
echo "✗ Test failed: Could not retrieve account balance"
echo "The test account may not exist on the network"
exit 1
else
echo "✗ Test failed: Output is not valid JSON"
exit 1
fi
55 changes: 55 additions & 0 deletions .github/scripts/wallet/test-balance-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Test the wallet balance command with --address (JSON format)

# Check for required environment variables before enabling strict mode
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
echo "Please set it to a GraphQL endpoint URL, e.g.:"
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
exit 1
fi

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"

# Check for jq
if ! command -v jq &> /dev/null; then
echo "Error: jq is required but not installed"
echo "Install with: apt-get install jq (Ubuntu/Debian) or brew install jq (macOS)"
exit 1
fi

# Define test parameters
PUBLIC_KEY=$(cat "tests/files/accounts/test-block-producer.pub")

echo "Test: Verify --address option works with public key (JSON format)"
BALANCE_JSON=$(./target/release/mina wallet balance --address "$PUBLIC_KEY" --endpoint "$MINA_NODE_ENDPOINT" --format json 2>&1 || true)

echo "Balance command output:"
echo "$BALANCE_JSON"
echo ""

# Command should execute and produce JSON output
# Try to parse as JSON using jq
if echo "$BALANCE_JSON" | jq empty 2>/dev/null; then
echo "✓ Command executed successfully with JSON format"
# Verify JSON format structure using jq
if echo "$BALANCE_JSON" | jq -e '.account and .balance and .nonce' > /dev/null 2>&1; then
echo "✓ JSON output has expected structure"
exit 0
else
echo "✗ Test failed: JSON output missing expected fields"
exit 1
fi
elif echo "$BALANCE_JSON" | grep -qE "(Error:|\\[ERROR\\])"; then
# Command executed but got an error (e.g., account doesn't exist)
echo "✓ Command executed (account may not exist on network)"
exit 0
else
echo "✗ Test failed: Unexpected output"
exit 1
fi
32 changes: 32 additions & 0 deletions .github/scripts/wallet/test-balance-no-account.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Test the wallet balance command error when no account specified

# Check for required environment variables before enabling strict mode
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
echo "Please set it to a GraphQL endpoint URL, e.g.:"
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
exit 1
fi

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"

echo "Test: Verify error when no account specified"
ERROR_OUTPUT=$(./target/release/mina wallet balance --endpoint "$MINA_NODE_ENDPOINT" 2>&1 || true)

echo "Command output:"
echo "$ERROR_OUTPUT"
echo ""

if echo "$ERROR_OUTPUT" | grep -qE "(\\[ERROR\\].*Either --address or --from must be provided|Either --address or --from must be provided)"; then
echo "✓ Test passed: Proper error when no account specified"
exit 0
else
echo "✗ Test failed: Expected error message not found"
exit 1
fi
48 changes: 48 additions & 0 deletions .github/scripts/wallet/test-balance-text-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Test the wallet balance command text format output structure

# Check for required environment variables before enabling strict mode
if [ -z "${MINA_NODE_ENDPOINT:-}" ]; then
echo "Error: MINA_NODE_ENDPOINT environment variable is not set"
echo "Please set it to a GraphQL endpoint URL, e.g.:"
echo " export MINA_NODE_ENDPOINT=http://mina-rust-plain-1.gcp.o1test.net/graphql"
exit 1
fi

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"

echo "Test: Verify text format output structure"
TEXT_OUTPUT=$(./target/release/mina wallet balance \
--address "B62qkiqPXFDayJV8JutYvjerERZ35EKrdmdcXh3j1rDUHRs1bJkFFcX" \
--endpoint "$MINA_NODE_ENDPOINT" \
--format text 2>&1 || true)

echo "Text format output:"
echo "$TEXT_OUTPUT"
echo ""

if echo "$TEXT_OUTPUT" | grep -q "Account:"; then
# Check for proper text format structure
if echo "$TEXT_OUTPUT" | grep -qE "Balance:" && \
echo "$TEXT_OUTPUT" | grep -qE "Total:.*MINA" && \
echo "$TEXT_OUTPUT" | grep -qE "Nonce:"; then
echo "✓ Test passed: Text format has proper structure"
exit 0
else
echo "✗ Test failed: Text output structure is incomplete"
echo "Expected fields: Balance:, Total: X MINA, Nonce:"
exit 1
fi
elif echo "$TEXT_OUTPUT" | grep -qE "(Error:|\\[ERROR\\])"; then
echo "✗ Test failed: Could not retrieve account balance"
echo "The test account may not exist on the network"
exit 1
else
echo "✗ Test failed: Unexpected output format"
exit 1
fi
69 changes: 69 additions & 0 deletions .github/scripts/wallet/test-generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

set -euo pipefail

# Test the wallet generate command

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"

# Define test parameters
TEST_KEY="/tmp/mina-test-generated-key-$$"
TEST_PUBKEY="${TEST_KEY}.pub"
PASSWORD="test-password-e2e"

# Cleanup function
cleanup() {
# shellcheck disable=SC2317
rm -f "$TEST_KEY" "$TEST_PUBKEY"
}

# Set trap to cleanup on exit
trap cleanup EXIT

echo "Testing: mina wallet generate"
echo "Output file: $TEST_KEY"
echo ""

# Generate a new key
export MINA_PRIVKEY_PASS="$PASSWORD"
GENERATE_OUTPUT=$(./target/release/mina wallet generate --output "$TEST_KEY")

echo "Generate command output:"
echo "$GENERATE_OUTPUT"
echo ""

# Verify the private key file was created
if [ ! -f "$TEST_KEY" ]; then
echo "✗ Test failed: Private key file was not created"
exit 1
fi
echo "✓ Private key file created"

# Verify the public key file was created
if [ ! -f "$TEST_PUBKEY" ]; then
echo "✗ Test failed: Public key file was not created"
exit 1
fi
echo "✓ Public key file created"

# Extract the public key from the generate output
EXPECTED_PUBKEY=$(cat "$TEST_PUBKEY")
echo "Expected public key: $EXPECTED_PUBKEY"

# Verify the key can be read back with wallet address command
ACTUAL_PUBKEY=$(./target/release/mina wallet address --from "$TEST_KEY")
echo "Actual public key: $ACTUAL_PUBKEY"
echo ""

# Compare the public keys
if [ "$ACTUAL_PUBKEY" = "$EXPECTED_PUBKEY" ]; then
echo "✓ Test passed: Generated key can be read back successfully"
exit 0
else
echo "✗ Test failed: Public key mismatch"
echo " Expected: $EXPECTED_PUBKEY"
echo " Got: $ACTUAL_PUBKEY"
exit 1
fi
Loading
Loading