diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index af1c3a64f..64d8d519d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: dotnet format --no-restore --verify-no-changes --verbosity diagnostic - name: Build Neo.Compiler.CSharp run: dotnet build ./src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj - - name: Build Neo.SmartContract.Template and generate artifacts + - name: Build Neo.SmartContract.Template and test templates run: | dotnet pack ./src/Neo.SmartContract.Template/Neo.SmartContract.Template.csproj dotnet new install ./src/Neo.SmartContract.Template/bin/Debug/Neo.SmartContract.Template.*.nupkg @@ -41,9 +41,9 @@ jobs: dotnet add ./src/Neo.SmartContract.Template/bin/Debug/ownable/Ownable.csproj reference ./src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj dotnet remove ./src/Neo.SmartContract.Template/bin/Debug/oracle/OracleRequest.csproj package Neo.SmartContract.Framework dotnet add ./src/Neo.SmartContract.Template/bin/Debug/oracle/OracleRequest.csproj reference ./src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj - dotnet ./src/Neo.Compiler.CSharp/bin/Debug/net7.0/nccs.dll ./src/Neo.SmartContract.Template/bin/Debug/nep17/Nep17Contract.csproj -o ./tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Artifacts/ --generate-artifacts source --debug - dotnet ./src/Neo.Compiler.CSharp/bin/Debug/net7.0/nccs.dll ./src/Neo.SmartContract.Template/bin/Debug/ownable/Ownable.csproj -o ./tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/Artifacts/ --generate-artifacts source --debug - dotnet ./src/Neo.Compiler.CSharp/bin/Debug/net7.0/nccs.dll ./src/Neo.SmartContract.Template/bin/Debug/oracle/OracleRequest.csproj -o ./tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/Artifacts/ --generate-artifacts source --debug + dotnet ./src/Neo.Compiler.CSharp/bin/Debug/net7.0/nccs.dll ./src/Neo.SmartContract.Template/bin/Debug/nep17/Nep17Contract.csproj -o ./tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Artifacts/ + dotnet ./src/Neo.Compiler.CSharp/bin/Debug/net7.0/nccs.dll ./src/Neo.SmartContract.Template/bin/Debug/ownable/Ownable.csproj -o ./tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/Artifacts/ + dotnet ./src/Neo.Compiler.CSharp/bin/Debug/net7.0/nccs.dll ./src/Neo.SmartContract.Template/bin/Debug/oracle/OracleRequest.csproj -o ./tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/Artifacts/ - name: Build Solution run: dotnet build ./neo-devpack-dotnet.sln - name: Add package coverlet.msbuild diff --git a/src/Neo.Compiler.CSharp/CompilationContext.cs b/src/Neo.Compiler.CSharp/CompilationContext.cs index 0d166c8bf..c3b58ed13 100644 --- a/src/Neo.Compiler.CSharp/CompilationContext.cs +++ b/src/Neo.Compiler.CSharp/CompilationContext.cs @@ -36,7 +36,7 @@ public class CompilationContext { private readonly CompilationEngine _engine; readonly INamedTypeSymbol _targetContract; - internal Options Options => _engine.Options; + internal CompilationOptions Options => _engine.Options; private string? _displayName, _className; private readonly List _diagnostics = new(); private readonly HashSet _supportedStandards = new(); diff --git a/src/Neo.Compiler.CSharp/CompilationEngine.cs b/src/Neo.Compiler.CSharp/CompilationEngine.cs index fa9e42227..c5c49bd09 100644 --- a/src/Neo.Compiler.CSharp/CompilationEngine.cs +++ b/src/Neo.Compiler.CSharp/CompilationEngine.cs @@ -28,7 +28,7 @@ namespace Neo.Compiler public class CompilationEngine { internal Compilation? Compilation; - internal Options Options { get; private set; } + internal CompilationOptions Options { get; private set; } private static readonly MetadataReference[] CommonReferences; private static readonly Dictionary MetaReferences = new(); internal readonly Dictionary Contexts = new(SymbolEqualityComparer.Default); @@ -46,7 +46,7 @@ static CompilationEngine() }; } - public CompilationEngine(Options options) + public CompilationEngine(CompilationOptions options) { Options = options; } @@ -59,11 +59,24 @@ public List Compile(IEnumerable sourceFiles, IEnumer return CompileProjectContracts(Compilation); } - public List CompileSources(params string[] sourceFiles) + public List CompileSources(params string[] sourceFiles) => CompileSources(null, sourceFiles); + + public List CompileSources((string packageName, string packageVersion) package, params string[] sourceFiles) + { + return CompileSources(new[] { package }, sourceFiles); + } + + public List CompileSources(IEnumerable<(string packageName, string packageVersion)>? packages = null, params string[] sourceFiles) { // Generate a dummy csproj - var version = typeof(scfx.Neo.SmartContract.Framework.SmartContract).Assembly.GetName().Version!.ToString(); + var packageGroup = packages is null ? "" : +$@" + + {(packages is null ? "" : string.Join(Environment.NewLine, packages.Select(u => $" ")))} + +"; + var csproj = $@" @@ -83,9 +96,7 @@ public List CompileSources(params string[] sourceFiles) {string.Join(Environment.NewLine, sourceFiles.Select(u => $""))} - - - + {packageGroup} "; @@ -94,7 +105,10 @@ public List CompileSources(params string[] sourceFiles) var path = Path.GetTempFileName(); File.WriteAllText(path, csproj); - try { return CompileProject(path); } + try + { + return CompileProject(path); + } catch { throw; } finally { File.Delete(path); } } @@ -138,14 +152,13 @@ private List CompileProjectContracts(Compilation compilation if (classDependencies.Count == 0) throw new FormatException("No valid neo SmartContract found. Please make sure your contract is subclass of SmartContract and is not abstract."); // Check contract dependencies, make sure there is no cycle in the dependency graph var sortedClasses = TopologicalSort(classDependencies); - sortedClasses.ForEach(c => - { - var context = new CompilationContext(this, c); - context.Compile(); - // Process the target contract add this compilation context - this.Contexts.Add(c, context); - }); + { + var context = new CompilationContext(this, c); + context.Compile(); + // Process the target contract add this compilation context + Contexts.Add(c, context); + }); return Contexts.Select(p => p.Value).ToList(); } @@ -216,23 +229,31 @@ public Compilation GetCompilation(string csproj) Process.Start(new ProcessStartInfo { FileName = "dotnet", - Arguments = $"restore \"{csproj}\"", + Arguments = $"restore \"{csproj}\" --source \"https://www.myget.org/F/neo/api/v3/index.json\"", WorkingDirectory = folder })!.WaitForExit(); - // Get sources + // Parse csproj XDocument document = XDocument.Load(csproj); - var remove = document.Root!.Elements("ItemGroup").Elements("Compile").Attributes("Remove").Select(p => p.Value).ToArray(); - var obj = Path.Combine(folder, "obj"); - var binSc = Path.Combine(Path.Combine(folder, "bin"), "sc"); - var sourceFiles = - remove.Contains("*.cs") ? new HashSet(StringComparer.OrdinalIgnoreCase) : - Directory.EnumerateFiles(folder, "*.cs", SearchOption.AllDirectories) - .Where(p => !p.StartsWith(obj) && !p.StartsWith(binSc)) - .GroupBy(Path.GetFileName) - .Select(g => g.First()) - .ToHashSet(StringComparer.OrdinalIgnoreCase); + var remove = document.Root!.Elements("ItemGroup").Elements("Compile").Attributes("Remove") + .Select(p => p.Value.Contains("*") ? p.Value : Path.GetFullPath(p.Value)).ToArray(); + var sourceFiles = new HashSet(StringComparer.OrdinalIgnoreCase); + + if (!remove.Contains("*.cs")) + { + var obj = Path.Combine(folder, "obj"); + var binSc = Path.Combine(Path.Combine(folder, "bin"), "sc"); + foreach (var entry in Directory.EnumerateFiles(folder, "*.cs", SearchOption.AllDirectories) + .Where(p => !p.StartsWith(obj) && !p.StartsWith(binSc)) + .Select(u => u)) + //.GroupBy(Path.GetFileName) + //.Select(g => g.First())) + { + if (!remove.Contains(entry)) sourceFiles.Add(entry); + } + } + sourceFiles.UnionWith(document.Root!.Elements("ItemGroup").Elements("Compile").Attributes("Include").Select(p => Path.GetFullPath(p.Value, folder))); var assetsPath = Path.Combine(folder, "obj", "project.assets.json"); var assets = (JObject)JToken.Parse(File.ReadAllBytes(assetsPath))!; @@ -240,14 +261,14 @@ public Compilation GetCompilation(string csproj) CSharpCompilationOptions compilationOptions = new(OutputKind.DynamicallyLinkedLibrary, deterministic: true, nullableContextOptions: Options.Nullable); foreach (var (name, package) in ((JObject)assets["targets"]![0]!).Properties) { - MetadataReference? reference = GetReference(name, (JObject)package!, assets, folder, Options, compilationOptions); + MetadataReference? reference = GetReference(name, (JObject)package!, assets, folder, compilationOptions); if (reference is not null) references.Add(reference); } IEnumerable syntaxTrees = sourceFiles.OrderBy(p => p).Select(p => CSharpSyntaxTree.ParseText(File.ReadAllText(p), options: Options.GetParseOptions(), path: p)); return CSharpCompilation.Create(assets["project"]!["restore"]!["projectName"]!.GetString(), syntaxTrees, references, compilationOptions); } - private MetadataReference? GetReference(string name, JObject package, JObject assets, string folder, Options options, CSharpCompilationOptions compilationOptions) + private MetadataReference? GetReference(string name, JObject package, JObject assets, string folder, CSharpCompilationOptions compilationOptions) { string assemblyName = Path.GetDirectoryName(name)!; if (!MetaReferences.TryGetValue(assemblyName, out var reference)) diff --git a/src/Neo.Compiler.CSharp/CompilationOptions.cs b/src/Neo.Compiler.CSharp/CompilationOptions.cs new file mode 100644 index 000000000..39cfc6690 --- /dev/null +++ b/src/Neo.Compiler.CSharp/CompilationOptions.cs @@ -0,0 +1,39 @@ +// Copyright (C) 2015-2023 The Neo Project. +// +// The Neo.Compiler.CSharp is free software distributed under the MIT +// software license, see the accompanying file LICENSE in the main directory +// of the project or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using System.Collections.Generic; + +namespace Neo.Compiler +{ + public class CompilationOptions + { + public NullableContextOptions Nullable { get; set; } + public bool Debug { get; set; } + public bool NoOptimize { get; set; } + public bool Checked { get; set; } + public bool NoInline { get; set; } + public byte AddressVersion { get; set; } + public string? BaseName { get; set; } + + private CSharpParseOptions? parseOptions = null; + public CSharpParseOptions GetParseOptions() + { + if (parseOptions is null) + { + List preprocessorSymbols = new(); + if (Debug) preprocessorSymbols.Add("DEBUG"); + parseOptions = new CSharpParseOptions(preprocessorSymbols: preprocessorSymbols); + } + return parseOptions; + } + } +} diff --git a/src/Neo.Compiler.CSharp/Helper.cs b/src/Neo.Compiler.CSharp/Helper.cs index a437fc90f..929735bfb 100644 --- a/src/Neo.Compiler.CSharp/Helper.cs +++ b/src/Neo.Compiler.CSharp/Helper.cs @@ -79,10 +79,13 @@ public static ContractParameterType GetContractParameterType(this ITypeSymbol ty case "string": return ContractParameterType.String; case "byte[]": return ContractParameterType.ByteArray; case "object": return ContractParameterType.Any; - case "Neo.Cryptography.ECC.ECPoint": return ContractParameterType.PublicKey; + case "Neo.Cryptography.ECC.ECPoint": // Old Neo.SmartContract.Framework + case "Neo.SmartContract.Framework.ECPoint": return ContractParameterType.PublicKey; case "Neo.SmartContract.Framework.ByteString": return ContractParameterType.ByteArray; - case "Neo.UInt160": return ContractParameterType.Hash160; - case "Neo.UInt256": return ContractParameterType.Hash256; + case "Neo.UInt160": // Old Neo.SmartContract.Framework + case "Neo.SmartContract.Framework.UInt160": return ContractParameterType.Hash160; + case "Neo.UInt256": // Old Neo.SmartContract.Framework + case "Neo.SmartContract.Framework.UInt256": return ContractParameterType.Hash256; case "System.Numerics.BigInteger": return ContractParameterType.Integer; } if (type.Name == "Map") return ContractParameterType.Map; diff --git a/src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs b/src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs index 2b185ca15..89ae863de 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/Expression/Expression.cs @@ -181,7 +181,7 @@ private void ConvertObjectToString(SemanticModel model, ExpressionSyntax express Call(NativeContract.StdLib.Hash, "itoa", 1, true); break; case "string": - case "Neo.Cryptography.ECC.ECPoint": + case "Neo.SmartContract.Framework.ECPoint": case "Neo.SmartContract.Framework.ByteString": case "Neo.SmartContract.Framework.UInt160": case "Neo.SmartContract.Framework.UInt256": diff --git a/src/Neo.Compiler.CSharp/Options.cs b/src/Neo.Compiler.CSharp/Options.cs index 83a79c608..8a649c78c 100644 --- a/src/Neo.Compiler.CSharp/Options.cs +++ b/src/Neo.Compiler.CSharp/Options.cs @@ -8,13 +8,9 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using System.Collections.Generic; - namespace Neo.Compiler { - public class Options + public class Options : CompilationOptions { public enum GenerateArtifactsKind { @@ -25,26 +21,7 @@ public enum GenerateArtifactsKind } public string? Output { get; set; } - public string? BaseName { get; set; } - public NullableContextOptions Nullable { get; set; } - public bool Checked { get; set; } - public bool Debug { get; set; } public bool Assembly { get; set; } - public GenerateArtifactsKind GenerateArtifacts { get; set; } = GenerateArtifactsKind.Source; - public bool NoOptimize { get; set; } - public bool NoInline { get; set; } - public byte AddressVersion { get; set; } - - private CSharpParseOptions? parseOptions = null; - public CSharpParseOptions GetParseOptions() - { - if (parseOptions is null) - { - List preprocessorSymbols = new(); - if (Debug) preprocessorSymbols.Add("DEBUG"); - parseOptions = new CSharpParseOptions(preprocessorSymbols: preprocessorSymbols); - } - return parseOptions; - } + public GenerateArtifactsKind GenerateArtifacts { get; set; } = GenerateArtifactsKind.None; } } diff --git a/src/Neo.Compiler.CSharp/Program.cs b/src/Neo.Compiler.CSharp/Program.cs index c20f0fbeb..645aaa871 100644 --- a/src/Neo.Compiler.CSharp/Program.cs +++ b/src/Neo.Compiler.CSharp/Program.cs @@ -133,7 +133,7 @@ private static int ProcessCsproj(Options options, string path) private static int ProcessSources(Options options, string folder, string[] sourceFiles) { - return ProcessOutputs(options, folder, new CompilationEngine(options).CompileSources(sourceFiles)); + return ProcessOutputs(options, folder, new CompilationEngine(options).CompileSources(null, sourceFiles)); } private static int ProcessOutputs(Options options, string folder, List contexts) @@ -212,7 +212,7 @@ private static int ProcessOutput(Options options, string folder, CompilationCont if (options.GenerateArtifacts != Options.GenerateArtifactsKind.None) { - var artifact = manifest.GetArtifactsSource(baseName, nef, debugInfo); + var artifact = manifest.GetArtifactsSource(baseName, nef); if (options.GenerateArtifacts == Options.GenerateArtifactsKind.All || options.GenerateArtifacts == Options.GenerateArtifactsKind.Source) { diff --git a/src/Neo.SmartContract.Framework/ContractParameterType.cs b/src/Neo.SmartContract.Framework/ContractParameterType.cs index 2c444242f..b7e48b9b0 100644 --- a/src/Neo.SmartContract.Framework/ContractParameterType.cs +++ b/src/Neo.SmartContract.Framework/ContractParameterType.cs @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -namespace Neo.SmartContract +namespace Neo.SmartContract.Framework { public enum ContractParameterType : byte { diff --git a/src/Neo.SmartContract.Framework/ECPoint.cs b/src/Neo.SmartContract.Framework/ECPoint.cs index 6f0fad367..d622498ff 100644 --- a/src/Neo.SmartContract.Framework/ECPoint.cs +++ b/src/Neo.SmartContract.Framework/ECPoint.cs @@ -8,10 +8,9 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; -namespace Neo.Cryptography.ECC +namespace Neo.SmartContract.Framework { public abstract class ECPoint : ByteString { diff --git a/src/Neo.SmartContract.Framework/Native/CalledByGroupCondition.cs b/src/Neo.SmartContract.Framework/Native/CalledByGroupCondition.cs index a5d7475bf..191bc8372 100644 --- a/src/Neo.SmartContract.Framework/Native/CalledByGroupCondition.cs +++ b/src/Neo.SmartContract.Framework/Native/CalledByGroupCondition.cs @@ -8,8 +8,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.Cryptography.ECC; - namespace Neo.SmartContract.Framework.Native { public class CalledByGroupCondition : WitnessCondition diff --git a/src/Neo.SmartContract.Framework/Native/CryptoLib.cs b/src/Neo.SmartContract.Framework/Native/CryptoLib.cs index e85004aa3..be3b522fc 100644 --- a/src/Neo.SmartContract.Framework/Native/CryptoLib.cs +++ b/src/Neo.SmartContract.Framework/Native/CryptoLib.cs @@ -26,6 +26,6 @@ public static partial class CryptoLib public static extern ByteString Murmur32(ByteString value, uint seed); - public static extern bool VerifyWithECDsa(ByteString message, Cryptography.ECC.ECPoint pubkey, ByteString signature, NamedCurve curve); + public static extern bool VerifyWithECDsa(ByteString message, ECPoint pubkey, ByteString signature, NamedCurve curve); } } diff --git a/src/Neo.SmartContract.Framework/Native/GroupCondition.cs b/src/Neo.SmartContract.Framework/Native/GroupCondition.cs index d9c4432c8..1f6ff2c9f 100644 --- a/src/Neo.SmartContract.Framework/Native/GroupCondition.cs +++ b/src/Neo.SmartContract.Framework/Native/GroupCondition.cs @@ -8,8 +8,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.Cryptography.ECC; - namespace Neo.SmartContract.Framework.Native { public class GroupCondition : WitnessCondition diff --git a/src/Neo.SmartContract.Framework/Native/NEO.cs b/src/Neo.SmartContract.Framework/Native/NEO.cs index 1aa4456ac..fbe31f0ee 100644 --- a/src/Neo.SmartContract.Framework/Native/NEO.cs +++ b/src/Neo.SmartContract.Framework/Native/NEO.cs @@ -10,7 +10,6 @@ #pragma warning disable CS0626 -using Neo.Cryptography.ECC; using Neo.SmartContract.Framework.Attributes; using Neo.SmartContract.Framework.Services; using System.Numerics; diff --git a/src/Neo.SmartContract.Framework/Native/NeoAccountState.cs b/src/Neo.SmartContract.Framework/Native/NeoAccountState.cs index db76444ef..93e1f3f71 100644 --- a/src/Neo.SmartContract.Framework/Native/NeoAccountState.cs +++ b/src/Neo.SmartContract.Framework/Native/NeoAccountState.cs @@ -8,7 +8,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.Cryptography.ECC; using System.Numerics; namespace Neo.SmartContract.Framework.Native diff --git a/src/Neo.SmartContract.Framework/Native/RoleManagement.cs b/src/Neo.SmartContract.Framework/Native/RoleManagement.cs index 7235a285a..e8ba132d7 100644 --- a/src/Neo.SmartContract.Framework/Native/RoleManagement.cs +++ b/src/Neo.SmartContract.Framework/Native/RoleManagement.cs @@ -19,6 +19,6 @@ public class RoleManagement { [ContractHash] public static extern UInt160 Hash { get; } - public static extern Cryptography.ECC.ECPoint[] GetDesignatedByRole(Role role, uint index); + public static extern ECPoint[] GetDesignatedByRole(Role role, uint index); } } diff --git a/src/Neo.SmartContract.Framework/Native/Signer.cs b/src/Neo.SmartContract.Framework/Native/Signer.cs index 9bba6bf9a..ffca0fe17 100644 --- a/src/Neo.SmartContract.Framework/Native/Signer.cs +++ b/src/Neo.SmartContract.Framework/Native/Signer.cs @@ -8,8 +8,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.Cryptography.ECC; - namespace Neo.SmartContract.Framework.Native { public class Signer diff --git a/src/Neo.SmartContract.Framework/Services/Contract.cs b/src/Neo.SmartContract.Framework/Services/Contract.cs index 58c5f8666..53d690f5d 100644 --- a/src/Neo.SmartContract.Framework/Services/Contract.cs +++ b/src/Neo.SmartContract.Framework/Services/Contract.cs @@ -46,9 +46,9 @@ public class Contract public static extern CallFlags GetCallFlags(); [Syscall("System.Contract.CreateStandardAccount")] - public static extern UInt160 CreateStandardAccount(Cryptography.ECC.ECPoint pubKey); + public static extern UInt160 CreateStandardAccount(ECPoint pubKey); [Syscall("System.Contract.CreateMultisigAccount")] - public static extern UInt160 CreateMultisigAccount(int m, params Cryptography.ECC.ECPoint[] pubKey); + public static extern UInt160 CreateMultisigAccount(int m, params ECPoint[] pubKey); } } diff --git a/src/Neo.SmartContract.Framework/Services/ContractGroup.cs b/src/Neo.SmartContract.Framework/Services/ContractGroup.cs index 5ac72d6a8..5f209bbfa 100644 --- a/src/Neo.SmartContract.Framework/Services/ContractGroup.cs +++ b/src/Neo.SmartContract.Framework/Services/ContractGroup.cs @@ -1,5 +1,3 @@ -using Neo.Cryptography.ECC; - namespace Neo.SmartContract.Framework.Services { public struct ContractGroup diff --git a/src/Neo.SmartContract.Framework/Services/Crypto.cs b/src/Neo.SmartContract.Framework/Services/Crypto.cs index 5f3a74502..5cc2a77cf 100644 --- a/src/Neo.SmartContract.Framework/Services/Crypto.cs +++ b/src/Neo.SmartContract.Framework/Services/Crypto.cs @@ -15,9 +15,9 @@ namespace Neo.SmartContract.Framework.Services public static class Crypto { [Syscall("System.Crypto.CheckSig")] - public extern static bool CheckSig(Cryptography.ECC.ECPoint pubkey, ByteString signature); + public extern static bool CheckSig(ECPoint pubkey, ByteString signature); [Syscall("System.Crypto.CheckMultisig")] - public extern static bool CheckMultisig(Cryptography.ECC.ECPoint[] pubkey, ByteString[] signature); + public extern static bool CheckMultisig(ECPoint[] pubkey, ByteString[] signature); } } diff --git a/src/Neo.SmartContract.Framework/Services/Runtime.cs b/src/Neo.SmartContract.Framework/Services/Runtime.cs index 314b1f063..3c342cc02 100644 --- a/src/Neo.SmartContract.Framework/Services/Runtime.cs +++ b/src/Neo.SmartContract.Framework/Services/Runtime.cs @@ -98,7 +98,7 @@ public static extern byte AddressVersion public static extern bool CheckWitness(UInt160 hash); [Syscall("System.Runtime.CheckWitness")] - public static extern bool CheckWitness(Cryptography.ECC.ECPoint pubkey); + public static extern bool CheckWitness(ECPoint pubkey); [Syscall("System.Runtime.Log")] public static extern void Log(string message); diff --git a/src/Neo.SmartContract.Framework/Services/StorageMap.cs b/src/Neo.SmartContract.Framework/Services/StorageMap.cs index cadf1947b..59e3e4ea6 100644 --- a/src/Neo.SmartContract.Framework/Services/StorageMap.cs +++ b/src/Neo.SmartContract.Framework/Services/StorageMap.cs @@ -15,7 +15,6 @@ using Neo.SmartContract.Framework.Native; using System.Numerics; using System.Runtime.InteropServices; -using Neo.Cryptography.ECC; namespace Neo.SmartContract.Framework.Services { diff --git a/src/Neo.SmartContract.Framework/UInt160.cs b/src/Neo.SmartContract.Framework/UInt160.cs index f80aedff3..c62ff090f 100644 --- a/src/Neo.SmartContract.Framework/UInt160.cs +++ b/src/Neo.SmartContract.Framework/UInt160.cs @@ -8,12 +8,11 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; using Neo.SmartContract.Framework.Native; using Neo.SmartContract.Framework.Services; -namespace Neo +namespace Neo.SmartContract.Framework { public abstract class UInt160 : ByteString { diff --git a/src/Neo.SmartContract.Framework/UInt256.cs b/src/Neo.SmartContract.Framework/UInt256.cs index 17777e8dc..db61ade04 100644 --- a/src/Neo.SmartContract.Framework/UInt256.cs +++ b/src/Neo.SmartContract.Framework/UInt256.cs @@ -8,10 +8,9 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; -namespace Neo +namespace Neo.SmartContract.Framework { public abstract class UInt256 : ByteString { diff --git a/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/template.json b/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/template.json index b940f5e1c..02dc6566f 100644 --- a/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/template.json +++ b/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/template.json @@ -17,13 +17,10 @@ "datatype": "choice", "choices": [ { - "choice": "3.6.0" - }, - { - "choice": "3.6.2" + "choice": "3.6.2-CI00519" } ], - "defaultValue": "3.6.2", + "defaultValue": "3.6.2-CI00519", "replaces": "TemplateNeoVersion" } } diff --git a/src/Neo.SmartContract.Template/templates/neocontractnep17/Nep17Contract.cs b/src/Neo.SmartContract.Template/templates/neocontractnep17/Nep17Contract.cs index 59c9b62b2..3778a5163 100644 --- a/src/Neo.SmartContract.Template/templates/neocontractnep17/Nep17Contract.cs +++ b/src/Neo.SmartContract.Template/templates/neocontractnep17/Nep17Contract.cs @@ -1,4 +1,3 @@ -using Neo; using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; using Neo.SmartContract.Framework.Native; @@ -18,7 +17,7 @@ namespace Neo.SmartContract.Template [ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/src/Neo.SmartContract.Template/templates/neocontractnep17/Nep17Contract.cs")] [ContractPermission("*", "*")] [SupportedStandards("NEP-17")] - public class Nep17Contract : Nep17Token + public class Nep17Contract : Neo.SmartContract.Framework.Nep17Token { #region Owner diff --git a/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/template.json b/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/template.json index af853ee72..adb90fa37 100644 --- a/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/template.json +++ b/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/template.json @@ -17,13 +17,10 @@ "datatype": "choice", "choices": [ { - "choice": "3.6.0" - }, - { - "choice": "3.6.2" + "choice": "3.6.2-CI00519" } ], - "defaultValue": "3.6.2", + "defaultValue": "3.6.2-CI00519", "replaces": "TemplateNeoVersion" } } diff --git a/src/Neo.SmartContract.Template/templates/neocontractoracle/OracleRequest.cs b/src/Neo.SmartContract.Template/templates/neocontractoracle/OracleRequest.cs index fb3514484..47c9ff267 100644 --- a/src/Neo.SmartContract.Template/templates/neocontractoracle/OracleRequest.cs +++ b/src/Neo.SmartContract.Template/templates/neocontractoracle/OracleRequest.cs @@ -1,4 +1,3 @@ -using Neo; using Neo.SmartContract; using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; diff --git a/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json b/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json index 3c40192de..ea70a18fc 100644 --- a/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json +++ b/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json @@ -17,13 +17,10 @@ "datatype": "choice", "choices": [ { - "choice": "3.6.0" - }, - { - "choice": "3.6.2" + "choice": "3.6.2-CI00519" } ], - "defaultValue": "3.6.2", + "defaultValue": "3.6.2-CI00519", "replaces": "TemplateNeoVersion" } } diff --git a/src/Neo.SmartContract.Template/templates/neocontractowner/Ownable.cs b/src/Neo.SmartContract.Template/templates/neocontractowner/Ownable.cs index d4431f25e..9f54ad119 100644 --- a/src/Neo.SmartContract.Template/templates/neocontractowner/Ownable.cs +++ b/src/Neo.SmartContract.Template/templates/neocontractowner/Ownable.cs @@ -1,4 +1,3 @@ -using Neo; using Neo.SmartContract; using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; diff --git a/src/Neo.SmartContract.Testing/Coverage/CoveredCollection.cs b/src/Neo.SmartContract.Testing/Coverage/CoveredCollection.cs index e2d2d59dd..89ca49d13 100644 --- a/src/Neo.SmartContract.Testing/Coverage/CoveredCollection.cs +++ b/src/Neo.SmartContract.Testing/Coverage/CoveredCollection.cs @@ -1,7 +1,6 @@ using Neo.SmartContract.Testing.Coverage.Formats; using System; using System.Collections.Generic; -using System.Linq; namespace Neo.SmartContract.Testing.Coverage { @@ -62,28 +61,31 @@ public CoveredCollection(params CoverageBase[] entries) /// Coverage dump public override string Dump(DumpFormat format = DumpFormat.Console) { - IEnumerable<(CoveredContract, Func?)> entries = Entries.Select(u => + switch (format) { - if (u is CoveredContract co) return (co, (Func?)null); - if (u is CoveredMethod cm) return (cm.Contract, new Func((CoveredMethod method) => ReferenceEquals(method, cm))); - - throw new NotImplementedException(); - })!; + case DumpFormat.Console: return new ConsoleFormat(GetEntries()).Dump(); + case DumpFormat.Html: return new IntructionHtmlFormat(GetEntries()).Dump(); + default: throw new NotImplementedException(); + } + } - switch (format) + /// + /// Get covered entries + /// + /// IEnumerable + private IEnumerable<(CoveredContract, Func?)> GetEntries() + { + foreach (var entry in Entries) { - case DumpFormat.Console: - { - return new ConsoleFormat(entries).Dump(); - } - case DumpFormat.Html: - { - return new IntructionHtmlFormat(entries).Dump(); - } - default: + if (entry is CoveredContract co) yield return (co, null); + if (entry is CoveredMethod cm) yield return (cm.Contract, (CoveredMethod method) => ReferenceEquals(method, cm)); + if (entry is CoveredCollection cl) + { + foreach (var subEntry in cl.GetEntries()) { - throw new NotImplementedException(); + yield return subEntry; } + } } } } diff --git a/src/Neo.SmartContract.Testing/Coverage/CoveredContract.cs b/src/Neo.SmartContract.Testing/Coverage/CoveredContract.cs index d457fc8ac..02bedc97a 100644 --- a/src/Neo.SmartContract.Testing/Coverage/CoveredContract.cs +++ b/src/Neo.SmartContract.Testing/Coverage/CoveredContract.cs @@ -294,18 +294,9 @@ public override string Dump(DumpFormat format = DumpFormat.Console) { switch (format) { - case DumpFormat.Console: - { - return new ConsoleFormat(this).Dump(); - } - case DumpFormat.Html: - { - return new IntructionHtmlFormat(this).Dump(); - } - default: - { - throw new NotImplementedException(); - } + case DumpFormat.Console: return new ConsoleFormat(this).Dump(); + case DumpFormat.Html: return new IntructionHtmlFormat(this).Dump(); + default: throw new NotImplementedException(); } } diff --git a/src/Neo.SmartContract.Testing/Coverage/CoveredMethod.cs b/src/Neo.SmartContract.Testing/Coverage/CoveredMethod.cs index da207397a..56d898b4b 100644 --- a/src/Neo.SmartContract.Testing/Coverage/CoveredMethod.cs +++ b/src/Neo.SmartContract.Testing/Coverage/CoveredMethod.cs @@ -63,18 +63,9 @@ public override string Dump(DumpFormat format = DumpFormat.Console) { switch (format) { - case DumpFormat.Console: - { - return new ConsoleFormat(Contract, m => ReferenceEquals(m, this)).Dump(); - } - case DumpFormat.Html: - { - return new IntructionHtmlFormat(Contract, m => ReferenceEquals(m, this)).Dump(); - } - default: - { - throw new NotImplementedException(); - } + case DumpFormat.Console: return new ConsoleFormat(Contract, m => ReferenceEquals(m, this)).Dump(); + case DumpFormat.Html: return new IntructionHtmlFormat(Contract, m => ReferenceEquals(m, this)).Dump(); + default: throw new NotImplementedException(); } } diff --git a/src/Neo.SmartContract.Testing/Coverage/Formats/ConsoleFormat.cs b/src/Neo.SmartContract.Testing/Coverage/Formats/ConsoleFormat.cs index 9ed775556..0f63e5189 100644 --- a/src/Neo.SmartContract.Testing/Coverage/Formats/ConsoleFormat.cs +++ b/src/Neo.SmartContract.Testing/Coverage/Formats/ConsoleFormat.cs @@ -16,10 +16,10 @@ public partial class ConsoleFormat : CoverageFormatBase /// Constructor /// /// Contract - /// Method Filter - public ConsoleFormat(CoveredContract contract, Func? Filter = null) + /// Method Filter + public ConsoleFormat(CoveredContract contract, Func? filter = null) { - Entries = new (CoveredContract, Func?)[] { (contract, Filter) }; + Entries = new (CoveredContract, Func?)[] { (contract, filter) }; } /// diff --git a/src/Neo.SmartContract.Testing/Extensions/ArtifactExtensions.cs b/src/Neo.SmartContract.Testing/Extensions/ArtifactExtensions.cs index 212522c82..3c86e9a05 100644 --- a/src/Neo.SmartContract.Testing/Extensions/ArtifactExtensions.cs +++ b/src/Neo.SmartContract.Testing/Extensions/ArtifactExtensions.cs @@ -36,10 +36,9 @@ public static class ArtifactExtensions /// Manifest /// Class name, by default is manifest.Name /// Nef file - /// Debug Info /// Generate properties /// Source - public static string GetArtifactsSource(this ContractManifest manifest, string? name = null, NefFile? nef = null, JToken? debugInfo = null, bool generateProperties = true) + public static string GetArtifactsSource(this ContractManifest manifest, string? name = null, NefFile? nef = null, bool generateProperties = true) { name ??= manifest.Name; @@ -84,13 +83,6 @@ public static string GetArtifactsSource(this ContractManifest manifest, string? sourceCode.WriteLine(); } - if (debugInfo is not null) - { - value = debugInfo.ToString(false).Replace("\"", "\"\""); - sourceCode.WriteLine($" public static readonly {typeof(NeoDebugInfo).FullName} DebugInfo = {typeof(NeoDebugInfo).FullName}.FromDebugInfoJson(@\"{value}\");"); - sourceCode.WriteLine(); - } - sourceCode.WriteLine(" #endregion"); sourceCode.WriteLine(); diff --git a/src/Neo.SmartContract.Testing/Extensions/MockExtensions.cs b/src/Neo.SmartContract.Testing/Extensions/MockExtensions.cs index 300c42139..5c3985cf4 100644 --- a/src/Neo.SmartContract.Testing/Extensions/MockExtensions.cs +++ b/src/Neo.SmartContract.Testing/Extensions/MockExtensions.cs @@ -29,7 +29,7 @@ public static bool IsMocked(this Mock mock, MethodInfo method) // Sometimes method comparation with Equals doesn't work as expected with moq - if (method.DeclaringType.Equals(mSetup.DeclaringType) && + if (method.DeclaringType?.Equals(mSetup.DeclaringType) == true && method.Attributes.Equals(mSetup.Attributes) && method.Name.Equals(mSetup.Name) && method.ReturnType.Equals(mSetup.ReturnType) && @@ -92,7 +92,7 @@ public static void MockFunction(this Mock mock, string name, Type[] args, ) .MakeGenericMethod(returnType); - var setup = setupMethod.Invoke(mock, new object[] { exp })!; + var setup = setupMethod.Invoke(mock, new[] { exp })!; var retMethod = setup.GetType() .GetMethod("Returns", new Type[] { typeof(InvocationFunc) })!; @@ -119,7 +119,7 @@ public static void MockAction(this Mock mock, string name, Type[] args) u.GetParameters()[0].ParameterType.ToString().Contains("[System.Action`") ); - var setup = setupMethod.Invoke(mock, new object[] { exp })!; + var setup = setupMethod.Invoke(mock, new[] { exp })!; var retMethod = setup.GetType() .GetMethod("Callback", new Type[] { typeof(InvocationAction) })!; diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_Foreach.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_Foreach.cs index c87bb731c..d8e00fc9f 100644 --- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_Foreach.cs +++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_Foreach.cs @@ -1,8 +1,6 @@ -using System.Numerics; using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; -using Neo.SmartContract; -using Neo.Cryptography.ECC; +using System.Numerics; namespace Neo.Compiler.CSharp.UnitTests.TestClasses { diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_Interfaces.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_Interfaces.cs index 70d578a83..51b76128f 100644 --- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_Interfaces.cs +++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_Interfaces.cs @@ -1,3 +1,4 @@ +using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Services; using System.Numerics; diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_NativeContracts.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_NativeContracts.cs index 5e41c39c9..f818e4ff6 100644 --- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_NativeContracts.cs +++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_NativeContracts.cs @@ -1,3 +1,4 @@ +using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Native; namespace Neo.Compiler.CSharp.UnitTests.TestClasses @@ -19,7 +20,7 @@ public static string GASSymbol() return GAS.Symbol; } - public static Cryptography.ECC.ECPoint[] getOracleNodes() + public static ECPoint[] getOracleNodes() { return RoleManagement.GetDesignatedByRole(Role.Oracle, 0); } diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_ParameterType.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_ParameterType.cs index 9dd279a4c..135e182d6 100644 --- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_ParameterType.cs +++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_ParameterType.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Numerics; -using Neo.SmartContract; using Neo.SmartContract.Framework; -using Neo.Cryptography.ECC; +using System.Numerics; namespace Neo.Compiler.CSharp.UnitTests.TestClasses { diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_StaticVar.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_StaticVar.cs index 7db3f369a..576f81da8 100644 --- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_StaticVar.cs +++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_StaticVar.cs @@ -1,7 +1,6 @@ -using System.Numerics; -using Neo.Cryptography.ECC; -using Neo.SmartContract; +using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; +using System.Numerics; namespace Neo.Compiler.CSharp.UnitTests.TestClasses { diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_TryCatch.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_TryCatch.cs index c3b4d732e..3b817b8d2 100644 --- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_TryCatch.cs +++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_TryCatch.cs @@ -1,5 +1,3 @@ -using Neo.Cryptography.ECC; -using Neo.SmartContract; using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; diff --git a/tests/Neo.Compiler.CSharp.TestContracts/Contract_Types_ECPoint.cs b/tests/Neo.Compiler.CSharp.TestContracts/Contract_Types_ECPoint.cs index 0e7bacdfe..978e407b1 100644 --- a/tests/Neo.Compiler.CSharp.TestContracts/Contract_Types_ECPoint.cs +++ b/tests/Neo.Compiler.CSharp.TestContracts/Contract_Types_ECPoint.cs @@ -1,5 +1,3 @@ -using Neo.Cryptography.ECC; -using Neo.SmartContract; using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Attributes; diff --git a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Contract.cs b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Contract.cs index a12fcd0c8..693edda9b 100644 --- a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Contract.cs +++ b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Contract.cs @@ -30,7 +30,7 @@ public static int GetCallFlags() return (int)Contract.GetCallFlags(); } - public static UInt160 CreateStandardAccount(Cryptography.ECC.ECPoint pubKey) + public static UInt160 CreateStandardAccount(ECPoint pubKey) { return Contract.CreateStandardAccount(pubKey); } diff --git a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Crypto.cs b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Crypto.cs index eb17a74b4..4106125d8 100644 --- a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Crypto.cs +++ b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Crypto.cs @@ -1,4 +1,3 @@ -using Neo.Cryptography.ECC; using Neo.SmartContract.Framework.Native; using System.ComponentModel; diff --git a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Native.cs b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Native.cs index bef5beba8..985bf6e2b 100644 --- a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Native.cs +++ b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Native.cs @@ -1,6 +1,4 @@ -using Neo.Cryptography.ECC; using Neo.SmartContract.Framework.Native; -using System; using System.ComponentModel; using System.Numerics; diff --git a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Storage.cs b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Storage.cs index 207a9bd9d..65bad4720 100644 --- a/tests/Neo.SmartContract.Framework.TestContracts/Contract_Storage.cs +++ b/tests/Neo.SmartContract.Framework.TestContracts/Contract_Storage.cs @@ -1,6 +1,4 @@ -using Neo.Cryptography.ECC; using Neo.SmartContract.Framework.Services; -using Neo.SmartContract.Framework; namespace Neo.SmartContract.Framework.UnitTests.TestClasses { diff --git a/tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj b/tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj index 8852d19ea..2226ba6ce 100644 --- a/tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj +++ b/tests/Neo.SmartContract.Template.UnitTests/Neo.SmartContract.Template.UnitTests.csproj @@ -8,26 +8,8 @@ + - - - - - - - - - - - - - - - - - - - diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/CoverageContractTests.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/CoverageContractTests.cs deleted file mode 100644 index a947c8507..000000000 --- a/tests/Neo.SmartContract.Template.UnitTests/templates/CoverageContractTests.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Neo.SmartContract.Template.UnitTests.templates.neocontractnep17; -using Neo.SmartContract.Template.UnitTests.templates.neocontractowner; -using Neo.SmartContract.Testing; -using Neo.SmartContract.Testing.Coverage; -using Neo.SmartContract.Testing.Coverage.Formats; - -namespace Neo.SmartContract.Template.UnitTests.templates -{ - [TestClass] - public class CoverageContractTests - { - /// - /// Required coverage to be success - /// - public static decimal RequiredCoverage { get; set; } = 1M; - - [AssemblyCleanup] - public static void EnsureCoverage() - { - // Join here all of your coverage sources - - var coverageNep17 = Nep17ContractTests.Coverage; - coverageNep17?.Join(OwnerContractTests.Coverage); - var coverageOwnable = OwnableContractTests.Coverage; - var coverageOracle = OracleRequestTests.Coverage; - - // Dump coverage to console - - Assert.IsNotNull(coverageNep17, "NEP17 coverage can't be null"); - Assert.IsNotNull(coverageOwnable, "Ownable coverage can't be null"); - Assert.IsNotNull(coverageOracle, "Oracle coverage can't be null"); - - var coverage = new CoveredCollection(coverageNep17, coverageOwnable, coverageOracle); - - // Dump current coverage - - Console.WriteLine(coverage.Dump()); - File.WriteAllText("coverage.instruction.html", coverage.Dump(DumpFormat.Html)); - - // Write the cobertura format - - File.WriteAllText("coverage.cobertura.xml", new CoberturaFormat( - (coverageNep17, Nep17Contract.DebugInfo), - (coverageOwnable, Ownable.DebugInfo), - (coverageOracle, OracleRequest.DebugInfo) - ).Dump()); - - // Write the report to the specific path - - CoverageReporting.CreateReport("coverage.cobertura.xml", "./coverageReport/"); - - // Ensure that the coverage is more than X% at the end of the tests - - Assert.IsTrue(coverage.CoveredLinesPercentage >= RequiredCoverage, $"Coverage is less than {RequiredCoverage:P2}"); - } - } -} diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/TestCleanup.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/TestCleanup.cs new file mode 100644 index 000000000..5223a1e94 --- /dev/null +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/TestCleanup.cs @@ -0,0 +1,123 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.Compiler; +using Neo.SmartContract.Template.UnitTests.templates.neocontractnep17; +using Neo.SmartContract.Template.UnitTests.templates.neocontractowner; +using Neo.SmartContract.Testing; +using Neo.SmartContract.Testing.Coverage; +using Neo.SmartContract.Testing.Coverage.Formats; +using Neo.SmartContract.Testing.Extensions; + +namespace Neo.SmartContract.Template.UnitTests.templates +{ + [TestClass] + public class TestCleanup + { + private static NeoDebugInfo? DebugInfo_NEP17; + private static NeoDebugInfo? DebugInfo_Oracle; + private static NeoDebugInfo? DebugInfo_Ownable; + + /// + /// Required coverage to be success + /// + public static decimal RequiredCoverage { get; set; } = 0.85M; + + [TestMethod] + public void EnsureArtifactsUpToDate() + { + string frameworkPath = Path.GetFullPath("../../../../../src/Neo.SmartContract.Framework"); + string templatePath = Path.GetFullPath("../../../../../src/Neo.SmartContract.Template/templates"); + string artifactsPath = Path.GetFullPath("../../../templates"); + + // Compile + + var result = new CompilationEngine(new CompilationOptions() + { + Debug = true, + Nullable = Microsoft.CodeAnalysis.NullableContextOptions.Disable + }) + .CompileSources( + ("Neo.SmartContract.Framework", "3.6.2-CI00520"), + Path.Combine(templatePath, "neocontractnep17/Nep17Contract.cs"), + Path.Combine(templatePath, "neocontractoracle/OracleRequest.cs"), + Path.Combine(templatePath, "neocontractowner/Ownable.cs") + ); + + Assert.IsTrue(result.Count() == 3 && result.All(u => u.Success), "Error compiling templates"); + + // Ensure Nep17 + + var root = Path.GetPathRoot(templatePath) ?? ""; + var content = File.ReadAllText(Path.Combine(artifactsPath, "neocontractnep17/TestingArtifacts/Nep17ContractTemplate.artifacts.cs")); + (var artifact, DebugInfo_NEP17) = CreateArtifact(result[0], root); + Assert.AreEqual(artifact, content, "Nep17ContractTemplate artifact was wrong"); + + // Ensure Oracle + + content = File.ReadAllText(Path.Combine(artifactsPath, "neocontractoracle/TestingArtifacts/OracleRequestTemplate.artifacts.cs")); + (artifact, DebugInfo_Oracle) = CreateArtifact(result[1], root); + Assert.AreEqual(artifact, content, "OracleRequestTemplate artifact was wrong"); + + // Ensure Ownable + + content = File.ReadAllText(Path.Combine(artifactsPath, "neocontractowner/TestingArtifacts/OwnableTemplate.artifacts.cs")); + (artifact, DebugInfo_Ownable) = CreateArtifact(result[2], root); + Assert.AreEqual(artifact, content, "OwnableTemplate artifact was wrong"); + } + + private static (string, NeoDebugInfo) CreateArtifact(CompilationContext context, string rootDebug) + { + var manifest = context.CreateManifest(); + var nef = context.CreateExecutable(); + var debug = NeoDebugInfo.FromDebugInfoJson(context.CreateDebugInformation(rootDebug)); + + return (manifest.GetArtifactsSource(typeof(T).Name, nef, generateProperties: true), debug); + } + + [AssemblyCleanup] + public static void EnsureCoverage() + { + // Join here all of your coverage sources + + var coverageNep17 = Nep17ContractTests.Coverage; + coverageNep17?.Join(OwnerContractTests.Coverage); + var coverageOwnable = OwnableContractTests.Coverage; + var coverageOracle = OracleRequestTests.Coverage; + + // Dump coverage to console + + Assert.IsNotNull(coverageNep17, "NEP17 coverage can't be null"); + Assert.IsNotNull(coverageOwnable, "Ownable coverage can't be null"); + Assert.IsNotNull(coverageOracle, "Oracle coverage can't be null"); + + var coverage = coverageNep17 + coverageOwnable + coverageOracle; + + Assert.IsNotNull(coverage, "Coverage can't be null"); + + // Dump current coverage + + Console.WriteLine(coverage.Dump(DumpFormat.Console)); + File.WriteAllText("coverage.instruction.html", coverage.Dump(DumpFormat.Html)); + + if (DebugInfo_NEP17 is not null && + DebugInfo_Ownable is not null && + DebugInfo_Oracle is not null) + { + // Write the cobertura format + + File.WriteAllText("coverage.cobertura.xml", new CoberturaFormat( + (coverageNep17, DebugInfo_NEP17), + (coverageOwnable, DebugInfo_Ownable), + (coverageOracle, DebugInfo_Oracle) + ).Dump()); + + // Write the report to the specific path + + CoverageReporting.CreateReport("coverage.cobertura.xml", "./coverageReport/"); + } + + // Ensure that the coverage is more than X% at the end of the tests + + Assert.IsTrue(coverage.CoveredLinesPercentage >= RequiredCoverage, $"Coverage is less than {RequiredCoverage:P2}"); + } + } +} diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs index cff5fbe1d..83c4619f8 100644 --- a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/Nep17ContractTests.cs @@ -12,7 +12,7 @@ namespace Neo.SmartContract.Template.UnitTests.templates.neocontractnep17 /// You need to build the solution to resolve Nep17Contract class. /// [TestClass] - public class Nep17ContractTests : Nep17Tests + public class Nep17ContractTests : Nep17Tests { #region Expected values in base tests @@ -25,7 +25,7 @@ public class Nep17ContractTests : Nep17Tests /// /// Initialize Test /// - public Nep17ContractTests() : base(Nep17Contract.Nef, Nep17Contract.Manifest) { } + public Nep17ContractTests() : base(Nep17ContractTemplate.Nef, Nep17ContractTemplate.Manifest) { } [TestMethod] public void TestMyMethod() @@ -158,9 +158,9 @@ public void TestDeployWithOwner() // Try with invalid owners - Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, UInt160.Zero)); - Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, InvalidUInt160.InvalidLength)); - Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, InvalidUInt160.InvalidType)); + Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, UInt160.Zero)); + Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, InvalidUInt160.InvalidLength)); + Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, InvalidUInt160.InvalidType)); // Test SetOwner notification @@ -168,7 +168,7 @@ public void TestDeployWithOwner() UInt160? newOwnerRaised = null; var expectedHash = Engine.GetDeployHash(NefFile, Manifest); - var check = Engine.FromHash(expectedHash, false); + var check = Engine.FromHash(expectedHash, false); check.OnSetOwner += (previous, newOwner) => { previousOwnerRaised = previous; @@ -179,7 +179,7 @@ public void TestDeployWithOwner() // because the contract hash contains the Sender, and now it's random var rand = TestEngine.GetNewSigner().Account; - var nep17 = Engine.Deploy(NefFile, Manifest, rand); + var nep17 = Engine.Deploy(NefFile, Manifest, rand); Assert.AreEqual(check.Hash, nep17.Hash); Coverage?.Join(nep17.GetCoverage()); diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/OwnerContractTests.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/OwnerContractTests.cs index e9c8b6b01..533ca3777 100644 --- a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/OwnerContractTests.cs +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/OwnerContractTests.cs @@ -9,12 +9,12 @@ namespace Neo.SmartContract.Template.UnitTests.templates.neocontractnep17 /// You need to build the solution to resolve Nep17Contract class. /// [TestClass] - public class OwnerContractTests : OwnableTests + public class OwnerContractTests : OwnableTests { /// /// Initialize Test /// - public OwnerContractTests() : base(Nep17Contract.Nef, Nep17Contract.Manifest) { } + public OwnerContractTests() : base(Nep17ContractTemplate.Nef, Nep17ContractTemplate.Manifest) { } [TestMethod] public override void TestSetGetOwner() diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/TestingArtifacts/Nep17ContractTemplate.artifacts.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/TestingArtifacts/Nep17ContractTemplate.artifacts.cs new file mode 100644 index 000000000..b67503306 --- /dev/null +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractnep17/TestingArtifacts/Nep17ContractTemplate.artifacts.cs @@ -0,0 +1,106 @@ +using Neo.Cryptography.ECC; +using System.Collections.Generic; +using System.ComponentModel; +using System.Numerics; + +namespace Neo.SmartContract.Testing; + +public abstract class Nep17ContractTemplate : Neo.SmartContract.Testing.SmartContract, Neo.SmartContract.Testing.TestingStandards.INep17Standard, Neo.SmartContract.Testing.TestingStandards.IOwnable, Neo.SmartContract.Testing.TestingStandards.IVerificable +{ + #region Compiled data + + public static readonly Neo.SmartContract.Manifest.ContractManifest Manifest = Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""Nep17Contract"",""groups"":[],""features"":{},""supportedstandards"":[""NEP-17""],""abi"":{""methods"":[{""name"":""symbol"",""parameters"":[],""returntype"":""String"",""offset"":1308,""safe"":true},{""name"":""decimals"",""parameters"":[],""returntype"":""Integer"",""offset"":1323,""safe"":true},{""name"":""totalSupply"",""parameters"":[],""returntype"":""Integer"",""offset"":43,""safe"":true},{""name"":""balanceOf"",""parameters"":[{""name"":""owner"",""type"":""Hash160""}],""returntype"":""Integer"",""offset"":89,""safe"":true},{""name"":""transfer"",""parameters"":[{""name"":""from"",""type"":""Hash160""},{""name"":""to"",""type"":""Hash160""},{""name"":""amount"",""type"":""Integer""},{""name"":""data"",""type"":""Any""}],""returntype"":""Boolean"",""offset"":353,""safe"":false},{""name"":""getOwner"",""parameters"":[],""returntype"":""Hash160"",""offset"":799,""safe"":true},{""name"":""setOwner"",""parameters"":[{""name"":""newOwner"",""type"":""Hash160""}],""returntype"":""Void"",""offset"":855,""safe"":false},{""name"":""burn"",""parameters"":[{""name"":""account"",""type"":""Hash160""},{""name"":""amount"",""type"":""Integer""}],""returntype"":""Void"",""offset"":993,""safe"":false},{""name"":""mint"",""parameters"":[{""name"":""to"",""type"":""Hash160""},{""name"":""amount"",""type"":""Integer""}],""returntype"":""Void"",""offset"":1035,""safe"":false},{""name"":""verify"",""parameters"":[],""returntype"":""Boolean"",""offset"":1077,""safe"":true},{""name"":""myMethod"",""parameters"":[],""returntype"":""String"",""offset"":1083,""safe"":false},{""name"":""_deploy"",""parameters"":[{""name"":""data"",""type"":""Any""},{""name"":""update"",""type"":""Boolean""}],""returntype"":""Void"",""offset"":1109,""safe"":false},{""name"":""update"",""parameters"":[{""name"":""nefFile"",""type"":""ByteArray""},{""name"":""manifest"",""type"":""String""},{""name"":""data"",""type"":""Any""}],""returntype"":""Void"",""offset"":1247,""safe"":false},{""name"":""_initialize"",""parameters"":[],""returntype"":""Void"",""offset"":1292,""safe"":false}],""events"":[{""name"":""Transfer"",""parameters"":[{""name"":""from"",""type"":""Hash160""},{""name"":""to"",""type"":""Hash160""},{""name"":""amount"",""type"":""Integer""}]},{""name"":""SetOwner"",""parameters"":[{""name"":""previousOwner"",""type"":""Hash160""},{""name"":""newOwner"",""type"":""Hash160""}]}]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""extra"":{""Author"":""\u003CYour Name Or Company Here\u003E"",""Description"":""\u003CDescription Here\u003E"",""Email"":""\u003CYour Public Email Here\u003E"",""Version"":""\u003CVersion String Here\u003E""}}"); + + public static readonly Neo.SmartContract.NefFile Nef = Neo.IO.Helper.AsSerializable(Convert.FromBase64String(@"TkVGM05lby5Db21waWxlci5DU2hhcnAgMy42LjIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACIaHR0cHM6Ly9naXRodWIuY29tL25lby1wcm9qZWN0L25lby1kZXZwYWNrLWRvdG5ldC90cmVlL21hc3Rlci9zcmMvTmVvLlNtYXJ0Q29udHJhY3QuVGVtcGxhdGUvdGVtcGxhdGVzL25lb2NvbnRyYWN0bmVwMTcvTmVwMTdDb250cmFjdC5jcwAC/aP6Q0bqUyolj8SX3a3bZDfJ/f8LZ2V0Q29udHJhY3QBAAEP/aP6Q0bqUyolj8SX3a3bZDfJ/f8GdXBkYXRlAwAADwAA/ToFVwABDAdFWEFNUExFQFcAAXg0A0BXAAF4NANAVwABeDQDQFcAAUBXAAEYQFnYJhcMAQBB9rRr4kGSXegxStgmBEUQSmFAVwABeGF4DAEAQZv2Z85B5j8YhEBXAQF4cGgLlyYHEdsgIg14StkoUMoAFLOrqiYlDCBUaGUgYXJndW1lbnQgIm93bmVyIiBpcyBpbnZhbGlkLjpBm/ZnzhERiE4QUdBQEsBweGjBRVOLUEGSXegxStgmBEUQ2yEiAkBK2ShQygAUs6tAEYhOEFHQUBLAQEGb9mfOQErYJgRFENshQMFFU4tQQZJd6DFAVwICQZv2Z84REYhOEFHQUBLAcHhowUVTi1BBkl3oMUrYJgRFENshcWl5nkpxRWkQtSYHENsgIidpELMmEHhowUVTi1BBL1jF7SIPaXhowUVTi1BB5j8YhBHbICICQMFFU4tQQS9Yxe1AwUVTi1BB5j8YhEBXAQR4cGgLlyYHEdsgIg14StkoUMoAFLOrqiYkDB9UaGUgYXJndW1lbnQgImZyb20iIGlzIGludmFsaWQuOnlwaAuXJgcR2yAiDXlK2ShQygAUs6uqJiIMHVRoZSBhcmd1bWVudCAidG8iIGlzIGludmFsaWQuOnoQtSYqDCVUaGUgYW1vdW50IG11c3QgYmUgYSBwb3NpdGl2ZSBudW1iZXIuOnhB+CfsjKomBxDbICIqehCYJhp6m3g10v7//6omBxDbICIVenk1w/7//0V7enl4NA4R2yAiAkBB+CfsjEBXAQTCSnjPSnnPSnrPDAhUcmFuc2ZlckGVAW9heXBoC5eqJAcQ2yAiC3k3AABwaAuXqiYfe3p4E8AfDA5vbk5FUDE3UGF5bWVudHlBYn1bUkVANwAAQEFifVtSQFcAAnmZELUmCwwGYW1vdW50OnkQsyYEIiF5eDU0/v//RTVs/f//eZ5KNX79//9FC3l4CzVx////QFcAAnmZELUmCwwGYW1vdW50OnkQsyYEIjB5m3g1+v3//6omDgwJZXhjZXB0aW9uOjUk/f//eZ9KNTb9//9FC3kLeDUp////QAwB/9swNBBK2CQJSsoAFCgDOiICQFcAAXhB9rRr4kGSXegxQEGSXegxQEH2tGviQDTQQfgn7IxAVwEBNPUQ2yCXJhYMEU5vIEF1dGhvcml6YXRpb24hOnhK2ShQygAUs6skBxDbICIGeBCzqgwTb3duZXIgbXVzdCBiZSB2YWxpZOE1fv///3B4DAH/2zA0HsJKaM9KeM8MCFNldE93bmVyQZUBb2FA4UAQs0BXAAJ5eEGb9mfOQeY/GIRAQeY/GIRAVwACNWv///8Q2yCXJhYMEU5vIEF1dGhvcml6YXRpb24hOnl4NdL+//9AVwACNUH///8Q2yCXJhYMEU5vIEF1dGhvcml6YXRpb24hOnl4NW/+//9ANRr///9ADAVIZWxsb0Gb9mfOQZJd6DEiAkBBkl3oMUBXAQJ5JgQid3hwaAuXJgxBLVEIMBPOSoBFeHBoStkoUMoAFLOrJAcQ2yAiBmgQs6oMEW93bmVyIG11c3QgZXhpc3Rz4WgMAf/bMDUs////wkoLz0pozwwIU2V0T3duZXJBlQFvYQwFV29ybGQMBUhlbGxvQZv2Z85B5j8YhEBBLVEIMEBB5j8YhEBXAAM1bf7//xDbIJcmFgwRTm8gYXV0aG9yaXphdGlvbi46enl4NwEAQDcBAEBWAgoY+///Cu36//8SwGBAwkpYz0o17Pr//yPa+v//wkpYz0o13fr//yPx+v//7Q0Edw==")); + + #endregion + + #region Events + + [DisplayName("SetOwner")] + public event Neo.SmartContract.Testing.TestingStandards.IOwnable.delSetOwner? OnSetOwner; + + [DisplayName("Transfer")] + public event Neo.SmartContract.Testing.TestingStandards.INep17Standard.delTransfer? OnTransfer; + + #endregion + + #region Properties + + /// + /// Safe property + /// + public abstract BigInteger? Decimals { [DisplayName("decimals")] get; } + + /// + /// Safe property + /// + public abstract UInt160? Owner { [DisplayName("getOwner")] get; [DisplayName("setOwner")] set; } + + /// + /// Safe property + /// + public abstract string? Symbol { [DisplayName("symbol")] get; } + + /// + /// Safe property + /// + public abstract BigInteger? TotalSupply { [DisplayName("totalSupply")] get; } + + /// + /// Safe property + /// + public abstract bool? Verify { [DisplayName("verify")] get; } + + #endregion + + #region Safe methods + + /// + /// Safe method + /// + [DisplayName("balanceOf")] + public abstract BigInteger? BalanceOf(UInt160? owner); + + #endregion + + #region Unsafe methods + + /// + /// Unsafe method + /// + [DisplayName("burn")] + public abstract void Burn(UInt160? account, BigInteger? amount); + + /// + /// Unsafe method + /// + [DisplayName("mint")] + public abstract void Mint(UInt160? to, BigInteger? amount); + + /// + /// Unsafe method + /// + [DisplayName("myMethod")] + public abstract string? MyMethod(); + + /// + /// Unsafe method + /// + [DisplayName("transfer")] + public abstract bool? Transfer(UInt160? from, UInt160? to, BigInteger? amount, object? data = null); + + /// + /// Unsafe method + /// + [DisplayName("update")] + public abstract void Update(byte[]? nefFile, string? manifest, object? data = null); + + #endregion + + #region Constructor for internal use only + + protected Nep17ContractTemplate(Neo.SmartContract.Testing.SmartContractInitialize initialize) : base(initialize) { } + + #endregion +} diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/OracleRequestTests.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/OracleRequestTests.cs index c9a83b933..8e5703609 100644 --- a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/OracleRequestTests.cs +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/OracleRequestTests.cs @@ -12,12 +12,12 @@ namespace Neo.SmartContract.Template.UnitTests.templates.neocontractowner /// You need to build the solution to resolve OracleRequest class. /// [TestClass] - public class OracleRequestTests : TestBase + public class OracleRequestTests : TestBase { /// /// Initialize Test /// - public OracleRequestTests() : base(OracleRequest.Nef, OracleRequest.Manifest) { } + public OracleRequestTests() : base(OracleRequestTemplate.Nef, OracleRequestTemplate.Manifest) { } [TestMethod] public void TestGetResponse() diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/TestingArtifacts/OracleRequestTemplate.artifacts.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/TestingArtifacts/OracleRequestTemplate.artifacts.cs new file mode 100644 index 000000000..3492659aa --- /dev/null +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractoracle/TestingArtifacts/OracleRequestTemplate.artifacts.cs @@ -0,0 +1,48 @@ +using Neo.Cryptography.ECC; +using System.Collections.Generic; +using System.ComponentModel; +using System.Numerics; + +namespace Neo.SmartContract.Testing; + +public abstract class OracleRequestTemplate : Neo.SmartContract.Testing.SmartContract +{ + #region Compiled data + + public static readonly Neo.SmartContract.Manifest.ContractManifest Manifest = Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""OracleRequest"",""groups"":[],""features"":{},""supportedstandards"":[],""abi"":{""methods"":[{""name"":""getResponse"",""parameters"":[],""returntype"":""String"",""offset"":0,""safe"":true},{""name"":""doRequest"",""parameters"":[],""returntype"":""Void"",""offset"":35,""safe"":false},{""name"":""onOracleResponse"",""parameters"":[{""name"":""requestedUrl"",""type"":""String""},{""name"":""userData"",""type"":""Any""},{""name"":""oracleResponse"",""type"":""Integer""},{""name"":""jsonString"",""type"":""String""}],""returntype"":""Void"",""offset"":150,""safe"":false}],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""extra"":{""Author"":""\u003CYour Name Or Company Here\u003E"",""Description"":""\u003CDescription Here\u003E"",""Email"":""\u003CYour Public Email Here\u003E"",""Version"":""\u003CVersion String Here\u003E""}}"); + + public static readonly Neo.SmartContract.NefFile Nef = Neo.IO.Helper.AsSerializable(Convert.FromBase64String(@"TkVGM05lby5Db21waWxlci5DU2hhcnAgMy42LjIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACJaHR0cHM6Ly9naXRodWIuY29tL25lby1wcm9qZWN0L25lby1kZXZwYWNrLWRvdG5ldC90cmVlL21hc3Rlci9zcmMvTmVvLlNtYXJ0Q29udHJhY3QuVGVtcGxhdGUvdGVtcGxhdGVzL25lb2NvbnRyYWN0b3JhY2xlL09yYWNsZVJlcXVlc3QuY3MAA1iHFxF+CqgQcq+rcdLdif58S5L+B3JlcXVlc3QFAAAPwO85zuDk6SXGwqBqeeFEDdhvzqwEaXRvYQEAAQ/A7znO4OTpJcbCoGp54UQN2G/OrA9qc29uRGVzZXJpYWxpemUBAAEPAAD9QgEMCFJlc3BvbnNlQZv2Z85Bkl3oMSICQEGSXegxQEGb9mfOQFcBAAw1aHR0cHM6Ly9hcGkuanNvbmJpbi5pby92My9xcy82NTIwYWQzYzEyYTVkMzc2NTk4ODU0MmFwAoCWmAALDBBvbk9yYWNsZVJlc3BvbnNlDBUkLnJlY29yZC5wcm9wZXJ0eU5hbWVoNwAAQDcAAEBXAgRBOVNuPAwUWIcXEX4KqBByr6tx0t2J/nxLkv6YJhYMEU5vIEF1dGhvcml6YXRpb24hOnoQmCYuDCJPcmFjbGUgcmVzcG9uc2UgZmFpbHVyZSB3aXRoIGNvZGUgejcBAIvbKDp7NwIAcGgQznFpDAhSZXNwb25zZUGb9mfOQeY/GIRAQTlTbjxADBRYhxcRfgqoEHKvq3HS3Yn+fEuS/kA3AgBAQeY/GIRA/F7I2w==")); + + #endregion + + #region Properties + + /// + /// Safe property + /// + public abstract string? Response { [DisplayName("getResponse")] get; } + + #endregion + + #region Unsafe methods + + /// + /// Unsafe method + /// + [DisplayName("doRequest")] + public abstract void DoRequest(); + + /// + /// Unsafe method + /// + [DisplayName("onOracleResponse")] + public abstract void OnOracleResponse(string? requestedUrl, object? userData, BigInteger? oracleResponse, string? jsonString); + + #endregion + + #region Constructor for internal use only + + protected OracleRequestTemplate(Neo.SmartContract.Testing.SmartContractInitialize initialize) : base(initialize) { } + + #endregion +} diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/OwnableContractTests.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/OwnableContractTests.cs index 3a0d79bdc..1e0b99ebf 100644 --- a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/OwnableContractTests.cs +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/OwnableContractTests.cs @@ -11,12 +11,12 @@ namespace Neo.SmartContract.Template.UnitTests.templates.neocontractowner /// You need to build the solution to resolve Ownable class. /// [TestClass] - public class OwnableContractTests : OwnableTests + public class OwnableContractTests : OwnableTests { /// /// Initialize Test /// - public OwnableContractTests() : base(Ownable.Nef, Ownable.Manifest) { } + public OwnableContractTests() : base(OwnableTemplate.Nef, OwnableTemplate.Manifest) { } [TestMethod] public override void TestSetGetOwner() @@ -65,9 +65,9 @@ public void TestDeployWithOwner() // Try with invalid owners - Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, UInt160.Zero)); - Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, InvalidUInt160.InvalidLength)); - Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, InvalidUInt160.InvalidType)); + Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, UInt160.Zero)); + Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, InvalidUInt160.InvalidLength)); + Assert.ThrowsException(() => Engine.Deploy(NefFile, Manifest, InvalidUInt160.InvalidType)); // Test SetOwner notification @@ -75,7 +75,7 @@ public void TestDeployWithOwner() UInt160? newOwnerRaised = null; var expectedHash = Engine.GetDeployHash(NefFile, Manifest); - var check = Engine.FromHash(expectedHash, false); + var check = Engine.FromHash(expectedHash, false); check.OnSetOwner += (previous, newOwner) => { previousOwnerRaised = previous; @@ -86,7 +86,7 @@ public void TestDeployWithOwner() // because the contract hash contains the Sender, and now it's random var rand = TestEngine.GetNewSigner().Account; - var nep17 = Engine.Deploy(NefFile, Manifest, rand); + var nep17 = Engine.Deploy(NefFile, Manifest, rand); Assert.AreEqual(check.Hash, nep17.Hash); Coverage?.Join(nep17.GetCoverage()); diff --git a/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/TestingArtifacts/OwnableTemplate.artifacts.cs b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/TestingArtifacts/OwnableTemplate.artifacts.cs new file mode 100644 index 000000000..64d2d6a15 --- /dev/null +++ b/tests/Neo.SmartContract.Template.UnitTests/templates/neocontractowner/TestingArtifacts/OwnableTemplate.artifacts.cs @@ -0,0 +1,61 @@ +using Neo.Cryptography.ECC; +using System.Collections.Generic; +using System.ComponentModel; +using System.Numerics; + +namespace Neo.SmartContract.Testing; + +public abstract class OwnableTemplate : Neo.SmartContract.Testing.SmartContract, Neo.SmartContract.Testing.TestingStandards.IOwnable +{ + #region Compiled data + + public static readonly Neo.SmartContract.Manifest.ContractManifest Manifest = Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""Ownable"",""groups"":[],""features"":{},""supportedstandards"":[],""abi"":{""methods"":[{""name"":""getOwner"",""parameters"":[],""returntype"":""Hash160"",""offset"":0,""safe"":true},{""name"":""setOwner"",""parameters"":[{""name"":""newOwner"",""type"":""Hash160""}],""returntype"":""Void"",""offset"":62,""safe"":false},{""name"":""myMethod"",""parameters"":[],""returntype"":""String"",""offset"":216,""safe"":false},{""name"":""_deploy"",""parameters"":[{""name"":""data"",""type"":""Any""},{""name"":""update"",""type"":""Boolean""}],""returntype"":""Void"",""offset"":242,""safe"":false},{""name"":""update"",""parameters"":[{""name"":""nefFile"",""type"":""ByteArray""},{""name"":""manifest"",""type"":""String""},{""name"":""data"",""type"":""Any""}],""returntype"":""Void"",""offset"":377,""safe"":false},{""name"":""destroy"",""parameters"":[],""returntype"":""Void"",""offset"":422,""safe"":false}],""events"":[{""name"":""SetOwner"",""parameters"":[{""name"":""previousOwner"",""type"":""Hash160""},{""name"":""newOwner"",""type"":""Hash160""}]}]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""extra"":{""Author"":""\u003CYour Name Or Company Here\u003E"",""Description"":""\u003CDescription Here\u003E"",""Email"":""\u003CYour Public Email Here\u003E"",""Version"":""\u003CVersion String Here\u003E""}}"); + + public static readonly Neo.SmartContract.NefFile Nef = Neo.IO.Helper.AsSerializable(Convert.FromBase64String(@"TkVGM05lby5Db21waWxlci5DU2hhcnAgMy42LjIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCaHR0cHM6Ly9naXRodWIuY29tL25lby1wcm9qZWN0L25lby1kZXZwYWNrLWRvdG5ldC90cmVlL21hc3Rlci9zcmMvTmVvLlNtYXJ0Q29udHJhY3QuVGVtcGxhdGUvdGVtcGxhdGVzL25lb2NvbnRyYWN0b3duZXIvT3duYWJsZS5jcwAC/aP6Q0bqUyolj8SX3a3bZDfJ/f8GdXBkYXRlAwAAD/2j+kNG6lMqJY/El92t22Q3yf3/B2Rlc3Ryb3kAAAAPAAD9ygEMAf/bMDQQStgkCUrKABQoAzoiAkBXAAF4Qfa0a+JBkl3oMUBBkl3oMUBB9rRr4kA00EH4J+yMQEH4J+yMQFcBATTvENsglyYWDBFObyBBdXRob3JpemF0aW9uITp4StkoUMoAFLOrJAcQ2yAiBngQs6oME293bmVyIG11c3QgYmUgdmFsaWThNXj///9weAwB/9swNCjCSmjPSnjPDAhTZXRPd25lckGVAW9hQOFAStkoUMoAFLOrQBCzQFcAAnl4QZv2Z85B5j8YhEBB5j8YhEBBm/ZnzkAMBUhlbGxvQZv2Z85Bkl3oMSICQEGSXegxQFcBAnkmBCJ0eHBoC5cmDEEtUQgwE85KgEV4cGhK2ShQygAUs6skBxDbICIGaBCzqgwRb3duZXIgbXVzdCBleGlzdHPhaAwB/9swNIDCSgvPSmjPDAhTZXRPd25lckGVAW9hDAVXb3JsZAwFSGVsbG9Bm/ZnzkHmPxiEQEEtUQgwQEHmPxiEQFcAAzW0/v//ENsglyYWDBFObyBhdXRob3JpemF0aW9uLjp6eXg3AABANwAAQDWK/v//qiYWDBFObyBhdXRob3JpemF0aW9uLjo3AQBANwEAQOAcT+k=")); + + #endregion + + #region Events + + [DisplayName("SetOwner")] + public event Neo.SmartContract.Testing.TestingStandards.IOwnable.delSetOwner? OnSetOwner; + + #endregion + + #region Properties + + /// + /// Safe property + /// + public abstract UInt160? Owner { [DisplayName("getOwner")] get; [DisplayName("setOwner")] set; } + + #endregion + + #region Unsafe methods + + /// + /// Unsafe method + /// + [DisplayName("destroy")] + public abstract void Destroy(); + + /// + /// Unsafe method + /// + [DisplayName("myMethod")] + public abstract string? MyMethod(); + + /// + /// Unsafe method + /// + [DisplayName("update")] + public abstract void Update(byte[]? nefFile, string? manifest, object? data = null); + + #endregion + + #region Constructor for internal use only + + protected OwnableTemplate(Neo.SmartContract.Testing.SmartContractInitialize initialize) : base(initialize) { } + + #endregion +}