Skip to content

Commit

Permalink
Merge branch 'master' into fix/neo-projects
Browse files Browse the repository at this point in the history
  • Loading branch information
cschuchardt88 authored Feb 15, 2025
2 parents 6bdfc41 + 251cb6d commit 247e04e
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 96 deletions.
54 changes: 22 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:

env:
DOTNET_VERSION: 9.0.x
COVERLET_EXCLUDE_COVERAGE: -p:Exclude="[Neo.UnitTests]*"

jobs:

Expand Down Expand Up @@ -39,7 +38,7 @@ jobs:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Build (Everything)
run: dotnet build -p:GITHUB_ACTIONS=true
run: dotnet build --disable-parallel -p:GITHUB_ACTIONS=true

- name: Install dependencies
run: |
Expand Down Expand Up @@ -70,53 +69,44 @@ jobs:
run: |
brew install leveldb
brew install gperftools
dotnet build -p:GITHUB_ACTIONS=true
dotnet build --disable-parallel -p:GITHUB_ACTIONS=true
dotnet test --no-build -p:GITHUB_ACTIONS=true
- name: Test (windows)
if: matrix.os == 'windows-latest'
run: |
dotnet build -p:GITHUB_ACTIONS=true
dotnet build --disable-parallel -p:GITHUB_ACTIONS=true
dotnet test --no-build -p:GITHUB_ACTIONS=true
- name: Test for coverall
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get --assume-yes install libleveldb-dev librocksdb-dev
dotnet test ./tests/Neo.Cryptography.BLS12_381.Tests --output ./bin/tests/Neo.Cryptography.BLS12_381.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.ConsoleService.Tests --output ./bin/tests/Neo.ConsoleService.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.UnitTests --output ./bin/tests/Neo.UnitTests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.VM.Tests --output ./bin/tests/Neo.VM.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.Json.UnitTests --output ./bin/tests/Neo.Json.UnitTests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.Extensions.Tests --output ./bin/tests/Neo.Extensions.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
# Plugins
dotnet test ./tests/Neo.Cryptography.MPTTrie.Tests --output ./bin/tests/Neo.Cryptography.MPTTrie.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.Network.RPC.Tests --output ./bin/tests/Neo.Network.RPC.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.Plugins.OracleService.Tests --output ./bin/tests/Neo.Plugins.OracleService.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.Plugins.RpcServer.Tests --output ./bin/tests/Neo.Plugins.RpcServer.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.Plugins.Storage.Tests --output ./bin/tests/Neo.Plugins.Storage.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet test ./tests/Neo.Plugins.ApplicationLogs.Tests --output ./bin/tests/Neo.Plugins.ApplicationLogs.Tests ${{ env.COVERLET_EXCLUDE_COVERAGE }} -p:GITHUB_ACTIONS=true
dotnet build --disable-parallel -p:GITHUB_ACTIONS=true
dotnet test --no-build -p:GITHUB_ACTIONS=true -p:Exclude="[Neo.UnitTests]*"
- name: Coveralls
if: matrix.os == 'ubuntu-latest'
uses: coverallsapp/[email protected].0
uses: coverallsapp/[email protected].6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
debug: false
measure: true
allow-empty: true
format: lcov
files:
${{ github.workspace }}/tests/Neo.Cryptography.BLS12_381.Tests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.ConsoleService.Tests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.UnitTests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.VM.Tests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.Json.UnitTests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.Cryptography.MPTTrie.Tests/TestResults/coverage.info
${{ github.workspace }}/tests/Neo.Network.RPC.Tests/TestResults/coverage.info
${{ 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
${{ github.workspace }}/tests/Neo.Extensions.Tests/TestResults/coverage.info
${{ github.workspace }}/TestResults/Neo.UnitTests/coverage.info
${{ github.workspace }}/TestResults/Neo.Cryptography.BLS12_381.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.ConsoleService.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.VM.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.Json.UnitTests/coverage.info
${{ github.workspace }}/TestResults/Neo.Cryptography.MPTTrie.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.Network.RPC.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.Plugins.OracleService.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.Plugins.RpcServer.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.Plugins.Storage.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.Plugins.ApplicationLogs.Tests/coverage.info
${{ github.workspace }}/TestResults/Neo.Extensions.Tests/coverage.info

PublishPackage:
if: github.ref == 'refs/heads/master' && startsWith(github.repository, 'neo-project/')
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<WarningLevel>4</WarningLevel>
<AnalysisLevel>latest</AnalysisLevel>
<OutputPath>../../bin/$(PackageId)</OutputPath>
<OverwriteReadOnlyFiles>true</OverwriteReadOnlyFiles>
</PropertyGroup>

<ItemGroup>
Expand Down
38 changes: 23 additions & 15 deletions src/Neo/Cryptography/BloomFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

#nullable enable

using System;
using System.Collections;
using System.Linq;
Expand All @@ -20,18 +22,18 @@ namespace Neo.Cryptography
/// </summary>
public class BloomFilter
{
private readonly uint[] seeds;
private readonly BitArray bits;
private readonly uint[] _seeds;
private readonly BitArray _bits;

/// <summary>
/// The number of hash functions used by the bloom filter.
/// </summary>
public int K => seeds.Length;
public int K => _seeds.Length;

/// <summary>
/// The size of the bit array used by the bloom filter.
/// </summary>
public int M => bits.Length;
public int M => _bits.Length;

/// <summary>
/// Used to generate the seeds of the murmur hash functions.
Expand All @@ -47,9 +49,11 @@ public class BloomFilter
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="k"/> or <paramref name="m"/> is less than or equal to 0.</exception>
public BloomFilter(int m, int k, uint nTweak)
{
if (k <= 0 || m <= 0) throw new ArgumentOutOfRangeException();
seeds = Enumerable.Range(0, k).Select(p => (uint)p * 0xFBA4C795 + nTweak).ToArray();
bits = new BitArray(m)
if (k <= 0) throw new ArgumentOutOfRangeException(nameof(k));
if (m <= 0) throw new ArgumentOutOfRangeException(nameof(m));

_seeds = Enumerable.Range(0, k).Select(p => (uint)p * 0xFBA4C795 + nTweak).ToArray();
_bits = new BitArray(m)
{
Length = m
};
Expand All @@ -66,9 +70,11 @@ public BloomFilter(int m, int k, uint nTweak)
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="k"/> or <paramref name="m"/> is less than or equal to 0.</exception>
public BloomFilter(int m, int k, uint nTweak, ReadOnlyMemory<byte> elements)
{
if (k <= 0 || m <= 0) throw new ArgumentOutOfRangeException();
seeds = Enumerable.Range(0, k).Select(p => (uint)p * 0xFBA4C795 + nTweak).ToArray();
bits = new BitArray(elements.ToArray())
if (k <= 0) throw new ArgumentOutOfRangeException(nameof(k));
if (m <= 0) throw new ArgumentOutOfRangeException(nameof(m));

_seeds = Enumerable.Range(0, k).Select(p => (uint)p * 0xFBA4C795 + nTweak).ToArray();
_bits = new BitArray(elements.ToArray())
{
Length = m
};
Expand All @@ -81,8 +87,8 @@ public BloomFilter(int m, int k, uint nTweak, ReadOnlyMemory<byte> elements)
/// <param name="element">The object to add to the <see cref="BloomFilter"/>.</param>
public void Add(ReadOnlyMemory<byte> element)
{
foreach (uint i in seeds.AsParallel().Select(s => element.Span.Murmur32(s)))
bits.Set((int)(i % (uint)bits.Length), true);
foreach (var i in _seeds.AsParallel().Select(s => element.Span.Murmur32(s)))
_bits.Set((int)(i % (uint)_bits.Length), true);
}

/// <summary>
Expand All @@ -92,8 +98,8 @@ public void Add(ReadOnlyMemory<byte> element)
/// <returns><see langword="true"/> if <paramref name="element"/> is found in the <see cref="BloomFilter"/>; otherwise, <see langword="false"/>.</returns>
public bool Check(byte[] element)
{
foreach (uint i in seeds.AsParallel().Select(s => element.Murmur32(s)))
if (!bits.Get((int)(i % (uint)bits.Length)))
foreach (var i in _seeds.AsParallel().Select(element.Murmur32))
if (!_bits.Get((int)(i % (uint)_bits.Length)))
return false;
return true;
}
Expand All @@ -104,7 +110,9 @@ public bool Check(byte[] element)
/// <param name="newBits">The byte array to store the bits.</param>
public void GetBits(byte[] newBits)
{
bits.CopyTo(newBits, 0);
_bits.CopyTo(newBits, 0);
}
}
}

#nullable disable
44 changes: 25 additions & 19 deletions src/Neo/Cryptography/MerkleTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

#nullable enable

using Neo.Extensions;
using System;
using System.Collections;
Expand All @@ -23,7 +25,7 @@ namespace Neo.Cryptography
/// </summary>
public class MerkleTree
{
private readonly MerkleTreeNode root;
private readonly MerkleTreeNode? _root;

/// <summary>
/// The depth of the tree.
Expand All @@ -32,22 +34,23 @@ public class MerkleTree

internal MerkleTree(UInt256[] hashes)
{
root = Build(hashes.Select(p => new MerkleTreeNode { Hash = p }).ToArray());
if (root is null) return;
int depth = 1;
for (MerkleTreeNode i = root; i.LeftChild != null; i = i.LeftChild)
_root = Build(hashes.Select(p => new MerkleTreeNode { Hash = p }).ToArray());
if (_root is null) return;

var depth = 1;
for (var i = _root; i.LeftChild != null; i = i.LeftChild)
depth++;
Depth = depth;
}

private static MerkleTreeNode Build(MerkleTreeNode[] leaves)
private static MerkleTreeNode? Build(MerkleTreeNode[] leaves)
{
if (leaves.Length == 0) return null;
if (leaves.Length == 1) return leaves[0];

Span<byte> buffer = stackalloc byte[64];
MerkleTreeNode[] parents = new MerkleTreeNode[(leaves.Length + 1) / 2];
for (int i = 0; i < parents.Length; i++)
var parents = new MerkleTreeNode[(leaves.Length + 1) / 2];
for (var i = 0; i < parents.Length; i++)
{
parents[i] = new MerkleTreeNode
{
Expand All @@ -71,8 +74,8 @@ private static MerkleTreeNode Build(MerkleTreeNode[] leaves)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static UInt256 Concat(Span<byte> buffer, UInt256 hash1, UInt256 hash2)
{
hash1.ToArray().CopyTo(buffer);
hash2.ToArray().CopyTo(buffer[32..]);
hash1.GetSpan().CopyTo(buffer);
hash2.GetSpan().CopyTo(buffer[32..]);

return new UInt256(Crypto.Hash256(buffer));
}
Expand All @@ -86,11 +89,12 @@ public static UInt256 ComputeRoot(UInt256[] hashes)
{
if (hashes.Length == 0) return UInt256.Zero;
if (hashes.Length == 1) return hashes[0];
MerkleTree tree = new(hashes);
return tree.root.Hash;

var tree = new MerkleTree(hashes);
return tree._root!.Hash;
}

private static void DepthFirstSearch(MerkleTreeNode node, IList<UInt256> hashes)
private static void DepthFirstSearch(MerkleTreeNode node, List<UInt256> hashes)
{
if (node.LeftChild == null)
{
Expand All @@ -110,10 +114,10 @@ private static void DepthFirstSearch(MerkleTreeNode node, IList<UInt256> hashes)
/// <returns>All nodes of the hash tree.</returns>
public UInt256[] ToHashArray()
{
if (root is null) return Array.Empty<UInt256>();
List<UInt256> hashes = new();
DepthFirstSearch(root, hashes);
return hashes.ToArray();
if (_root is null) return Array.Empty<UInt256>();
var hashes = new List<UInt256>();
DepthFirstSearch(_root, hashes);
return [.. hashes];
}

/// <summary>
Expand All @@ -122,12 +126,12 @@ public UInt256[] ToHashArray()
/// <param name="flags">The bit array to be used.</param>
public void Trim(BitArray flags)
{
if (root is null) return;
if (_root is null) return;
flags = new BitArray(flags)
{
Length = 1 << (Depth - 1)
};
Trim(root, 0, Depth, flags);
Trim(_root, 0, Depth, flags);
}

private static void Trim(MerkleTreeNode node, int index, int depth, BitArray flags)
Expand Down Expand Up @@ -155,3 +159,5 @@ private static void Trim(MerkleTreeNode node, int index, int depth, BitArray fla
}
}
}

#nullable disable
5 changes: 3 additions & 2 deletions src/Plugins/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<Import Project="../$(MSBuildThisFile)" />

<PropertyGroup>
<PackageId>Neo.Plugins.$(MSBuildProjectName)</PackageId>
<PackageOutputPath>../../../pkgs/</PackageOutputPath>
<OutputPath>../../../bin/$(PackageId)</OutputPath>
<OverwriteReadOnlyFiles>true</OverwriteReadOnlyFiles>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../Neo/Neo.csproj" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Plugins/LevelDBStore/LevelDBStore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<Target Name="DownloadNativeLibs" BeforeTargets="PreBuildEvent">
<DownloadFile Condition="!Exists('runtimes/%(NativeLib.RuntimeId)/native/%(NativeLib.Lib)')" SourceUrl="https://github.com/neo-ngd/leveldb/releases/download/v1.23/libleveldb-%(NativeLib.RuntimeId).zip" DestinationFolder="$(BaseIntermediateOutputPath)" />
<Unzip Condition="Exists('$(BaseIntermediateOutputPath)libleveldb-%(NativeLib.RuntimeId).zip') And !Exists('runtimes/%(NativeLib.RuntimeId)/native/%(NativeLib.Lib)')" SourceFiles="$(BaseIntermediateOutputPath)libleveldb-%(NativeLib.RuntimeId).zip" DestinationFolder="$(BaseIntermediateOutputPath)" />
<Move SourceFiles="$(BaseIntermediateOutputPath)libleveldb-%(NativeLib.RuntimeId)/%(NativeLib.Lib)" DestinationFolder="$(BaseIntermediateOutputPath)libleveldb-%(NativeLib.RuntimeId)/runtimes/%(NativeLib.RuntimeId)/native/" />
<DownloadFile Condition="!Exists('runtimes/%(NativeLib.RuntimeId)/native/%(NativeLib.Lib)')" SourceUrl="https://github.com/neo-ngd/leveldb/releases/download/v1.23/libleveldb-%(NativeLib.RuntimeId).zip" DestinationFolder="$(BaseIntermediateOutputPath)" Retries="3" />
<Unzip Condition="Exists('$(BaseIntermediateOutputPath)libleveldb-%(NativeLib.RuntimeId).zip') And !Exists('runtimes/%(NativeLib.RuntimeId)/native/%(NativeLib.Lib)')" SourceFiles="$(BaseIntermediateOutputPath)libleveldb-%(NativeLib.RuntimeId).zip" DestinationFolder="$(BaseIntermediateOutputPath)" OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)" />
<Move SourceFiles="$(BaseIntermediateOutputPath)libleveldb-%(NativeLib.RuntimeId)/%(NativeLib.Lib)" DestinationFolder="$(BaseIntermediateOutputPath)libleveldb-%(NativeLib.RuntimeId)/runtimes/%(NativeLib.RuntimeId)/native/" OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)" />
</Target>

<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<CollectCoverage>true</CollectCoverage>
<CoverletOutput>TestResults/</CoverletOutput>
<CoverletOutput>../../TestResults/$(MSBuildProjectName)/</CoverletOutput>
<CoverletOutputFormat>lcov</CoverletOutputFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<AnalysisLevel>latest</AnalysisLevel>
<OptimizeImplicitlyTriggeredBuild>true</OptimizeImplicitlyTriggeredBuild>
<OutputPath>../../bin/tests/$(MSBuildProjectName)</OutputPath>
<OverwriteReadOnlyFiles>true</OverwriteReadOnlyFiles>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="coverlet.collector" Version="6.0.4" >
<IncludeAssets>all</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<IncludeAssets>all</IncludeAssets>
</PackageReference>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>neo_cli.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Neo.Cryptography.MPT.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 247e04e

Please sign in to comment.