Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ut: fix HF_Echidna unit tests #3646

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/Neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,42 @@ public record ProtocolSettings

public static ProtocolSettings Custom { get; set; }

/// <summary>
/// Searches for a file in the given path. If not found, checks in the executable directory.
/// </summary>
/// <param name="fileName">The name of the file to search for.</param>
/// <param name="path">The primary path to search in.</param>
/// <returns>Full path of the file if found, null otherwise.</returns>
public static string FindFile(string fileName, string path)
{

// Check if the given path is relative
if (!Path.IsPathRooted(path))
{
// Combine with the executable directory if relative
var executablePath = AppDomain.CurrentDomain.BaseDirectory;
path = Path.Combine(executablePath, path);
}

// Check if file exists in the specified (resolved) path
var fullPath = Path.Combine(path, fileName);
if (File.Exists(fullPath))
{
return fullPath;
}

// Check if file exists in the executable directory
var executableDir = AppContext.BaseDirectory;
fullPath = Path.Combine(executableDir, fileName);
if (File.Exists(fullPath))
{
return fullPath;
}

// File not found in either location
return null;
}

/// <summary>
/// Loads the <see cref="ProtocolSettings"/> from the specified stream.
/// </summary>
Expand All @@ -143,7 +179,9 @@ public static ProtocolSettings Load(Stream stream)
/// <returns>The loaded <see cref="ProtocolSettings"/>.</returns>
public static ProtocolSettings Load(string path)
{
if (!File.Exists(path))
path = FindFile(path, Environment.CurrentDirectory);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My primary concern here is that this code should be compatible with the old behaviour of neo-cli binary for production usage (default config.json file from the neo-cli binary dir will be used). From what I see, it's OK, but we'd better recheck.


if (path is null)
{
return Default;
}
Expand Down
Loading