Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6abf167
Added ApplicationLogs Tests
cschuchardt88 Jun 17, 2024
86acb72
Fixed pathing and naming
cschuchardt88 Jun 17, 2024
965be9c
Merge branch 'master' into add/tests/applicationlogs
cschuchardt88 Jun 18, 2024
e477abb
Merge branch 'master' into add/tests/applicationlogs
NGDAdmin Jun 20, 2024
2d101f8
Merge branch 'master' into add/tests/applicationlogs
cschuchardt88 Jun 24, 2024
f704e20
Merged `Part-2`
cschuchardt88 Jun 24, 2024
56d438d
Fixed Test for `Test_Put_Get_NotifyState_Storage`
cschuchardt88 Jun 24, 2024
e27945d
Merge branch 'master' into add/tests/applicationlogs
cschuchardt88 Jul 1, 2024
115bede
Merge branch 'master' into add/tests/applicationlogs
cschuchardt88 Jul 3, 2024
ba910bf
Merge branch 'master' into add/tests/applicationlogs
cschuchardt88 Jul 5, 2024
b3b06c7
Merge branch 'master' into add/tests/applicationlogs
shargon Jul 5, 2024
2d43b89
Merge branch 'master' into add/tests/applicationlogs
shargon Jul 5, 2024
fff1be2
Merge branch 'master' into add/tests/applicationlogs
Jul 16, 2024
103de9e
Merge branch 'master' into add/tests/applicationlogs
cschuchardt88 Jul 16, 2024
fbd3943
Merge branch 'master' into add/tests/applicationlogs
cschuchardt88 Jul 17, 2024
59da6cd
Merge branch 'master' into add/tests/applicationlogs
NGDAdmin Jul 17, 2024
075389d
Merge branch 'master' into add/tests/applicationlogs
Jul 23, 2024
95af1c4
Merge branch 'master' into add/tests/applicationlogs
NGDAdmin Jul 23, 2024
0e83b02
Merge branch 'master' into add/tests/applicationlogs
cschuchardt88 Jul 23, 2024
dce6933
Merge branch 'master' into add/tests/applicationlogs
NGDAdmin Jul 23, 2024
77bf53f
Merge branch 'master' into add/tests/applicationlogs
NGDAdmin Jul 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:
dotnet test ./tests/Neo.Plugins.OracleService.Tests --output ./bin/tests/Neo.Plugins.OracleService.Tests
dotnet test ./tests/Neo.Plugins.RpcServer.Tests --output ./bin/tests/Neo.Plugins.RpcServer.Tests
dotnet test ./tests/Neo.Plugins.Storage.Tests --output ./bin/tests/Neo.Plugins.Storage.Tests
dotnet test ./tests/Neo.Plugins.ApplicationLogs.Tests --output ./bin/tests/Neo.Plugins.ApplicationLogs.Tests

- name: Coveralls
if: matrix.os == 'ubuntu-latest'
Expand All @@ -104,6 +105,7 @@ jobs:
${{ github.workspace }}/tests/Neo.Plugins.OracleService.Tests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.Plugins.RpcServer.Tests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.Plugins.Storage.Tests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.Plugins.ApplicationLogs.Tests/TestResults/coverage.info

