public static void AssertTestData(LedgerResponse ledger) { Assert.AreEqual(ledger.Hash, "686bb246db89b099cd3963a4633eb5e4315d89dfd3c00594c80b41a483847bfa"); Assert.AreEqual(ledger.PagingToken, "3860428274794496"); Assert.AreEqual(ledger.PrevHash, "50c8695eb32171a19858413e397cc50b504ceacc819010bdf8ff873aff7858d7"); Assert.AreEqual(ledger.Sequence, 898826); Assert.AreEqual(ledger.TransactionCount, 1); Assert.AreEqual(ledger.OperationCount, 2); Assert.AreEqual(ledger.ClosedAt, "2015-11-19T21:35:59Z"); Assert.AreEqual(ledger.TotalCoins, "101343867604.8975480"); Assert.AreEqual(ledger.FeePool, "1908.2248818"); Assert.AreEqual(ledger.BaseFee, 100); Assert.AreEqual(ledger.BaseReserve, "10.0000000"); Assert.AreEqual(ledger.MaxTxSetSize, 50); Assert.AreEqual(ledger.Links.Effects.Href, "/ledgers/898826/effects{?cursor,limit,order}"); Assert.AreEqual(ledger.Links.Operations.Href, "/ledgers/898826/operations{?cursor,limit,order}"); Assert.AreEqual(ledger.Links.Self.Href, "/ledgers/898826"); Assert.AreEqual(ledger.Links.Transactions.Href, "/ledgers/898826/transactions{?cursor,limit,order}"); }
public void TestMultipleRemotes_Sequence(int count) { var watch = new Stopwatch(); watch.Start(); var results = new LedgerResponse[count]; var tasks = new Task[count]; for (int i = 0; i < count; i++) { var remote = new Remote(ServerUrl); var tc = remote.ConnectAsync(null, DeferredWaitingTime * 10); var index = i; var task = tc.ContinueWith(_ => { var tr = remote.RequestLedger().SubmitAsync(null, DeferredWaitingTime); if (tr.Wait(DeferredWaitingTime)) { results[index] = tr.Result.Result; } }); task.Wait(DeferredWaitingTime * 2); } watch.Stop(); TestContext.WriteLine(watch.ElapsedMilliseconds.ToString()); var failedCount = 0; foreach (var result in results) { var hash = result?.Ledger?.Hash; if (hash == null) { failedCount++; } } Assert.AreEqual(0, failedCount); }
public async Task TestStream() { var json = File.ReadAllText(Path.Combine("testdata", "ledger.json")) .Replace(Environment.NewLine, ""); var fakeHandler = new FakeHttpMessageHandler(); var stream = $"event: open\ndata: hello\n\nid: 1234\ndata: {json}\n\n"; fakeHandler.QueueResponse(FakeResponse.StartsStream(StreamAction.Write(stream))); var eventSource = new SSEEventSource(new Uri("http://test.com"), builder => builder.MessageHandler(fakeHandler)); LedgerResponse dataReceived = null; eventSource.Message += (sender, args) => { dataReceived = JsonSingleton.GetInstance <LedgerResponse>(args.Data); eventSource.Shutdown(); }; await eventSource.Connect(); LedgerDeserializeTest.AssertTestData(dataReceived); }
public void TestOneRemoteMultipleRequests_Sequence(int count) { var remote = new Remote(ServerUrl); var tc = remote.ConnectAsync(); Assert.IsTrue(tc.Wait(DeferredWaitingTime)); var watch = new Stopwatch(); watch.Start(); var results = new LedgerResponse[count]; for (int i = 0; i < count; i++) { var task = remote.RequestLedger().SubmitAsync(); if (task.Wait(DeferredWaitingTime)) { results[i] = task.Result.Result; } } watch.Stop(); TestContext.WriteLine(watch.ElapsedMilliseconds.ToString()); var failedCount = 0; foreach (var result in results) { var hash = result?.Ledger?.Hash; if (hash == null) { failedCount++; } } Assert.AreEqual(0, failedCount); }
private static async void ShowOperationResponse(Server server, object sender, LedgerResponse lr) { var operationRequestBuilder = server.Operations.ForLedger(lr.Sequence); var operations = await operationRequestBuilder.Execute(); var accts = 0; var payments = 0; var offers = 0; var options = 0; foreach (var op in operations.Records) { switch (op.Type) { case "create_account": accts++; break; case "payment": payments++; break; case "manage_offer": offers++; break; case "set_options": options++; break; } } Console.WriteLine($"id: {lr.Sequence}, tx/ops: {lr.SuccessfulTransactionCount + "/" + lr.OperationCount}, accts: {accts}, payments: {payments}, offers: {offers}, options: {options}"); Console.WriteLine($"Uri: {((LedgersRequestBuilder) sender).Uri}"); }