|
| 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