Monorepo for Aesthetic.Computer aesthetic.computer
at main 217 lines 7.9 kB view raw
1#!/usr/bin/env fish 2# 3# Keeps Contract Test Suite 4# 5# Tests all contract entrypoints on Ghostnet 6# 7 8set -l CONTRACT_ADDRESS (cat contract-address.txt 2>/dev/null) 9 10if test -z "$CONTRACT_ADDRESS" 11 echo "❌ No contract address found. Run: node keeps.mjs deploy" 12 exit 1 13end 14 15echo "╔══════════════════════════════════════════════════════════════╗" 16echo "║ 🧪 Keeps Contract Test Suite ║" 17echo "╚══════════════════════════════════════════════════════════════╝" 18echo "" 19echo "📍 Contract: $CONTRACT_ADDRESS" 20echo "🌐 Network: Ghostnet" 21echo "" 22 23set -l PASSED 0 24set -l FAILED 0 25set -l SKIPPED 0 26 27function test_step 28 set -l name $argv[1] 29 echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" 30 echo "🔬 Test: $name" 31 echo "" 32end 33 34function pass 35 set -l msg $argv[1] 36 echo "✅ PASS: $msg" 37 echo "" 38 set -g PASSED (math $PASSED + 1) 39end 40 41function fail 42 set -l msg $argv[1] 43 echo "❌ FAIL: $msg" 44 echo "" 45 set -g FAILED (math $FAILED + 1) 46end 47 48function skip 49 set -l msg $argv[1] 50 echo "⚠️ SKIP: $msg" 51 echo "" 52 set -g SKIPPED (math $SKIPPED + 1) 53end 54 55# ============================================================================ 56# Test 1: Contract Status 57# ============================================================================ 58test_step "Contract Status Query" 59 60node keeps.mjs status > /tmp/test-status.txt 2>&1 61if test $status -eq 0 62 pass "Contract status retrieved successfully" 63 cat /tmp/test-status.txt | grep -E "Next Token ID|Administrator|Balance" 64else 65 fail "Failed to get contract status" 66end 67 68# ============================================================================ 69# Test 2: Check Balance 70# ============================================================================ 71test_step "Wallet Balance Query" 72 73node keeps.mjs balance > /tmp/test-balance.txt 2>&1 74if test $status -eq 0 75 pass "Wallet balance retrieved" 76 cat /tmp/test-balance.txt | grep -E "Balance|Address" 77else 78 fail "Failed to get wallet balance" 79end 80 81# ============================================================================ 82# Test 3: List Tokens 83# ============================================================================ 84test_step "Token Listing Query" 85 86node keeps.mjs tokens > /tmp/test-tokens.txt 2>&1 87if test $status -eq 0 88 pass "Token list retrieved" 89 cat /tmp/test-tokens.txt | tail -5 90else 91 fail "Failed to list tokens" 92end 93 94# ============================================================================ 95# Test 4: Check if piece exists (should be available) 96# ============================================================================ 97test_step "Check Piece Availability (test-piece-99)" 98 99# We'll add this command to keeps.mjs 100echo "⚠️ SKIP: check-piece command not yet implemented" 101set -g SKIPPED (math $SKIPPED + 1) 102echo "" 103 104# ============================================================================ 105# Test 5: Mint a test token 106# ============================================================================ 107test_step "Mint Test Token (keep)" 108 109echo "🚀 Attempting to mint test token..." 110echo "" 111 112# Create a simple test piece 113set -l TEST_PIECE "test-"(date +%s) 114echo " Piece name: $TEST_PIECE" 115echo "" 116 117# Note: This will prompt for confirmation in interactive mode 118echo " Run manually to test: node keeps.mjs mint $TEST_PIECE" 119skip "Minting requires manual confirmation (would take 30+ seconds)" 120 121# ============================================================================ 122# Test 6: Fee Management (expected to fail on current contract) 123# ============================================================================ 124test_step "Check Current Fee" 125 126node keeps.mjs fee > /tmp/test-fee.txt 2>&1 127if test $status -eq 0 128 pass "Fee retrieved" 129 cat /tmp/test-fee.txt | grep -E "Fee|Contract" 130else 131 echo "Expected to fail on contract without fee entrypoints" 132 skip "Fee system not available (requires recompile)" 133end 134 135# ============================================================================ 136# Test 7: Set Fee (expected to fail) 137# ============================================================================ 138test_step "Set Keep Fee (admin operation)" 139 140skip "Requires fee entrypoints (contract needs recompile)" 141 142# ============================================================================ 143# Test 8: Withdraw Fees (expected to fail) 144# ============================================================================ 145test_step "Withdraw Fees (admin operation)" 146 147skip "Requires fee entrypoints (contract needs recompile)" 148 149# ============================================================================ 150# Test 9: Query via TzKT API 151# ============================================================================ 152test_step "TzKT API - Contract Storage" 153 154curl -s "https://api.ghostnet.tzkt.io/v1/contracts/$CONTRACT_ADDRESS/storage" > /tmp/test-tzkt-storage.json 2>&1 155if test $status -eq 0 156 pass "TzKT storage query successful" 157 cat /tmp/test-tzkt-storage.json | jq -r '. | "Next ID: \(.next_token_id), Admin: \(.administrator)"' 158else 159 fail "TzKT API query failed" 160end 161 162# ============================================================================ 163# Test 10: Query Contract Entrypoints 164# ============================================================================ 165test_step "TzKT API - Contract Entrypoints" 166 167curl -s "https://api.ghostnet.tzkt.io/v1/contracts/$CONTRACT_ADDRESS/entrypoints" > /tmp/test-tzkt-entrypoints.json 2>&1 168if test $status -eq 0 169 pass "Entrypoints retrieved" 170 echo " Available entrypoints:" 171 cat /tmp/test-tzkt-entrypoints.json | jq -r '.[].name' | sed 's/^/ - /' 172 echo "" 173 174 # Check for fee entrypoints 175 if cat /tmp/test-tzkt-entrypoints.json | jq -e '.[] | select(.name == "set_keep_fee")' > /dev/null 176 pass "Fee entrypoints present ✓" 177 else 178 echo " ⚠️ Fee entrypoints missing (expected for current contract)" 179 end 180else 181 fail "Failed to fetch entrypoints" 182end 183 184# ============================================================================ 185# Test 11: Query Token Metadata (if any tokens exist) 186# ============================================================================ 187test_step "Token Metadata Query" 188 189curl -s "https://api.ghostnet.tzkt.io/v1/tokens?contract=$CONTRACT_ADDRESS&limit=1" > /tmp/test-tokens.json 2>&1 190set -l token_count (cat /tmp/test-tokens.json | jq 'length') 191 192if test $token_count -gt 0 193 pass "Token metadata retrieved (found $token_count tokens)" 194 cat /tmp/test-tokens.json | jq -r '.[0] | "Token #\(.tokenId): \(.metadata.name // "unnamed")"' 195else 196 skip "No tokens minted yet" 197end 198 199# ============================================================================ 200# Summary 201# ============================================================================ 202echo "" 203echo "╔══════════════════════════════════════════════════════════════╗" 204echo "║ 📊 Test Summary ║" 205echo "╚══════════════════════════════════════════════════════════════╝" 206echo "" 207echo " ✅ Passed: $PASSED" 208echo " ❌ Failed: $FAILED" 209echo " ⚠️ Skipped: $SKIPPED" 210echo "" 211 212if test $FAILED -eq 0 213 echo " 🎉 All non-skipped tests passed!" 214else 215 echo " ⚠️ Some tests failed" 216 exit 1 217end