stones/scripts/moloch_dao/test_daohaus_query.py

269 lines
7.1 KiB
Python

#!/usr/bin/env python3
"""
Test script for querying the DAOhaus v2 subgraph.
This script tests different query formats and subgraph URLs to find the correct way to query
Raid Guild members from the DAOhaus subgraphs.
Usage:
python test_daohaus_query.py
"""
import requests
import json
import time
# Potential DAOhaus subgraph URLs to try
SUBGRAPH_URLS = [
# Original URL that didn't work
"https://api.thegraph.com/subgraphs/id/B4YHqrAJuQ1yD2U2tqgGXWGWJVeBrD25WRus3o9jLLBJ",
# Try the hosted service URL for DAOhaus on xDai/Gnosis Chain
"https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-xdai",
# Try the hosted service URL for DAOhaus on Mainnet
"https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus",
# Try the hosted service URL for DAOhaus v2
"https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-v2",
# Try the hosted service URL for DAOhaus v2 on xDai/Gnosis Chain
"https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-v2-xdai",
# Try the hosted service URL for DAOhaus v3
"https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-v3",
# Try the hosted service URL for DAOhaus v3 on Gnosis Chain
"https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-v3-gnosis"
]
# Raid Guild DAO address
DAO_ADDRESS = "0xfe1084bc16427e5eb7f13fc19bcd4e641f7d571f"
def print_separator():
"""Print a separator line."""
print("\n" + "=" * 80 + "\n")
def test_query(subgraph_url, query, variables=None, description=""):
"""
Test a GraphQL query against a DAOhaus subgraph.
Args:
subgraph_url: The URL of the subgraph to query
query: The GraphQL query to test
variables: Variables for the query (optional)
description: Description of the query
"""
print(f"Testing subgraph URL: {subgraph_url}")
print(f"Testing query: {description}")
print(f"Query: {query}")
if variables:
print(f"Variables: {json.dumps(variables, indent=2)}")
try:
response = requests.post(
subgraph_url,
json={"query": query, "variables": variables} if variables else {"query": query}
)
if response.status_code == 200:
data = response.json()
if "errors" in data:
print(f"GraphQL errors: {json.dumps(data['errors'], indent=2)}")
else:
print(f"Success! Response: {json.dumps(data, indent=2)}")
else:
print(f"HTTP error: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Exception: {str(e)}")
print_separator()
def test_subgraph(subgraph_url):
"""
Test a specific subgraph URL with various queries.
Args:
subgraph_url: The URL of the subgraph to test
"""
print(f"Testing subgraph URL: {subgraph_url}")
print_separator()
# Test 1: Simple query to get schema information
test_query(
subgraph_url,
"""
{
__schema {
queryType {
name
fields {
name
}
}
}
}
""",
description="Get schema information"
)
# Test 2: Simple query to get all moloches/daos
test_query(
subgraph_url,
"""
{
daos: moloches(first: 5) {
id
title
version
totalShares
totalLoot
memberCount
}
}
""",
description="Get first 5 DAOs"
)
# Test 3: Query for Raid Guild DAO with network ID 100 (Gnosis Chain)
test_query(
subgraph_url,
"""
query GetDao($daoId: String!) {
moloch(id: $daoId) {
id
title
version
totalShares
totalLoot
memberCount
}
}
""",
variables={"daoId": f"100:{DAO_ADDRESS.lower()}"},
description="Get Raid Guild DAO with network ID 100"
)
# Test 4: Query for Raid Guild DAO with network ID 0x64 (Gnosis Chain in hex)
test_query(
subgraph_url,
"""
query GetDao($daoId: String!) {
moloch(id: $daoId) {
id
title
version
totalShares
totalLoot
memberCount
}
}
""",
variables={"daoId": f"0x64:{DAO_ADDRESS.lower()}"},
description="Get Raid Guild DAO with network ID 0x64"
)
# Test 5: Query for Raid Guild DAO with just the address
test_query(
subgraph_url,
"""
query GetDao($daoId: String!) {
moloch(id: $daoId) {
id
title
version
totalShares
totalLoot
memberCount
}
}
""",
variables={"daoId": DAO_ADDRESS.lower()},
description="Get Raid Guild DAO with just the address"
)
# Test 6: Query for members with network ID 100
test_query(
subgraph_url,
"""
query GetMembers($daoAddress: String!) {
members(where: {molochAddress: $daoAddress}, first: 10) {
id
memberAddress
shares
loot
}
}
""",
variables={"daoAddress": f"100:{DAO_ADDRESS.lower()}"},
description="Get first 10 members with network ID 100"
)
# Test 7: Query for members with just the address
test_query(
subgraph_url,
"""
query GetMembers($daoAddress: String!) {
members(where: {molochAddress: $daoAddress}, first: 10) {
id
memberAddress
shares
loot
}
}
""",
variables={"daoAddress": DAO_ADDRESS.lower()},
description="Get first 10 members with just the address"
)
# Test 8: Alternative query format
test_query(
subgraph_url,
"""
{
moloches(where: {id: "0xfe1084bc16427e5eb7f13fc19bcd4e641f7d571f"}) {
id
title
members(first: 10) {
id
memberAddress
shares
loot
}
}
}
""",
description="Alternative query format with just the address"
)
# Test 9: Search for Raid Guild by name
test_query(
subgraph_url,
"""
{
moloches(where: {title_contains: "Raid"}, first: 5) {
id
title
network
totalShares
totalLoot
memberCount
}
}
""",
description="Search for Raid Guild by name"
)
def main():
"""Run the test queries on different subgraph URLs."""
print("Testing DAOhaus subgraph queries for Raid Guild DAO")
print(f"DAO Address: {DAO_ADDRESS}")
print_separator()
# Test each subgraph URL
for url in SUBGRAPH_URLS:
test_subgraph(url)
if __name__ == "__main__":
main()