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!32
  • Loading branch information
zone117x committed Oct 3, 2018
2 parents 1b776a3 + dad1a41 commit d13094d
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 84 deletions.
25 changes: 0 additions & 25 deletions .vscode/launch.json

This file was deleted.

25 changes: 0 additions & 25 deletions .vscode/tasks.json

This file was deleted.

13 changes: 9 additions & 4 deletions src/Meadow.EVM/Debugging/Tracing/ExecutionTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class ExecutionTrace
/// The last memory change count we had recorded.
/// </summary>
private ulong _lastMemoryChangeCount;
/// <summary>
/// Indicates if the last tracepoint had changed storage, so it is known to be included for the current step.
/// </summary>
private bool _lastStorageChanged;
#endregion

#region Properties
Expand All @@ -42,6 +46,7 @@ public ExecutionTrace()
Exceptions = new List<ExecutionTraceException>();
_lastContractAddress = null;
_lastMemoryChangeCount = 0;
_lastStorageChanged = false;
}
#endregion

Expand Down Expand Up @@ -69,12 +74,9 @@ public void RecordExecution(MeadowEVM evm, InstructionBase instruction, BigInteg
_lastContractAddress = deployedAddress;
_lastMemoryChangeCount = evm.ExecutionState.Memory.ChangeCount;

// Determine if our storage changed
bool storageChanged = instruction is InstructionStorageStore;

// Determine our storage we will have for this point (null if unchanged, otherwise set)
Dictionary<Memory<byte>, byte[]> storage = null;
if (contextChanged || storageChanged)
if (contextChanged || _lastStorageChanged)
{
// Obtain our storage dictionary.
var account = evm.State.GetAccount(evm.Message.To);
Expand All @@ -98,6 +100,9 @@ public void RecordExecution(MeadowEVM evm, InstructionBase instruction, BigInteg
}
}

// Determine if our storage changed this step and mark it for our next step.
_lastStorageChanged = instruction is InstructionStorageStore;

// If our context changed, we want to include code hash.
byte[] codeSegment = null;
if (contextChanged)
Expand Down
56 changes: 56 additions & 0 deletions src/Meadow.UnitTestTemplate.Test/CustomTestDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Meadow.UnitTestTemplate.Test
{

[MeadowTestClass]
public class CustomTestDescriptionWithMeadowTestClassAttribute : ContractTest
{
[TestMethod]
[Description("Custom example description")]
public async Task ExampleTestWithDescription()
{
await Task.CompletedTask;
}

[TestMethod]
[System.ComponentModel.Description("Custom example description")]
public async Task ExampleTestWithDescription2()
{
await Task.CompletedTask;
}

[DataTestMethod]
[Description("thing {0} and thing {1}")]
[DataRow("some val 1", 32465)]
[DataRow("next valll", 1111)]
public async Task ExampleDataDrivenTest(string val1, int num2)
{
await Task.CompletedTask;
}
}

[TestClass]
public class CustomTestDescriptionWithMeadowTestMethodAttributes : ContractTest
{
[MeadowTestMethod]
[Description("Custom example description")]
public async Task ExampleTestWithDescription()
{
await Task.CompletedTask;
}

[MeadowDataTestMethod]
[Description("thing {0} and thing {1}")]
[DataRow("some val 1", 32465)]
[DataRow("next valll", 1111)]
public async Task ExampleDataDrivenTest(string val1, int num2)
{
await Task.CompletedTask;
}
}
}
23 changes: 12 additions & 11 deletions src/Meadow.UnitTestTemplate/ContractTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
Expand All @@ -18,11 +17,11 @@
namespace Meadow.UnitTestTemplate
{

[TestClass]
[MeadowTestClass]
public abstract class ContractTest
{
#region Fields
private ulong _baseSnapshotID;
private ulong? _baseSnapshotID;
private static Semaphore _sequentialExecutionSemaphore = new Semaphore(1, 1);
#endregion

Expand Down Expand Up @@ -66,6 +65,7 @@ public async Task OnTestInitialize()
{
try
{

// With parallel tests, all code should execute in pairs (main vs. external for every test)
// so we need to ensure sequential execution to avoid issues with other tests running and trying
// to snapshot, execute, restore on the external node, ending up with a race condition.
Expand Down Expand Up @@ -98,7 +98,10 @@ public async Task OnTestInitialize()
InternalTestState.StartTime = DateTimeOffset.UtcNow;

// Create a snapshot to revert to when test is completed.
_baseSnapshotID = await TestServices.TestNodeClient.Snapshot();
if (!_baseSnapshotID.HasValue)
{
_baseSnapshotID = await TestServices.TestNodeClient.Snapshot();
}

// Determine what message to log
if (InternalTestState.InExternalNodeContext)
Expand Down Expand Up @@ -155,7 +158,7 @@ public async Task OnTestCleanup()
}

// Revert the node chain for the next unit test to start with a clean slate.
await TestServices.TestNodeClient.Revert(_baseSnapshotID);
await TestServices.TestNodeClient.Revert(_baseSnapshotID.Value);

// Calculate our time elapsed.
var testDuration = (InternalTestState.EndTime - InternalTestState.StartTime);
Expand All @@ -170,24 +173,21 @@ public async Task OnTestCleanup()
var testOutcome = new UnitTestResult
{
Namespace = TestContext.FullyQualifiedTestClassName,
TestName = TestContext.TestName,
TestName = InternalTestState.CustomDisplayName ?? TestContext.TestName,
Passed = TestContext.CurrentTestOutcome == UnitTestOutcome.Passed,
Duration = testDuration
};

// Add the test to our global testing result test output.
Global.UnitTestResults.Add(testOutcome);

// As this is our built in node, we put the test services back in the pool.
await Global.TestServicesPool.PutAsync(TestServices);
}

// Blank out the local test services after the test has completed.
TestServices = null;

// Set our cleanup as a success
InternalTestState.CleanupSuccess = true;

// If we are running an external node, we'll want to make tests run sequentially.
if (Global.ExternalNodeTestServices != null)
{
Expand All @@ -200,7 +200,8 @@ public async Task OnTestCleanup()
}
finally
{

// Reset test state so its not reused in another test.
InternalTestState = null;
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/Meadow.UnitTestTemplate/ITestMethodExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using ExposedObject;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Meadow.UnitTestTemplate
{
static class ITestMethodExtensions
{
public static TestContext GetTestContext(this ITestMethod testMethod)
{
// Obtain our test method options
var testMethodOptions = Exposed.From(testMethod).TestMethodOptions;

// Obtain our test context.
var testContext = Exposed.From(testMethodOptions).TestContext as TestContext;

// Return the test context
return testContext;
}
}
}
6 changes: 2 additions & 4 deletions src/Meadow.UnitTestTemplate/InternalTestState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ internal class InternalTestState
/// Indicates whether test initialization occurred without error.
/// </summary>
internal bool InitializationSuccess { get; set; }
/// <summary>
/// Indicates whether test cleanup occurred without error.
/// </summary>
internal bool CleanupSuccess { get; set; }

internal string CustomDisplayName { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions src/Meadow.UnitTestTemplate/MSTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ Action<TestResult> GetConsoleLogger()
stderrWriter.Flush();
}
foreach (var msg in testResult.Messages)
{
stdoutWriter.WriteLine($"[{msg.Category}] {msg.Text}");
stdoutWriter.Flush();
}
}
};
}
Expand Down
1 change: 1 addition & 0 deletions src/Meadow.UnitTestTemplate/Meadow.UnitTestTemplate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.UnitTestFramework.Extensions" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="15.8.0" />
<PackageReference Include="System.ComponentModel.Primitives" Version="4.3.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
</ItemGroup>

Expand Down
17 changes: 17 additions & 0 deletions src/Meadow.UnitTestTemplate/MeadowTestClassAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Meadow.UnitTestTemplate
{
public class MeadowTestClassAttribute : TestClassAttribute
{
public override TestMethodAttribute GetTestMethodAttribute(TestMethodAttribute testMethodAttribute)
{
return new MeadowTestMethodAttribute();
}

public override bool IsDefaultAttribute()
{
return base.IsDefaultAttribute();
}
}
}

0 comments on commit d13094d

Please sign in to comment.