diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs index 38d1d715fc..dae5943b78 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs @@ -298,10 +298,8 @@ public void TestGenerateNativeContractApi() markdownTables[(contract.Id, contract.Name)] = GenMarkdownTable(contractName, contractMethods); } - var currentDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent; - Assert.AreEqual(currentDir.Name, "neo"); // neo/bin/tests/Neo.UnitTests/net9.0 - - var outputPath = Path.Combine(currentDir.FullName, "docs", "native-contracts-api.md"); + var docsDirectory = LocateDocsDirectory(new DirectoryInfo(Directory.GetCurrentDirectory())); + var outputPath = Path.Combine(docsDirectory.FullName, "native-contracts-api.md"); using (var writer = new StreamWriter(outputPath)) { writer.WriteLine(""" @@ -336,6 +334,17 @@ 3. A native contract method may have different behaviors in different hardforks. Assert.IsTrue(File.Exists(outputPath), $"Generated file should exist at {outputPath}"); } + private static DirectoryInfo LocateDocsDirectory(DirectoryInfo start) + { + for (var current = start; current is not null; current = current.Parent) + { + var candidate = new DirectoryInfo(Path.Combine(current.FullName, "docs")); + if (candidate.Exists) + return candidate; + } + throw new DirectoryNotFoundException($"Unable to locate 'docs' directory starting from '{start.FullName}'."); + } + private static string GenMarkdownTable(string contractName, List methods) { var table = new System.Text.StringBuilder();