Skip to content

Commit

Permalink
Added UT
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Jul 1, 2024
1 parent 0ce7b9d commit e089c26
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Neo/SmartContract/Native/ContractEventAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public ContractEventAttribute(int order, string name, string arg1Name, ContractP
ActiveIn = activeIn;
}

public ContractEventAttribute(Hardfork activeIn, int order, string name,
string arg1Name, ContractParameterType arg1Value,
string arg2Name, ContractParameterType arg2Value, Hardfork deprecatedIn) : this(activeIn, order, name, arg1Name, arg1Value, arg2Name, arg2Value)
{
DeprecatedIn = deprecatedIn;
}

public ContractEventAttribute(int order, string name,
string arg1Name, ContractParameterType arg1Value,
string arg2Name, ContractParameterType arg2Value)
Expand All @@ -90,6 +97,14 @@ public ContractEventAttribute(int order, string name, string arg1Name, ContractP
};
}

public ContractEventAttribute(int order, string name,
string arg1Name, ContractParameterType arg1Value,
string arg2Name, ContractParameterType arg2Value, Hardfork deprecatedIn) : this(order, name, arg1Name, arg1Value, arg2Name, arg2Value)
{
DeprecatedIn = deprecatedIn;
}


public ContractEventAttribute(Hardfork activeIn, int order, string name,
string arg1Name, ContractParameterType arg1Value,
string arg2Name, ContractParameterType arg2Value,
Expand Down
2 changes: 1 addition & 1 deletion src/Neo/SmartContract/Native/NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private NativeContractsCache.CacheEntry GetAllowedMethods(IsHardforkEnabledDeleg
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ContractState GetContractState(ProtocolSettings settings, uint blockHeight) => GetContractState(settings.IsHardforkEnabled, blockHeight);

private static bool IsActive(IHardforkActivable u, IsHardforkEnabledDelegate hfChecker, uint blockHeight)
internal static bool IsActive(IHardforkActivable u, IsHardforkEnabledDelegate hfChecker, uint blockHeight)
{
return // no hardfork is involved
u.ActiveIn is null && u.DeprecatedIn is null ||
Expand Down
23 changes: 23 additions & 0 deletions tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Akka.Util;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Network.P2P.Payloads;
Expand Down Expand Up @@ -58,6 +59,28 @@ public void Clean()
TestBlockchain.ResetStore();
}

class active : IHardforkActivable
{
public Hardfork? ActiveIn { get; init; }
public Hardfork? DeprecatedIn { get; init; }
}

[TestMethod]
public void TestActiveDeprecatedIn()
{
string json = UT_ProtocolSettings.CreateHKSettings("\"HF_Cockatrice\": 20");
var file = Path.GetTempFileName();
File.WriteAllText(file, json);
ProtocolSettings settings = ProtocolSettings.Load(file, false);
File.Delete(file);

Assert.IsFalse(NativeContract.IsActive(new active() { ActiveIn = Hardfork.HF_Cockatrice, DeprecatedIn = null }, settings.IsHardforkEnabled, 1));
Assert.IsTrue(NativeContract.IsActive(new active() { ActiveIn = Hardfork.HF_Cockatrice, DeprecatedIn = null }, settings.IsHardforkEnabled, 20));

Assert.IsTrue(NativeContract.IsActive(new active() { ActiveIn = null, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 1));
Assert.IsFalse(NativeContract.IsActive(new active() { ActiveIn = null, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 20));
}

[TestMethod]
public void TestGetContract()
{
Expand Down

0 comments on commit e089c26

Please sign in to comment.