Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request company-projects/Meadow!24
  • Loading branch information
zone117x committed Sep 29, 2018
2 parents 1344126 + 577dfd1 commit 3528e96
Show file tree
Hide file tree
Showing 24 changed files with 720 additions and 198 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,4 @@ src/pwsh_testing/GeneratedAssembly/
src/coverage/
src/report/
src/reportgenerator/
src/Meadow.VSCode.Debugger/solidity-debugger*.vsix
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Provides an intuitive framework for writing C# tests against contract deployment

<img src="/images/screenshot3.png?raw=true" width="800" />

See [Solidity Debugger](#solidity-debugger).

---

#### Solidity unit test code coverage HTML reports
Expand All @@ -51,6 +53,14 @@ Provides an intuitive framework for writing C# tests against contract deployment

---

# Solidity Debugger

[![vs marketplace](https://img.shields.io/vscode-marketplace/v/hosho.solidity-debugger.svg)](https://marketplace.visualstudio.com/items?itemName=hosho.solidity-debugger)

Solidity debugger extension for VSCode supporting beakpoints, stepping, rewinding, call stacks, local & state variable inspection.

---

# Components

| Library | Package | |
Expand All @@ -61,7 +71,6 @@ Provides an intuitive framework for writing C# tests against contract deployment
| [Meadow.CoverageReport](src/Meadow.CoverageReport) | [![nuget](https://img.shields.io/nuget/v/Meadow.CoverageReport.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.CoverageReport) | Generates HTML and JSON code coverage reports for Solidity source files. Uses execution trace data from the EVM. |
| [Meadow.UnitTestTemplate](src/Meadow.UnitTestTemplate) | [![nuget](https://img.shields.io/nuget/v/Meadow.UnitTestTemplate.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.UnitTestTemplate) | Test harness providing seamless integration between MSTest and Solidity contracts. Provides a simple workflow where Solidity source files are dropped into a unit test project and C# contract code is automatically generated. C# unit tests can easily deploy/call/transact with contracts. RPC test node servers & clients are automatically boostrapped and provided to unit tests. Code coverage reports are automatically generated after unit tests are ran. |
| [Meadow.Cli](src/Meadow.Cli) | [![nuget](https://img.shields.io/nuget/v/Meadow.Cli.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.Cli) | Tool that allows contract deployments and interaction through the command line. Solidity source files are live-compiled using a file system watcher. Can be ran against a automatically bootstrapped test RPC node or an externally configured node. Leverages PowerShell Core to a provide cross platform REPL-like environment with powerful tab-completion when interacting with contracts. |
| [Meadow.VSCode.Debugger](src/Meadow.VSCode.Debugger) | TODO.. | Solidity debugger extension for VSCode supporting beakpoints, stepping, rewinding, call stacks, local & state variable inspection. |
| [Meadow.Core](src/Meadow.Core) | [![nuget](https://img.shields.io/nuget/v/Meadow.Core.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.Core) | <ul><li>RLP and ABI encoding & decoding utils. <li>Implementations of Ethereum / solidity types such as Address, UInt256, Hash, etc. <li>BIP32, BIP39, BIP44, HD account derivation implementation. <li>Fast managed Keccak hashing. <li> ECDSA / secp256k1 utils.</ul> |
| [Meadow.JsonRpc](src/Meadow.JsonRpc) | [![nuget](https://img.shields.io/nuget/v/Meadow.JsonRpc.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.JsonRpc) | <ul><li>.NET types for the Ethereum JSON-RPC request & response data structures. <li>.NET interface for all RPC methods. <li>Serialization for JSON/hex object formats <-> Solidity/.NET types.</ul> |
| [Meadow.JsonRpc.Client](src/Meadow.JsonRpc.Client) | [![nuget](https://img.shields.io/nuget/v/Meadow.JsonRpc.Client.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.JsonRpc.Client) | JSON-RPC client implementation, supported transports: http, WebSocket, and IPC. |
Expand Down
9 changes: 1 addition & 8 deletions src/Meadow.Core/Meadow.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\WordLists\wordlist_chinese_simplified.txt" />
<EmbeddedResource Include="Resources\WordLists\wordlist_chinese_traditional.txt" />
<EmbeddedResource Include="Resources\WordLists\wordlist_english.txt" />
<EmbeddedResource Include="Resources\WordLists\wordlist_french.txt" />
<EmbeddedResource Include="Resources\WordLists\wordlist_italian.txt" />
<EmbeddedResource Include="Resources\WordLists\wordlist_japanese.txt" />
<EmbeddedResource Include="Resources\WordLists\wordlist_korean.txt" />
<EmbeddedResource Include="Resources\WordLists\wordlist_spanish.txt" />
<EmbeddedResource Include="Resources\WordLists\*.txt" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.2.5" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="1.0.6" />
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="1.0.7" />
<PackageReference Include="System.IO.Pipelines" Version="4.5.1" />
</ItemGroup>

Expand Down
10 changes: 7 additions & 3 deletions src/Meadow.DebugAdapterProxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.IO.Pipelines;
using System.Buffers.Text;
using McMaster.Extensions.CommandLineUtils.Abstractions;
using System.Collections.Generic;

namespace Meadow.DebugAdapterProxy
{
Expand Down Expand Up @@ -104,7 +105,7 @@ static async Task StartIpcProxyClient(string pipeName, CancellationToken cancell
{
// If verbose logging is enabled, setup interception streams for both the input & output of the debugger
// protocol stream.
Task verboseProxyLogTask = Task.CompletedTask;
List<Task> streamTasks = new List<Task>();
Stream proxyStreamInput = null;
Stream proxyStreamOutput = null;
if (_args.Trace)
Expand All @@ -115,9 +116,10 @@ static async Task StartIpcProxyClient(string pipeName, CancellationToken cancell
var proxyPipeOutput = new Pipe();
proxyStreamOutput = StreamConnection.GetDuplex(proxyPipeOutput.Reader, proxyPipeOutput.Writer);

verboseProxyLogTask = Task.WhenAll(
var verboseProxyLogTask = Task.WhenAll(
CreateVerboseProxyLogger("-> ", proxyPipeInput.Reader, cancellationToken),
CreateVerboseProxyLogger("<- ", proxyPipeOutput.Reader, cancellationToken));
streamTasks.Add(verboseProxyLogTask);
}

var pipeInputTask = NamedPipes.ConnectStream(stdIn, pipeClient, proxyStreamInput, cancellationToken);
Expand All @@ -131,7 +133,9 @@ static async Task StartIpcProxyClient(string pipeName, CancellationToken cancell
}
});

var completedTask = await Task.WhenAny(checkClosedTask, pipeInputTask, pipeOutputTask, verboseProxyLogTask);
streamTasks.AddRange(new[] { checkClosedTask, pipeInputTask, pipeOutputTask });

var completedTask = await Task.WhenAny(streamTasks.ToArray());

if (completedTask.IsFaulted)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Meadow.DebugAdapterServer/MeadowSolidityDebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class MeadowSolidityDebugAdapter : DebugAdapterBase

#region Events
public delegate void ExitingEventHandler(MeadowSolidityDebugAdapter sender);
public event ExitingEventHandler OnExiting;
public event ExitingEventHandler OnDebuggerDisconnect;
#endregion

#region Constructor
Expand Down Expand Up @@ -374,14 +374,14 @@ protected override void HandleDisconnectRequestAsync(IRequestResponder<Disconnec
threadStateKeyValuePair.Value.Semaphore.Release();
}

// If we have an event, invoke it
OnExiting?.Invoke(this);

// Set our response to the disconnect request.
responder.SetResponse(new DisconnectResponse());
Protocol.SendEvent(new TerminatedEvent());
Protocol.SendEvent(new ExitedEvent(0));
_terminatedTcs.TrySetResult(null);

// If we have an event, invoke it
OnDebuggerDisconnect?.Invoke(this);
}

public void SendTerminateAndExit()
Expand Down
5 changes: 5 additions & 0 deletions src/Meadow.DebugExampleTests/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "solidityMeadow",
"request": "launch",
"name": "Debug Solidity (via unit test run)"
},
{
"type": "solidityMeadow",
"request": "launch",
Expand Down
12 changes: 9 additions & 3 deletions src/Meadow.MSTest.Runner/ApplicationTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Xml;

namespace Meadow.MSTest.Runner
Expand Down Expand Up @@ -44,7 +45,7 @@ public static ApplicationTestRunner CreateFromSpecificTests(params (string Fully
return runner;
}

public static void RunAllTests(Assembly scanAssembly = null)
public static void RunAllTests(Assembly scanAssembly = null, CancellationToken cancellationToken = default)
{
var assemblies = new HashSet<Assembly>();
if (scanAssembly != null)
Expand All @@ -56,7 +57,7 @@ public static void RunAllTests(Assembly scanAssembly = null)
assemblies.Add(Assembly.GetCallingAssembly());

var applicationTestRunner = CreateFromAssemblies(assemblies.ToArray());
applicationTestRunner.RunTests();
applicationTestRunner.RunTests(cancellationToken);
}

public static void RunSpecificTests(Assembly assembly, params string[] fullyQualifiedTestNames)
Expand Down Expand Up @@ -85,7 +86,7 @@ static void RunSpecificTests(Assembly[] assemblies, string[] fullyQualifiedTestN
runner.RunTests();
}

public void RunTests()
public void RunTests(CancellationToken cancellationToken = default)
{
var runContext = new MyRunContext(_testCases);
var frameworkHandler = new MyFrameworkHandle(GetConsoleLogger());
Expand Down Expand Up @@ -116,6 +117,11 @@ public void RunTests()

dynamic testExecutor = Activator.CreateInstance(testExecutorType);

cancellationToken.Register(() =>
{
testExecutor.Cancel();
});

testExecutor.RunTests(_assemblies, runContext, frameworkHandler);

//var tDisc = new MSTestDiscoverer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
Expand Down
33 changes: 31 additions & 2 deletions src/Meadow.UnitTestTemplate/Debugging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
using System.IO.Pipes;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Meadow.UnitTestTemplate
{
public class Debugging : IDisposable
{

public static void Launch()
{
var debugSessionID = Environment.GetEnvironmentVariable("DEBUG_SESSION_ID");
Expand All @@ -36,8 +38,21 @@ public static void Launch()
debuggingInstance.InitializeDebugConnection();
debuggingInstance.SetupRpcDebuggingHook();

var cancelToken = new CancellationTokenSource();

debuggingInstance.OnDebuggerDisconnect += () =>
{
// If the C# debugger is not attached, we don't care about running the rest of the tests
// so exit program
if (!Debugger.IsAttached)
{
cancelToken.Cancel();
Environment.Exit(0);
}
};

// Run all tests (blocking)
ApplicationTestRunner.RunAllTests(Assembly.GetExecutingAssembly());
ApplicationTestRunner.RunAllTests(Assembly.GetExecutingAssembly(), cancelToken.Token);
Console.WriteLine("Tests completed");
}
}
Expand All @@ -47,12 +62,17 @@ public static void Launch()
readonly NamedPipeServerStream _pipeServer;
readonly MeadowSolidityDebugAdapter _debugAdapter;

#pragma warning disable CA1710 // Identifiers should have correct suffix
public event Action OnDebuggerDisconnect;
#pragma warning restore CA1710 // Identifiers should have correct suffix

private Debugging(string debugSessionID)
{
_debugSessionID = debugSessionID;
_pipeServer = new NamedPipeServerStream(_debugSessionID, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
_debugAdapter = new MeadowSolidityDebugAdapter();
_debugAdapter.OnExiting += TeardownRpcDebuggingHook;
_debugAdapter.OnDebuggerDisconnect += DebugAdapter_OnDebuggerDisconnect;
_debugAdapter.OnDebuggerDisconnect += TeardownRpcDebuggingHook;
}

public void InitializeDebugConnection()
Expand Down Expand Up @@ -89,8 +109,17 @@ private void TeardownRpcDebuggingHook(MeadowSolidityDebugAdapter debugAdapter)
{
// Teardown our hook by setting the target as null.
JsonRpcClient.JsonRpcExecutionAnalysis = null;


}

private void DebugAdapter_OnDebuggerDisconnect(MeadowSolidityDebugAdapter sender)
{
TeardownRpcDebuggingHook(sender);
OnDebuggerDisconnect?.Invoke();
}


public async Task RpcExecutionCallback(IJsonRpcClient client)
{
// Obtain an execution trace from our client.
Expand Down
7 changes: 7 additions & 0 deletions src/Meadow.VSCode.Debugger/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
},
{
"type": "node",
"request": "launch",
"name": "Prepare Package",
"preLaunchTask": "npm: watch",
"program": "${workspaceFolder}/out/preparePackage.js"
}
]
}
1 change: 1 addition & 0 deletions src/Meadow.VSCode.Debugger/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.vscode-test/**
out/test/**
out/**/*.map
out/preparePackage.js
src/**
tsconfig.json
tslint.json

0 comments on commit 3528e96

Please sign in to comment.