Skip to content

Commit

Permalink
Add entries to Designation event (#3397)
Browse files Browse the repository at this point in the history
* Add entries to Designation event

* Change to HF_Echidna

* Add UT

* Add count
  • Loading branch information
shargon committed Aug 8, 2024
1 parent bcc5fd0 commit e63f10b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
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.SnapshotCache.Add(key, new StorageItem(list));
engine.SendNotification(Hash, "Designation", new VM.Types.Array(engine.ReferenceCounter, new StackItem[] { (int)role, engine.PersistingBlock.Index }));

Check warning on line 81 in src/Neo/SmartContract/Native/RoleManagement.cs

View workflow job for this annotation

GitHub Actions / Format

Fix formatting
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

0 comments on commit e63f10b

Please sign in to comment.