-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added all relevant models. Started unit test project.
- Loading branch information
Showing
17 changed files
with
630 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"method":"accountSubscribe","params":["CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12",{"encoding":"base64"}],"jsonrpc":"2.0","id":0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Solnet.Rpc.Core.Sockets; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using Solnet.Rpc.Messages; | ||
using Solnet.Rpc.Models; | ||
using System; | ||
using System.Threading; | ||
using System.IO; | ||
using System.Net.WebSockets; | ||
using System.Text; | ||
|
||
namespace Solnet.Rpc.Test | ||
{ | ||
[TestClass] | ||
public class SolanaStreamingClientTest | ||
{ | ||
[TestMethod] | ||
public void SubscribeAccountInfoTest() | ||
{ | ||
var expected = File.ReadAllText("Resources/AccountSubscribe.json"); | ||
ReadOnlyMemory<byte> result = new ReadOnlyMemory<byte>(); | ||
var socket = new Mock<IWebSocket>(); | ||
|
||
SolanaStreamingClient sut = new SolanaStreamingClient("wss://api.mainnet-beta.solana.com/", socket.Object); | ||
|
||
var pubKey = "CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12"; | ||
|
||
var action = new Mock<Action<SubscriptionState, ResponseValue<AccountInfo>>>(); | ||
|
||
socket.Setup(_ => _.ConnectAsync(It.IsAny<Uri>(), It.IsAny<CancellationToken>())) | ||
.Callback(() => socket.SetupGet(s => s.State).Returns(WebSocketState.Open)); | ||
|
||
socket.Setup(_ => _.SendAsync(It.IsAny<ReadOnlyMemory<byte>>(), WebSocketMessageType.Text, true, It.IsAny<CancellationToken>())) | ||
.Callback<ReadOnlyMemory<byte>, WebSocketMessageType, bool, CancellationToken>((mem, _, _, _) => result = mem); | ||
|
||
sut.Init().Wait(); | ||
sut.SubscribeAccountInfo(pubKey, action.Object); | ||
|
||
socket.Verify(s => s.SendAsync(It.IsAny<ReadOnlyMemory<byte>>(), WebSocketMessageType.Text, true, It.IsAny<CancellationToken>())); | ||
var res = Encoding.UTF8.GetString(result.Span); | ||
Assert.AreEqual(expected, res); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> | ||
<PackageReference Include="Moq" Version="4.16.1" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" /> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\src\Solnet.Rpc\Solnet.Rpc.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Resources\AccountSubscribe.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Net.WebSockets; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Solnet.Rpc.Core.Sockets | ||
{ | ||
public interface IWebSocket : IDisposable | ||
{ | ||
WebSocketState State { get; } | ||
|
||
Task ConnectAsync(Uri uri, CancellationToken cancellationToken); | ||
ValueTask SendAsync(ReadOnlyMemory<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken); | ||
Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken); | ||
ValueTask<ValueWebSocketReceiveResult> ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken); | ||
} | ||
} |
Oops, something went wrong.