elucidsoft / dotnet-stellar-sdk

Stellar API SDK for .NET 6.x
Apache License 2.0
116 stars 55 forks source link

Failed to "LoadAllOperationsForLedger" with `Invalid operation 'type_i'='22'` #335

Closed avolkov-dev closed 2 years ago

avolkov-dev commented 2 years ago

Describe the bug Latest SDK (stellar-dotnet-sdk version 7.2.0) not able to decode LoadAllOperationsForLedger

To Reproduce Run code:

using System;
using System.Linq;
using System.Threading.Tasks;
using stellar_dotnet_sdk;
using Xunit;
using stellar_dotnet_sdk.xdr;

namespace Tests
{
    public class DecodeFail
    {
        [Fact]
        public async Task FailsToLoadAllOperationsForLedger()
        {
            var server = new Server("https://horizon-testnet.stellar.org/");
            var page = await server.Operations.ForLedger(351182).IncludeFailed(true)
                .Limit(100)
                .Execute();
        }
    }
}

And receive error:

Tests.BlockReaderTests.FailsToLoadAllOperationsForLedger

Newtonsoft.Json.JsonSerializationException: Invalid operation 'type_i'='22'

Newtonsoft.Json.JsonSerializationException
Invalid operation 'type_i'='22'
   at stellar_dotnet_sdk.responses.OperationDeserializer.CreateResponse(Int32 type)
   at stellar_dotnet_sdk.responses.OperationDeserializer.ReadJson(JsonReader reader, Type objectType, OperationResponse existingValue, Boolean hasExistingValue, JsonSerializer serializer)
   at Newtonsoft.Json.JsonConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonConverter[] converters)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters)
   at stellar_dotnet_sdk.responses.JsonSingleton.GetInstance[T](String content)
   at stellar_dotnet_sdk.requests.ResponseHandler`1.HandleResponse(HttpResponseMessage response)
   at stellar_dotnet_sdk.requests.RequestBuilder`1.Execute[TZ](Uri uri)
   at stellar_dotnet_sdk.requests.RequestBuilderExecutePageable`2.Execute()
   at Tests.BlockReaderTests.FailsToLoadAllOperationsForLedger() in D:\Projects\Swisschain\Sirius.Integrations.Stellar\tests\Tests\BlockReaderTests.cs:line 51
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 264
--- End of stack trace from previous location ---
   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in C:\Dev\xunit\xunit\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90

Expected behavior No error occured

Kirbyrawr commented 2 years ago

Will take a look after work!

Kirbyrawr commented 2 years ago

Found the error, fixing!

Kirbyrawr commented 2 years ago

Hi, this is the PR, https://github.com/elucidsoft/dotnet-stellar-sdk/pull/336 I still need to add the tests but so far should work, i could reproduce your issue and with this, it's working ok.

Thanks for report the errors, the AMM protocol was huge and it was a pain to do it, let me know if you see more issues.

We will try to publish the SDK Nuget soon, tomorrow for sure i will include the tests and will merge the PR to master.

Kirbyrawr commented 2 years ago

Tests included, i also made some updates to the Reserve class and other refactor/bugfixing, thanks!

avolkov-dev commented 2 years ago

The issue is resolved on 7.2.8. Thank you so much!