test_aptos_contract
Evaluate Aptos Move contracts by specifying the contract path, optionally testing a specific function and its arguments. This tool integrates with the Aptos CLI for effective contract validation.
Instructions
Test an Aptos Move contract using the Aptos CLI.
Args:
contract_path: Path to the contract directory or file
function_name: Optional function to test specifically
args: Optional list of arguments for the function
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| args | No | ||
| contract_path | Yes | ||
| function_name | No |
Input Schema (JSON Schema)
{
"properties": {
"args": {
"default": null,
"items": {},
"title": "Args",
"type": "array"
},
"contract_path": {
"title": "Contract Path",
"type": "string"
},
"function_name": {
"default": "",
"title": "Function Name",
"type": "string"
}
},
"required": [
"contract_path"
],
"title": "test_aptos_contractArguments",
"type": "object"
}
Implementation Reference
- aptos_mcp_server.py:952-987 (handler)The main handler function for the 'test_aptos_contract' tool. It is decorated with @mcp.tool(), serving as both the implementation and registration. The function tests an Aptos Move contract using the Aptos CLI by running 'aptos move test', handling paths, optional function filtering, and returning test results or errors.@mcp.tool() async def test_aptos_contract(contract_path: str, function_name: str = "", args: list = None) -> str: """ Test an Aptos Move contract using the Aptos CLI. Args: contract_path: Path to the contract directory or file function_name: Optional function to test specifically args: Optional list of arguments for the function """ contract_path = os.path.expanduser(contract_path) # Expand ~ in paths if not os.path.exists(contract_path): return f"Contract path not found: {contract_path}" try: cmd = ["aptos", "move", "test"] if os.path.isfile(contract_path): cmd.extend(["--path", os.path.dirname(contract_path)]) if function_name: cmd.extend(["--filter", function_name]) else: cmd.extend(["--path", contract_path]) if function_name: cmd.extend(["--filter", function_name]) result = subprocess.run(cmd, capture_output=True, text=True) if result.returncode == 0: return f"Tests passed successfully:\n\n{result.stdout}" else: return f"Tests failed:\n\n{result.stderr}" except Exception as e: return f"Error testing contract: {str(e)}"