import { ethers } from "ethers";
const CONTRACT_ADDRESS = "0x6a4420f696c9ba6997f41dddc15b938b54aa009a";
const BASE_RPC = "https://mainnet.base.org";
const ABI = [
"function getProject(uint256 projectId) external view returns (tuple(address funder, address agent, uint256 totalAmount, uint256 releasedAmount, uint256 currentMilestone, uint256 totalMilestones, uint8 status))",
"function projectCount() external view returns (uint256)"
];
async function test() {
console.log("🧪 Testing AgentFund MCP Tools...\n");
const provider = new ethers.JsonRpcProvider(BASE_RPC);
const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, provider);
// Test 1: Get project count
console.log("1️⃣ Testing agentfund_get_stats...");
const count = await contract.projectCount();
console.log(` ✅ Total projects: ${count.toString()}\n`);
// Test 2: Get project details (if any exist)
if (Number(count) > 0) {
console.log("2️⃣ Testing agentfund_get_project...");
const project = await contract.getProject(1);
console.log(` ✅ Project #1:`);
console.log(` Funder: ${project[0]}`);
console.log(` Agent: ${project[1]}`);
console.log(` Total: ${ethers.formatEther(project[2])} ETH`);
console.log(` Status: ${["Active", "Completed", "Cancelled"][Number(project[6])]}\n`);
}
// Test 3: Generate fundraise proposal
console.log("3️⃣ Testing agentfund_create_fundraise...");
const agentAddress = "0xc2212629Ef3b17C755682b9490711a39468dA6bB";
const milestones = ["0.01", "0.02"];
const milestoneWei = milestones.map(a => ethers.parseEther(a));
const totalEth = milestones.reduce((a, b) => parseFloat(a) + parseFloat(b), 0);
console.log(` ✅ Generated proposal:`);
console.log(` Agent: ${agentAddress}`);
console.log(` Total: ${totalEth} ETH`);
console.log(` Milestones: ${milestones.length}\n`);
// Test 4: Find projects for an address
console.log("4️⃣ Testing agentfund_find_my_projects...");
const myProjects = [];
const searchLimit = Math.min(Number(count), 10);
for (let i = 1; i <= searchLimit; i++) {
try {
const p = await contract.getProject(i);
if (p[1].toLowerCase() === agentAddress.toLowerCase()) {
myProjects.push(i);
}
} catch (e) {}
}
console.log(` ✅ Found ${myProjects.length} projects for ${agentAddress.slice(0, 10)}...\n`);
console.log("✅ All tests passed! MCP server is functional.\n");
console.log("📝 Tools available:");
console.log(" • agentfund_get_stats - Platform statistics");
console.log(" • agentfund_get_project - Get project details");
console.log(" • agentfund_find_my_projects - Find your projects");
console.log(" • agentfund_create_fundraise - Create funding proposal");
console.log(" • agentfund_check_milestone - Check milestone status");
console.log(" • agentfund_generate_release_request - Request payment");
}
test().catch(console.error);