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

Fixed TransactionError parsing in log notifications #123

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/Solnet.Rpc/Models/Logs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Log
/// The error associated with the transaction simulation.
/// </summary>
[JsonPropertyName("err")]
public string Error { get; set; }
public TransactionError Error { get; set; }

/// <summary>
/// The log messages the transaction instructions output during execution.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"jsonrpc": "2.0",
"method": "logsNotification",
"params": {
"result": {
"context": { "slot": 84392429 },
"value": {
"err": {
"InstructionError": [
1,
{ "Custom": 41 }
]
},
"logs": [ "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin invoke [1]", "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin consumed 3769 of 200000 compute units", "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin success", "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin invoke [1]", "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin consumed 5619 of 200000 compute units", "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin failed: custom program error: 0x29" ],
"signature": "bGNVGCa1WFchzJStauKFVk7anzuFvA7hkMcx8Zi2o4euJaivzpwz8346yJ4Xn8H7XzMp44coTxdcDRd9d4yzj4m"
}
},
"subscription": 23784
}
}
36 changes: 36 additions & 0 deletions test/Solnet.Rpc.Test/SolanaStreamingClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,42 @@ public void SubscribeLogsAllProcessed()
Assert.AreEqual("BPF program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success", resultNotification.Value.Logs[0]);
}

[TestMethod]
public void SubscribeLogsWithErrors()
{
var expected = File.ReadAllText("Resources/Streaming/Logs/LogsSubscribeAllProcessed.json");
var subConfirmContent = File.ReadAllBytes("Resources/Streaming/SubscribeConfirm.json");
var notificationContents = File.ReadAllBytes("Resources/Streaming/Logs/LogsSubscribeNotificationWithError.json");
ResponseValue<LogInfo> resultNotification = null;
var result = new ReadOnlyMemory<byte>();

SetupAction(out Action<SubscriptionState, ResponseValue<LogInfo>> action,
(x) => resultNotification = x,
(x) => result = x,
subConfirmContent,
notificationContents);

var sut = new SolanaStreamingRpcClient("wss://api.mainnet-beta.solana.com/", null, _socketMock.Object);

sut.Init().Wait();
_ = sut.SubscribeLogInfo(Types.LogsSubscriptionType.All, action, Types.Commitment.Processed);
_subConfirmEvent.Set();

_socketMock.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);

Assert.IsTrue(_notificationEvent.WaitOne());
Assert.AreEqual(TransactionErrorType.InstructionError, resultNotification.Value.Error.Type);
Assert.AreEqual(InstructionErrorType.Custom, resultNotification.Value.Error.InstructionError.Type);
Assert.AreEqual(41, resultNotification.Value.Error.InstructionError.CustomError);

Assert.AreEqual("bGNVGCa1WFchzJStauKFVk7anzuFvA7hkMcx8Zi2o4euJaivzpwz8346yJ4Xn8H7XzMp44coTxdcDRd9d4yzj4m", resultNotification.Value.Signature);
}

[TestMethod]
public void SubscribeProgramTest()
{
Expand Down
3 changes: 3 additions & 0 deletions test/Solnet.Rpc.Test/Solnet.Rpc.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@
<None Update="Resources\Streaming\Logs\LogsSubscribeMentionConfirmed.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Streaming\Logs\LogsSubscribeNotificationWithError.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Streaming\Program\ProgramSubscribeConfirmed.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down