Skip to content

Commit

Permalink
Fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Jun 11, 2020
1 parent eb8f03d commit 26f5c41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
24 changes: 19 additions & 5 deletions tests/neo.UnitTests/SmartContract/UT_InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ public void Runtime_GetNotifications_Test()
scriptHash2 = script.ToArray().ToScriptHash();

snapshot.Contracts.Delete(scriptHash2);
snapshot.Contracts.Add(scriptHash2, new ContractState()
var state = new ContractState()
{
Script = script.ToArray(),
Manifest = TestUtils.CreateDefaultManifest(scriptHash2, "test"),
});
};
state.Manifest.Abi.Methods[0].Parameters = new ContractParameterDefinition[]
{
new ContractParameterDefinition(){ Name="a", Type= ContractParameterType.Integer},
new ContractParameterDefinition(){ Name="b", Type= ContractParameterType.Integer}
};
snapshot.Contracts.Add(scriptHash2, state);
}

// Wrong length
Expand Down Expand Up @@ -217,8 +223,6 @@ public void TestExecutionEngine_GetCallingScriptHash()
// Test real

using ScriptBuilder scriptA = new ScriptBuilder();
scriptA.Emit(OpCode.DROP); // Drop arguments
scriptA.Emit(OpCode.DROP); // Drop method
scriptA.EmitSysCall(ApplicationEngine.System_Runtime_GetCallingScriptHash);

var contract = new ContractState()
Expand All @@ -230,7 +234,7 @@ public void TestExecutionEngine_GetCallingScriptHash()
engine.Snapshot.Contracts.Add(contract.ScriptHash, contract);

using ScriptBuilder scriptB = new ScriptBuilder();
scriptB.EmitAppCall(contract.ScriptHash, "test", 0, 1);
scriptB.EmitAppCall(contract.ScriptHash, "test");
engine.LoadScript(scriptB.ToArray());

Assert.AreEqual(VMState.HALT, engine.Execute());
Expand Down Expand Up @@ -601,6 +605,11 @@ public void TestContract_Call()
{
var snapshot = Blockchain.Singleton.GetSnapshot();
var state = TestUtils.GetContract("method");
state.Manifest.Abi.Methods[0].Parameters = new ContractParameterDefinition[]
{
new ContractParameterDefinition(){ Name="a", Type= ContractParameterType.Integer},
new ContractParameterDefinition(){ Name="b", Type= ContractParameterType.Integer}
};
state.Manifest.Features = ContractFeatures.HasStorage;
string method = "method";
var args = new VM.Types.Array { 0, 1 };
Expand Down Expand Up @@ -628,6 +637,11 @@ public void TestContract_CallEx()
var snapshot = Blockchain.Singleton.GetSnapshot();

var state = TestUtils.GetContract("method");
state.Manifest.Abi.Methods[0].Parameters = new ContractParameterDefinition[]
{
new ContractParameterDefinition(){ Name="a", Type= ContractParameterType.Integer},
new ContractParameterDefinition(){ Name="b", Type= ContractParameterType.Integer}
};
state.Manifest.Features = ContractFeatures.HasStorage;
snapshot.Contracts.Add(state.ScriptHash, state);

Expand Down
8 changes: 8 additions & 0 deletions tests/neo.UnitTests/SmartContract/UT_Syscalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ public void System_Runtime_GetInvocationCounter()
contracts.Add(contractA.ScriptHash, contractA);
contracts.Add(contractB.ScriptHash, contractB);
contracts.Add(contractC.ScriptHash, contractC);

contractA.Manifest.Abi.Methods[0].Parameters =
contractB.Manifest.Abi.Methods[0].Parameters =
contractC.Manifest.Abi.Methods[0].Parameters = new Neo.SmartContract.Manifest.ContractParameterDefinition[]
{
new Neo.SmartContract.Manifest.ContractParameterDefinition(){ Name="a", Type= ContractParameterType.Integer},
new Neo.SmartContract.Manifest.ContractParameterDefinition(){ Name="b", Type= ContractParameterType.Integer}
};
}

// Call A,B,B,C
Expand Down
8 changes: 4 additions & 4 deletions tests/neo.UnitTests/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ public static ContractManifest CreateDefaultManifest(UInt160 hash, string method
Abi = new ContractAbi()
{
Hash = hash,
Events = new ContractEventDescriptor[0],
Methods = method == null ? new ContractMethodDescriptor[0] : new ContractMethodDescriptor[]
Events = Array.Empty<ContractEventDescriptor>(),
Methods = method == null ? Array.Empty<ContractMethodDescriptor>() : new ContractMethodDescriptor[]
{
new ContractMethodDescriptor()
{
Name = method,
Parameters = new ContractParameterDefinition[0],
Parameters = Array.Empty<ContractParameterDefinition>(),
ReturnType = ContractParameterType.Integer
}
}
},
Features = ContractFeatures.NoProperty,
Groups = new ContractGroup[0],
Groups = Array.Empty<ContractGroup>(),
SafeMethods = WildcardContainer<string>.Create(),
Trusts = WildcardContainer<UInt160>.Create(),
Extra = null,
Expand Down

0 comments on commit 26f5c41

Please sign in to comment.