Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/Neo.Compiler.CSharp/ContractInterfaceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static string GenerateInterface(string contractName, ContractManifest man
sourceCode.WriteLine($" [Safe]");
}

if (property.setter != null)
if (property.setter is not null)
{
sourceCode.WriteLine($" {returnType} {propertyName} {{ get; set; }}");
}
Expand Down Expand Up @@ -157,7 +157,7 @@ private static (ContractMethodDescriptor[] methods, (ContractMethodDescriptor ge
string propertyName = getter.Name.Substring(4);
var setter = methods.FirstOrDefault(m => m.Name == $"set_{propertyName}");

if (setter != null)
if (setter is not null)
remainingMethods.Remove(setter);

properties.Add((getter, setter));
Expand Down
102 changes: 50 additions & 52 deletions src/Neo.Compiler.CSharp/Manifest/ContractManifestExtension.Nep11.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Neo.Compiler.CSharp/Manifest/ContractManifestExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static System.Collections.Generic.List<CompilationException>
CheckNep29Compliant(this ContractManifest manifest)
{
var deployMethod = manifest.Abi.GetMethod("_deploy", 2);
var deployValid = deployMethod != null &&
var deployValid = deployMethod is not null &&
deployMethod.ReturnType == ContractParameterType.Void &&
deployMethod.Parameters.Length == 2 &&
deployMethod.Parameters[0].Type == ContractParameterType.Any &&
Expand All @@ -40,7 +40,7 @@ private static System.Collections.Generic.List<CompilationException>
CheckNep30Compliant(this ContractManifest manifest)
{
var verifyMethod = manifest.Abi.GetMethod("verify", -1);
var verifyValid = verifyMethod != null && verifyMethod.Safe &&
var verifyValid = verifyMethod is not null && verifyMethod.Safe &&
verifyMethod.ReturnType == ContractParameterType.Boolean;

System.Collections.Generic.List<CompilationException> errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,84 +31,84 @@ private static System.Collections.Generic.List<CompilationException>
var transferMethod = manifest.Abi.GetMethod("transfer", 4);

// Check symbol method
if (symbolMethod == null)
if (symbolMethod is null)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: symbol, it is not found in the ABI"));

if (symbolMethod is { Safe: false })
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: symbol, it is not safe, you should add a 'Safe' attribute to the symbol method"));

if (symbolMethod != null && symbolMethod.ReturnType != ContractParameterType.String)
if (symbolMethod is not null && symbolMethod.ReturnType != ContractParameterType.String)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: symbol, it's return type is not a String"));

// Check decimals method
if (decimalsMethod == null)
if (decimalsMethod is null)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: decimals, it is not found in the ABI"));

if (decimalsMethod is { Safe: false })
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: decimals, it is not safe, you should add a 'Safe' attribute to the decimals method"));

if (decimalsMethod != null && decimalsMethod.ReturnType != ContractParameterType.Integer)
if (decimalsMethod is not null && decimalsMethod.ReturnType != ContractParameterType.Integer)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: decimals, it's return type is not an Integer"));

// Check totalSupply method
if (totalSupplyMethod == null)
if (totalSupplyMethod is null)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: totalSupply, it is not found in the ABI"));

if (totalSupplyMethod is { Safe: false })
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: totalSupply, it is not safe, you should add a 'Safe' attribute to the totalSupply method"));

if (totalSupplyMethod != null && totalSupplyMethod.ReturnType != ContractParameterType.Integer)
if (totalSupplyMethod is not null && totalSupplyMethod.ReturnType != ContractParameterType.Integer)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: totalSupply, it's return type is not an Integer"));

// Check balanceOf method
if (balanceOfMethod == null)
if (balanceOfMethod is null)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: balanceOf, it is not found in the ABI"));

if (balanceOfMethod is { Safe: false })
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: balanceOf, it is not safe, you should add a 'Safe' attribute to the balanceOf method"));

if (balanceOfMethod != null && balanceOfMethod.ReturnType != ContractParameterType.Integer)
if (balanceOfMethod is not null && balanceOfMethod.ReturnType != ContractParameterType.Integer)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: balanceOf, it's return type is not an Integer"));

if (balanceOfMethod != null && balanceOfMethod.Parameters.Length != 1)
if (balanceOfMethod is not null && balanceOfMethod.Parameters.Length != 1)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: balanceOf, it's parameters length is not 1"));

if (balanceOfMethod != null && balanceOfMethod.Parameters[0].Type != ContractParameterType.Hash160)
if (balanceOfMethod is not null && balanceOfMethod.Parameters[0].Type != ContractParameterType.Hash160)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: balanceOf, it's parameter type is not a Hash160"));

// Check transfer method
if (transferMethod == null)
if (transferMethod is null)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: transfer, it is not found in the ABI"));

// Note: transfer method should NOT be safe as per NEP-17 standard
if (transferMethod != null && transferMethod.Safe)
if (transferMethod is not null && transferMethod.Safe)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: transfer, it should not be marked as Safe"));

if (transferMethod != null && transferMethod.ReturnType != ContractParameterType.Boolean)
if (transferMethod is not null && transferMethod.ReturnType != ContractParameterType.Boolean)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: transfer, it's return type is not a Boolean"));

if (transferMethod != null && transferMethod.Parameters.Length != 4)
if (transferMethod is not null && transferMethod.Parameters.Length != 4)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep17.ToStandard()} implementation: transfer, it's parameters length is not 4"));

if (transferMethod != null && transferMethod.Parameters.Length == 4)
if (transferMethod is not null && transferMethod.Parameters.Length == 4)
{
if (transferMethod.Parameters[0].Type != ContractParameterType.Hash160)
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
Expand All @@ -128,12 +128,12 @@ private static System.Collections.Generic.List<CompilationException>
}

// Check Transfer event
var transferEvent = manifest.Abi.Events.FirstOrDefault(e =>
e.Name == "Transfer");

if (transferEvent == null)
var transferEvent = manifest.Abi.Events.FirstOrDefault(e => e.Name == "Transfer");
if (transferEvent is null)
{
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete NEP standard {NepStandard.Nep17.ToStandard()} implementation: Transfer event is not found in the ABI"));
}
else
{
if (transferEvent.Parameters.Length != 3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static System.Collections.Generic.List<CompilationException>
var royaltyInfoMethod = manifest.Abi.GetMethod("royaltyInfo", 3);

// Check if method exists
if (royaltyInfoMethod == null)
if (royaltyInfoMethod is null)
{
errors.Add(new CompilationException(DiagnosticId.IncorrectNEPStandard,
$"Incomplete or unsafe NEP standard {NepStandard.Nep24.ToStandard()} implementation: royaltyInfo, it is not found in the ABI"));
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static extern UInt160 EntryScriptHash
}

/// <summary>
/// Gets the unixtimestamp in seconds of the current block.
/// Gets the unixtimestamp in milliseconds of the current block.
/// </summary>
public static extern ulong Time
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static (ContractMethodDescriptor[] methods, (ContractMethodDescriptor ge
properties.Add((getter, setter));
methodList.Remove(getter);

if (setter != null)
if (setter is not null)
{
methodList.Remove(setter);
}
Expand Down Expand Up @@ -431,7 +431,7 @@ private static string CreateSourceMethodFromManifest(ContractMethodDescriptor me
if (debugInfo != null && nefFile != null)
{
var debugMethod = Disassembler.CSharp.Disassembler.GetMethod(method, debugInfo);
if (debugMethod != null)
if (debugMethod is not null)
{
var (start, end) = Disassembler.CSharp.Disassembler.GetMethodStartEndAddress(debugMethod);
var instructions = Disassembler.CSharp.Disassembler.ConvertMethodToInstructions(nefFile, start, end);
Expand Down Expand Up @@ -530,7 +530,7 @@ private static string BuildExtraInformation(JObject sequenceV2)

foreach (var entry in compilerArray)
{
if (entry == null) continue;
if (entry is null) continue;
if (first) first = false;
else builder.Append(',');
builder.Append($"{entry["file"]?.AsString()}:{entry["line"]}({entry["method"]?.AsString()})");
Expand Down
7 changes: 5 additions & 2 deletions src/Neo.SmartContract.Testing/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Neo.SmartContract.Testing
{
public class TestEngine
{
public delegate UInt160? OnGetScriptHash(UInt160 current, UInt160 expected);
public delegate UInt160? OnGetScriptHash(UInt160? current, UInt160? expected);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be null

From the definition of ApplicationEngine.CallingScriptHash and ApplicationEngine.EntryScriptHash, these two parameters can be null.


internal readonly List<FeeWatcher> _feeWatchers = [];
internal readonly Dictionary<UInt160, CoveredContract> Coverage = [];
Expand Down Expand Up @@ -301,7 +301,10 @@ public TestEngine(EngineStorage storage, ProtocolSettings settings, bool initial
if (Storage.IsInitialized)
{
var currentHash = NativeContract.Ledger.CurrentHash(Storage.Snapshot);
PersistingBlock = new PersistingBlock(this, NativeContract.Ledger.GetBlock(Storage.Snapshot, currentHash));
var block = NativeContract.Ledger.GetBlock(Storage.Snapshot, currentHash);
if (block is null) throw new InvalidOperationException($"Can't get the current block {currentHash}");

PersistingBlock = new PersistingBlock(this, block);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/Neo.SmartContract.Testing/TestingApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static TestingApplicationEngine()
{
Name = TestingSyscall.Name,
Handler = typeof(TestingApplicationEngine).GetMethod(nameof(InvokeTestingSyscall),
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic),
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!,
FixedPrice = 0,
RequiredCallFlags = CallFlags.None,
};
Expand All @@ -66,7 +66,7 @@ static TestingApplicationEngine()
/// <summary>
/// Override CallingScriptHash
/// </summary>
public override UInt160 CallingScriptHash
public override UInt160? CallingScriptHash
{
get
{
Expand All @@ -78,7 +78,7 @@ public override UInt160 CallingScriptHash
/// <summary>
/// Override EntryScriptHash
/// </summary>
public override UInt160 EntryScriptHash
public override UInt160? EntryScriptHash
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ public void Test_GAS()
public void Test_Ledger()
{
var genesisBlock = NativeContract.Ledger.GetBlock(Engine.Storage.Snapshot, 0);
Assert.IsNotNull(genesisBlock);
Assert.AreEqual(NativeContract.Ledger.Hash, Contract.LedgerHash());
AssertGasConsumed(984270);
Assert.AreEqual(0, Contract.LedgerCurrentIndex());
AssertGasConsumed(2950140);
Assert.AreEqual(genesisBlock.Hash, Contract.LedgerCurrentHash());

var currentHash = Contract.LedgerCurrentHash();
Assert.IsNotNull(currentHash);
Assert.AreEqual(genesisBlock.Hash, currentHash);
AssertGasConsumed(2950140);
}
}
Expand Down
Loading