-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add_maxvaliduntilblockincrement_into_config
- Loading branch information
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); | ||
} | ||
} | ||
} |