Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merkle Patricia Tries (2x) #97

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
28 changes: 28 additions & 0 deletions MPTStates.UnitTests/MPTStates.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>MPTStates.UnitTests</AssemblyName>
<RootNamespace>MPTStates.UnitTests</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.3.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="4.19.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Moq" Version="4.7.63" />
<PackageReference Include="Akka.TestKit" Version="1.3.10" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.3.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MPTStates\MPTStates.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
52 changes: 52 additions & 0 deletions MPTStates.UnitTests/TestDataCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Neo.IO;
using Neo.IO.Caching;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Neo.UnitTests
{
public class TestDataCache<TKey, TValue> : DataCache<TKey, TValue>
where TKey : IEquatable<TKey>, ISerializable
where TValue : class, ICloneable<TValue>, ISerializable, new()
{
private readonly TValue _defaultValue;

public TestDataCache()
{
_defaultValue = null;
}

public TestDataCache(TValue defaultValue)
{
this._defaultValue = defaultValue;
}
public override void DeleteInternal(TKey key)
{
}

protected override void AddInternal(TKey key, TValue value)
{
}

protected override IEnumerable<KeyValuePair<TKey, TValue>> FindInternal(byte[] key_prefix)
{
return Enumerable.Empty<KeyValuePair<TKey, TValue>>();
}

protected override TValue GetInternal(TKey key)
{
if (_defaultValue == null) throw new NotImplementedException();
return _defaultValue;
}

protected override TValue TryGetInternal(TKey key)
{
return _defaultValue;
}

protected override void UpdateInternal(TKey key, TValue value)
{
}
}
}
33 changes: 33 additions & 0 deletions MPTStates.UnitTests/TestDataCacheWithInternal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Neo.IO;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Neo.UnitTests
{
public class TestDataCacheWithInternal<TKey, TValue> : TestDataCache<TKey, TValue>
where TKey : IEquatable<TKey>, ISerializable
where TValue : class, ICloneable<TValue>, ISerializable, new()
{
private readonly Dictionary<TKey, TValue> _internal = new Dictionary<TKey, TValue>();

public override void DeleteInternal(TKey key) => _internal.Remove(key);

protected override void AddInternal(TKey key, TValue value) => _internal.Add(key, value);

protected override IEnumerable<KeyValuePair<TKey, TValue>> FindInternal(byte[] key_prefix)
{
return Enumerable.Empty<KeyValuePair<TKey, TValue>>();
}

protected override TValue GetInternal(TKey key) => _internal[key];

protected override TValue TryGetInternal(TKey key)
{
_internal.TryGetValue(key, out var value);
return value;
}

protected override void UpdateInternal(TKey key, TValue value) => _internal[key] = value;
}
}
Loading