Skip to content

Commit

Permalink
ut: fix HF_Echidna unit tests (#3646)
Browse files Browse the repository at this point in the history
* Fix UT

* Update src/Neo/ProtocolSettings.cs

Co-authored-by: nan01ab <[email protected]>

* Update src/Neo/ProtocolSettings.cs

Co-authored-by: nan01ab <[email protected]>

* Update src/Neo/ProtocolSettings.cs

Co-authored-by: Christopher Schuchardt <[email protected]>

---------

Co-authored-by: Jimmy <[email protected]>
Co-authored-by: nan01ab <[email protected]>
Co-authored-by: Christopher Schuchardt <[email protected]>
  • Loading branch information
4 people authored Dec 31, 2024
1 parent 8470de5 commit 93fc37b
Showing 1 changed file with 39 additions and 1 deletion.
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);

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

0 comments on commit 93fc37b

Please sign in to comment.