diff --git a/tests/neo.UnitTests/SmartContract/UT_InteropService.cs b/tests/neo.UnitTests/SmartContract/UT_InteropService.cs index 399f063ec7..5b83133e37 100644 --- a/tests/neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/tests/neo.UnitTests/SmartContract/UT_InteropService.cs @@ -55,7 +55,7 @@ public void Runtime_GetNotifications_Test() snapshot.Contracts.Add(scriptHash2, new ContractState() { Script = script.ToArray(), - Manifest = TestUtils.CreateDefaultManifest(scriptHash2, "test"), + Manifest = TestUtils.CreateManifest(scriptHash2, "test", ContractParameterType.Any, ContractParameterType.Integer, ContractParameterType.Integer), }); } @@ -223,7 +223,7 @@ public void TestExecutionEngine_GetCallingScriptHash() var contract = new ContractState() { - Manifest = TestUtils.CreateDefaultManifest(scriptA.ToArray().ToScriptHash(), "test"), + Manifest = TestUtils.CreateManifest(scriptA.ToArray().ToScriptHash(), "test", ContractParameterType.Any, ContractParameterType.Integer, ContractParameterType.Integer), Script = scriptA.ToArray() }; engine = GetEngine(true, true, false); @@ -600,10 +600,10 @@ public void TestStorageContext_AsReadOnly() public void TestContract_Call() { var snapshot = Blockchain.Singleton.GetSnapshot(); - var state = TestUtils.GetContract("method"); - state.Manifest.Features = ContractFeatures.HasStorage; string method = "method"; var args = new VM.Types.Array { 0, 1 }; + var state = TestUtils.GetContract(method, args.Count); + state.Manifest.Features = ContractFeatures.HasStorage; snapshot.Contracts.Add(state.ScriptHash, state); var engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0, true); @@ -627,12 +627,12 @@ public void TestContract_CallEx() { var snapshot = Blockchain.Singleton.GetSnapshot(); - var state = TestUtils.GetContract("method"); + string method = "method"; + var args = new VM.Types.Array { 0, 1 }; + var state = TestUtils.GetContract(method, args.Count); state.Manifest.Features = ContractFeatures.HasStorage; snapshot.Contracts.Add(state.ScriptHash, state); - string method = "method"; - var args = new VM.Types.Array { 0, 1 }; foreach (var flags in new CallFlags[] { CallFlags.None, CallFlags.AllowCall, CallFlags.AllowModifyStates, CallFlags.All }) { diff --git a/tests/neo.UnitTests/SmartContract/UT_SmartContractHelper.cs b/tests/neo.UnitTests/SmartContract/UT_SmartContractHelper.cs index 3677041aa2..0f4e9f5f74 100644 --- a/tests/neo.UnitTests/SmartContract/UT_SmartContractHelper.cs +++ b/tests/neo.UnitTests/SmartContract/UT_SmartContractHelper.cs @@ -139,7 +139,7 @@ public void TestVerifyWitnesses() Header header3 = new Header() { PrevHash = index3, Witness = new Witness { VerificationScript = new byte[0] } }; snapshot3.Contracts.Add(UInt160.Zero, new ContractState() { - Manifest = TestUtils.CreateDefaultManifest(UInt160.Zero, "verify"), + Manifest = TestUtils.CreateManifest(UInt160.Zero, "verify", ContractParameterType.Boolean, ContractParameterType.Signature), }); Assert.AreEqual(false, Neo.SmartContract.Helper.VerifyWitnesses(header3, snapshot3, 100)); } diff --git a/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs b/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs index 848079aef3..96b2ac0345 100644 --- a/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs +++ b/tests/neo.UnitTests/SmartContract/UT_Syscalls.cs @@ -339,9 +339,9 @@ public void System_Runtime_GetInvocationCounter() contracts.Delete(contractA.ScriptHash); contracts.Delete(contractB.ScriptHash); contracts.Delete(contractC.ScriptHash); - contractA.Manifest = TestUtils.CreateDefaultManifest(contractA.ScriptHash, "dummyMain"); - contractB.Manifest = TestUtils.CreateDefaultManifest(contractA.ScriptHash, "dummyMain"); - contractC.Manifest = TestUtils.CreateDefaultManifest(contractA.ScriptHash, "dummyMain"); + contractA.Manifest = TestUtils.CreateManifest(contractA.ScriptHash, "dummyMain", ContractParameterType.Any, ContractParameterType.Integer, ContractParameterType.Integer); + contractB.Manifest = TestUtils.CreateManifest(contractA.ScriptHash, "dummyMain", ContractParameterType.Any, ContractParameterType.Integer, ContractParameterType.Integer); + contractC.Manifest = TestUtils.CreateManifest(contractA.ScriptHash, "dummyMain", ContractParameterType.Any, ContractParameterType.Integer, ContractParameterType.Integer); contracts.Add(contractA.ScriptHash, contractA); contracts.Add(contractB.ScriptHash, contractB); contracts.Add(contractC.ScriptHash, contractC); diff --git a/tests/neo.UnitTests/TestUtils.cs b/tests/neo.UnitTests/TestUtils.cs index fd8e6fd620..ef380908dd 100644 --- a/tests/neo.UnitTests/TestUtils.cs +++ b/tests/neo.UnitTests/TestUtils.cs @@ -17,7 +17,7 @@ public static class TestUtils { public static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism - public static ContractManifest CreateDefaultManifest(UInt160 hash, string method = null) + public static ContractManifest CreateDefaultManifest(UInt160 hash) { return new ContractManifest() { @@ -26,15 +26,7 @@ public static ContractManifest CreateDefaultManifest(UInt160 hash, string method { Hash = hash, Events = new ContractEventDescriptor[0], - Methods = method == null ? new ContractMethodDescriptor[0] : new ContractMethodDescriptor[] - { - new ContractMethodDescriptor() - { - Name = method, - Parameters = new ContractParameterDefinition[0], - ReturnType = ContractParameterType.Integer - } - } + Methods = new ContractMethodDescriptor[0] }, Features = ContractFeatures.NoProperty, Groups = new ContractGroup[0], @@ -44,6 +36,25 @@ public static ContractManifest CreateDefaultManifest(UInt160 hash, string method }; } + public static ContractManifest CreateManifest(UInt160 hash, string method, ContractParameterType returnType, params ContractParameterType[] parameterTypes) + { + ContractManifest manifest = CreateDefaultManifest(hash); + manifest.Abi.Methods = new ContractMethodDescriptor[] + { + new ContractMethodDescriptor() + { + Name = method, + Parameters = parameterTypes.Select((p, i) => new ContractParameterDefinition + { + Name = $"p{i}", + Type = p + }).ToArray(), + ReturnType = returnType + } + }; + return manifest; + } + public static byte[] GetByteArray(int length, byte firstByte) { byte[] array = new byte[length]; @@ -82,13 +93,13 @@ public static Transaction GetTransaction() }; } - internal static ContractState GetContract(string method = null) + internal static ContractState GetContract(string method = "test", int parametersCount = 0) { return new ContractState { Id = 0x43000000, Script = new byte[] { 0x01, 0x01, 0x01, 0x01 }, - Manifest = CreateDefaultManifest(UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01"), method) + Manifest = CreateManifest(UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01"), method, ContractParameterType.Any, Enumerable.Repeat(ContractParameterType.Any, parametersCount).ToArray()) }; }