simple-test.jsโข7.1 kB
#!/usr/bin/env node
/**
* Simple test to demonstrate MCP server functionality
*/
import { RootstockClient } from './build/rootstock-client.js';
import { WalletManager } from './build/wallet-manager.js';
async function testBalanceDirectly() {
console.log('๐งช Testing Rootstock Client Balance Functionality');
console.log('================================================\n');
try {
// Initialize the Rootstock client with a public RPC endpoint
const config = {
rpcUrl: 'https://eth.llamarpc.com', // Public Ethereum RPC
chainId: 1,
networkName: 'Ethereum Mainnet'
};
console.log('๐ Connecting to Ethereum network...');
const client = new RootstockClient(config);
// Test with Vitalik's well-known address
const testAddress = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
console.log(`๐ Testing balance for address: ${testAddress}`);
console.log('โณ Fetching balance...\n');
// Test native balance
const balance = await client.getBalance(testAddress);
console.log('โ
Native Balance Retrieved:');
console.log(` Address: ${testAddress}`);
console.log(` Balance: ${balance} ETH\n`);
// Test network info
console.log('๐ Getting network information...');
const networkInfo = await client.getNetworkInfo();
console.log('โ
Network Info Retrieved:');
console.log(` Network: ${networkInfo.networkName}`);
console.log(` Chain ID: ${networkInfo.chainId}`);
console.log(` Latest Block: ${networkInfo.blockNumber}`);
console.log(` Connected: ${networkInfo.isConnected}\n`);
// Test gas estimation
console.log('โฝ Testing gas estimation...');
const gasEstimate = await client.estimateGas(
'0x1234567890123456789012345678901234567890',
'0.1'
);
console.log('โ
Gas Estimate Retrieved:');
console.log(` Gas Limit: ${gasEstimate.gasLimit}`);
console.log(` Gas Price: ${gasEstimate.gasPrice} wei`);
console.log(` Estimated Cost: ${gasEstimate.estimatedCost} ETH\n`);
console.log('๐ All tests completed successfully!');
return true;
} catch (error) {
console.log('โ Test failed:', error.message);
console.log('๐ก This might be due to network connectivity or RPC limits');
return false;
}
}
async function testWalletManager() {
console.log('๐ Testing Wallet Manager Functionality');
console.log('======================================\n');
try {
const walletManager = new WalletManager();
// Test wallet creation
console.log('๐ Creating a new test wallet...');
const newWallet = walletManager.createWallet('TestWallet');
console.log('โ
Wallet Created:');
console.log(` Address: ${newWallet.address}`);
console.log(` Mnemonic: ${newWallet.mnemonic?.substring(0, 20)}...`);
console.log(` Has Private Key: ${!!newWallet.privateKey}\n`);
// Test wallet listing
console.log('๐ Listing all wallets...');
const wallets = walletManager.listWallets();
console.log('โ
Wallets Listed:');
wallets.forEach((wallet, index) => {
console.log(` ${index + 1}. ${wallet.address}`);
});
console.log();
// Test current wallet
console.log('๐ฏ Getting current wallet...');
const currentAddress = walletManager.getCurrentAddress();
console.log('โ
Current Wallet:');
console.log(` Address: ${currentAddress}\n`);
console.log('๐ Wallet manager tests completed successfully!');
return true;
} catch (error) {
console.log('โ Wallet test failed:', error.message);
return false;
}
}
async function demonstrateMCPTools() {
console.log('๐ ๏ธ MCP Tools Demonstration');
console.log('===========================\n');
const tools = [
{
name: 'create_wallet',
description: 'Create a new wallet with mnemonic phrase',
example: '{ name: "MyWallet" }'
},
{
name: 'get_balance',
description: 'Get wallet balance (native or ERC20)',
example: '{ address: "0x...", tokenAddress: "0x..." }'
},
{
name: 'send_transaction',
description: 'Send tokens to another address',
example: '{ to: "0x...", amount: "0.1" }'
},
{
name: 'get_transaction',
description: 'Get transaction details by hash',
example: '{ hash: "0x..." }'
},
{
name: 'get_network_info',
description: 'Get current network information',
example: '{}'
},
{
name: 'estimate_gas',
description: 'Estimate transaction gas costs',
example: '{ to: "0x...", value: "0.1" }'
},
{
name: 'call_contract',
description: 'Call smart contract method (read-only)',
example: '{ contractAddress: "0x...", methodName: "balanceOf" }'
}
];
console.log('๐ Available MCP Tools:\n');
tools.forEach((tool, index) => {
console.log(`${index + 1}. ${tool.name}`);
console.log(` ๐ ${tool.description}`);
console.log(` ๐ก Example: ${tool.example}\n`);
});
console.log('๐ Integration Examples:\n');
console.log('๐ฑ Claude Desktop Integration:');
console.log(`{
"mcpServers": {
"rootstock-mcp": {
"command": "node",
"args": ["build/index.js"],
"env": {
"ROOTSTOCK_RPC_URL": "https://your-rpc-url",
"ROOTSTOCK_PRIVATE_KEYS": "your_private_key"
}
}
}
}\n`);
console.log('๐ณ Docker Usage:');
console.log('docker run -e ROOTSTOCK_RPC_URL=your_url rootstock-mcp\n');
console.log('๐ Web Dashboard:');
console.log('cd dashboard && npm run dev\n');
}
async function main() {
console.log('๐ Rootstock MCP Server - Comprehensive Test Suite');
console.log('==================================================\n');
const args = process.argv.slice(2);
if (args.includes('--demo') || args.includes('-d')) {
await demonstrateMCPTools();
} else if (args.includes('--wallet') || args.includes('-w')) {
await testWalletManager();
} else if (args.includes('--balance') || args.includes('-b')) {
await testBalanceDirectly();
} else {
// Run all tests
console.log('๐ฏ Running all tests...\n');
const walletTest = await testWalletManager();
console.log('โ'.repeat(50) + '\n');
const balanceTest = await testBalanceDirectly();
console.log('โ'.repeat(50) + '\n');
await demonstrateMCPTools();
console.log('๐ Test Summary:');
console.log(` Wallet Manager: ${walletTest ? 'โ
PASSED' : 'โ FAILED'}`);
console.log(` Balance Check: ${balanceTest ? 'โ
PASSED' : 'โ FAILED'}`);
console.log(` Tools Demo: โ
COMPLETED\n`);
}
console.log('๐ Test suite completed!');
console.log('\n๐ก Usage options:');
console.log(' node simple-test.js --balance # Test balance functionality');
console.log(' node simple-test.js --wallet # Test wallet management');
console.log(' node simple-test.js --demo # Show MCP tools demo');
console.log(' node simple-test.js # Run all tests');
}
main().catch(console.error);