parent
ae67b12313
commit
fefa2da218
43 changed files with 884 additions and 477 deletions
78
src/FrostFS.SDK.Tests/Mocks/NetworkMocker.cs
Normal file
78
src/FrostFS.SDK.Tests/Mocks/NetworkMocker.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using Moq;
|
||||
using FrostFS.Netmap;
|
||||
using Grpc.Core;
|
||||
using FrostFS.SDK.ClientV2;
|
||||
using Google.Protobuf;
|
||||
using NuGet.Frameworks;
|
||||
|
||||
namespace FrostFS.SDK.Tests;
|
||||
|
||||
public class NetworkMocker(string key) : ServiceBase(key)
|
||||
{
|
||||
private static readonly string[] parameterKeys = [
|
||||
"ContainerFee",
|
||||
"EpochDuration",
|
||||
"IRCandidateFee",
|
||||
"MaxECDataCount",
|
||||
"MaxECParityCount",
|
||||
"MaxObjectSize",
|
||||
"WithdrawalFee",
|
||||
"HomomorphicHashingDisabled",
|
||||
"MaintenanceModeAllowed" ];
|
||||
|
||||
public Dictionary<string, byte[]>? Parameters { get; set; }
|
||||
|
||||
public Mock<NetmapService.NetmapServiceClient> GetMock()
|
||||
{
|
||||
var mock = new Mock<NetmapService.NetmapServiceClient>();
|
||||
|
||||
var networkInfoResponse = new NetworkInfoResponse();
|
||||
|
||||
var networkConfig = new NetworkConfig();
|
||||
|
||||
foreach (var key in parameterKeys)
|
||||
{
|
||||
networkConfig.Parameters.Add(new NetworkConfig.Types.Parameter
|
||||
{
|
||||
Key = ByteString.CopyFromUtf8(key),
|
||||
Value = (Parameters != null && Parameters.TryGetValue(key, out byte[]? value)) ? ByteString.CopyFrom(value) : ByteString.CopyFrom(0)
|
||||
});
|
||||
}
|
||||
|
||||
var response = new NetworkInfoResponse
|
||||
{
|
||||
Body = new NetworkInfoResponse.Types.Body
|
||||
{
|
||||
NetworkInfo = new NetworkInfo
|
||||
{
|
||||
CurrentEpoch = 99,
|
||||
MagicNumber = 13,
|
||||
MsPerBlock = 999,
|
||||
NetworkConfig = networkConfig
|
||||
}
|
||||
},
|
||||
MetaHeader = ResponseMetaHeader
|
||||
};
|
||||
|
||||
response.VerifyHeader = GetResponseVerificationHeader(response);
|
||||
|
||||
mock.Setup(x => x.NetworkInfoAsync(
|
||||
It.IsAny<NetworkInfoRequest>(),
|
||||
It.IsAny<Metadata>(),
|
||||
It.IsAny<DateTime?>(),
|
||||
It.IsAny<CancellationToken>()))
|
||||
.Returns((NetworkInfoRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
|
||||
{
|
||||
Verifier.CheckRequest(r);
|
||||
|
||||
return new AsyncUnaryCall<NetworkInfoResponse>(
|
||||
Task.FromResult(response),
|
||||
Task.FromResult(ResponseMetaData),
|
||||
() => new Grpc.Core.Status(StatusCode.OK, string.Empty),
|
||||
() => ResponseMetaData,
|
||||
() => { });
|
||||
});
|
||||
|
||||
return mock;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue