Skip to content

Commit

Permalink
Disable/Fix some tests warnings (#1266)
Browse files Browse the repository at this point in the history
* Fix: disable some warnings in tests

* Update tests/Neo.SmartContract.Framework.TestContracts/Contract_Storage.cs

---------

Co-authored-by: Shargon <[email protected]>
  • Loading branch information
nan01ab and shargon authored Dec 17, 2024
1 parent 028445c commit c6fcf9d
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/Neo.Compiler.CSharp.TestContracts/Contract_Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Neo.Compiler.CSharp.TestContracts
{
internal struct State
{
public byte[] from = default;
public byte[]? from = default;
public byte[] to = null!;
public BigInteger amount = default;
public State()
Expand Down Expand Up @@ -159,7 +159,7 @@ public static void TestElementBinding()
var a = Ledger.GetBlock(0);
var array = new[] { a };
var firstItem = array?[0];
Runtime.Log(firstItem?.Timestamp.ToString());
Runtime.Log(firstItem?.Timestamp.ToString()!);
}

// This is new language feature introduced in C# 12
Expand Down
4 changes: 4 additions & 0 deletions tests/Neo.Compiler.CSharp.TestContracts/Contract_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static char TestCharDefault()
return a;
}

#pragma warning disable CS8600,CS8603
public static string TestStringDefault()
{
string a = default;
Expand All @@ -75,6 +76,7 @@ public static object TestObjectDefault()
object a = default;
return a;
}
#pragma warning restore CS8600,CS8603

public static BigInteger TestBigIntegerDefault()
{
Expand All @@ -93,11 +95,13 @@ public struct TestStruct
public int Value;
}

#pragma warning disable CS8600,CS8603
public static TestClass TestClassDefault()
{
TestClass a = default;
return a;
}
#pragma warning restore CS8600,CS8603

public class TestClass
{
Expand Down
4 changes: 4 additions & 0 deletions tests/Neo.Compiler.CSharp.TestContracts/Contract_Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static object TestEnumParseIgnoreCase(string value, bool ignoreCase)
return System.Enum.Parse(typeof(TestEnum), value, ignoreCase);
}

#pragma warning disable CS8600
public static bool TestEnumTryParse(string value)
{
return System.Enum.TryParse(typeof(TestEnum), value, out object result);
Expand All @@ -32,6 +33,7 @@ public static bool TestEnumTryParseIgnoreCase(string value, bool ignoreCase)
{
return System.Enum.TryParse(typeof(TestEnum), value, ignoreCase, out object result);
}
#pragma warning restore CS8600

public static string[] TestEnumGetNames()
{
Expand All @@ -53,6 +55,7 @@ public static bool TestEnumIsDefinedByName(string name)
return System.Enum.IsDefined(typeof(TestEnum), name);
}

#pragma warning disable CS8603
public static string TestEnumGetName(TestEnum value)
{
return System.Enum.GetName(value);
Expand All @@ -62,5 +65,6 @@ public static string TestEnumGetNameWithType(object value)
{
return System.Enum.GetName(typeof(TestEnum), value);
}
#pragma warning restore CS8603
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public static void TestIteratorForEach()
var tokens = new StorageMap(Storage.CurrentContext, 3).Find(FindOptions.KeysOnly | FindOptions.RemovePrefix);
foreach (var item in tokens)
{
Runtime.Log(item.ToString());
Runtime.Log(item.ToString()!);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Person
public int Age { get; }
public string Address { get; init; }

#pragma warning disable CS8618
public Person(string name, int age)
{
Name = name;
Expand All @@ -60,5 +61,6 @@ public Person(string name, int age)
public Person()
{
}
#pragma warning restore CS8618
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Neo.Compiler.CSharp.TestContracts
{
#pragma warning disable CS8625
public class Contract_Reentrancy : SmartContract.Framework.SmartContract
{
public static void HasReentrancy()
Expand Down Expand Up @@ -50,5 +51,6 @@ public static void NoReentrancyByAttribute()
{
HasReentrancyFromSingleBasicBlock();
}
#pragma warning restore CS8625
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Neo.Compiler.CSharp.TestContracts
public class Contract_StaticByteArray : SmartContract.Framework.SmartContract
{
[DisplayName("TestEvent")]
#pragma warning disable CS0067 // Event is never used
#pragma warning disable CS0067, CS0414 // Event is never used
public static event Action<byte[]> OnEvent = default!;
#pragma warning restore CS0067 // Event is never used
#pragma warning restore CS0067, CS0414 // Event is never used

static byte[] NeoToken = new byte[] { 0x89, 0x77, 0x20, 0xd8, 0xcd, 0x76, 0xf4, 0xf0, 0x0a, 0xbf, 0xa3, 0x7c, 0x0e, 0xdd, 0x88, 0x9c, 0x20, 0x8f, 0xde, 0x9b };

Expand Down
2 changes: 2 additions & 0 deletions tests/Neo.Compiler.CSharp.TestContracts/Contract_Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ public static object Call(UInt160 scriptHash, string method, CallFlags flag, obj
return Contract.Call(scriptHash, method, flag, args);
}

#pragma warning disable CS8625
public static object Create(byte[] nef, string manifest)
{
return ContractManagement.Deploy((ByteString)nef, manifest, null);
}
#pragma warning restore CS8625
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>CS0067;CS8981</NoWarn> <!-- disable CS0067(event is never used) -->
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public static object Call(UInt160 scriptHash, string method, CallFlags flag, obj
return Contract.Call(scriptHash, method, flag, args);
}

#pragma warning disable CS8625
public static object Create(byte[] nef, string manifest)
{
return ContractManagement.Deploy((ByteString)nef, manifest, null);
}
#pragma warning restore CS8625

public static int GetCallFlags()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public static object GetContractHashes()
return iter.Value.Item2;
}

#pragma warning disable CS8625
public static void Update(byte[] nef, string manifest)
{
ContractManagement.Update((ByteString)nef, manifest, null);
}
#pragma warning restore CS8625

public static void Destroy()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public static int NEO_Decimals()
return NEO.Decimals;
}

#pragma warning disable CS8625
[DisplayName("NEO_Transfer")]
public static bool NEO_Transfer(UInt160 from, UInt160 to, BigInteger amount)
{
return NEO.Transfer(from, to, amount, null);
}
#pragma warning restore CS8625

[DisplayName("NEO_BalanceOf")]
public static BigInteger NEO_BalanceOf(UInt160 account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static bool BigIntegerNullableEqualNull(BigInteger? a)
return a == null && !a.HasValue;
}

#pragma warning disable CS8602
public static bool H160NullableNotEqual(UInt160 a, UInt160? b)
{
return a != b && !a.Equals(b) && !b.Equals(a) && b != a;
Expand All @@ -35,6 +36,7 @@ public static bool H256NullableNotEqual(UInt256 a, UInt256? b)
{
return a != b && !a.Equals(b) && !b.Equals(a) && b != a;
}
#pragma warning restore CS8602

public static bool H256NullableEqual(UInt256 a, UInt256? b)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static void Put(string message)
Data.Put(message, 1);
}

#pragma warning disable CS8604
public static BigInteger Get(string msg)
{
return (BigInteger)Data.Get(msg);
Expand Down Expand Up @@ -51,5 +52,6 @@ public static BigInteger teststoragemap_Getbyteprefix(byte x)
var store = new StorageMap(Storage.CurrentContext, x);
return (BigInteger)store.Get("test1");
}
#pragma warning restore CS8604
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Neo.SmartContract.Framework.UnitTests.TestClasses
{

#pragma warning disable CS8604
public class Contract_Storage : SmartContract
{
// There is no main here, it can be auto generation.
Expand Down Expand Up @@ -177,7 +179,7 @@ public static int SerializeTest(byte[] key, int value)
var storage = new StorageMap(context, prefix);
var val = new Value() { Val = value };
storage.PutObject(key, val);
val = (Value)storage.GetObject(key);
val = (Value)storage.GetObject(key)!;
return val.Val;
}

Expand Down Expand Up @@ -218,4 +220,5 @@ public static byte[] TestIndexGet(byte[] key)

#endregion
}
#pragma warning restore CS8604
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>CS0067</NoWarn> <!-- disable CS0067(event is never used) -->
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>CS0067</NoWarn> <!-- disable CS0067(event is never used) -->
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit c6fcf9d

Please sign in to comment.