File size: 1,366 Bytes
0bda635
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

import os
import sys
import random
import string
from dotenv import load_dotenv

# Add backend directory to sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

# Load env
load_dotenv(os.path.join(os.path.dirname(__file__), '..', '.env'))

from app.database import get_db

def generate_wallet():
    return "test_wallet_" + ''.join(random.choices(string.ascii_lowercase + string.digits, k=10))

def main():
    print("Testing Insert...")
    db = get_db()
    
    # Test 1: Minimal Insert (just wallet_address, assuming it exists)
    w1 = generate_wallet()
    print(f"1. Inserting {w1} (no username)...")
    try:
        res = db.table("users").insert({"wallet_address": w1}).execute()
        print("Success!", res.data)
    except Exception as e:
        with open("error.log", "w") as f:
            f.write(str(e))
        print(f"Failed: {e}")

    # Test 2: Insert with username
    w2 = generate_wallet()
    print(f"2. Inserting {w2} WITH username...")
    try:
        res = db.table("users").insert({"wallet_address": w2, "username": "testuser"}).execute()
        print("Success!", res.data)
    except Exception as e:
        with open("error_username.log", "w") as f:
            f.write(str(e))
        print(f"Failed: {e}")

if __name__ == "__main__":
    main()