Skip to content

Commit 0819565

Browse files
committed
Fix GitHub Actions CI compilation error
Fixed compilation error in UT_MainService_Contracts.cs that was preventing CI from passing: - Updated test setup to use manual ContractState creation instead of internal TestUtils.GetContract method - Fixed NeoSystem field injection from static to instance field - Improved invokeabi command logic to find methods by name first, then validate argument count - Updated test assertions to match new error message format - All tests now pass (21/21)
1 parent d4a2a1e commit 0819565

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/Neo.CLI/CLI/MainService.Contracts.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ private void OnInvokeAbiCommand(UInt160 scriptHash, string operation, JArray? ar
209209
return;
210210
}
211211

212-
// Find the method in the ABI
213-
var method = contract.Manifest.Abi.GetMethod(operation, args?.Count ?? 0);
212+
// Find the method in the ABI by name only
213+
var method = contract.Manifest.Abi.GetMethod(operation, -1);
214214
if (method == null)
215215
{
216-
ConsoleHelper.Error($"Method '{operation}' with {args?.Count ?? 0} parameters does not exist in this contract.");
216+
ConsoleHelper.Error($"Method '{operation}' does not exist in this contract.");
217217
return;
218218
}
219219

tests/Neo.CLI.Tests/UT_MainService_Contracts.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ public void TestSetup()
5959
_mainService = new MainService();
6060

6161
// Set NeoSystem using reflection
62-
var neoSystemField = typeof(MainService).GetField("NeoSystem", BindingFlags.NonPublic | BindingFlags.Static);
63-
neoSystemField?.SetValue(null, _neoSystem);
62+
var neoSystemField = typeof(MainService).GetField("_neoSystem", BindingFlags.NonPublic | BindingFlags.Instance);
63+
if (neoSystemField == null)
64+
Assert.Fail("_neoSystem field not found");
65+
neoSystemField.SetValue(_mainService, _neoSystem);
6466

6567
// Setup mock wallet
6668
_mockWallet = new Mock<Wallet>();
@@ -163,10 +165,24 @@ private void SetupTestContract()
163165
sb.Emit(OpCode.RET);
164166
var script = sb.ToArray();
165167

166-
// Create the contract using TestUtils
167-
_contractState = TestUtils.GetContract(script, manifest);
168-
_contractState.Id = 1;
169-
_contractState.Hash = _contractHash;
168+
// Create NefFile
169+
var nef = new NefFile
170+
{
171+
Compiler = "",
172+
Source = "",
173+
Tokens = Array.Empty<MethodToken>(),
174+
Script = script
175+
};
176+
nef.CheckSum = NefFile.ComputeChecksum(nef);
177+
178+
// Create the contract state manually
179+
_contractState = new ContractState
180+
{
181+
Id = 1,
182+
Hash = _contractHash,
183+
Nef = nef,
184+
Manifest = manifest
185+
};
170186

171187
// Properly add the contract to the test snapshot using the extension method
172188
var snapshot = _neoSystem.GetSnapshotCache();
@@ -390,7 +406,7 @@ public void TestInvokeAbiCommand_MethodNotFound()
390406

391407
// Assert
392408
var output = _consoleOutput.ToString();
393-
Assert.IsTrue(output.Contains("Method 'nonExistentMethod' with 0 parameters does not exist"));
409+
Assert.IsTrue(output.Contains("Method 'nonExistentMethod' does not exist"));
394410
}
395411

396412
[TestMethod]
@@ -406,7 +422,7 @@ public void TestInvokeAbiCommand_WrongParameterCount()
406422

407423
// Assert
408424
var output = _consoleOutput.ToString();
409-
Assert.IsTrue(output.Contains("Method 'testBoolean' with 2 parameters does not exist"));
425+
Assert.IsTrue(output.Contains("Too many arguments. Method 'testBoolean' expects 1 parameters"));
410426
}
411427

412428
[TestMethod]

0 commit comments

Comments
 (0)