neo icon indicating copy to clipboard operation
neo copied to clipboard

[UT] - Add unit tests in NeoSystem

Open ajara87 opened this issue 9 months ago • 5 comments

Description

Increasing test coverage for NeoSystem by adding new unit tests. New tests were added because many methods or branches were previously untested.

  • TestAddAndGetService. Add a new service and retrieve it to verify that is the same value. This test targets the AddService method (previosly untested) and GetService without a filter. [Coverage: 100% of AddService and 50% of GetService]
  • TestGetServiceWithFilter. Adds two new service and retrieve one using a filter to test the filtered version of GetService. [Coverage: 100% of AddService, remaining 50% of GetService]
  • TestResumeNodeStartup. Tests two branches of ResumeNodeStartup: one where more then one node is suspended and another where only one node is suspended. [Coverage: 66% of ResumeNodeStartup]
  • TestStartNodeWhenNoSuspended. Test StarNode method when there are not suspended nodes. [Coverage 50% of StartNode]
  • TestStartNodeWhenSuspended. Test StarNode method when there are suspended nodes. [Coverage: Ramaining 50% of StartNode and final 33% of ResumeNodeStartup]
  • TestEnsureStoppedStopsActor. Test EnsureStopped method to confirm it completes without throwing exceptions [Coverage 100% of EnsureStopped]
  • TestContainsTransactionNotExist. Test ContainsTransaction when the transaction doesn't exists [Coverage: 33% of ContainsTransaction]

Fixes # (issue)

Type of change

  • [ ] Optimization (the change is only an optimization)
  • [ ] Style (the change is only a code style for better maintenance or standard purpose)
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

How Has This Been Tested?

  • [x] TestAddAndGetService
  • [x] TestGetServiceWithFilter
  • [x] TestResumeNodeStartup
  • [x] TestStartNodeWhenNoSuspended
  • [x] TestStartNodeWhenSuspended
  • [x] TestEnsureStoppedStopsActor
  • [x] TestContainsTransactionNotExist

Test Configuration:

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [ ] Any dependent changes have been merged and published in downstream modules

ajara87 avatar Jun 02 '25 20:06 ajara87

need explaination why adding these uts, to make sure these uts are not duplicate

Jim8y avatar Jun 04 '25 01:06 Jim8y

need explaination why adding these uts, to make sure these uts are not duplicate

Added more explanation

ajara87 avatar Jun 10 '25 18:06 ajara87

/_/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs(75): error test failed: TestSetAndGet (58ms): Assert.AreEqual failed. Expected:<1>. Actual:<2>.  [/home/runner/work/neo/neo/tests/Neo.UnitTests/Neo.UnitTests.csproj]
/_/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs(75): error test failed: Stack Trace: [/home/runner/work/neo/neo/tests/Neo.UnitTests/Neo.UnitTests.csproj]
/_/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs(75): error test failed:    at Neo.UnitTests.SmartContract.Native.UT_RoleManagement.TestSetAndGet() in /_/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs:line 75 [/home/runner/work/neo/neo/tests/Neo.UnitTests/Neo.UnitTests.csproj]
/_/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs(75): error test failed:    at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) [/home/runner/work/neo/neo/tests/Neo.UnitTests/Neo.UnitTests.csproj]
/_/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs(75): error test failed:    at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) [/home/runner/work/neo/neo/tests/Neo.UnitTests/Neo.UnitTests.csproj]
/_/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs(75): error test failed:  [/home/runner/work/neo/neo/tests/Neo.UnitTests/Neo.UnitTests.csproj]
/_/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs(75): error test failed:  [/home/runner/work/neo/neo/tests/Neo.UnitTests/Neo.UnitTests.csproj]
  Failed! - Failed: 1, Passed: 910, Skipped: 0, Total: 911, Duration: 1m 03s 066ms
/home/runner/work/neo/neo/bin/tests/Neo.UnitTests/net9.0/Neo.UnitTests.dll : error run failed: Tests failed: '/home/runner/work/neo/neo/bin/tests/Neo.UnitTests/net9.0/TestResults/Neo.UnitTests_net9.0_x64.log' [net9.0|x64] [/home/runner/work/neo/neo/tests/Neo.UnitTests/Neo.UnitTests.csproj]
Error: Process completed with exit code 1.

Jim8y avatar Jun 19 '25 03:06 Jim8y

I'm reviewing it because it's failing in a unit test that hasn't been modified in this PR, and this PR only contains unit tests. There are no logic changes.

ajara87 avatar Jun 21 '25 10:06 ajara87

Wait for https://github.com/neo-project/neo/pull/4016

shargon avatar Jun 24 '25 17:06 shargon

@ajara87 could you update the pr?

shargon avatar Jun 28 '25 12:06 shargon

Please resolve conflicts.

Wi1l-B0t avatar Jun 28 '25 16:06 Wi1l-B0t