forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add role designation history (neo-project#2007)
* record historical designation * fix ut * sort * Remove sort * use different key * fix some * Store it as BiEndian * avoid in same block * Optimize * use findrange * optimize index get * Erik's feedback * Fix UT * fix empty sequence * optimize height * fix ut * index * fix ut Co-authored-by: Luchuan <luchuan@ngd.neo.org> Co-authored-by: Shargon <shargon@gmail.com> Co-authored-by: Erik Zhang <erik@neo.org>
- Loading branch information
1 parent
d3d26b1
commit b021100
Showing
5 changed files
with
95 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
tests/neo.UnitTests/SmartContract/Native/UT_DesignateContract.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Cryptography.ECC; | ||
using Neo.IO; | ||
using Neo.Ledger; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.SmartContract; | ||
using Neo.SmartContract.Native; | ||
using Neo.SmartContract.Native.Designate; | ||
using Neo.UnitTests.Extensions; | ||
using System.Linq; | ||
using System.Numerics; | ||
|
||
namespace Neo.UnitTests.SmartContract.Native | ||
{ | ||
[TestClass] | ||
public class UT_DesignateContract | ||
{ | ||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
TestBlockchain.InitializeMockNeoSystem(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestSetAndGet() | ||
{ | ||
using var snapshot1 = Blockchain.Singleton.GetSnapshot(); | ||
snapshot1.PersistingBlock = new Block | ||
{ | ||
Index = 0, | ||
}; | ||
UInt160 committeeMultiSigAddr = NativeContract.NEO.GetCommitteeAddress(snapshot1); | ||
ECPoint[] validators = NativeContract.NEO.ComputeNextBlockValidators(snapshot1); | ||
var ret = NativeContract.Designate.Call( | ||
snapshot1, | ||
new Nep5NativeContractExtensions.ManualWitness(committeeMultiSigAddr), | ||
"designateAsRole", | ||
new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger((int)Role.StateValidator) }, | ||
new ContractParameter(ContractParameterType.Array) { Value = validators.Select(p => new ContractParameter(ContractParameterType.ByteArray) { Value = p.ToArray() }).ToList() } | ||
); | ||
snapshot1.Commit(); | ||
using var snapshot2 = Blockchain.Singleton.GetSnapshot(); | ||
ret = NativeContract.Designate.Call( | ||
snapshot2, | ||
"getDesignatedByRole", | ||
new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger((int)Role.StateValidator) }, | ||
new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger(1u) } | ||
); | ||
ret.Should().BeOfType<VM.Types.Array>(); | ||
(ret as VM.Types.Array).Count.Should().Be(7); | ||
(ret as VM.Types.Array)[0].GetSpan().ToHexString().Should().Be(validators[0].ToArray().ToHexString()); | ||
(ret as VM.Types.Array)[1].GetSpan().ToHexString().Should().Be(validators[1].ToArray().ToHexString()); | ||
(ret as VM.Types.Array)[2].GetSpan().ToHexString().Should().Be(validators[2].ToArray().ToHexString()); | ||
(ret as VM.Types.Array)[3].GetSpan().ToHexString().Should().Be(validators[3].ToArray().ToHexString()); | ||
(ret as VM.Types.Array)[4].GetSpan().ToHexString().Should().Be(validators[4].ToArray().ToHexString()); | ||
(ret as VM.Types.Array)[5].GetSpan().ToHexString().Should().Be(validators[5].ToArray().ToHexString()); | ||
(ret as VM.Types.Array)[6].GetSpan().ToHexString().Should().Be(validators[6].ToArray().ToHexString()); | ||
|
||
ret = NativeContract.Designate.Call( | ||
snapshot2, | ||
"getDesignatedByRole", | ||
new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger((int)Role.StateValidator) }, | ||
new ContractParameter(ContractParameterType.Integer) { Value = new BigInteger(0) } | ||
); | ||
ret.Should().BeOfType<VM.Types.Array>(); | ||
(ret as VM.Types.Array).Count.Should().Be(0); | ||
} | ||
} | ||
} |