Skip to content

Commit

Permalink
GetContractSourceCodeCoverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Jan 10, 2024
1 parent c01bc32 commit 7f78941
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Fairy.Coverage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ namespace Neo.Plugins
{
public partial class Fairy
{
/// <summary>
///
/// </summary>
/// <param name="_params"></param>
/// <returns>opcode -> coveredOrNot</returns>
/// <exception cref="ArgumentException"></exception>
[RpcMethod]
protected virtual JObject GetContractOpCodeCoverage(JArray _params)
{
Expand All @@ -18,6 +24,27 @@ protected virtual JObject GetContractOpCodeCoverage(JArray _params)
return json;
}

/// <summary>
///
/// </summary>
/// <param name="_params"></param>
/// <returns>SourceFilenameAndLineNum -> {opcode -> coveredOrNot}</returns>
[RpcMethod]
protected virtual JObject GetContractSourceCodeCoverage(JArray _params)
{
JObject opcodeCoverage = GetContractOpCodeCoverage(_params);
UInt160 scripthash = UInt160.Parse(_params[0]!.AsString());
JObject result = new();
foreach((uint opcode, SourceFilenameAndLineNum source) in contractScriptHashToAllInstructionPointerToSourceLineNum[scripthash])
{
string key = $"{source.sourceFilename}::line {source.lineNum}: {source.sourceContent}";
if (result[key] == null)
result[key] = new JObject();
result[key]![opcode.ToString()] = opcodeCoverage[opcode.ToString()];
}
return result;
}

[RpcMethod]
protected virtual JObject ClearContractOpCodeCoverage(JArray _params)
{
Expand Down

0 comments on commit 7f78941

Please sign in to comment.