PublishPackage:
if: github.ref == 'refs/heads/master' && startsWith(github.repository, 'neo-project/')
Expand Down
7 changes: 7 additions & 0 deletions neo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TokensTracker", "src\Plugin
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcClient", "src\Plugins\RpcClient\RpcClient.csproj", "{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.ApplicationLogs.Tests", "tests\Neo.Plugins.ApplicationLogs.Tests\Neo.Plugins.ApplicationLogs.Tests.csproj", "{8C866DC8-2E55-4399-9563-2F47FD4602EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -216,6 +218,10 @@ Global
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0}.Release|Any CPU.Build.0 = Release|Any CPU
{8C866DC8-2E55-4399-9563-2F47FD4602EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C866DC8-2E55-4399-9563-2F47FD4602EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C866DC8-2E55-4399-9563-2F47FD4602EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C866DC8-2E55-4399-9563-2F47FD4602EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -255,6 +261,7 @@ Global
{FF76D8A4-356B-461A-8471-BC1B83E57BBC} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{5E4947F3-05D3-4806-B0F3-30DAC71B5986} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{185ADAFC-BFC6-413D-BC2E-97F9FB0A8AF0} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{8C866DC8-2E55-4399-9563-2F47FD4602EC} = {7F257712-D033-47FF-B439-9D4320D06599}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCBA19D9-F868-4C6D-8061-A2B91E06E3EC}
Expand Down
5 changes: 5 additions & 0 deletions src/Plugins/ApplicationLogs/ApplicationLogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<None Update="ApplicationLogs.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="$(PackageId).Tests" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Neo.Plugins.ApplicationsLogs.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Plugins\ApplicationLogs\ApplicationLogs.csproj" />
<ProjectReference Include="..\..\src\Plugins\RocksDBStore\RocksDBStore.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// PutTestTransactionEngineState.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.Persistence;
using Neo.Plugins.ApplicationLogs.Store;
using Neo.Plugins.ApplicationLogs.Store.States;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Xunit.Sdk;

namespace Neo.Plugins.ApplicationsLogs.Tests.Setup
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class InsertTransactionEngineState : BeforeAfterTestAttribute
{
private readonly ISnapshot _snapshot;
private readonly Guid _expectedGuid;
private readonly UInt256 _expectedBlockHash;

public InsertTransactionEngineState(
string logId,
string blockHash)
{
_expectedGuid = Guid.Parse(logId);
_expectedBlockHash = UInt256.Parse(blockHash);
_snapshot = TestStorage.Store.GetSnapshot();
}

public override void Before(MethodInfo methodUnderTest)
{
using var lss = new LogStorageStore(_snapshot);
lss.PutTransactionEngineState(_expectedBlockHash, TransactionEngineLogState.Create([_expectedGuid]));
_snapshot.Commit();
}

public override void After(MethodInfo methodUnderTest)
{
_snapshot.Dispose();
}
}
}
31 changes: 31 additions & 0 deletions tests/Neo.Plugins.ApplicationLogs.Tests/Setup/TestStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// StorageFixture.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.Persistence;
using Neo.Plugins.ApplicationLogs.Store;
using Neo.Plugins.Storage;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Neo.Plugins.ApplicationsLogs.Tests.Setup
{
public class TestStorage
{
private static readonly string s_dirPath = Path.GetRandomFileName();
private static readonly RocksDBStore rocksDbStore = new RocksDBStore();
public static readonly IStore Store = rocksDbStore.GetStore(s_dirPath);
}
}
81 changes: 81 additions & 0 deletions tests/Neo.Plugins.ApplicationLogs.Tests/UT_LogStorageStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// UT_LogStorageStore.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.Persistence;
using Neo.Plugins.ApplicationLogs.Store;
using Neo.Plugins.ApplicationLogs.Store.States;
using Neo.Plugins.ApplicationsLogs.Tests.Setup;
using Neo.SmartContract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Neo.Plugins.ApplicationsLogs.Tests
{
public class UT_LogStorageStore
{
[Theory]
[InlineData(TriggerType.OnPersist, "0x0000000000000000000000000000000000000000000000000000000000000001")]
[InlineData(TriggerType.Application, "0x0000000000000000000000000000000000000000000000000000000000000002")]
[InlineData(TriggerType.PostPersist, "0x0000000000000000000000000000000000000000000000000000000000000003")]
public void Test_Put_Get_BlockState_Storage(TriggerType trigger, string blockHash)
{
var expectedGuid = Guid.NewGuid();
var expectedHash = UInt256.Parse(blockHash);

using (var snapshot = TestStorage.Store.GetSnapshot())
{
using (var lss = new LogStorageStore(snapshot))
{
// Put Block States in Storage for each Trigger
lss.PutBlockState(expectedHash, trigger, BlockLogState.Create([expectedGuid]));
// Commit Data to "Store" Storage for Lookup
snapshot.Commit();
}
}

// The Current way that ISnapshot Works we need to Create New Instance of LogStorageStore
using (var lss = new LogStorageStore(TestStorage.Store.GetSnapshot()))
{
// Get OnPersist Block State from Storage
lss.TryGetBlockState(expectedHash, trigger, out var actualState);

Assert.NotNull(actualState);
Assert.NotNull(actualState.NotifyLogIds);
Assert.Single(actualState.NotifyLogIds);
Assert.Equal(expectedGuid, actualState.NotifyLogIds[0]);
}
}

[Theory]
[InlineData("00000000-0000-0000-0000-000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001")]
[InsertTransactionEngineState("00000000-0000-0000-0000-000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001")]
public void Test_Put_Get_TransactionEngineState_Storage(string expectedLogId, string expectedHashString)
{
var expectedGuid = Guid.Parse(expectedLogId);
var expectedHash = UInt256.Parse(expectedHashString);

using (var lss = new LogStorageStore(TestStorage.Store.GetSnapshot()))
{
// Get OnPersist Block State from Storage
lss.TryGetTransactionEngineState(expectedHash, out var actualState);

Assert.NotNull(actualState);
Assert.NotNull(actualState.LogIds);
Assert.Single(actualState.LogIds);
Assert.Equal(expectedGuid, actualState.LogIds[0]);
}
}
}
}