Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entries to Designation event #3397

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/Neo/Hardfork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum Hardfork : byte
HF_Aspidochelone,
HF_Basilisk,
HF_Cockatrice,
HF_Domovoi
HF_Domovoi,
HF_Echidna
}
}
24 changes: 22 additions & 2 deletions src/Neo/SmartContract/Native/RoleManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ public sealed class RoleManagement : NativeContract
{
[ContractEvent(0, name: "Designation",
"Role", ContractParameterType.Integer,
"BlockIndex", ContractParameterType.Integer)]
"BlockIndex", ContractParameterType.Integer,
Hardfork.HF_Echidna)]

[ContractEvent(Hardfork.HF_Echidna, 0, name: "Designation",
"Role", ContractParameterType.Integer,
"BlockIndex", ContractParameterType.Integer,
"Old", ContractParameterType.Array,
"New", ContractParameterType.Array
)]

internal RoleManagement() : base() { }

/// <summary>
Expand Down Expand Up @@ -69,7 +78,18 @@ private void DesignateAsRole(ApplicationEngine engine, Role role, ECPoint[] node
list.AddRange(nodes);
list.Sort();
engine.Snapshot.Add(key, new StorageItem(list));
engine.SendNotification(Hash, "Designation", new VM.Types.Array(engine.ReferenceCounter, new StackItem[] { (int)role, engine.PersistingBlock.Index }));

if (engine.IsHardforkEnabled(Hardfork.HF_Echidna))
{
var oldNodes = new VM.Types.Array(engine.ReferenceCounter, GetDesignatedByRole(engine.Snapshot, role, index - 1).Select(u => (ByteString)u.EncodePoint(true)));
var newNodes = new VM.Types.Array(engine.ReferenceCounter, nodes.Select(u => (ByteString)u.EncodePoint(true)));

engine.SendNotification(Hash, "Designation", new VM.Types.Array(engine.ReferenceCounter, [(int)role, engine.PersistingBlock.Index, oldNodes, newNodes]));
}
else
{
engine.SendNotification(Hash, "Designation", new VM.Types.Array(engine.ReferenceCounter, [(int)role, engine.PersistingBlock.Index]));
}
}

private class NodeList : InteroperableList<ECPoint>
Expand Down
18 changes: 18 additions & 0 deletions tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ public void TestActiveDeprecatedIn()
Assert.IsFalse(NativeContract.IsActive(new active() { ActiveIn = null, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 20));
}

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

var before = NativeContract.RoleManagement.GetContractState(settings.IsHardforkEnabled, 19);
var after = NativeContract.RoleManagement.GetContractState(settings.IsHardforkEnabled, 20);

Assert.AreEqual(2, before.Manifest.Abi.Events[0].Parameters.Length);
Assert.AreEqual(1, before.Manifest.Abi.Events.Length);
Assert.AreEqual(4, after.Manifest.Abi.Events[0].Parameters.Length);
Assert.AreEqual(1, after.Manifest.Abi.Events.Length);
}

[TestMethod]
public void TestGetContract()
{
Expand Down
Loading