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

new Testing environment #890

Merged
merged 112 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
f0fe865
Creating source from nef
shargon Feb 9, 2024
93a5646
change to LF
shargon Feb 9, 2024
2e3655f
Fix _deploy in NEP17 template
shargon Feb 9, 2024
fd567ea
change comment
shargon Feb 9, 2024
6d897da
Replace SetOwner
shargon Feb 9, 2024
a8a28cb
Remove extra file
shargon Feb 9, 2024
e8271e7
Remove _deploy and _initialize
shargon Feb 9, 2024
3b62d7a
change to _
shargon Feb 9, 2024
3de58e0
Add args
shargon Feb 9, 2024
165cac4
Separate safe from unsafe
shargon Feb 9, 2024
10a363f
abstract Class
shargon Feb 9, 2024
633cbe1
format
shargon Feb 9, 2024
e37d638
Merge branch 'master' into core-create-artifacts
shargon Feb 9, 2024
e4a71d8
Only source
shargon Feb 10, 2024
6e03cd5
Merge branch 'core-create-artifacts' of https://github.com/neo-projec…
shargon Feb 10, 2024
eb93622
Generate events
shargon Feb 10, 2024
a3f9aed
Mock
shargon Feb 10, 2024
fcc0bf9
starting native artifacts
shargon Feb 10, 2024
bae9a32
CryptoLib
shargon Feb 10, 2024
1cdf706
Rename project to avoid old one
shargon Feb 10, 2024
3b1fc80
LF
shargon Feb 10, 2024
16fd895
Escape name
shargon Feb 10, 2024
5ab3cd4
Avoid generation native artifacts
shargon Feb 10, 2024
2ecd121
TestNativeContracts
shargon Feb 10, 2024
45c3e29
Redirect Logs and Notifications to the mocked smart contract
shargon Feb 10, 2024
e0795d7
Mock notifications
shargon Feb 10, 2024
346c412
Converts
shargon Feb 10, 2024
4ad592a
format
shargon Feb 10, 2024
b380e7a
LoadFromJson
shargon Feb 10, 2024
15f3566
Initialize native contracts
shargon Feb 10, 2024
b852249
Partially mocked
shargon Feb 10, 2024
6938ccc
Mocked with args
shargon Feb 10, 2024
d6a2202
Fix Scope
shargon Feb 10, 2024
26397a3
Found bug in MemoryStore
shargon Feb 10, 2024
70632d6
TriggerType.Application
shargon Feb 10, 2024
f00d32a
clean and fixes
shargon Feb 10, 2024
20b9ae2
format
shargon Feb 10, 2024
b62efb4
Remove utartifact
shargon Feb 10, 2024
c552403
Fix FromHash
shargon Feb 10, 2024
9189bd2
Clean code
shargon Feb 10, 2024
f0bca7f
Store current script in transaction
shargon Feb 10, 2024
3d8a9a6
Allow to set the Gas
shargon Feb 10, 2024
c3d3c61
Clean code
shargon Feb 10, 2024
1d5b0ed
Reduce changes
shargon Feb 10, 2024
4a45434
Change Snapshot
shargon Feb 11, 2024
dea0149
Change to Artifact to ArtifactExtensions
shargon Feb 11, 2024
7bc66de
Clean code
shargon Feb 11, 2024
49f78e1
Merge branch 'master' into core-create-artifacts
shargon Feb 11, 2024
5f27b44
Merge branch 'master' into core-create-artifacts
shargon Feb 11, 2024
3c57448
Move to Extensions folder
shargon Feb 11, 2024
fdb7c54
Merge branch 'core-create-artifacts' of https://github.com/neo-projec…
shargon Feb 11, 2024
4b1e448
Fix Native initialization
shargon Feb 11, 2024
670c24d
Allow Custom mocks
shargon Feb 11, 2024
dc3d33c
Format
shargon Feb 11, 2024
6b7e35e
some vars
shargon Feb 11, 2024
37d9b2c
Add some summaries
shargon Feb 11, 2024
aff569c
Allow to mock undeployed contracts
shargon Feb 11, 2024
8324b1a
Test undeployed mocked contracts
shargon Feb 11, 2024
ca460ef
Change init native to true by default
shargon Feb 11, 2024
9af21d2
Clean using
shargon Feb 11, 2024
fea0222
Allow null in deploy
shargon Feb 11, 2024
c231475
Modify ContractManagement artifact
shargon Feb 11, 2024
67544d9
Readme
shargon Feb 11, 2024
29133bc
Fix menu
shargon Feb 11, 2024
f545e6b
Resume example using native access
shargon Feb 11, 2024
b02b1ee
Clean storage example
shargon Feb 11, 2024
04ca629
fix readme
shargon Feb 11, 2024
7e0a5c9
Fix readme
shargon Feb 11, 2024
e934820
Fix readme and move CommitteeAddress
shargon Feb 11, 2024
f0cd97d
Add event testing to readme
shargon Feb 11, 2024
98c0b44
Allow properties!
shargon Feb 11, 2024
8bd03ba
Allow properties if the method is without args and safe
shargon Feb 11, 2024
a662f37
User uppercase for first letter (conflicts with events and methods in…
shargon Feb 11, 2024
1e868e7
All events start with "On" (avoid native conflicts)
shargon Feb 11, 2024
55c73f7
Rename log event
shargon Feb 11, 2024
82899c2
Avoid re-query contract id if it was checked
shargon Feb 11, 2024
7bcec89
format
shargon Feb 11, 2024
ba125d8
Update Readme examples
shargon Feb 11, 2024
c6863f1
Improve Mock.OnSysCall
shargon Feb 11, 2024
5b2e819
Some small changes
shargon Feb 11, 2024
b556d43
Generate compiled artifacts (.dll)
shargon Feb 11, 2024
e6569b7
LF
shargon Feb 11, 2024
3db2778
is 3 not 2
shargon Feb 11, 2024
46c525d
Update src/Neo.SmartContract.Testing/README.md
shargon Feb 11, 2024
e118630
Update src/Neo.SmartContract.Testing/NativeArtifacts.cs
shargon Feb 11, 2024
f141fe9
Sign by default with Validators and committee
shargon Feb 12, 2024
e96c8ac
Merge branch 'core-create-artifacts' of https://github.com/neo-projec…
shargon Feb 12, 2024
ef2e0f0
Rename to ValidatorsAddress
shargon Feb 12, 2024
57f9edc
Allow to get address without initialize
shargon Feb 12, 2024
4e8a7d4
Clean comment
shargon Feb 12, 2024
5576c9a
Allow deploy with byte[]
shargon Feb 12, 2024
bb548b2
allow null on deploy and update
shargon Feb 12, 2024
23207a6
Update readme
shargon Feb 12, 2024
ef96fda
Fix static event
shargon Feb 12, 2024
b4a1082
Allow native init notifications
shargon Feb 12, 2024
728098b
Belane's feedback
shargon Feb 12, 2024
b6f1066
Nullable when ends in object argument
shargon Feb 12, 2024
5ba45f6
Speedup InvokeOnNotify
shargon Feb 12, 2024
fa74be2
Increase protected words
shargon Feb 12, 2024
6908a11
Allow Export and Import contract storage
shargon Feb 12, 2024
6512e95
format
shargon Feb 12, 2024
ab1ea20
Fix summary
shargon Feb 12, 2024
03d5756
Known limitations
shargon Feb 12, 2024
d962fa8
Fix comments
shargon Feb 12, 2024
8431bca
Fix "Value" string
shargon Feb 12, 2024
04cc1ef
devcontainer ready for testing PR
vncoelho Feb 12, 2024
5941f26
Revert "devcontainer ready for testing PR"
shargon Feb 12, 2024
44b5cdd
Add more ways to set the signers easy
shargon Feb 12, 2024
caaa9ff
Avoid base64 strings
shargon Feb 12, 2024
9228cca
cschuchardt88's feedback
shargon Feb 12, 2024
7d4a8ed
Change to IList when Array
shargon Feb 12, 2024
b9b48e6
Clean Check initialized
shargon Feb 13, 2024
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
34 changes: 24 additions & 10 deletions neo-devpack-dotnet.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.452
# Visual Studio Version 17
VisualStudioVersion = 17.7.34003.232
shargon marked this conversation as resolved.
Show resolved Hide resolved
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.SmartContract.Framework", "src\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj", "{C30B5859-D4B9-46E8-A797-6B0A1B49B590}"
EndProject
Expand All @@ -16,22 +16,26 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{79389FC0-C62
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D5266066-0AFD-44D5-A83E-2F73668A63C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Compiler.CSharp.TestContracts", "tests\Neo.Compiler.CSharp.TestContracts\Neo.Compiler.CSharp.TestContracts.csproj", "{8D67DD5A-D683-481F-915E-98683EA38791}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Compiler.CSharp.TestContracts", "tests\Neo.Compiler.CSharp.TestContracts\Neo.Compiler.CSharp.TestContracts.csproj", "{8D67DD5A-D683-481F-915E-98683EA38791}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.SmartContract.Framework.TestContracts", "tests\Neo.SmartContract.Framework.TestContracts\Neo.SmartContract.Framework.TestContracts.csproj", "{A372F1D6-51FF-472C-9508-FDAF7E6FEB13}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.SmartContract.Framework.TestContracts", "tests\Neo.SmartContract.Framework.TestContracts\Neo.SmartContract.Framework.TestContracts.csproj", "{A372F1D6-51FF-472C-9508-FDAF7E6FEB13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.SmartContract.TestEngine", "tests\Neo.SmartContract.TestEngine\Neo.SmartContract.TestEngine.csproj", "{D0153204-6AEF-4D94-B0E1-8124C38C91D4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.SmartContract.TestEngine", "tests\Neo.SmartContract.TestEngine\Neo.SmartContract.TestEngine.csproj", "{D0153204-6AEF-4D94-B0E1-8124C38C91D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo", "neo\src\Neo\Neo.csproj", "{73223FBD-C562-4FA0-9722-C7F1C382A9DE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo", "neo\src\Neo\Neo.csproj", "{73223FBD-C562-4FA0-9722-C7F1C382A9DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Cryptography.BLS12_381", "neo\src\Neo.Cryptography.BLS12_381\Neo.Cryptography.BLS12_381.csproj", "{D541BCE9-65BC-475B-94E5-19B6BFFF2B8E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Cryptography.BLS12_381", "neo\src\Neo.Cryptography.BLS12_381\Neo.Cryptography.BLS12_381.csproj", "{D541BCE9-65BC-475B-94E5-19B6BFFF2B8E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Json", "neo\src\Neo.Json\Neo.Json.csproj", "{35A34EBD-F2BF-4D83-A096-D5F007B12732}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Json", "neo\src\Neo.Json\Neo.Json.csproj", "{35A34EBD-F2BF-4D83-A096-D5F007B12732}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.VM", "neo\src\Neo.VM\Neo.VM.csproj", "{D6D53889-5A10-46A4-BA66-E78B56EC1881}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.VM", "neo\src\Neo.VM\Neo.VM.csproj", "{D6D53889-5A10-46A4-BA66-E78B56EC1881}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependency", "Dependency", "{49D5873D-7B38-48A5-B853-85146F032091}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.SmartContract.Testing", "src\Neo.SmartContract.Testing\Neo.SmartContract.Testing.csproj", "{648DCE6F-A0BA-4032-951B-20CF5BBFD998}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.SmartContract.Testing.UnitTests", "tests\Neo.SmartContract.Testing.UnitTests\Neo.SmartContract.Testing.UnitTests.csproj", "{B772B8A9-9362-4C6F-A6D3-2A4138439B2C}"
EndProject
shargon marked this conversation as resolved.
Show resolved Hide resolved
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -86,6 +90,14 @@ Global
{D6D53889-5A10-46A4-BA66-E78B56EC1881}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6D53889-5A10-46A4-BA66-E78B56EC1881}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6D53889-5A10-46A4-BA66-E78B56EC1881}.Release|Any CPU.Build.0 = Release|Any CPU
{648DCE6F-A0BA-4032-951B-20CF5BBFD998}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{648DCE6F-A0BA-4032-951B-20CF5BBFD998}.Debug|Any CPU.Build.0 = Debug|Any CPU
{648DCE6F-A0BA-4032-951B-20CF5BBFD998}.Release|Any CPU.ActiveCfg = Release|Any CPU
{648DCE6F-A0BA-4032-951B-20CF5BBFD998}.Release|Any CPU.Build.0 = Release|Any CPU
{B772B8A9-9362-4C6F-A6D3-2A4138439B2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B772B8A9-9362-4C6F-A6D3-2A4138439B2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B772B8A9-9362-4C6F-A6D3-2A4138439B2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B772B8A9-9362-4C6F-A6D3-2A4138439B2C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -101,8 +113,10 @@ Global
{D0153204-6AEF-4D94-B0E1-8124C38C91D4} = {D5266066-0AFD-44D5-A83E-2F73668A63C8}
{73223FBD-C562-4FA0-9722-C7F1C382A9DE} = {49D5873D-7B38-48A5-B853-85146F032091}
{D541BCE9-65BC-475B-94E5-19B6BFFF2B8E} = {49D5873D-7B38-48A5-B853-85146F032091}
{D6D53889-5A10-46A4-BA66-E78B56EC1881} = {49D5873D-7B38-48A5-B853-85146F032091}
{35A34EBD-F2BF-4D83-A096-D5F007B12732} = {49D5873D-7B38-48A5-B853-85146F032091}
{D6D53889-5A10-46A4-BA66-E78B56EC1881} = {49D5873D-7B38-48A5-B853-85146F032091}
{648DCE6F-A0BA-4032-951B-20CF5BBFD998} = {79389FC0-C621-4CEA-AD2B-6074C32E7BCA}
{B772B8A9-9362-4C6F-A6D3-2A4138439B2C} = {D5266066-0AFD-44D5-A83E-2F73668A63C8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DA935E1-C674-4364-B087-F1B511B79215}
Expand Down
1 change: 1 addition & 0 deletions src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ProjectReference Include="..\Neo.SmartContract.Framework\Neo.SmartContract.Framework.csproj">
<Aliases>scfx</Aliases>
</ProjectReference>
<ProjectReference Include="..\Neo.SmartContract.Testing\Neo.SmartContract.Testing.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Neo.Compiler.CSharp/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Options
public bool Checked { get; set; }
public bool Debug { get; set; }
public bool Assembly { get; set; }
public bool NoArtifacts { get; set; }
public bool NoOptimize { get; set; }
public bool NoInline { get; set; }
public byte AddressVersion { get; set; }
Expand Down
63 changes: 63 additions & 0 deletions src/Neo.Compiler.CSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
// modifications are permitted.

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using Neo.IO;
using Neo.Json;
using Neo.Optimizer;
using Neo.SmartContract;
using Neo.SmartContract.Manifest;
using Neo.SmartContract.Testing.Extensions;
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.NamingConventionBinder;
using System.ComponentModel;
using System.IO;
using System.IO.Compression;
using System.Linq;
Expand All @@ -38,6 +42,7 @@ static int Main(string[] args)
new Option<bool>("--checked", "Indicates whether to check for overflow and underflow."),
new Option<bool>(new[] { "-d", "--debug" }, "Indicates whether to generate debugging information."),
new Option<bool>("--assembly", "Indicates whether to generate assembly."),
new Option<bool>("--no-artifacts", "Instruct the compiler not to generate artifacts."),
new Option<bool>("--no-optimize", "Instruct the compiler not to optimize the code."),
new Option<bool>("--no-inline", "Instruct the compiler not to insert inline code."),
new Option<byte>("--address-version", () => ProtocolSettings.Default.AddressVersion, "Indicates the address version used by the compiler.")
Expand Down Expand Up @@ -176,6 +181,64 @@ private static int ProcessOutputs(Options options, string folder, CompilationCon
return 1;
}
Console.WriteLine($"Created {path}");
if (!options.NoArtifacts)
{
var artifact = manifest.Abi.GetArtifactsSource(baseName);
path = Path.Combine(outputFolder, $"{baseName}.artifacts.cs");
File.WriteAllText(path, artifact);
Console.WriteLine($"Created {path}");

try
{
// Try to compile the artifacts into a dll

string coreDir = Path.GetDirectoryName(typeof(object).Assembly.Location)!;

var syntaxTree = CSharpSyntaxTree.ParseText(artifact);
var references = new MetadataReference[]
{
MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.dll")),
MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Runtime.InteropServices.dll")),
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(DisplayNameAttribute).Assembly.Location),
MetadataReference.CreateFromFile(typeof(System.Numerics.BigInteger).Assembly.Location),
MetadataReference.CreateFromFile(typeof(UInt160).Assembly.Location),
MetadataReference.CreateFromFile(typeof(SmartContract.Testing.SmartContract).Assembly.Location)
};

var compilation = CSharpCompilation.Create(baseName, new[] { syntaxTree }, references,
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

using var ms = new MemoryStream();
EmitResult result = compilation.Emit(ms);

if (!result.Success)
{
var failures = result.Diagnostics.Where(diagnostic =>
diagnostic.IsWarningAsError ||
diagnostic.Severity == DiagnosticSeverity.Error);

foreach (var diagnostic in failures)
{
Console.Error.WriteLine("{0}: {1}", diagnostic.Id, diagnostic.GetMessage());
}
}
else
{
ms.Seek(0, SeekOrigin.Begin);

// Write dll

path = Path.Combine(outputFolder, $"{baseName}.artifacts.dll");
File.WriteAllBytes(path, ms.ToArray());
Console.WriteLine($"Created {path}");
}
}
catch
{
Console.Error.WriteLine("Artifacts compilation error.");
}
}
if (options.Debug)
{
path = Path.Combine(outputFolder, $"{baseName}.nefdbgnfo");
Expand Down
17 changes: 17 additions & 0 deletions src/Neo.SmartContract.Testing/CustomMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Reflection;

namespace Neo.SmartContract.Testing
{
internal class CustomMock
{
/// <summary>
/// Mocked contract
/// </summary>
public required SmartContract Contract { get; init; }

/// <summary>
/// Mocked method
/// </summary>
public required MethodInfo Method { get; init; }
}
}
Loading