From 70e85c3bbdfd3d8da65ed9b3b8dc705609673f39 Mon Sep 17 00:00:00 2001 From: Alfred Neequaye Date: Wed, 25 Nov 2020 11:59:32 +0000 Subject: [PATCH 01/37] Initial Invalid Block Request Implementation for #16 --- .../Bank/Api/InvalidBlockServiceTests.cs | 7 +++ .../Bank/Api/IInvalidBlocksService.cs | 16 +++++ .../Bank/Api/InvalidBlocksService.cs | 61 +++++++++++++++++++ .../Bank/Models/BankInvalidBlock.cs | 30 +++++++++ .../Bank/Models/BankInvalidBlockRequest.cs | 58 ++++++++++++++++++ 5 files changed, 172 insertions(+) create mode 100644 src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs create mode 100644 src/Thenewboston/Bank/Api/IInvalidBlocksService.cs create mode 100644 src/Thenewboston/Bank/Api/InvalidBlocksService.cs create mode 100644 src/Thenewboston/Bank/Models/BankInvalidBlock.cs create mode 100644 src/Thenewboston/Bank/Models/BankInvalidBlockRequest.cs diff --git a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs new file mode 100644 index 0000000..24a9cd8 --- /dev/null +++ b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs @@ -0,0 +1,7 @@ +namespace Thenewboston.Tests.Bank.Api +{ + public class InvalidBlockServiceTests + { + static + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs new file mode 100644 index 0000000..5a88eed --- /dev/null +++ b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Threading.Tasks; +using Thenewboston.Bank.Models; + +namespace Thenewboston.Bank.Api +{ + public interface IInvalidBlocksService + { + Task> GetInvalidBankBlocks(); + Task SendInvalidBlocksToBank(BankInvalidBlockRequest model); + + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs new file mode 100644 index 0000000..de5ee19 --- /dev/null +++ b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Http; + +namespace Thenewboston.Bank.Api +{ + public class InvalidBlocksService : IInvalidBlocksService + { + private readonly IHttpRequestSender _requestSender; + + public InvalidBlocksService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + public async Task> GetInvalidBankBlocks() + { + try + { + var response = await _requestSender.GetAsync("/invalid_blocks"); + if (!response.IsSuccessStatusCode) + { + //TODO Use a More Specific Exception Type + throw new Exception(); + } + + var responseContent = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject>(responseContent); + } + catch (Exception ) + { + //TODO Handle Possible Known Exception Types + throw; + } + } + + public async Task SendInvalidBlocksToBank(BankInvalidBlockRequest model) + { + try + { + var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); + var response = await _requestSender.PostAsync("/invalid_blocks", content); + if (!response.IsSuccessStatusCode) + throw new Exception("Error Sending Invalid Block to Bank"); //TODO Use Specific Exception + + var responseContent = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(responseContent); + } + catch + { + //TODO Handle Specific Exceptions Types + throw; + } + } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Models/BankInvalidBlock.cs b/src/Thenewboston/Bank/Models/BankInvalidBlock.cs new file mode 100644 index 0000000..537f527 --- /dev/null +++ b/src/Thenewboston/Bank/Models/BankInvalidBlock.cs @@ -0,0 +1,30 @@ +using System; +using Newtonsoft.Json; + +namespace Thenewboston.Bank.Models +{ + public class BankInvalidBlock + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("created_date")] + public DateTime CreatedDate { get; set; } + + [JsonProperty("modified_date")] + public DateTime ModifiedDate { get; set; } + + [JsonProperty("block_identifier")] + public string BlockIdentifier { get; set; } + + [JsonProperty("block")] + public string Block { get; set; } + + [JsonProperty("confirmation_validator")] + public string ConfirmationValidator { get; set; } + + [JsonProperty("primary_validator")] + public string PrimaryValidator { get; set; } + } + +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Models/BankInvalidBlockRequest.cs b/src/Thenewboston/Bank/Models/BankInvalidBlockRequest.cs new file mode 100644 index 0000000..8acc1bc --- /dev/null +++ b/src/Thenewboston/Bank/Models/BankInvalidBlockRequest.cs @@ -0,0 +1,58 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Bank.Models +{ + public class BankInvalidBlockRequest + { + [JsonProperty("message")] + public InvalidBlockBankRequestMessage Message { get; set; } + + [JsonProperty("node_identifier")] + public string NodeIdentifier { get; set; } + + [JsonProperty("signature")] + public string Signature { get; set; } + } + + public class InvalidBlockBankRequestMessage + { + [JsonProperty("block")] + public Block Block { get; set; } + + [JsonProperty("block_identifier")] + public string BlockIdentifier { get; set; } + + [JsonProperty("primary_validator_node_identifier")] + public string PrimaryValidatorNodeIdentifier { get; set; } + } + + public class Block + { + [JsonProperty("account_number")] + public string AccountNumber { get; set; } + + [JsonProperty("message")] + public BlockMessage Message { get; set; } + + [JsonProperty("signature")] + public string Signature { get; set; } + } + + public class BlockMessage + { + [JsonProperty("balance_key")] + public string BalanceKey { get; set; } + + [JsonProperty("txs")] + public BlockTransactions[] Txs { get; set; } + } + + public class BlockTransactions + { + [JsonProperty("amount")] + public double Amount { get; set; } + + [JsonProperty("recipient")] + public string Recipient { get; set; } + } +} \ No newline at end of file From 2f6486d5450558514cacd0043fd5c54c47b42eaa Mon Sep 17 00:00:00 2001 From: Alfred Neequaye Date: Wed, 25 Nov 2020 18:41:02 +0000 Subject: [PATCH 02/37] Added Base Tests for BankInvalidBlockService --- .../Bank/Api/InvalidBlockServiceTests.cs | 90 ++++++++++++++++++- .../Bank/Api/IInvalidBlocksService.cs | 4 +- .../Bank/Api/InvalidBlocksService.cs | 4 +- .../Bank/Models/BankInvalidBlock.cs | 4 +- 4 files changed, 94 insertions(+), 8 deletions(-) diff --git a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs index 24a9cd8..3c633d7 100644 --- a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs @@ -1,7 +1,93 @@ -namespace Thenewboston.Tests.Bank.Api +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Moq; +using Newtonsoft.Json; +using Thenewboston.Bank.Api; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Http; +using Xunit; + +namespace Thenewboston.Tests.Bank.Api { public class InvalidBlockServiceTests { - static + public class GetInvalidBankBlocksAsync + { + [Fact] + public async void GetInvalidBlockReturnedSuccessCodeandData() + { + var service = BuildBankInvalidServiceMock(); + + var invalidBankBlocks = await service.GetInvalidBankBlocksAsync(); + + Assert.Equal(2, invalidBankBlocks.Count()); + Assert.Equal("2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", invalidBankBlocks.ElementAt(0).Id); + } + } + public class SendInvalidBankBlocksAsync + { + [Fact] + public async void SendInvalidBlockReturnedSuccessCodeandData() + { + var service = BuildBankInvalidServiceMock(); + var invalidBankBlocks = await service.SendInvalidBlocksToBankAsync( new BankInvalidBlockRequest()); + + Assert.Equal("2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", invalidBankBlocks.Id); + } + } + + private static InvalidBlocksService BuildBankInvalidServiceMock() + { + var requestSender = new Mock(); + + var listResult = new List + { + new BankInvalidBlock + { + Id = "2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", + BlockIdentifier = "65ae26192dfb9ec41f88c6d582b374a9b42ab58833e1612452d7a8f685dcd4d5", + Block = "3ff4ebb0-2b3d-429b-ba90-08133fcdee4e", + PrimaryValidator = "51461a75-dd8d-4133-81f4-543a3b054149", + ConfirmationValidator= "fcd2dce8-9e4f-4bf1-8dac-cdbaf64e5ce8", + Created = DateTime.Now.AddDays(-3), + Modified = DateTime.Now + }, + new BankInvalidBlock + { + Id = "2b9e3180-cf38-4772-9d73-6318ee4113b9", + BlockIdentifier = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", + Block = "3ff4ebb0-2b3d-429b-ba90-08133fcdee4e", + PrimaryValidator = "51461a75-dd8d-4133-81f4-543a3b054149", + ConfirmationValidator= "fcd2dce8-9e4f-4bf1-8dac-cdbaf64e5ce8", + Created = DateTime.Now.AddDays(-3), + Modified = DateTime.Now + } + }; + + var getAllResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + getAllResponse.Content = new StringContent(JsonConvert.SerializeObject(listResult), Encoding.UTF8, "application/json"); + + requestSender + .Setup(x => x.GetAsync(It.IsAny())) + .Returns(Task.FromResult(getAllResponse)); + + var postResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + postResponse.Content = new StringContent(JsonConvert.SerializeObject(listResult.First()), Encoding.UTF8, "application/json"); + + //TODO Setup for more Scenarios + requestSender + .Setup(x => x.PostAsync("/invalid_blocks", It.IsAny())) + .Returns(Task.FromResult(postResponse)); + requestSender + .Setup(x => x.GetAsync("/invalid_blocks")) + .Returns(Task.FromResult(getAllResponse)); + + var invalidBlockService = new InvalidBlocksService(requestSender.Object); + return invalidBlockService; + } } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs index 5a88eed..d1cc0a0 100644 --- a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs @@ -9,8 +9,8 @@ namespace Thenewboston.Bank.Api { public interface IInvalidBlocksService { - Task> GetInvalidBankBlocks(); - Task SendInvalidBlocksToBank(BankInvalidBlockRequest model); + Task> GetInvalidBankBlocksAsync(); + Task SendInvalidBlocksToBankAsync(BankInvalidBlockRequest model); } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs index de5ee19..fef4348 100644 --- a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs @@ -18,7 +18,7 @@ public InvalidBlocksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetInvalidBankBlocks() + public async Task> GetInvalidBankBlocksAsync() { try { @@ -39,7 +39,7 @@ public async Task> GetInvalidBankBlocks() } } - public async Task SendInvalidBlocksToBank(BankInvalidBlockRequest model) + public async Task SendInvalidBlocksToBankAsync(BankInvalidBlockRequest model) { try { diff --git a/src/Thenewboston/Bank/Models/BankInvalidBlock.cs b/src/Thenewboston/Bank/Models/BankInvalidBlock.cs index 537f527..8b28911 100644 --- a/src/Thenewboston/Bank/Models/BankInvalidBlock.cs +++ b/src/Thenewboston/Bank/Models/BankInvalidBlock.cs @@ -9,10 +9,10 @@ public class BankInvalidBlock public string Id { get; set; } [JsonProperty("created_date")] - public DateTime CreatedDate { get; set; } + public DateTime Created { get; set; } [JsonProperty("modified_date")] - public DateTime ModifiedDate { get; set; } + public DateTime Modified { get; set; } [JsonProperty("block_identifier")] public string BlockIdentifier { get; set; } From df4eb37bb1855a54f4390d38f5c1484db104f169 Mon Sep 17 00:00:00 2001 From: Nish Date: Wed, 25 Nov 2020 17:19:10 -0600 Subject: [PATCH 03/37] =?UTF-8?q?Fixed=20the=20typo=20in=20confirmationblo?= =?UTF-8?q?ck=20and=20done=20with=20get=20and=20post=20request=20for=20ban?= =?UTF-8?q?k=20api=20=E2=98=BA=E2=98=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/BankConfirmationBlockServiceTests.cs | 4 +- .../Bank/Api/BlocksServiceTests.cs | 118 ++++++++++++++++++ .../Bank/Api/BankConfirmationBlockService.cs | 2 +- src/Thenewboston/Bank/Api/BlocksService.cs | 60 +++++++++ .../Bank/Api/IBankConfirmationBlockService.cs | 2 +- src/Thenewboston/Bank/Api/IBlocksService.cs | 14 +++ .../{BankBlock.cs => BankBlockResponse.cs} | 20 ++- src/Thenewboston/Common/Models/Block.cs | 16 +++ .../Common/Models/BlockMessage.cs | 14 +++ .../Common/Models/BlockTransaction.cs | 13 ++ 10 files changed, 253 insertions(+), 10 deletions(-) create mode 100644 src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs create mode 100644 src/Thenewboston/Bank/Api/BlocksService.cs create mode 100644 src/Thenewboston/Bank/Api/IBlocksService.cs rename src/Thenewboston/Bank/Models/{BankBlock.cs => BankBlockResponse.cs} (51%) create mode 100644 src/Thenewboston/Common/Models/Block.cs create mode 100644 src/Thenewboston/Common/Models/BlockMessage.cs create mode 100644 src/Thenewboston/Common/Models/BlockTransaction.cs diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs index 3d0dab0..72ab7d1 100644 --- a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs @@ -143,10 +143,10 @@ private IBankConfirmationBlockService BuildConfirmationBlockPostMock() #region Tests [Fact] - public async void BankConfiramtionBlockReturnedAsync() + public async void BankConfirmationBlockReturnedAsync() { var service = BuildConfirmationBlockGetMock(); - var returnedBankConfirmationBlock = await service.GetAllBankConfiramtionBlocksAsync(); + var returnedBankConfirmationBlock = await service.GetAllBankConfirmationBlocksAsync(); var expectedResult = JsonConvert.SerializeObject(CreateMockBankConfirmationBlock()); var actualResult = JsonConvert.SerializeObject(returnedBankConfirmationBlock); Assert.Equal(expectedResult, actualResult); diff --git a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs new file mode 100644 index 0000000..4ce4c79 --- /dev/null +++ b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using Moq; +using Newtonsoft.Json; +using Thenewboston.Bank.Api; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; +using Thenewboston.Common.Http; +using Thenewboston.Common.Models; +using Xunit; + +namespace Thenewboston.Tests.Bank +{ + public class BlocksServiceTests + { + #region Test Models + + private PaginatedResponseModel CreateMockBlock() + { + return new PaginatedResponseModel() { + Count = 1, + Next = string.Empty, + Previous = string.Empty, + Results = + new List() { + new BankBlock { + Id = "c6fc11cf-8948-4d32-96c9-d56caa6d5b24", + Created = DateTime.Parse("2020-10-08T02:18:07.324999Z"), + Modified = DateTime.Parse("2020-10-08T02:18:07.325044Z"), + BalanceKey = "a37e2836805975f334108b55523634c995bd2a4db610062f404510617e83126f", + Sender = "a37e2836805975f334108b55523634c995bd2a4db610062f404510617e83126f", + Signature = + "a2ba346d98cb1f7ce6bf017240d674a9928796ddb564a2c8817e68ead0ea02d960e970fe581c6d3a25b9876e1873d51c882b23d843e32f511d9575ef60d2940d" + } + } + }; + } + + private Block CreateMockBlockMessage() + { + return new Block() { + AccountNumber = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", + Message = new BlockMessage() { + BalanceKey = "ce51f0d9facaa7d3e69657429dd3f961ce70077a8efb53dcda508c7c0a19d2e3", + Transactions = new List() { + new BlockTransaction() { + Amount = "12.5", + Recipient = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" + }, + new BlockTransaction() { + Amount = "1", Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8" + }, + new BlockTransaction() { + Amount = "4", Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314" + } + } + }, + Signature = + "ee5a2f2a2f5261c1b633e08dd61182fd0db5604c853ebd8498f6f28ce8e2ccbbc38093918610ea88a7ad47c7f3192ed955d9d1529e7e390013e43f25a5915c0f" + }; + } + + #endregion + + #region Mock Service + + private IBlocksService BuildBlockGetMock() + { + var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + response.Content = new StringContent(JsonConvert.SerializeObject(CreateMockBlock()), Encoding.UTF8, + "application/json"); + var requestSenderMock = new Mock(); + + requestSenderMock + .Setup(s => s.GetAsync(It.IsAny())) + .ReturnsAsync(response); + + IBlocksService service = new BlocksService(requestSenderMock.Object); + return service; + } + + private IBlocksService BuildBlockPostMock() + { + var requestSenderMock = new Mock(); + requestSenderMock.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.Created)); + + IBlocksService service = new BlocksService(requestSenderMock.Object); + return service; + } + + #endregion + + #region Tests + + [Fact] + public async void BlockReturnedAsync() + { + var service = BuildBlockGetMock(); + var returnedBlock = await service.GetBlocksAsync(); + var expectedResult = JsonConvert.SerializeObject(CreateMockBlock()); + var actualResult = JsonConvert.SerializeObject(returnedBlock); + Assert.Equal(expectedResult, actualResult); + } + + [Fact] + public async void BlockPostedAsync() + { + var service = BuildBlockPostMock(); + var response = await service.PostBlocksAsync(CreateMockBlockMessage()); + Assert.True(response.StatusCode == System.Net.HttpStatusCode.Created); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs index 8769d57..60bd965 100644 --- a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs @@ -22,7 +22,7 @@ public BankConfirmationBlockService(IHttpRequestSender requestSender) /// Retrieves confirmation blocks from the connected bank via paginated /// /// containing all bank to client confirmation blocks - public async Task GetAllBankConfiramtionBlocksAsync() + public async Task GetAllBankConfirmationBlocksAsync() { var response = await _requestSender.GetAsync("/confirmation_blocks"); diff --git a/src/Thenewboston/Bank/Api/BlocksService.cs b/src/Thenewboston/Bank/Api/BlocksService.cs new file mode 100644 index 0000000..916d039 --- /dev/null +++ b/src/Thenewboston/Bank/Api/BlocksService.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Common.Api.Models; +using Thenewboston.Common.Http; +using Thenewboston.Common.Models; + +namespace Thenewboston.Bank.Api +{ + public class BlocksService : IBlocksService + { + private IHttpRequestSender _requestSender; + + public BlocksService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + public async Task GetBlocksAsync() + { + var response = await _requestSender.GetAsync("/blocks"); + + if (!response.IsSuccessStatusCode) + { + //TODO: create specific exception + throw new Exception(); + } + + var stringResult = await response.Content.ReadAsStringAsync(); + + if (string.IsNullOrEmpty(stringResult)) + { + //TODO: create specific exception + throw new Exception(); + } + + var result = JsonConvert.DeserializeObject(stringResult); + + return result; + } + + public async Task PostBlocksAsync(Block block) + { + var httpContent = new StringContent(JsonConvert.SerializeObject(block), Encoding.UTF8, "application/json"); + var request = await _requestSender.PostAsync("/blocks", httpContent); + + if(!request.IsSuccessStatusCode) + { + // TODO: Create specific exception + throw new Exception(); + } + + var response = new HttpResponseMessage(System.Net.HttpStatusCode.Created); + return response; + } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs index 5cb2f86..231c90f 100644 --- a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs @@ -7,7 +7,7 @@ namespace Thenewboston.Bank.Api { public interface IBankConfirmationBlockService { - public Task GetAllBankConfiramtionBlocksAsync(); + public Task GetAllBankConfirmationBlocksAsync(); public Task PostConfirmationBlockAsync(ConfirmationBlock confirmationBlock); } } diff --git a/src/Thenewboston/Bank/Api/IBlocksService.cs b/src/Thenewboston/Bank/Api/IBlocksService.cs new file mode 100644 index 0000000..af28500 --- /dev/null +++ b/src/Thenewboston/Bank/Api/IBlocksService.cs @@ -0,0 +1,14 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Thenewboston.Common.Api.Models; +using Thenewboston.Common.Models; + +namespace Thenewboston.Bank.Api +{ + public interface IBlocksService + { + public Task GetBlocksAsync(); + + public Task PostBlocksAsync(Block block); + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Models/BankBlock.cs b/src/Thenewboston/Bank/Models/BankBlockResponse.cs similarity index 51% rename from src/Thenewboston/Bank/Models/BankBlock.cs rename to src/Thenewboston/Bank/Models/BankBlockResponse.cs index 3ac4c3e..f7eb28b 100644 --- a/src/Thenewboston/Bank/Models/BankBlock.cs +++ b/src/Thenewboston/Bank/Models/BankBlockResponse.cs @@ -1,18 +1,26 @@ using System; +using Newtonsoft.Json; + namespace Thenewboston.Bank.Models { public class BankBlock { + [JsonProperty(PropertyName ="id")] public string Id { get; set; } - public string BalanceKey { get; set; } - - public string Sender { get; set; } - - public string Signature { get; set; } - + [JsonProperty(PropertyName ="created_date")] public DateTime Created { get; set; } + [JsonProperty(PropertyName ="modified_date")] public DateTime Modified { get; set; } + + [JsonProperty(PropertyName ="balance_key")] + public string BalanceKey { get; set; } + + [JsonProperty(PropertyName ="sender")] + public string Sender { get; set; } + + [JsonProperty(PropertyName ="signature")] + public string Signature { get; set; } } } diff --git a/src/Thenewboston/Common/Models/Block.cs b/src/Thenewboston/Common/Models/Block.cs new file mode 100644 index 0000000..fcf5111 --- /dev/null +++ b/src/Thenewboston/Common/Models/Block.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Common.Models +{ + public class Block + { + [JsonProperty(PropertyName ="account_number")] + public string AccountNumber { get; set; } + + [JsonProperty(PropertyName ="message")] + public BlockMessage Message { get; set; } + + [JsonProperty(PropertyName ="signature")] + public string Signature { get; set; } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Common/Models/BlockMessage.cs b/src/Thenewboston/Common/Models/BlockMessage.cs new file mode 100644 index 0000000..78b7398 --- /dev/null +++ b/src/Thenewboston/Common/Models/BlockMessage.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Thenewboston.Common.Models +{ + public class BlockMessage + { + [JsonProperty(PropertyName ="balance_key")] + public string BalanceKey { get; set; } + + [JsonProperty(PropertyName ="txs")] + public List Transactions { get; set; } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Common/Models/BlockTransaction.cs b/src/Thenewboston/Common/Models/BlockTransaction.cs new file mode 100644 index 0000000..cebb961 --- /dev/null +++ b/src/Thenewboston/Common/Models/BlockTransaction.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Common.Models +{ + public class BlockTransaction + { + [JsonProperty(PropertyName ="amount")] + public string Amount { get; set; } + + [JsonProperty(PropertyName ="recipient")] + public string Recipient { get; set; } + } +} \ No newline at end of file From 00305ce8aa28a750c13ee299ec197af23db626a2 Mon Sep 17 00:00:00 2001 From: Alfred Neequaye Date: Thu, 26 Nov 2020 11:43:56 +0000 Subject: [PATCH 04/37] Made PaginationResponseModel Generic Updated IInvalidBlocksService to use PaginationRespnseModel --- .../Api/BankConfirmationBlockServiceTests.cs | 4 +- .../Bank/Api/ConnectedBanksServiceTests.cs | 4 +- .../Bank/Api/InvalidBlockServiceTests.cs | 86 ++++++++++++------- .../Bank/Api/ValidatorServiceTests.cs | 4 +- .../Api/ConnectedBanksServiceTests.cs | 5 +- .../Validator/Api/ValidatorsServiceTests.cs | 4 +- src/Thenewboston/Bank/Api/AccountsService.cs | 1 - .../Bank/Api/BankConfirmationBlockService.cs | 5 +- .../Bank/Api/ConnectedBanksService.cs | 4 +- src/Thenewboston/Bank/Api/IAccountsService.cs | 3 +- .../Bank/Api/IBankConfirmationBlockService.cs | 3 +- .../Bank/Api/IConnectedBanksService.cs | 2 +- .../Bank/Api/IInvalidBlocksService.cs | 9 +- .../Bank/Api/IValidatorService.cs | 8 +- .../Bank/Api/InvalidBlocksService.cs | 53 +++++------- .../Bank/Api/Models/RequestModel.cs | 4 +- .../Bank/Api/TransactionsService.cs | 1 - src/Thenewboston/Bank/Api/ValidatorService.cs | 6 +- .../Api/Models/PaginatedResponseModel.cs | 4 +- .../Common/Api/Models/PaginationParams.cs | 16 ++++ src/Thenewboston/Thenewboston.csproj | 1 + .../Validator/Api/ConnectedBanksService.cs | 5 +- .../Validator/Api/IAccountsService.cs | 4 +- .../Validator/Api/IConnectedBanksService.cs | 3 +- .../Validator/Api/IValidatorsService.cs | 9 +- .../Validator/Api/ValidatorsService.cs | 8 +- 26 files changed, 137 insertions(+), 119 deletions(-) create mode 100644 src/Thenewboston/Common/Api/Models/PaginationParams.cs diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs index 3d0dab0..f072b0d 100644 --- a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs @@ -23,9 +23,9 @@ public class BankConfirmationBlockServiceTests #region Test Models - private PaginatedResponseModel CreateMockBankConfirmationBlock() + private PaginatedResponseModel CreateMockBankConfirmationBlock() { - return new PaginatedResponseModel() + return new PaginatedResponseModel() { Count = 1, Next = string.Empty, diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs index c308fdb..f326b56 100644 --- a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs @@ -20,7 +20,7 @@ public class GetBanksAsync [Fact] public async void ListOfBanksIsReturned() { - PaginatedResponseModel expectedResponseModel = new PaginatedResponseModel + var expectedResponseModel = new PaginatedResponseModel { Count = 2, Next = null, @@ -92,7 +92,7 @@ public async void UpdatedBankIsReturned() } } - public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock(PaginatedResponseModel expectedResponseModel) + public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock(PaginatedResponseModel expectedResponseModel) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(expectedResponseModel), Encoding.UTF8, "application/json"); diff --git a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs index 3c633d7..2065d17 100644 --- a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json; using Thenewboston.Bank.Api; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Xunit; @@ -18,14 +19,26 @@ public class InvalidBlockServiceTests public class GetInvalidBankBlocksAsync { [Fact] - public async void GetInvalidBlockReturnedSuccessCodeandData() + public async void GetInvalidBlockWithNoPaginationModelReturnedSuccessCodeandData() { var service = BuildBankInvalidServiceMock(); var invalidBankBlocks = await service.GetInvalidBankBlocksAsync(); - Assert.Equal(2, invalidBankBlocks.Count()); - Assert.Equal("2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", invalidBankBlocks.ElementAt(0).Id); + Assert.Equal(3, invalidBankBlocks.Count); + Assert.Equal("2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", invalidBankBlocks.Results.ElementAt(0).Id); + } + + [Fact] + public async void GetInvalidBlockWithPageOnlyPaginationReturnedSuccessCodeandData() + { + var pagination = new PaginationParams() {Page = 1}; + var service = BuildBankInvalidServiceMock(); + + var invalidBankBlocks = await service.GetInvalidBankBlocksAsync(); + + Assert.Equal(3, invalidBankBlocks.Count); + Assert.Equal("2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", invalidBankBlocks.Results.ElementAt(0).Id); } } public class SendInvalidBankBlocksAsync @@ -40,49 +53,62 @@ public async void SendInvalidBlockReturnedSuccessCodeandData() } } + private static List INVALID_BLOCK_TEST_DATA = new List + { + new BankInvalidBlock + { + Id = "2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", + BlockIdentifier = "65ae26192dfb9ec41f88c6d582b374a9b42ab58833e1612452d7a8f685dcd4d5", + Block = "3ff4ebb0-2b3d-429b-ba90-08133fcdee4e", + PrimaryValidator = "51461a75-dd8d-4133-81f4-543a3b054149", + ConfirmationValidator= "fcd2dce8-9e4f-4bf1-8dac-cdbaf64e5ce8", + Created = DateTime.Now.AddDays(-3), + Modified = DateTime.Now + }, + new BankInvalidBlock + { + Id = "5bcd53c5-19f9-a43b-ab04-3dfb17c3a165", + BlockIdentifier = "65ae26192dfb9ec41f88c6d582b374a9b42ab58833e1612452d7a8f685dcd4d5", + Block = "3ff4ebb0-2b3d-429b-ba90-08133fcdee4e", + PrimaryValidator = "51461a75-dd8d-4133-81f4-543a3b054149", + ConfirmationValidator= "fcd2dce8-9e4f-4bf1-8dac-cdbaf64e5ce8", + Created = DateTime.Now.AddDays(-4), + Modified = DateTime.Now + }, + new BankInvalidBlock + { + Id = "2b9e3180-cf38-4772-9d73-6318ee4113b9", + BlockIdentifier = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", + Block = "3ff4ebb0-2b3d-429b-ba90-08133fcdee4e", + PrimaryValidator = "51461a75-dd8d-4133-81f4-543a3b054149", + ConfirmationValidator= "fcd2dce8-9e4f-4bf1-8dac-cdbaf64e5ce8", + Created = DateTime.Now.AddDays(-5), + Modified = DateTime.Now + } + }; + private static InvalidBlocksService BuildBankInvalidServiceMock() { + var mockResponse = new PaginatedResponseModel() {Results = INVALID_BLOCK_TEST_DATA, Count = INVALID_BLOCK_TEST_DATA.Count}; var requestSender = new Mock(); - var listResult = new List - { - new BankInvalidBlock - { - Id = "2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", - BlockIdentifier = "65ae26192dfb9ec41f88c6d582b374a9b42ab58833e1612452d7a8f685dcd4d5", - Block = "3ff4ebb0-2b3d-429b-ba90-08133fcdee4e", - PrimaryValidator = "51461a75-dd8d-4133-81f4-543a3b054149", - ConfirmationValidator= "fcd2dce8-9e4f-4bf1-8dac-cdbaf64e5ce8", - Created = DateTime.Now.AddDays(-3), - Modified = DateTime.Now - }, - new BankInvalidBlock - { - Id = "2b9e3180-cf38-4772-9d73-6318ee4113b9", - BlockIdentifier = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", - Block = "3ff4ebb0-2b3d-429b-ba90-08133fcdee4e", - PrimaryValidator = "51461a75-dd8d-4133-81f4-543a3b054149", - ConfirmationValidator= "fcd2dce8-9e4f-4bf1-8dac-cdbaf64e5ce8", - Created = DateTime.Now.AddDays(-3), - Modified = DateTime.Now - } - }; - var getAllResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - getAllResponse.Content = new StringContent(JsonConvert.SerializeObject(listResult), Encoding.UTF8, "application/json"); + getAllResponse.Content = new StringContent(JsonConvert.SerializeObject(mockResponse), Encoding.UTF8, "application/json"); requestSender .Setup(x => x.GetAsync(It.IsAny())) .Returns(Task.FromResult(getAllResponse)); var postResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - postResponse.Content = new StringContent(JsonConvert.SerializeObject(listResult.First()), Encoding.UTF8, "application/json"); + postResponse.Content = new StringContent(JsonConvert.SerializeObject(INVALID_BLOCK_TEST_DATA.First()), Encoding.UTF8, "application/json"); //TODO Setup for more Scenarios requestSender - .Setup(x => x.PostAsync("/invalid_blocks", It.IsAny())) + .Setup(x => x.PostAsync( "/invalid_blocks", It.IsAny())) .Returns(Task.FromResult(postResponse)); requestSender + .Setup(x => x.GetAsync(It.IsRegex(@"\/invalid_blocks\?offset=[0-9]*&limit=[0-9]*"))) + .Returns(Task.FromResult(getAllResponse)); requestSender .Setup(x => x.GetAsync("/invalid_blocks")) .Returns(Task.FromResult(getAllResponse)); diff --git a/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs index 81a9173..313fbee 100644 --- a/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs @@ -24,7 +24,7 @@ public class GetAllValidatorsAsync [Fact] public async void ListOfValidatorsIsReturned() { - PaginatedResponseModel expectedResponseModel = new PaginatedResponseModel + var expectedResponseModel = new PaginatedResponseModel { Count = 2, Next = null, @@ -116,7 +116,7 @@ public async void ValidatorIsPatched() } } - public static IValidatorService BuildBankValidatorMock(PaginatedResponseModel expectedResponseModel) + public static IValidatorService BuildBankValidatorMock(PaginatedResponseModel expectedResponseModel) { var requestSender = new Mock(); diff --git a/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs index 906212d..0d43e36 100644 --- a/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs @@ -4,6 +4,7 @@ using System.Text; using Moq; using Newtonsoft.Json; +using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Thenewboston.Validator.Api; @@ -19,7 +20,7 @@ public class GetBanksAsync [Fact] public async void ListOfBanksIsReturned() { - PaginatedResponseModel expectedResponseModel = new PaginatedResponseModel + var expectedResponseModel = new PaginatedResponseModel { Count = 2, Next = null, @@ -64,7 +65,7 @@ public async void ListOfBanksIsReturned() } } - public static IConnectedBanksService BuildGetBanksAsyncValidatorServiceMock(PaginatedResponseModel expectedResponseModel) + public static IConnectedBanksService BuildGetBanksAsyncValidatorServiceMock(PaginatedResponseModel expectedResponseModel) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(expectedResponseModel), Encoding.UTF8, "application/json"); diff --git a/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs index a17c22e..83296f6 100644 --- a/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs @@ -23,7 +23,7 @@ public class GetAllValidatorsAsync [Fact] public async void ListOfValidatorsIsReturned() { - PaginatedResponseModel expectedResponseModel = new PaginatedResponseModel + var expectedResponseModel = new PaginatedResponseModel { Count = 2, Next = null, @@ -75,7 +75,7 @@ public async void ListOfValidatorsIsReturned() } } - public static IValidatorsService BuildBankValidatorMock(PaginatedResponseModel expectedResponseModel) + public static IValidatorsService BuildBankValidatorMock(PaginatedResponseModel expectedResponseModel) { var requestSender = new Mock(); diff --git a/src/Thenewboston/Bank/Api/AccountsService.cs b/src/Thenewboston/Bank/Api/AccountsService.cs index cbc19b6..e4ec86f 100644 --- a/src/Thenewboston/Bank/Api/AccountsService.cs +++ b/src/Thenewboston/Bank/Api/AccountsService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Net.Http; using System.Text; diff --git a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs index 8769d57..364d971 100644 --- a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs @@ -6,6 +6,7 @@ using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Thenewboston.Common.Models; +using BankConfirmationBlockResponse = Thenewboston.Bank.Models.BankConfirmationBlockResponse; namespace Thenewboston.Bank.Api { @@ -22,7 +23,7 @@ public BankConfirmationBlockService(IHttpRequestSender requestSender) /// Retrieves confirmation blocks from the connected bank via paginated /// /// containing all bank to client confirmation blocks - public async Task GetAllBankConfiramtionBlocksAsync() + public async Task> GetAllBankConfiramtionBlocksAsync() { var response = await _requestSender.GetAsync("/confirmation_blocks"); @@ -40,7 +41,7 @@ public async Task GetAllBankConfiramtionBlocksAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResponse); + var result = JsonConvert.DeserializeObject>(stringResponse); return result; } diff --git a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs index 4367fdf..e97d203 100644 --- a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs @@ -19,7 +19,7 @@ public ConnectedBanksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task GetBanksAsync() + public async Task> GetBanksAsync() { var response = await _requestSender.GetAsync("/banks"); @@ -37,7 +37,7 @@ public async Task GetBanksAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } diff --git a/src/Thenewboston/Bank/Api/IAccountsService.cs b/src/Thenewboston/Bank/Api/IAccountsService.cs index c2055bf..51dd16f 100644 --- a/src/Thenewboston/Bank/Api/IAccountsService.cs +++ b/src/Thenewboston/Bank/Api/IAccountsService.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; diff --git a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs index 5cb2f86..9a2f9d5 100644 --- a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs @@ -2,12 +2,13 @@ using System.Threading.Tasks; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Models; +using BankConfirmationBlockResponse = Thenewboston.Bank.Models.BankConfirmationBlockResponse; namespace Thenewboston.Bank.Api { public interface IBankConfirmationBlockService { - public Task GetAllBankConfiramtionBlocksAsync(); + public Task> GetAllBankConfiramtionBlocksAsync(); public Task PostConfirmationBlockAsync(ConfirmationBlock confirmationBlock); } } diff --git a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs index b742af2..9f35ad8 100644 --- a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs @@ -6,7 +6,7 @@ namespace Thenewboston.Bank.Api.Models { public interface IConnectedBanksService { - Task GetBanksAsync(); + Task> GetBanksAsync(); Task UpdateBankAsync(string nodeIdentifier, RequestModel payload); } } diff --git a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs index d1cc0a0..67a915e 100644 --- a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs @@ -1,15 +1,12 @@ -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Threading.Tasks; +using System.Threading.Tasks; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; namespace Thenewboston.Bank.Api { public interface IInvalidBlocksService { - Task> GetInvalidBankBlocksAsync(); + Task> GetInvalidBankBlocksAsync(PaginationParams pagination = default); Task SendInvalidBlocksToBankAsync(BankInvalidBlockRequest model); } diff --git a/src/Thenewboston/Bank/Api/IValidatorService.cs b/src/Thenewboston/Bank/Api/IValidatorService.cs index c0850c8..3e3ac09 100644 --- a/src/Thenewboston/Bank/Api/IValidatorService.cs +++ b/src/Thenewboston/Bank/Api/IValidatorService.cs @@ -1,17 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; -using Thenewboston.Common.Models; namespace Thenewboston.Bank.Api { public interface IValidatorService { - Task GetAllValidatorsAsync(); + Task> GetAllValidatorsAsync(); Task PatchValidatorAsync(string nodeIdentifier, RequestModel trust); diff --git a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs index fef4348..61f65a5 100644 --- a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs @@ -1,10 +1,10 @@ using System; -using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; namespace Thenewboston.Bank.Api @@ -17,45 +17,36 @@ public InvalidBlocksService(IHttpRequestSender requestSender) { _requestSender = requestSender; } - - public async Task> GetInvalidBankBlocksAsync() + + public async Task> GetInvalidBankBlocksAsync(PaginationParams pagination = null) { - try - { - var response = await _requestSender.GetAsync("/invalid_blocks"); - if (!response.IsSuccessStatusCode) - { - //TODO Use a More Specific Exception Type - throw new Exception(); - } + var url = ""; - var responseContent = await response.Content.ReadAsStringAsync(); - return JsonConvert.DeserializeObject>(responseContent); - } - catch (Exception ) + url = pagination switch { + ( not null and >0 , _ ,_ ) => $"/invalid_blocks?page={pagination.Page}", + (<= 0 or null , >= 0 , > 0) => $"/invalid_blocks?offset={pagination.Offset}&limit={pagination.Limit}", + (<= 0 or null , >= 0 , <=0 or null) => $"/invalid_blocks?offset={pagination.Offset}&limit=20", + _ => $"/invalid_blocks?page=1" + }; + var response = await _requestSender.GetAsync(url); + if (!response.IsSuccessStatusCode) { - //TODO Handle Possible Known Exception Types - throw; + throw new Exception(); } + + var responseContent = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject>(responseContent); } public async Task SendInvalidBlocksToBankAsync(BankInvalidBlockRequest model) { - try - { - var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); - var response = await _requestSender.PostAsync("/invalid_blocks", content); - if (!response.IsSuccessStatusCode) - throw new Exception("Error Sending Invalid Block to Bank"); //TODO Use Specific Exception + var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); + var response = await _requestSender.PostAsync("/invalid_blocks", content); + if (!response.IsSuccessStatusCode) + throw new Exception("Error Sending Invalid Block to Bank"); - var responseContent = await response.Content.ReadAsStringAsync(); - return JsonConvert.DeserializeObject(responseContent); - } - catch - { - //TODO Handle Specific Exceptions Types - throw; - } + var responseContent = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(responseContent); } } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/Models/RequestModel.cs b/src/Thenewboston/Bank/Api/Models/RequestModel.cs index b7352ba..f2cd6f3 100644 --- a/src/Thenewboston/Bank/Api/Models/RequestModel.cs +++ b/src/Thenewboston/Bank/Api/Models/RequestModel.cs @@ -1,6 +1,4 @@ -using System; - -namespace Thenewboston.Bank.Api.Models +namespace Thenewboston.Bank.Api.Models { public class RequestModel { diff --git a/src/Thenewboston/Bank/Api/TransactionsService.cs b/src/Thenewboston/Bank/Api/TransactionsService.cs index 942e401..c5c5b81 100644 --- a/src/Thenewboston/Bank/Api/TransactionsService.cs +++ b/src/Thenewboston/Bank/Api/TransactionsService.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Net; using System.Threading.Tasks; using Newtonsoft.Json; using Thenewboston.Bank.Models; diff --git a/src/Thenewboston/Bank/Api/ValidatorService.cs b/src/Thenewboston/Bank/Api/ValidatorService.cs index c14274c..74ff95c 100644 --- a/src/Thenewboston/Bank/Api/ValidatorService.cs +++ b/src/Thenewboston/Bank/Api/ValidatorService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -8,7 +7,6 @@ using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; -using Thenewboston.Common.Models; namespace Thenewboston.Bank.Api { @@ -21,7 +19,7 @@ public ValidatorService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task GetAllValidatorsAsync() + public async Task> GetAllValidatorsAsync() { var response = await _requestSender.GetAsync("/validators"); @@ -39,7 +37,7 @@ public async Task GetAllValidatorsAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } diff --git a/src/Thenewboston/Common/Api/Models/PaginatedResponseModel.cs b/src/Thenewboston/Common/Api/Models/PaginatedResponseModel.cs index f5f59bd..02ebca7 100644 --- a/src/Thenewboston/Common/Api/Models/PaginatedResponseModel.cs +++ b/src/Thenewboston/Common/Api/Models/PaginatedResponseModel.cs @@ -5,7 +5,7 @@ namespace Thenewboston.Common.Api.Models { - public class PaginatedResponseModel + public class PaginatedResponseModel { [JsonProperty(PropertyName = "count")] public int Count { get; set; } @@ -17,6 +17,6 @@ public class PaginatedResponseModel public string Previous { get; set; } [JsonProperty(PropertyName = "results")] - public IEnumerable Results { get; set; } + public IEnumerable Results { get; set; } } } diff --git a/src/Thenewboston/Common/Api/Models/PaginationParams.cs b/src/Thenewboston/Common/Api/Models/PaginationParams.cs new file mode 100644 index 0000000..c487d43 --- /dev/null +++ b/src/Thenewboston/Common/Api/Models/PaginationParams.cs @@ -0,0 +1,16 @@ +namespace Thenewboston.Common.Api.Models +{ + public class PaginationParams + { + public int? Page { get; set; } + public int? Limit { get; set; } + public int? Offset { get; set; } + + public void Deconstruct(out int? page, out int? offset, out int? limit) + { + page = Page; + offset = Offset; + limit = Limit; + } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Thenewboston.csproj b/src/Thenewboston/Thenewboston.csproj index fec98d3..207af73 100644 --- a/src/Thenewboston/Thenewboston.csproj +++ b/src/Thenewboston/Thenewboston.csproj @@ -2,6 +2,7 @@ netcoreapp3.1 + 9 diff --git a/src/Thenewboston/Validator/Api/ConnectedBanksService.cs b/src/Thenewboston/Validator/Api/ConnectedBanksService.cs index cb7e553..fe5feef 100644 --- a/src/Thenewboston/Validator/Api/ConnectedBanksService.cs +++ b/src/Thenewboston/Validator/Api/ConnectedBanksService.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; +using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api { @@ -15,7 +16,7 @@ public ConnectedBanksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task GetBanksAsync() + public async Task> GetBanksAsync() { var response = await _requestSender.GetAsync("/banks"); @@ -33,7 +34,7 @@ public async Task GetBanksAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } diff --git a/src/Thenewboston/Validator/Api/IAccountsService.cs b/src/Thenewboston/Validator/Api/IAccountsService.cs index 79342c8..6b142b6 100644 --- a/src/Thenewboston/Validator/Api/IAccountsService.cs +++ b/src/Thenewboston/Validator/Api/IAccountsService.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Numerics; +using System.Collections.Generic; using System.Threading.Tasks; using Thenewboston.Validator.Models; diff --git a/src/Thenewboston/Validator/Api/IConnectedBanksService.cs b/src/Thenewboston/Validator/Api/IConnectedBanksService.cs index f2d7c24..2a6e967 100644 --- a/src/Thenewboston/Validator/Api/IConnectedBanksService.cs +++ b/src/Thenewboston/Validator/Api/IConnectedBanksService.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; using Thenewboston.Common.Api.Models; +using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api { public interface IConnectedBanksService { - Task GetBanksAsync(); + Task> GetBanksAsync(); } } diff --git a/src/Thenewboston/Validator/Api/IValidatorsService.cs b/src/Thenewboston/Validator/Api/IValidatorsService.cs index eec9377..fad8d19 100644 --- a/src/Thenewboston/Validator/Api/IValidatorsService.cs +++ b/src/Thenewboston/Validator/Api/IValidatorsService.cs @@ -1,14 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; using Thenewboston.Common.Api.Models; -using Thenewboston.Common.Models; +using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api { public interface IValidatorsService { - Task GetAllValidatorsAsync(); + Task> GetAllValidatorsAsync(); } } diff --git a/src/Thenewboston/Validator/Api/ValidatorsService.cs b/src/Thenewboston/Validator/Api/ValidatorsService.cs index 30302b6..b5f45d3 100644 --- a/src/Thenewboston/Validator/Api/ValidatorsService.cs +++ b/src/Thenewboston/Validator/Api/ValidatorsService.cs @@ -1,11 +1,9 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; -using Thenewboston.Common.Models; +using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api { @@ -18,7 +16,7 @@ public ValidatorsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task GetAllValidatorsAsync() + public async Task> GetAllValidatorsAsync() { var response = await _requestSender.GetAsync("/validators"); @@ -36,7 +34,7 @@ public async Task GetAllValidatorsAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } From a3c815e65096659f997f22d3c369918810f6952c Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Thu, 26 Nov 2020 15:15:08 +0200 Subject: [PATCH 05/37] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0587c05..b3d4a50 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ This is a .NET Core SDK for **thenewboston**, which will be available cross-platoform. The library itself will solely contain the domain and data layers of **thenewboston**. The presentation layer will be the responsibility of the host application. ## Status -![SDK CI pipeline](https://github.com/thenewboston-developers/dotnetcore-sdk/workflows/SDK%20CI%20pipeline/badge.svg) +![SDK CI pipeline](https://github.com/thenewboston-developers/dotnetcore-sdk/workflows/SDK%20CI%20pipeline/badge.svg) +![Create and Publish package](https://github.com/thenewboston-developers/dotnetcore-sdk/workflows/Create%20and%20Publish%20package/badge.svg?branch=main) ## How to get started From eaa68be0fdb26016932fd291c2402d0e95c60027 Mon Sep 17 00:00:00 2001 From: Nish Date: Thu, 26 Nov 2020 12:14:24 -0600 Subject: [PATCH 06/37] =?UTF-8?q?Done=20with=20validator=20api=20?= =?UTF-8?q?=F0=9F=98=8A=F0=9F=98=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Validator/Api/BankBlockServiceTest.cs | 77 +++++++++++++++++++ src/Thenewboston/Bank/Api/BlocksService.cs | 1 - .../Validator/Api/BankBlockService.cs | 36 +++++++++ .../Validator/Api/IBankBlockService.cs | 11 +++ .../Validator/Models/ValidatorBankBlock.cs | 17 ++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/Thenewboston.Tests/Validator/Api/BankBlockServiceTest.cs create mode 100644 src/Thenewboston/Validator/Api/BankBlockService.cs create mode 100644 src/Thenewboston/Validator/Api/IBankBlockService.cs create mode 100644 src/Thenewboston/Validator/Models/ValidatorBankBlock.cs diff --git a/src/Thenewboston.Tests/Validator/Api/BankBlockServiceTest.cs b/src/Thenewboston.Tests/Validator/Api/BankBlockServiceTest.cs new file mode 100644 index 0000000..3a33f10 --- /dev/null +++ b/src/Thenewboston.Tests/Validator/Api/BankBlockServiceTest.cs @@ -0,0 +1,77 @@ +using System.Collections.Generic; +using System.Net.Http; +using Moq; +using Thenewboston.Common.Http; +using Thenewboston.Common.Models; +using Thenewboston.Validator.Api; +using Thenewboston.Validator.Models; +using Xunit; + +namespace Thenewboston.Tests.Validator.Api +{ + public class BankBlockServiceTest + { + #region Test Models + private ValidatorBankBlock CreateMockBankBlock() + { + return new ValidatorBankBlock() + { + BankBlock = new Block() + { + AccountNumber = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", + Message = new BlockMessage() + { + BalanceKey = "ee7a6d21feb2905605f9af446566e003decec3de2f55a6eff9815d41fcde59e0", + Transactions = new List() + { + new BlockTransaction() { + Amount = "4.125", + Recipient = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" + }, + new BlockTransaction() { + Amount = "1", + Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8" + }, + new BlockTransaction() { + Amount = "4", + Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314" + } + } + }, + Signature = "e8b5215193cd5f91029b2a7a9ff2426b0a9fc0032f5a0f74ec0e6cc2f3ac9f20acd170f90e1557e561c85d34daa37d0cec90901f3d4c9579700847f67de22a05" + }, + NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", + Signature = "4f019d36d362f09960399fe51dd67d7ddbee27d73994558cf4015bb13260957f861afaa1694d40fd0397ed2a889834d8a20bff4c3417bbde383e2cd4e219cb0f" + }; + } + + #endregion + + #region Mock Service + + private IBankBlockService BuildBankBlockPostMock() + { + var requestSenderMock = new Mock(); + + requestSenderMock.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.Created)); + + IBankBlockService service = new BankBlockService(requestSenderMock.Object); + return service; + } + + #endregion + + #region Tests + + [Fact] + public async void BankConfirmationBlockMessagePostedAsync() + { + var service = BuildBankBlockPostMock(); + var response = await service.PostBankBlockAsync(CreateMockBankBlock()); + Assert.True(response.StatusCode == System.Net.HttpStatusCode.Created); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/BlocksService.cs b/src/Thenewboston/Bank/Api/BlocksService.cs index 916d039..918943b 100644 --- a/src/Thenewboston/Bank/Api/BlocksService.cs +++ b/src/Thenewboston/Bank/Api/BlocksService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading.Tasks; diff --git a/src/Thenewboston/Validator/Api/BankBlockService.cs b/src/Thenewboston/Validator/Api/BankBlockService.cs new file mode 100644 index 0000000..35d3133 --- /dev/null +++ b/src/Thenewboston/Validator/Api/BankBlockService.cs @@ -0,0 +1,36 @@ +using System; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Common.Http; +using Thenewboston.Validator.Models; + + +namespace Thenewboston.Validator.Api +{ + public class BankBlockService : IBankBlockService + { + private readonly IHttpRequestSender _requestSender; + + public BankBlockService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + public async Task PostBankBlockAsync(ValidatorBankBlock block) + { + var httpContent = new StringContent(JsonConvert.SerializeObject(block), Encoding.UTF8, "application/json"); + var request = await _requestSender.PostAsync("/bank_blocks", httpContent); + + if(!request.IsSuccessStatusCode) + { + // TODO: Create specific exception + throw new Exception(); + } + + var response = new HttpResponseMessage(System.Net.HttpStatusCode.Created); + return response; + } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Validator/Api/IBankBlockService.cs b/src/Thenewboston/Validator/Api/IBankBlockService.cs new file mode 100644 index 0000000..25d51c2 --- /dev/null +++ b/src/Thenewboston/Validator/Api/IBankBlockService.cs @@ -0,0 +1,11 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Thenewboston.Validator.Models; + +namespace Thenewboston.Validator.Api +{ + public interface IBankBlockService + { + public Task PostBankBlockAsync(ValidatorBankBlock block); + } +} \ No newline at end of file diff --git a/src/Thenewboston/Validator/Models/ValidatorBankBlock.cs b/src/Thenewboston/Validator/Models/ValidatorBankBlock.cs new file mode 100644 index 0000000..a1b3ed0 --- /dev/null +++ b/src/Thenewboston/Validator/Models/ValidatorBankBlock.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using Thenewboston.Common.Models; + +namespace Thenewboston.Validator.Models +{ + public class ValidatorBankBlock + { + [JsonProperty(PropertyName ="block")] + public Block BankBlock { get; set; } + + [JsonProperty(PropertyName ="node_identifier")] + public string NodeIdentifier { get; set; } + + [JsonProperty(PropertyName ="signature")] + public string Signature { get; set; } + } +} \ No newline at end of file From e5d7ea593ae1fd124950a10b67e5eb8b0499f85d Mon Sep 17 00:00:00 2001 From: Alfred Neequaye Date: Thu, 26 Nov 2020 19:20:24 +0000 Subject: [PATCH 07/37] Revert C#9 Support --- src/Thenewboston/Bank/Api/InvalidBlocksService.cs | 6 +++--- src/Thenewboston/Thenewboston.csproj | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs index 61f65a5..92561b4 100644 --- a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs @@ -23,9 +23,9 @@ public async Task> GetInvalidBankBlocks var url = ""; url = pagination switch { - ( not null and >0 , _ ,_ ) => $"/invalid_blocks?page={pagination.Page}", - (<= 0 or null , >= 0 , > 0) => $"/invalid_blocks?offset={pagination.Offset}&limit={pagination.Limit}", - (<= 0 or null , >= 0 , <=0 or null) => $"/invalid_blocks?offset={pagination.Offset}&limit=20", + PaginationParams p when p.Page != null && p.Page >0 => $"/invalid_blocks?page={p.Page}", + PaginationParams p when (p.Page == null || p.Page <= 0) && p.Offset >=0 && p.Limit >0 => $"/invalid_blocks?offset={p.Offset}&limit={p.Limit}", + PaginationParams p when (p.Page == null || p.Page <= 0) && p.Offset >= 0 && (p.Limit <=0 || p.Limit is null) => $"/invalid_blocks?offset={pagination.Offset}&limit=20", _ => $"/invalid_blocks?page=1" }; var response = await _requestSender.GetAsync(url); diff --git a/src/Thenewboston/Thenewboston.csproj b/src/Thenewboston/Thenewboston.csproj index 207af73..fec98d3 100644 --- a/src/Thenewboston/Thenewboston.csproj +++ b/src/Thenewboston/Thenewboston.csproj @@ -2,7 +2,6 @@ netcoreapp3.1 - 9 From b0ca9d51717ae2c9506a9c92a1ce5acdc45a5797 Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Fri, 27 Nov 2020 03:23:40 -0500 Subject: [PATCH 08/37] Create models for Upgrade Notice --- src/Thenewboston/Bank/Models/UpgradeNotice.cs | 16 ++++++++++++++++ .../Bank/Models/UpgradeNoticeMessage.cs | 10 ++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/Thenewboston/Bank/Models/UpgradeNotice.cs create mode 100644 src/Thenewboston/Bank/Models/UpgradeNoticeMessage.cs diff --git a/src/Thenewboston/Bank/Models/UpgradeNotice.cs b/src/Thenewboston/Bank/Models/UpgradeNotice.cs new file mode 100644 index 0000000..2029ad0 --- /dev/null +++ b/src/Thenewboston/Bank/Models/UpgradeNotice.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Bank.Models +{ + public class UpgradeNotice + { + [JsonProperty(PropertyName ="message")] + public UpgradeNoticeMessage Message { get; set; } + + [JsonProperty(PropertyName = "node_identifier")] + public string NodeIdentifier { get; set; } + + [JsonProperty(PropertyName ="signature")] + public string Signature { get; set; } + } +} diff --git a/src/Thenewboston/Bank/Models/UpgradeNoticeMessage.cs b/src/Thenewboston/Bank/Models/UpgradeNoticeMessage.cs new file mode 100644 index 0000000..6c38c5a --- /dev/null +++ b/src/Thenewboston/Bank/Models/UpgradeNoticeMessage.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Bank.Models +{ + public class UpgradeNoticeMessage + { + [JsonProperty(PropertyName = "bank_node_identifier")] + public string BankNodeIdentifier { get; set; } + } +} From b9a26490ff2314aab013cfeffaa41ac0776c3d3c Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Fri, 27 Nov 2020 03:38:14 -0500 Subject: [PATCH 09/37] Create service and interface for Upgrade Notices --- .../Bank/Api/IUpgradeNoticeService.cs | 11 +++++ .../Bank/Api/UpgradeNoticeService.cs | 40 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/Thenewboston/Bank/Api/IUpgradeNoticeService.cs create mode 100644 src/Thenewboston/Bank/Api/UpgradeNoticeService.cs diff --git a/src/Thenewboston/Bank/Api/IUpgradeNoticeService.cs b/src/Thenewboston/Bank/Api/IUpgradeNoticeService.cs new file mode 100644 index 0000000..b7019ce --- /dev/null +++ b/src/Thenewboston/Bank/Api/IUpgradeNoticeService.cs @@ -0,0 +1,11 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Thenewboston.Bank.Models; + +namespace Thenewboston.Bank.Api +{ + public interface IUpgradeNoticeService + { + Task PostUpgradeNoticeAsync(UpgradeNotice upgradeNotice); + } +} diff --git a/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs b/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs new file mode 100644 index 0000000..3dc356c --- /dev/null +++ b/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs @@ -0,0 +1,40 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Http; + +namespace Thenewboston.Bank.Api +{ + public class UpgradeNoticeService : IUpgradeNoticeService + { + IHttpRequestSender _requestSender; + + public UpgradeNoticeService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + public async Task PostUpgradeNoticeAsync(UpgradeNotice upgradeNotice) + { + if(upgradeNotice is null) + { + // TODO: Create specific exception + throw new Exception(); + } + + var httpContent = new StringContent(JsonConvert.SerializeObject(upgradeNotice)); + var jsonString = await new StringContent(JsonConvert.SerializeObject(upgradeNotice)).ReadAsStringAsync(); + + if(string.IsNullOrEmpty(jsonString)) + { + // TODO: Create specific exception + throw new Exception(); + } + + var result = await _requestSender.PostAsync($"/upgrade_notice/{upgradeNotice.NodeIdentifier}", httpContent); + return result; + } + } +} From 4839ad45d3670816fa80a36afc7a2a5bfddde10b Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Fri, 27 Nov 2020 03:51:39 -0500 Subject: [PATCH 10/37] Created Tests for Upgrade Notice Service --- .../Bank/Api/UpgradeNoticeTests.cs | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/Thenewboston.Tests/Bank/Api/UpgradeNoticeTests.cs diff --git a/src/Thenewboston.Tests/Bank/Api/UpgradeNoticeTests.cs b/src/Thenewboston.Tests/Bank/Api/UpgradeNoticeTests.cs new file mode 100644 index 0000000..746013b --- /dev/null +++ b/src/Thenewboston.Tests/Bank/Api/UpgradeNoticeTests.cs @@ -0,0 +1,87 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Moq; +using Newtonsoft.Json; +using Thenewboston.Bank.Api; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Http; +using Xunit; + +namespace Thenewboston.Tests.Bank.Api +{ + public class UpgradeNoticeTests + { + // *************************************** + // Bank Upgrade Notice Tests * + // Created 11/27/2020 based on available * + // documentation * + // *************************************** + + #region Mock Test Models + + private UpgradeNotice CreateUpgradeNoticeModelMock() + { + return new UpgradeNotice() + { + Message = new UpgradeNoticeMessage() + { + BankNodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1" + }, + NodeIdentifier = "59479a31c3b91d96bb7a0b3e07f18d4bf301f1bb0bde05f8d36d9611dcbe7cbf", + Signature = "e9862cf176523449417b5f3426cb7bf0a3813ef04fae3330faa50b6468d9da9c55967a24c40040eaa6bc33843804bda9a0307bffe906ed8c7b2a55c15dabaa0d" + }; + } + + #endregion + + #region Mock Services + + public IUpgradeNoticeService BuildUpgradeNoticeServiceServerAcceptsMock() + { + var requestSender = new Mock(); + var serializedContent = new StringContent(JsonConvert.SerializeObject(CreateUpgradeNoticeModelMock())); + var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + + requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(response); + + return new UpgradeNoticeService(requestSender.Object); + } + + public IUpgradeNoticeService BuildUpgradeNoticeServiceServerRejectsMock() + { + var requestSender = new Mock(); + var serializedContent = new StringContent(JsonConvert.SerializeObject(CreateUpgradeNoticeModelMock())); + var response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + + requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(response); + + return new UpgradeNoticeService(requestSender.Object); + } + + #endregion + + #region Tests + + [Fact] + public async Task UpgradeNoticeBankAcceptsTest() + { + var service = BuildUpgradeNoticeServiceServerAcceptsMock(); + var result = await service.PostUpgradeNoticeAsync(CreateUpgradeNoticeModelMock()); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + + [Fact] + public async Task UpgradeNoticeBankRejectsTest() + { + var service = BuildUpgradeNoticeServiceServerRejectsMock(); + var result = await service.PostUpgradeNoticeAsync(CreateUpgradeNoticeModelMock()); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + + #endregion + } +} From 2a728534b6c90440fdd6164d5a40b764a2081024 Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Fri, 27 Nov 2020 16:16:12 -0500 Subject: [PATCH 11/37] Created Upgrade Request Service, associated models, and tests. Fixed an inefficiency in UpgradeNoticeService. --- .../Bank/Api/UpgradeRequestTests.cs | 80 +++++++++++++++++++ .../Bank/Api/UpgradeNoticeService.cs | 2 +- .../Validator/Api/IUpgradeRequestService.cs | 11 +++ .../Validator/Api/UpgradeRequestService.cs | 47 +++++++++++ .../Validator/Models/UpgradeRequest.cs | 16 ++++ .../Validator/Models/UpgradeRequestMessage.cs | 10 +++ 6 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs create mode 100644 src/Thenewboston/Validator/Api/IUpgradeRequestService.cs create mode 100644 src/Thenewboston/Validator/Api/UpgradeRequestService.cs create mode 100644 src/Thenewboston/Validator/Models/UpgradeRequest.cs create mode 100644 src/Thenewboston/Validator/Models/UpgradeRequestMessage.cs diff --git a/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs b/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs new file mode 100644 index 0000000..b839f70 --- /dev/null +++ b/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs @@ -0,0 +1,80 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Moq; +using Thenewboston.Common.Http; +using Thenewboston.Validator.Api; +using Thenewboston.Validator.Models; +using Xunit; + +namespace Thenewboston.Tests.Bank.Api +{ + public class UpgradeRequestTests + { + #region Upgrade Request Mock Models + + public UpgradeRequest CreateMockUpgradeRequest() + { + return new UpgradeRequest() + { + Message = new UpgradeRequestMessage() + { + ValidatorNodeIdentifier = "59479a31c3b91d96bb7a0b3e07f18d4bf301f1bb0bde05f8d36d9611dcbe7cbf" + }, + NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", + Signature = "90a365d1950b1765b973d3d21d763f9bea7eb1f9d1f33d6e9c3f8eb4803022f97ad3173474707b4786e556cccf4ca0a0e81d18edb655b090967c96c22c40140a" + }; + } + + #endregion + + #region Upgrade Request Mock Services + + public IUpgradeRequestService BuildUpgradeRequestServiceNodeAcceptsMock() + { + var requestSender = new Mock(); + var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + + requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(httpResponse); + + var service = new UpgradeRequestService(requestSender.Object); + return service; + } + + public IUpgradeRequestService BuildUpgradeRequestServiceNodeRejectsMock() + { + var requestSender = new Mock(); + var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + + requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(httpResponse); + + var service = new UpgradeRequestService(requestSender.Object); + return service; + } + + #endregion + + #region Tests + + [Fact] + public async Task UpgradeRequestNodeAcceptsTest() + { + var service = BuildUpgradeRequestServiceNodeAcceptsMock(); + var result = await service.PostUpgradeRequestAsync(CreateMockUpgradeRequest()); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + + [Fact] + public async Task UpgradeRequestNodeRejectsTest() + { + var service = BuildUpgradeRequestServiceNodeRejectsMock(); + var result = await service.PostUpgradeRequestAsync(CreateMockUpgradeRequest()); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + + #endregion + } +} diff --git a/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs b/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs index 3dc356c..480ed67 100644 --- a/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs +++ b/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs @@ -25,7 +25,7 @@ public async Task PostUpgradeNoticeAsync(UpgradeNotice upgr } var httpContent = new StringContent(JsonConvert.SerializeObject(upgradeNotice)); - var jsonString = await new StringContent(JsonConvert.SerializeObject(upgradeNotice)).ReadAsStringAsync(); + var jsonString = await httpContent.ReadAsStringAsync(); if(string.IsNullOrEmpty(jsonString)) { diff --git a/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs b/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs new file mode 100644 index 0000000..b89d8e9 --- /dev/null +++ b/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs @@ -0,0 +1,11 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Thenewboston.Validator.Models; + +namespace Thenewboston.Validator.Api +{ + public interface IUpgradeRequestService + { + public Task PostUpgradeRequestAsync(UpgradeRequest upgradeRequest); + } +} diff --git a/src/Thenewboston/Validator/Api/UpgradeRequestService.cs b/src/Thenewboston/Validator/Api/UpgradeRequestService.cs new file mode 100644 index 0000000..3df74b5 --- /dev/null +++ b/src/Thenewboston/Validator/Api/UpgradeRequestService.cs @@ -0,0 +1,47 @@ +using System; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Common.Http; +using Thenewboston.Validator.Models; + +namespace Thenewboston.Validator.Api +{ + public class UpgradeRequestService : IUpgradeRequestService + { + private readonly IHttpRequestSender _requestSender; + + public UpgradeRequestService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + /// + /// Posts a new upgrade request to a confirmation validator requesting that it upgrade to a Primary Validator. + /// Requesting bank will pass a + /// + /// + /// NOTE: 200: Ok - Validator has accepted the upgrade request, 400: Bad Request - Validator has rejected the upgrade + public async Task PostUpgradeRequestAsync(UpgradeRequest upgradeRequest) + { + if(upgradeRequest is null) + { + // TODO: Create specific exception + throw new Exception(); + } + + var httpContent = new StringContent(JsonConvert.SerializeObject(upgradeRequest), Encoding.UTF8, "application/json"); + var jsonString = await httpContent.ReadAsStringAsync(); + + if (string.IsNullOrEmpty(jsonString)) + { + // TODO: Create specific exception + throw new Exception(); + } + + var response = await _requestSender.PostAsync("/upgrade_request/", httpContent); + return response; + } + } +} diff --git a/src/Thenewboston/Validator/Models/UpgradeRequest.cs b/src/Thenewboston/Validator/Models/UpgradeRequest.cs new file mode 100644 index 0000000..f69e1df --- /dev/null +++ b/src/Thenewboston/Validator/Models/UpgradeRequest.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Validator.Models +{ + public class UpgradeRequest + { + [JsonProperty(PropertyName ="")] + public UpgradeRequestMessage Message { get; set; } + + [JsonProperty(PropertyName ="node_identifier")] + public string NodeIdentifier { get; set; } + + [JsonProperty(PropertyName ="signature")] + public string Signature { get; set; } + } +} diff --git a/src/Thenewboston/Validator/Models/UpgradeRequestMessage.cs b/src/Thenewboston/Validator/Models/UpgradeRequestMessage.cs new file mode 100644 index 0000000..1521476 --- /dev/null +++ b/src/Thenewboston/Validator/Models/UpgradeRequestMessage.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Validator.Models +{ + public class UpgradeRequestMessage + { + [JsonProperty(PropertyName = "validator_node_identifier")] + public string ValidatorNodeIdentifier { get; set; } + } +} From c58bfc265394710499157c7ae0ac346465c74f9a Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Fri, 27 Nov 2020 16:29:00 -0500 Subject: [PATCH 12/37] Corrected missing PropertyName in JSON Property Decorator. --- src/Thenewboston/Validator/Models/UpgradeRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Thenewboston/Validator/Models/UpgradeRequest.cs b/src/Thenewboston/Validator/Models/UpgradeRequest.cs index f69e1df..05f8fe5 100644 --- a/src/Thenewboston/Validator/Models/UpgradeRequest.cs +++ b/src/Thenewboston/Validator/Models/UpgradeRequest.cs @@ -4,7 +4,7 @@ namespace Thenewboston.Validator.Models { public class UpgradeRequest { - [JsonProperty(PropertyName ="")] + [JsonProperty(PropertyName ="message")] public UpgradeRequestMessage Message { get; set; } [JsonProperty(PropertyName ="node_identifier")] From fb48c63d73b0b01b9fb6189d041a7419cdaa4970 Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Fri, 27 Nov 2020 16:33:00 -0500 Subject: [PATCH 13/37] Added test creation info to head of UpgradeRequestTests class. --- src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs b/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs index b839f70..c7d753b 100644 --- a/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs @@ -10,6 +10,13 @@ namespace Thenewboston.Tests.Bank.Api { public class UpgradeRequestTests { + + // *************************************** + // Validator Upgrade Request Tests * + // Created 11/27/2020 based on available * + // documentation * + // *************************************** + #region Upgrade Request Mock Models public UpgradeRequest CreateMockUpgradeRequest() From 99853e5919e2f710e0979a74c13800311362ff04 Mon Sep 17 00:00:00 2001 From: Nish Date: Sat, 28 Nov 2020 11:47:31 -0600 Subject: [PATCH 14/37] Done bank api but left tests --- .../Bank/Api/BankConfirmationServiceTests.cs | 7 ++++ .../Bank/Api/BankConfirmationService.cs | 41 +++++++++++++++++++ .../Bank/Api/IBankConfirmationService.cs | 11 +++++ 3 files changed, 59 insertions(+) create mode 100644 src/Thenewboston.Tests/Bank/Api/BankConfirmationServiceTests.cs create mode 100644 src/Thenewboston/Bank/Api/BankConfirmationService.cs create mode 100644 src/Thenewboston/Bank/Api/IBankConfirmationService.cs diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationServiceTests.cs new file mode 100644 index 0000000..23e854d --- /dev/null +++ b/src/Thenewboston.Tests/Bank/Api/BankConfirmationServiceTests.cs @@ -0,0 +1,7 @@ +namespace Thenewboston.Tests.Bank.Api +{ + public class BankConfirmationServiceTests + { + + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/BankConfirmationService.cs b/src/Thenewboston/Bank/Api/BankConfirmationService.cs new file mode 100644 index 0000000..3a3a495 --- /dev/null +++ b/src/Thenewboston/Bank/Api/BankConfirmationService.cs @@ -0,0 +1,41 @@ +using System; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Common.Api.Models; +using Thenewboston.Common.Http; + +namespace Thenewboston.Bank.Api +{ + public class BankConfirmationService : IBankConfirmationService + { + private readonly IHttpRequestSender _requestSender; + + public BankConfirmationService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + public async Task GetValidatorConfirmationServicesAsync() + { + var response = await _requestSender.GetAsync("/validator_confirmation_services"); + + if(!response.IsSuccessStatusCode) + { + // TODO: Create specific exception + throw new Exception(); + } + + var stringResponse = await response.Content.ReadAsStringAsync(); + + if(string.IsNullOrEmpty(stringResponse)) + { + // TODO: Create specific exception + throw new Exception(); + } + + var result = JsonConvert.DeserializeObject(stringResponse); + + return result; + } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IBankConfirmationService.cs b/src/Thenewboston/Bank/Api/IBankConfirmationService.cs new file mode 100644 index 0000000..e153260 --- /dev/null +++ b/src/Thenewboston/Bank/Api/IBankConfirmationService.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; +using Thenewboston.Common.Api.Models; + +namespace Thenewboston.Bank.Api +{ + public interface IBankConfirmationService + { + public Task GetValidatorConfirmationServicesAsync(); + + } +} \ No newline at end of file From 34989b0fc5932782f23651f971ceadba03085165 Mon Sep 17 00:00:00 2001 From: Nish Date: Sat, 28 Nov 2020 11:58:51 -0600 Subject: [PATCH 15/37] Refactored the code --- .../Bank/Api/BankConfirmationBlockServiceTests.cs | 2 +- src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs | 6 ++++-- src/Thenewboston/Bank/Api/BlocksService.cs | 7 ++++--- src/Thenewboston/Bank/Api/IBlocksService.cs | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs index b3da950..b778fea 100644 --- a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs @@ -146,7 +146,7 @@ private IBankConfirmationBlockService BuildConfirmationBlockPostMock() public async void BankConfirmationBlockReturnedAsync() { var service = BuildConfirmationBlockGetMock(); - var returnedBankConfirmationBlock = await service.GetAllBankConfirmationBlocksAsync(); + var returnedBankConfirmationBlock = await service.GetAllBankConfiramtionBlocksAsync(); var expectedResult = JsonConvert.SerializeObject(CreateMockBankConfirmationBlock()); var actualResult = JsonConvert.SerializeObject(returnedBankConfirmationBlock); Assert.Equal(expectedResult, actualResult); diff --git a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs index 4ce4c79..42670c5 100644 --- a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs @@ -10,6 +10,8 @@ using Thenewboston.Common.Http; using Thenewboston.Common.Models; using Xunit; +using Block = Thenewboston.Common.Models.Block; +using BlockMessage = Thenewboston.Common.Models.BlockMessage; namespace Thenewboston.Tests.Bank { @@ -17,9 +19,9 @@ public class BlocksServiceTests { #region Test Models - private PaginatedResponseModel CreateMockBlock() + private PaginatedResponseModel CreateMockBlock() { - return new PaginatedResponseModel() { + return new PaginatedResponseModel() { Count = 1, Next = string.Empty, Previous = string.Empty, diff --git a/src/Thenewboston/Bank/Api/BlocksService.cs b/src/Thenewboston/Bank/Api/BlocksService.cs index 918943b..d2cddea 100644 --- a/src/Thenewboston/Bank/Api/BlocksService.cs +++ b/src/Thenewboston/Bank/Api/BlocksService.cs @@ -3,9 +3,10 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; -using Thenewboston.Common.Models; +using Block = Thenewboston.Common.Models.Block; namespace Thenewboston.Bank.Api { @@ -18,7 +19,7 @@ public BlocksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task GetBlocksAsync() + public async Task> GetBlocksAsync() { var response = await _requestSender.GetAsync("/blocks"); @@ -36,7 +37,7 @@ public async Task GetBlocksAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } diff --git a/src/Thenewboston/Bank/Api/IBlocksService.cs b/src/Thenewboston/Bank/Api/IBlocksService.cs index af28500..d262b58 100644 --- a/src/Thenewboston/Bank/Api/IBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IBlocksService.cs @@ -1,13 +1,14 @@ using System.Net.Http; using System.Threading.Tasks; +using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; -using Thenewboston.Common.Models; +using Block = Thenewboston.Common.Models.Block; namespace Thenewboston.Bank.Api { public interface IBlocksService { - public Task GetBlocksAsync(); + public Task> GetBlocksAsync(); public Task PostBlocksAsync(Block block); } From 2a1fd5b50a8beb1f9a75cde53425de9ec8ebe64a Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 28 Nov 2020 21:16:27 +0200 Subject: [PATCH 16/37] Fix naming issues --- .../Bank/Api/BankConfirmationBlockServiceTests.cs | 1 + .../Bank/Api/ConnectedBanksServiceTests.cs | 14 +++++++------- .../Bank/Api/InvalidBlockServiceTests.cs | 1 + .../Bank/Api/UpgradeRequestTests.cs | 1 + .../Validator/Api/ValidatorsServiceTests.cs | 1 + .../Bank/Api/BankConfirmationBlockService.cs | 2 +- src/Thenewboston/Bank/Api/BlocksService.cs | 4 ++-- src/Thenewboston/Bank/Api/ConnectedBanksService.cs | 9 ++++----- .../Bank/Api/IBankConfirmationBlockService.cs | 2 +- src/Thenewboston/Bank/Api/IBlocksService.cs | 4 ++-- .../Bank/Api/IConnectedBanksService.cs | 4 ++-- src/Thenewboston/Bank/Api/IInvalidBlocksService.cs | 1 + src/Thenewboston/Bank/Api/InvalidBlocksService.cs | 1 + .../Models/BankConfirmationBlockResponse.cs | 2 +- .../{ => Api}/Models/BankInvalidBlockRequest.cs | 2 +- .../Models/BankResponse.cs} | 4 ++-- .../Models/{BankBlockResponse.cs => BankBlock.cs} | 0 src/Thenewboston/Thenewboston.csproj | 1 + .../Validator/Api/IUpgradeRequestService.cs | 1 + .../Validator/Api/IValidatorsService.cs | 1 + .../Validator/{ => Api}/Models/UpgradeRequest.cs | 2 +- .../{ => Api}/Models/UpgradeRequestMessage.cs | 2 +- .../{ => Api}/Models/ValidatorResponseModel.cs | 2 +- .../Validator/Api/UpgradeRequestService.cs | 1 + .../Validator/Api/ValidatorsService.cs | 1 + 25 files changed, 37 insertions(+), 27 deletions(-) rename src/Thenewboston/Bank/{ => Api}/Models/BankConfirmationBlockResponse.cs (94%) rename src/Thenewboston/Bank/{ => Api}/Models/BankInvalidBlockRequest.cs (97%) rename src/Thenewboston/Bank/{Models/BankResponseModel.cs => Api/Models/BankResponse.cs} (92%) rename src/Thenewboston/Bank/Models/{BankBlockResponse.cs => BankBlock.cs} (100%) rename src/Thenewboston/Validator/{ => Api}/Models/UpgradeRequest.cs (89%) rename src/Thenewboston/Validator/{ => Api}/Models/UpgradeRequestMessage.cs (82%) rename src/Thenewboston/Validator/{ => Api}/Models/ValidatorResponseModel.cs (97%) diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs index b778fea..4797369 100644 --- a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs @@ -5,6 +5,7 @@ using Moq; using Newtonsoft.Json; using Thenewboston.Bank.Api; +using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs index f326b56..cb041eb 100644 --- a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs @@ -20,15 +20,15 @@ public class GetBanksAsync [Fact] public async void ListOfBanksIsReturned() { - var expectedResponseModel = new PaginatedResponseModel + var expectedResponseModel = new PaginatedResponseModel { Count = 2, Next = null, Previous = null, Results = - new List + new List { - new BankResponseModel + new BankResponse { AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", IpAddress = "83.168.1.232", @@ -39,7 +39,7 @@ public async void ListOfBanksIsReturned() DefaultTransactionFee = 1, Trust = "100.00" }, - new BankResponseModel + new BankResponse { AccountNumber = "db1a9ac3c356ab744ab4ad5256bb86c2f6dfaa7c1aece1f026a08dbd8c7178f2", IpAddress = "74.124.1.68", @@ -68,7 +68,7 @@ public class UpdateBankAsync [Fact] public async void UpdatedBankIsReturned() { - var expectedBank = new BankResponseModel + var expectedBank = new BankResponse { AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", IpAddress = "83.168.1.232", @@ -92,7 +92,7 @@ public async void UpdatedBankIsReturned() } } - public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock(PaginatedResponseModel expectedResponseModel) + public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock(PaginatedResponseModel expectedResponseModel) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(expectedResponseModel), Encoding.UTF8, "application/json"); @@ -107,7 +107,7 @@ public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock return service; } - public static IConnectedBanksService BuildUpdateBankAsyncConnectedBanksServiceMock(BankResponseModel expectedBank) + public static IConnectedBanksService BuildUpdateBankAsyncConnectedBanksServiceMock(BankResponse expectedBank) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(expectedBank), Encoding.UTF8, "application/json"); diff --git a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs index 2065d17..45653fa 100644 --- a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs @@ -7,6 +7,7 @@ using Moq; using Newtonsoft.Json; using Thenewboston.Bank.Api; +using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; diff --git a/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs b/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs index c7d753b..ef1a1e0 100644 --- a/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs @@ -3,6 +3,7 @@ using Moq; using Thenewboston.Common.Http; using Thenewboston.Validator.Api; +using Thenewboston.Validator.Api.Models; using Thenewboston.Validator.Models; using Xunit; diff --git a/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs index 83296f6..41fb18c 100644 --- a/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs @@ -10,6 +10,7 @@ using Thenewboston.Common.Http; using Thenewboston.Common.Models; using Thenewboston.Validator.Api; +using Thenewboston.Validator.Api.Models; using Thenewboston.Validator.Models; using Xunit; diff --git a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs index 364d971..dae4db4 100644 --- a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs @@ -3,10 +3,10 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using Thenewboston.Bank.Api.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Thenewboston.Common.Models; -using BankConfirmationBlockResponse = Thenewboston.Bank.Models.BankConfirmationBlockResponse; namespace Thenewboston.Bank.Api { diff --git a/src/Thenewboston/Bank/Api/BlocksService.cs b/src/Thenewboston/Bank/Api/BlocksService.cs index d2cddea..338b463 100644 --- a/src/Thenewboston/Bank/Api/BlocksService.cs +++ b/src/Thenewboston/Bank/Api/BlocksService.cs @@ -3,10 +3,10 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; -using Block = Thenewboston.Common.Models.Block; namespace Thenewboston.Bank.Api { @@ -42,7 +42,7 @@ public async Task> GetBlocksAsync() return result; } - public async Task PostBlocksAsync(Block block) + public async Task PostBlocksAsync(Thenewboston.Common.Models.Block block) { var httpContent = new StringContent(JsonConvert.SerializeObject(block), Encoding.UTF8, "application/json"); var request = await _requestSender.PostAsync("/blocks", httpContent); diff --git a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs index e97d203..4ce0a96 100644 --- a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Thenewboston.Bank.Api.Models; -using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; @@ -19,7 +18,7 @@ public ConnectedBanksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetBanksAsync() + public async Task> GetBanksAsync() { var response = await _requestSender.GetAsync("/banks"); @@ -37,12 +36,12 @@ public async Task> GetBanksAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject>(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } - public async Task UpdateBankAsync(string nodeIdentifier, RequestModel payload) + public async Task UpdateBankAsync(string nodeIdentifier, RequestModel payload) { var jsonPayload = JsonConvert.SerializeObject(payload); var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); @@ -63,7 +62,7 @@ public async Task UpdateBankAsync(string nodeIdentifier, Requ throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var result = JsonConvert.DeserializeObject(stringResult); return result; } diff --git a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs index 9a2f9d5..d254a01 100644 --- a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs @@ -1,8 +1,8 @@ using System.Net.Http; using System.Threading.Tasks; +using Thenewboston.Bank.Api.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Models; -using BankConfirmationBlockResponse = Thenewboston.Bank.Models.BankConfirmationBlockResponse; namespace Thenewboston.Bank.Api { diff --git a/src/Thenewboston/Bank/Api/IBlocksService.cs b/src/Thenewboston/Bank/Api/IBlocksService.cs index d262b58..ddd5269 100644 --- a/src/Thenewboston/Bank/Api/IBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IBlocksService.cs @@ -1,8 +1,8 @@ using System.Net.Http; using System.Threading.Tasks; +using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; -using Block = Thenewboston.Common.Models.Block; namespace Thenewboston.Bank.Api { @@ -10,6 +10,6 @@ public interface IBlocksService { public Task> GetBlocksAsync(); - public Task PostBlocksAsync(Block block); + public Task PostBlocksAsync(Thenewboston.Common.Models.Block block); } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs index 9f35ad8..3485d6a 100644 --- a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs @@ -6,7 +6,7 @@ namespace Thenewboston.Bank.Api.Models { public interface IConnectedBanksService { - Task> GetBanksAsync(); - Task UpdateBankAsync(string nodeIdentifier, RequestModel payload); + Task> GetBanksAsync(); + Task UpdateBankAsync(string nodeIdentifier, RequestModel payload); } } diff --git a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs index 67a915e..0f89f8a 100644 --- a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; diff --git a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs index 92561b4..b7a4740 100644 --- a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs @@ -3,6 +3,7 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; diff --git a/src/Thenewboston/Bank/Models/BankConfirmationBlockResponse.cs b/src/Thenewboston/Bank/Api/Models/BankConfirmationBlockResponse.cs similarity index 94% rename from src/Thenewboston/Bank/Models/BankConfirmationBlockResponse.cs rename to src/Thenewboston/Bank/Api/Models/BankConfirmationBlockResponse.cs index e86756b..f940f3a 100644 --- a/src/Thenewboston/Bank/Models/BankConfirmationBlockResponse.cs +++ b/src/Thenewboston/Bank/Api/Models/BankConfirmationBlockResponse.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json; -namespace Thenewboston.Bank.Models +namespace Thenewboston.Bank.Api.Models { public class BankConfirmationBlockResponse { diff --git a/src/Thenewboston/Bank/Models/BankInvalidBlockRequest.cs b/src/Thenewboston/Bank/Api/Models/BankInvalidBlockRequest.cs similarity index 97% rename from src/Thenewboston/Bank/Models/BankInvalidBlockRequest.cs rename to src/Thenewboston/Bank/Api/Models/BankInvalidBlockRequest.cs index 8acc1bc..065d8f4 100644 --- a/src/Thenewboston/Bank/Models/BankInvalidBlockRequest.cs +++ b/src/Thenewboston/Bank/Api/Models/BankInvalidBlockRequest.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Thenewboston.Bank.Models +namespace Thenewboston.Bank.Api.Models { public class BankInvalidBlockRequest { diff --git a/src/Thenewboston/Bank/Models/BankResponseModel.cs b/src/Thenewboston/Bank/Api/Models/BankResponse.cs similarity index 92% rename from src/Thenewboston/Bank/Models/BankResponseModel.cs rename to src/Thenewboston/Bank/Api/Models/BankResponse.cs index c684265..851efb5 100644 --- a/src/Thenewboston/Bank/Models/BankResponseModel.cs +++ b/src/Thenewboston/Bank/Api/Models/BankResponse.cs @@ -3,9 +3,9 @@ using Newtonsoft.Json; using Thenewboston.Common.Models; -namespace Thenewboston.Bank.Models +namespace Thenewboston.Bank.Api.Models { - public class BankResponseModel + public class BankResponse { [JsonProperty(PropertyName = "account_number")] public string AccountNumber { get; set; } diff --git a/src/Thenewboston/Bank/Models/BankBlockResponse.cs b/src/Thenewboston/Bank/Models/BankBlock.cs similarity index 100% rename from src/Thenewboston/Bank/Models/BankBlockResponse.cs rename to src/Thenewboston/Bank/Models/BankBlock.cs diff --git a/src/Thenewboston/Thenewboston.csproj b/src/Thenewboston/Thenewboston.csproj index fec98d3..8af2e8d 100644 --- a/src/Thenewboston/Thenewboston.csproj +++ b/src/Thenewboston/Thenewboston.csproj @@ -10,6 +10,7 @@ + diff --git a/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs b/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs index b89d8e9..6899779 100644 --- a/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs +++ b/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs @@ -1,5 +1,6 @@ using System.Net.Http; using System.Threading.Tasks; +using Thenewboston.Validator.Api.Models; using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api diff --git a/src/Thenewboston/Validator/Api/IValidatorsService.cs b/src/Thenewboston/Validator/Api/IValidatorsService.cs index fad8d19..b8170dd 100644 --- a/src/Thenewboston/Validator/Api/IValidatorsService.cs +++ b/src/Thenewboston/Validator/Api/IValidatorsService.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Thenewboston.Common.Api.Models; +using Thenewboston.Validator.Api.Models; using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api diff --git a/src/Thenewboston/Validator/Models/UpgradeRequest.cs b/src/Thenewboston/Validator/Api/Models/UpgradeRequest.cs similarity index 89% rename from src/Thenewboston/Validator/Models/UpgradeRequest.cs rename to src/Thenewboston/Validator/Api/Models/UpgradeRequest.cs index 05f8fe5..8d39f4b 100644 --- a/src/Thenewboston/Validator/Models/UpgradeRequest.cs +++ b/src/Thenewboston/Validator/Api/Models/UpgradeRequest.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Thenewboston.Validator.Models +namespace Thenewboston.Validator.Api.Models { public class UpgradeRequest { diff --git a/src/Thenewboston/Validator/Models/UpgradeRequestMessage.cs b/src/Thenewboston/Validator/Api/Models/UpgradeRequestMessage.cs similarity index 82% rename from src/Thenewboston/Validator/Models/UpgradeRequestMessage.cs rename to src/Thenewboston/Validator/Api/Models/UpgradeRequestMessage.cs index 1521476..5111f15 100644 --- a/src/Thenewboston/Validator/Models/UpgradeRequestMessage.cs +++ b/src/Thenewboston/Validator/Api/Models/UpgradeRequestMessage.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Thenewboston.Validator.Models +namespace Thenewboston.Validator.Api.Models { public class UpgradeRequestMessage { diff --git a/src/Thenewboston/Validator/Models/ValidatorResponseModel.cs b/src/Thenewboston/Validator/Api/Models/ValidatorResponseModel.cs similarity index 97% rename from src/Thenewboston/Validator/Models/ValidatorResponseModel.cs rename to src/Thenewboston/Validator/Api/Models/ValidatorResponseModel.cs index 9c4952b..54f78e7 100644 --- a/src/Thenewboston/Validator/Models/ValidatorResponseModel.cs +++ b/src/Thenewboston/Validator/Api/Models/ValidatorResponseModel.cs @@ -3,7 +3,7 @@ using System.Text; using Newtonsoft.Json; -namespace Thenewboston.Validator.Models +namespace Thenewboston.Validator.Api.Models { public class ValidatorResponseModel { diff --git a/src/Thenewboston/Validator/Api/UpgradeRequestService.cs b/src/Thenewboston/Validator/Api/UpgradeRequestService.cs index 3df74b5..8a551fe 100644 --- a/src/Thenewboston/Validator/Api/UpgradeRequestService.cs +++ b/src/Thenewboston/Validator/Api/UpgradeRequestService.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Thenewboston.Common.Http; +using Thenewboston.Validator.Api.Models; using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api diff --git a/src/Thenewboston/Validator/Api/ValidatorsService.cs b/src/Thenewboston/Validator/Api/ValidatorsService.cs index b5f45d3..37c5acd 100644 --- a/src/Thenewboston/Validator/Api/ValidatorsService.cs +++ b/src/Thenewboston/Validator/Api/ValidatorsService.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; +using Thenewboston.Validator.Api.Models; using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api From 4377e78fd7efdaf2d45d974f8b1bfb047797ec2d Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Sat, 28 Nov 2020 20:22:11 -0500 Subject: [PATCH 17/37] Create Primary Validator Updated Models --- .../Models/PrimaryValidatorUpdatedMessage.cs | 16 ++++++++++++++++ .../Models/PrimaryValidatorUpdatedResponse.cs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedMessage.cs create mode 100644 src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedResponse.cs diff --git a/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedMessage.cs b/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedMessage.cs new file mode 100644 index 0000000..6cea70c --- /dev/null +++ b/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedMessage.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Validator.Models +{ + public class PrimaryValidatorUpdatedMessage + { + [JsonProperty(PropertyName ="ip_address")] + public string IPAddress { get; set; } + + [JsonProperty(PropertyName ="port")] + public string Port { get; set; } + + [JsonProperty(PropertyName ="protocol")] + public string Protocol { get; set; } + } +} diff --git a/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedResponse.cs b/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedResponse.cs new file mode 100644 index 0000000..c26676a --- /dev/null +++ b/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedResponse.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Thenewboston.Validator.Models +{ + public class PrimaryValidatorUpdatedResponse + { + [JsonProperty(PropertyName ="message")] + public PrimaryValidatorUpdatedMessage Message { get; set; } + + [JsonProperty(PropertyName ="property_name")] + public string NodeIdentifier { get; set; } + + [JsonProperty(PropertyName ="signature")] + public string Signature { get; set; } + } +} From a0f190b5bf483df40d7d3013d7e8f530281aaadf Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Sat, 28 Nov 2020 20:35:28 -0500 Subject: [PATCH 18/37] Created the PrimaryValidatorUpdated service and interface. Rename PrimaryValidatorUpdatedResponse to PrimaryValidatorUpdatedModel for clarity. --- .../Api/IPrimaryValidatorUpdatedService.cs | 10 ++++ .../Api/PrimaryValidatorUpdatedService.cs | 46 +++++++++++++++++++ ...nse.cs => PrimaryValidatorUpdatedModel.cs} | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/Thenewboston/Validator/Api/IPrimaryValidatorUpdatedService.cs create mode 100644 src/Thenewboston/Validator/Api/PrimaryValidatorUpdatedService.cs rename src/Thenewboston/Validator/Models/{PrimaryValidatorUpdatedResponse.cs => PrimaryValidatorUpdatedModel.cs} (89%) diff --git a/src/Thenewboston/Validator/Api/IPrimaryValidatorUpdatedService.cs b/src/Thenewboston/Validator/Api/IPrimaryValidatorUpdatedService.cs new file mode 100644 index 0000000..531af09 --- /dev/null +++ b/src/Thenewboston/Validator/Api/IPrimaryValidatorUpdatedService.cs @@ -0,0 +1,10 @@ +using System.Net.Http; +using System.Threading.Tasks; + +namespace Thenewboston.Validator.Api +{ + public interface IPrimaryValidatorUpdatedService + { + Task PostPrimaryValidatorUpdatedAsync(); + } +} diff --git a/src/Thenewboston/Validator/Api/PrimaryValidatorUpdatedService.cs b/src/Thenewboston/Validator/Api/PrimaryValidatorUpdatedService.cs new file mode 100644 index 0000000..166c421 --- /dev/null +++ b/src/Thenewboston/Validator/Api/PrimaryValidatorUpdatedService.cs @@ -0,0 +1,46 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Common.Http; +using Thenewboston.Validator.Models; + +namespace Thenewboston.Validator.Api +{ + public class PrimaryValidatorUpdatedService : IPrimaryValidatorUpdatedService + { + private readonly IHttpRequestSender _requestSender; + + public PrimaryValidatorUpdatedService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + /// + /// Notifies a validator on the network that a bank has upgraded its primary validator. + /// + /// + /// 200: Ok - Validator will follow bank and sync to the new primary validator or 400: + /// - Bad Request - The validator will not follow the bank and will remain on its current network + public async Task PostPrimaryValidatorUpdatedAsync(PrimaryValidatorUpdatedModel validatorUpdatedModel) + { + if(validatorUpdatedModel is null) + { + // TODO: Create specific exception + throw new Exception(); + } + + var httpContent = new StringContent(JsonConvert.SerializeObject(validatorUpdatedModel)); + var stringContent = await httpContent.ReadAsStringAsync(); + + if(string.IsNullOrEmpty(stringContent)) + { + // TODO: Create specific exception + throw new Exception(); + } + + var response = await _requestSender.PostAsync("primary_validator_updated", httpContent); + return response; + } + } +} diff --git a/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedResponse.cs b/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedModel.cs similarity index 89% rename from src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedResponse.cs rename to src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedModel.cs index c26676a..8edc7f2 100644 --- a/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedResponse.cs +++ b/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedModel.cs @@ -2,7 +2,7 @@ namespace Thenewboston.Validator.Models { - public class PrimaryValidatorUpdatedResponse + public class PrimaryValidatorUpdatedModel { [JsonProperty(PropertyName ="message")] public PrimaryValidatorUpdatedMessage Message { get; set; } From ef4cfa1ca3b5f8a558cc694565cf448a3e74808e Mon Sep 17 00:00:00 2001 From: joshman1019 <36560776+joshman1019@users.noreply.github.com> Date: Sat, 28 Nov 2020 20:57:33 -0500 Subject: [PATCH 19/37] Created Primary Validator Updated Tests --- .../Api/PrimaryValidatorUpdatedTests.cs | 89 +++++++++++++++++++ .../Api/IPrimaryValidatorUpdatedService.cs | 3 +- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/Thenewboston.Tests/Validator/Api/PrimaryValidatorUpdatedTests.cs diff --git a/src/Thenewboston.Tests/Validator/Api/PrimaryValidatorUpdatedTests.cs b/src/Thenewboston.Tests/Validator/Api/PrimaryValidatorUpdatedTests.cs new file mode 100644 index 0000000..38b0fd4 --- /dev/null +++ b/src/Thenewboston.Tests/Validator/Api/PrimaryValidatorUpdatedTests.cs @@ -0,0 +1,89 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Moq; +using Thenewboston.Common.Http; +using Thenewboston.Validator.Api; +using Thenewboston.Validator.Models; +using Xunit; + +namespace Thenewboston.Tests.Validator.Api +{ + public class PrimaryValidatorUpdatedTests + { + // ******************************************** + // Primary Validator Updated Tests * + // Created 11/28/2020 based on available * + // documentation * + // ******************************************** + + + #region Primary Validator Updated Mock Models + + private PrimaryValidatorUpdatedModel CreateMockPrimaryValidatorUpdatedModel() + { + return new PrimaryValidatorUpdatedModel() + { + Message = new PrimaryValidatorUpdatedMessage() + { + IPAddress = "192.168.1.20", + Port = "8000", + Protocol = "http" + }, + NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", + Signature = "ccb4c9f0669abfcd1cea330fa4e45d87689fb08d2fd26b4cf05c87b2fdb1dae543024888243a84d02fd9bb8320c41f4de45d6212747e49a02a365fd42883fd01" + }; + } + + #endregion + + #region Primary Validator Updated Mock Services + + public IPrimaryValidatorUpdatedService BuildMockPrimaryValidatorUpdatesServiceApproveUpgrade() + { + var httpRequest = new Mock(); + var returnContent = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + var service = new PrimaryValidatorUpdatedService(httpRequest.Object); + + httpRequest.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(returnContent); + + return service; + } + + public IPrimaryValidatorUpdatedService BuildMockPrimaryValidatorUpdatesServiceRejectUpgrade() + { + var httpRequest = new Mock(); + var returnContent = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + var service = new PrimaryValidatorUpdatedService(httpRequest.Object); + + httpRequest.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(returnContent); + + return service; + } + + #endregion + + #region Tests + + [Fact] + public async Task PrimaryValidatorUpdatedReceivingNodeApprovesTest() + { + var service = BuildMockPrimaryValidatorUpdatesServiceApproveUpgrade(); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + var result = await service.PostPrimaryValidatorUpdatedAsync(CreateMockPrimaryValidatorUpdatedModel()); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + + [Fact] + public async Task PrimaryValidatorUpdatedReceivingNodeRejectsTest() + { + var service = BuildMockPrimaryValidatorUpdatesServiceRejectUpgrade(); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + var result = await service.PostPrimaryValidatorUpdatedAsync(CreateMockPrimaryValidatorUpdatedModel()); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + + #endregion + } +} diff --git a/src/Thenewboston/Validator/Api/IPrimaryValidatorUpdatedService.cs b/src/Thenewboston/Validator/Api/IPrimaryValidatorUpdatedService.cs index 531af09..9edb051 100644 --- a/src/Thenewboston/Validator/Api/IPrimaryValidatorUpdatedService.cs +++ b/src/Thenewboston/Validator/Api/IPrimaryValidatorUpdatedService.cs @@ -1,10 +1,11 @@ using System.Net.Http; using System.Threading.Tasks; +using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api { public interface IPrimaryValidatorUpdatedService { - Task PostPrimaryValidatorUpdatedAsync(); + Task PostPrimaryValidatorUpdatedAsync(PrimaryValidatorUpdatedModel validatorUpdatedModel); } } From fdd3bdbfd375862ceb233bee5401546bf03ab773 Mon Sep 17 00:00:00 2001 From: Joshua Santiago <36560776+joshman1019@users.noreply.github.com> Date: Mon, 30 Nov 2020 13:45:19 -0500 Subject: [PATCH 20/37] Update DOCUMENTATION.md Added remaining services and reordered them alphabetically. Ready to begin adding actual documentation. --- DOCUMENTATION.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index a55b4e8..e354574 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -28,18 +28,25 @@ For projects that support adding a Nuget reference you may paste the following ## SDK References 1. Bank * AccountsService + * BankConfirmationBlockService + * BlocksService * ConfigService * ConnectedBankService - * TransactionService + * InvalidBlocksService + * TransactionsService + * UpgradeNoticeService * ValidatorService - * BankConfirmationBlockService + 2. Common * 3. Validator * AccountsService + * BankBlockService * ConfigService * ConnectedBankService + * PrimaryValidatorUpdatedService * TransactionService + * UpgradeRequestService * ValidatorService * ValidatorConfirmationBlockService @@ -64,14 +71,20 @@ Description Thenewboston.Bank.Api Thenewboston.Bank.Models -## AccountsService +## AccountsService +## BankConfirmationBLockService +## BlocksService ## ConfigService +## ConfirmationService ## ConnectedBankService +## ConnectionRequestService +## InvalidBlocksService ## TransactionService +## UpgradeNoticeService ## ValidatorService -## BankConfirmationBlockService ## Bank Exceptions (BNK) -|Exception|Class|Thrown From|Description | + +|Exception|Class|Thrown From|Description| |--|--|--|--| |BNK001|AccountsService|SampleMethod()|Sample Description| |BNK002|ConfigService|SampleMethod()|Sample Description| @@ -96,9 +109,14 @@ Description Thenewboston.Validator.Api Thenewboston.Validator.Models ## AccountsService +## BankBlockService ## ConfigService +## ConfirmationService ## ConnectedBankService +## ConnectionRequestService +## PrimaryValidatorUpdatedService ## TransactionService +## UpgradeRequestService ## ValidatorService ## ValidatorConfirmationBlockService ## Validator Exceptions (VLD) From 4db7ecc5aeed967331b6183fbc4cd780213503fa Mon Sep 17 00:00:00 2001 From: arjunraghurama Date: Wed, 2 Dec 2020 21:42:54 +0530 Subject: [PATCH 21/37] Issue #17 --- .../Bank/Api/ConnectionRequestServiceTest.cs | 73 +++++++++++++++++++ .../Api/ConnectionRequestServiceTest.cs | 73 +++++++++++++++++++ .../Bank/Api/ConnectionRequestService.cs | 42 +++++++++++ .../Bank/Api/IConnectionRequestService.cs | 14 ++++ .../Bank/Models/ConnectionMessage.cs | 19 +++++ .../Bank/Models/ConnectionRequest.cs | 19 +++++ .../Validator/Api/ConnectionRequestService.cs | 42 +++++++++++ .../Api/IConnectionRequestService.cs | 14 ++++ .../Validator/Models/ConnectionMessage.cs | 19 +++++ .../Validator/Models/ConnectionRequest.cs | 19 +++++ 10 files changed, 334 insertions(+) create mode 100644 src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs create mode 100644 src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs create mode 100644 src/Thenewboston/Bank/Api/ConnectionRequestService.cs create mode 100644 src/Thenewboston/Bank/Api/IConnectionRequestService.cs create mode 100644 src/Thenewboston/Bank/Models/ConnectionMessage.cs create mode 100644 src/Thenewboston/Bank/Models/ConnectionRequest.cs create mode 100644 src/Thenewboston/Validator/Api/ConnectionRequestService.cs create mode 100644 src/Thenewboston/Validator/Api/IConnectionRequestService.cs create mode 100644 src/Thenewboston/Validator/Models/ConnectionMessage.cs create mode 100644 src/Thenewboston/Validator/Models/ConnectionRequest.cs diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs b/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs new file mode 100644 index 0000000..26a238d --- /dev/null +++ b/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Moq; +using Thenewboston.Bank.Api; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Http; +using Xunit; + +namespace Thenewboston.Tests.Bank.Api +{ + public class ConnectionRequestServiceTest + { + public ConnectionRequest CreateMockConnectionRequest() + { + return new ConnectionRequest() + { + Message = new ConnectionMessage() + { + IpAddress = "192.168.1.232", + Port = "8000", + Protocol = "http" + }, + NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", + Signature = "3c88665e123e7e25a8b9d9592f3269ab4efc4bcba989a103a898e2625933261b1cccdaf2f52eca9c58d2bf033968ab6b702089bca8fc6e0c80b3b002a5e05b03" + }; + } + + public IConnectionRequestService ConnectionRequestAcceptsMock() + { + var requestSender = new Mock(); + var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + + requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(httpResponse); + + var service = new ConnectionRequestService(requestSender.Object); + return service; + } + + public IConnectionRequestService ConnectionRequestRejectsMock() + { + var requestSender = new Mock(); + var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + + requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(httpResponse); + + var service = new ConnectionRequestService(requestSender.Object); + return service; + } + + [Fact] + public async Task UpgradeRequestNodeAcceptsTest() + { + var service = ConnectionRequestAcceptsMock(); + var result = await service.PostConnectionRequestAsync(CreateMockConnectionRequest()); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + + [Fact] + public async Task UpgradeRequestNodeRejectsTest() + { + var service = ConnectionRequestRejectsMock(); + var result = await service.PostConnectionRequestAsync(CreateMockConnectionRequest()); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + } +} diff --git a/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs b/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs new file mode 100644 index 0000000..0f0aef5 --- /dev/null +++ b/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Moq; +using Thenewboston.Common.Http; +using Thenewboston.Validator.Api; +using Thenewboston.Validator.Models; +using Xunit; + +namespace Thenewboston.Tests.Validator.Api +{ + public class ConnectionRequestServiceTest + { + public ConnectionRequest CreateMockConnectionRequest() + { + return new ConnectionRequest() + { + Message = new ConnectionMessage() + { + IpAddress = "192.168.1.232", + Port = "8000", + Protocol = "http" + }, + NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", + Signature = "3c88665e123e7e25a8b9d9592f3269ab4efc4bcba989a103a898e2625933261b1cccdaf2f52eca9c58d2bf033968ab6b702089bca8fc6e0c80b3b002a5e05b03" + }; + } + + public IConnectionRequestService ConnectionRequestAcceptsMock() + { + var requestSender = new Mock(); + var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + + requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(httpResponse); + + var service = new ConnectionRequestService(requestSender.Object); + return service; + } + + public IConnectionRequestService ConnectionRequestRejectsMock() + { + var requestSender = new Mock(); + var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + + requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(httpResponse); + + var service = new ConnectionRequestService(requestSender.Object); + return service; + } + + [Fact] + public async Task UpgradeRequestNodeAcceptsTest() + { + var service = ConnectionRequestAcceptsMock(); + var result = await service.PostConnectionRequestAsync(CreateMockConnectionRequest()); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + + [Fact] + public async Task UpgradeRequestNodeRejectsTest() + { + var service = ConnectionRequestRejectsMock(); + var result = await service.PostConnectionRequestAsync(CreateMockConnectionRequest()); + var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + Assert.Equal(expectedResult.StatusCode, result.StatusCode); + } + } +} diff --git a/src/Thenewboston/Bank/Api/ConnectionRequestService.cs b/src/Thenewboston/Bank/Api/ConnectionRequestService.cs new file mode 100644 index 0000000..a5e5c83 --- /dev/null +++ b/src/Thenewboston/Bank/Api/ConnectionRequestService.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Http; + +namespace Thenewboston.Bank.Api +{ + public class ConnectionRequestService : IConnectionRequestService + { + IHttpRequestSender _requestSender; + + public ConnectionRequestService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + public async Task PostConnectionRequestAsync(ConnectionRequest connectionNotice) + { + if( connectionNotice is null ) + { + // TODO: Create specific exception + throw new Exception(); + } + + var httpContent = new StringContent(JsonConvert.SerializeObject(connectionNotice)); + var jsonString = await httpContent.ReadAsStringAsync(); + + if (string.IsNullOrEmpty(jsonString)) + { + // TODO: Create specific exception + throw new Exception(); + } + + var result = await _requestSender.PostAsync("/connection_requests", httpContent); + return result; + } + } +} diff --git a/src/Thenewboston/Bank/Api/IConnectionRequestService.cs b/src/Thenewboston/Bank/Api/IConnectionRequestService.cs new file mode 100644 index 0000000..9f03052 --- /dev/null +++ b/src/Thenewboston/Bank/Api/IConnectionRequestService.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Thenewboston.Bank.Models; + +namespace Thenewboston.Bank.Api +{ + public interface IConnectionRequestService + { + Task PostConnectionRequestAsync(ConnectionRequest connectionNotice); + } +} diff --git a/src/Thenewboston/Bank/Models/ConnectionMessage.cs b/src/Thenewboston/Bank/Models/ConnectionMessage.cs new file mode 100644 index 0000000..2f63311 --- /dev/null +++ b/src/Thenewboston/Bank/Models/ConnectionMessage.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Thenewboston.Bank.Models +{ + public class ConnectionMessage + { + [JsonProperty(PropertyName = "ip_address")] + public string IpAddress { get; set; } + + [JsonProperty(PropertyName = "port")] + public string Port { get; set; } + + [JsonProperty(PropertyName = "protocol")] + public string Protocol { get; set; } + } +} diff --git a/src/Thenewboston/Bank/Models/ConnectionRequest.cs b/src/Thenewboston/Bank/Models/ConnectionRequest.cs new file mode 100644 index 0000000..ae7af1d --- /dev/null +++ b/src/Thenewboston/Bank/Models/ConnectionRequest.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Thenewboston.Bank.Models +{ + public class ConnectionRequest + { + [JsonProperty(PropertyName = "message")] + public ConnectionMessage Message { get; set; } + + [JsonProperty(PropertyName = "node_identifier")] + public string NodeIdentifier { get; set; } + + [JsonProperty(PropertyName = "signature")] + public string Signature { get; set; } + } +} diff --git a/src/Thenewboston/Validator/Api/ConnectionRequestService.cs b/src/Thenewboston/Validator/Api/ConnectionRequestService.cs new file mode 100644 index 0000000..f8d6358 --- /dev/null +++ b/src/Thenewboston/Validator/Api/ConnectionRequestService.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Common.Http; +using Thenewboston.Validator.Models; + +namespace Thenewboston.Validator.Api +{ + public class ConnectionRequestService : IConnectionRequestService + { + IHttpRequestSender _requestSender; + + public ConnectionRequestService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + public async Task PostConnectionRequestAsync(ConnectionRequest connectionNotice) + { + if (connectionNotice is null) + { + // TODO: Create specific exception + throw new Exception(); + } + + var httpContent = new StringContent(JsonConvert.SerializeObject(connectionNotice)); + var jsonString = await httpContent.ReadAsStringAsync(); + + if (string.IsNullOrEmpty(jsonString)) + { + // TODO: Create specific exception + throw new Exception(); + } + + var result = await _requestSender.PostAsync("/connection_requests", httpContent); + return result; + } + } +} diff --git a/src/Thenewboston/Validator/Api/IConnectionRequestService.cs b/src/Thenewboston/Validator/Api/IConnectionRequestService.cs new file mode 100644 index 0000000..c7ba538 --- /dev/null +++ b/src/Thenewboston/Validator/Api/IConnectionRequestService.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Thenewboston.Validator.Models; + +namespace Thenewboston.Validator.Api +{ + public interface IConnectionRequestService + { + Task PostConnectionRequestAsync(ConnectionRequest connectionNotice); + } +} diff --git a/src/Thenewboston/Validator/Models/ConnectionMessage.cs b/src/Thenewboston/Validator/Models/ConnectionMessage.cs new file mode 100644 index 0000000..1f8119c --- /dev/null +++ b/src/Thenewboston/Validator/Models/ConnectionMessage.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Thenewboston.Validator.Models +{ + public class ConnectionMessage + { + [JsonProperty(PropertyName = "ip_address")] + public string IpAddress { get; set; } + + [JsonProperty(PropertyName = "port")] + public string Port { get; set; } + + [JsonProperty(PropertyName = "protocol")] + public string Protocol { get; set; } + } +} diff --git a/src/Thenewboston/Validator/Models/ConnectionRequest.cs b/src/Thenewboston/Validator/Models/ConnectionRequest.cs new file mode 100644 index 0000000..b8d5222 --- /dev/null +++ b/src/Thenewboston/Validator/Models/ConnectionRequest.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Thenewboston.Validator.Models +{ + public class ConnectionRequest + { + [JsonProperty(PropertyName = "message")] + public ConnectionMessage Message { get; set; } + + [JsonProperty(PropertyName = "node_identifier")] + public string NodeIdentifier { get; set; } + + [JsonProperty(PropertyName = "signature")] + public string Signature { get; set; } + } +} From a2aa92c26f193841e9d878ea8e3fe64b2e2da88d Mon Sep 17 00:00:00 2001 From: arjunraghurama Date: Sat, 5 Dec 2020 21:02:12 +0530 Subject: [PATCH 22/37] Changed ConnectionMessage to ConnectionRequestMessage --- src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs | 2 +- .../Validator/Api/ConnectionRequestServiceTest.cs | 2 +- src/Thenewboston/Bank/Models/ConnectionRequest.cs | 2 +- .../{ConnectionMessage.cs => ConnectionRequestMessage.cs} | 2 +- src/Thenewboston/Validator/Models/ConnectionRequest.cs | 2 +- .../{ConnectionMessage.cs => ConnectionRequestMessage.cs} | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/Thenewboston/Bank/Models/{ConnectionMessage.cs => ConnectionRequestMessage.cs} (87%) rename src/Thenewboston/Validator/Models/{ConnectionMessage.cs => ConnectionRequestMessage.cs} (87%) diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs b/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs index 26a238d..f19c88b 100644 --- a/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs +++ b/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs @@ -17,7 +17,7 @@ public ConnectionRequest CreateMockConnectionRequest() { return new ConnectionRequest() { - Message = new ConnectionMessage() + Message = new ConnectionRequestMessage() { IpAddress = "192.168.1.232", Port = "8000", diff --git a/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs b/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs index 0f0aef5..630771d 100644 --- a/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs +++ b/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs @@ -17,7 +17,7 @@ public ConnectionRequest CreateMockConnectionRequest() { return new ConnectionRequest() { - Message = new ConnectionMessage() + Message = new ConnectionRequestMessage() { IpAddress = "192.168.1.232", Port = "8000", diff --git a/src/Thenewboston/Bank/Models/ConnectionRequest.cs b/src/Thenewboston/Bank/Models/ConnectionRequest.cs index ae7af1d..c0d0078 100644 --- a/src/Thenewboston/Bank/Models/ConnectionRequest.cs +++ b/src/Thenewboston/Bank/Models/ConnectionRequest.cs @@ -8,7 +8,7 @@ namespace Thenewboston.Bank.Models public class ConnectionRequest { [JsonProperty(PropertyName = "message")] - public ConnectionMessage Message { get; set; } + public ConnectionRequestMessage Message { get; set; } [JsonProperty(PropertyName = "node_identifier")] public string NodeIdentifier { get; set; } diff --git a/src/Thenewboston/Bank/Models/ConnectionMessage.cs b/src/Thenewboston/Bank/Models/ConnectionRequestMessage.cs similarity index 87% rename from src/Thenewboston/Bank/Models/ConnectionMessage.cs rename to src/Thenewboston/Bank/Models/ConnectionRequestMessage.cs index 2f63311..4d002d2 100644 --- a/src/Thenewboston/Bank/Models/ConnectionMessage.cs +++ b/src/Thenewboston/Bank/Models/ConnectionRequestMessage.cs @@ -5,7 +5,7 @@ namespace Thenewboston.Bank.Models { - public class ConnectionMessage + public class ConnectionRequestMessage { [JsonProperty(PropertyName = "ip_address")] public string IpAddress { get; set; } diff --git a/src/Thenewboston/Validator/Models/ConnectionRequest.cs b/src/Thenewboston/Validator/Models/ConnectionRequest.cs index b8d5222..e811fc1 100644 --- a/src/Thenewboston/Validator/Models/ConnectionRequest.cs +++ b/src/Thenewboston/Validator/Models/ConnectionRequest.cs @@ -8,7 +8,7 @@ namespace Thenewboston.Validator.Models public class ConnectionRequest { [JsonProperty(PropertyName = "message")] - public ConnectionMessage Message { get; set; } + public ConnectionRequestMessage Message { get; set; } [JsonProperty(PropertyName = "node_identifier")] public string NodeIdentifier { get; set; } diff --git a/src/Thenewboston/Validator/Models/ConnectionMessage.cs b/src/Thenewboston/Validator/Models/ConnectionRequestMessage.cs similarity index 87% rename from src/Thenewboston/Validator/Models/ConnectionMessage.cs rename to src/Thenewboston/Validator/Models/ConnectionRequestMessage.cs index 1f8119c..a48232c 100644 --- a/src/Thenewboston/Validator/Models/ConnectionMessage.cs +++ b/src/Thenewboston/Validator/Models/ConnectionRequestMessage.cs @@ -5,7 +5,7 @@ namespace Thenewboston.Validator.Models { - public class ConnectionMessage + public class ConnectionRequestMessage { [JsonProperty(PropertyName = "ip_address")] public string IpAddress { get; set; } From a597a727283a0d7e3012d1a9771d82029c8256df Mon Sep 17 00:00:00 2001 From: Nishp77 Date: Mon, 7 Dec 2020 13:56:34 -0600 Subject: [PATCH 23/37] Done with confirmation services but left with tests --- ...ce.cs => IValidatorConfirmationService.cs} | 2 +- .../Bank/Api/ValidatorConfirmationService.cs | 41 +++++++++++++++++++ .../Api/BankConfirmationService.cs | 12 +++--- .../Validator/Api/IBankConfirmationService.cs | 10 +++++ 4 files changed, 58 insertions(+), 7 deletions(-) rename src/Thenewboston/Bank/Api/{IBankConfirmationService.cs => IValidatorConfirmationService.cs} (79%) create mode 100644 src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs rename src/Thenewboston/{Bank => Validator}/Api/BankConfirmationService.cs (78%) create mode 100644 src/Thenewboston/Validator/Api/IBankConfirmationService.cs diff --git a/src/Thenewboston/Bank/Api/IBankConfirmationService.cs b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs similarity index 79% rename from src/Thenewboston/Bank/Api/IBankConfirmationService.cs rename to src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs index e153260..3cc4581 100644 --- a/src/Thenewboston/Bank/Api/IBankConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs @@ -3,7 +3,7 @@ namespace Thenewboston.Bank.Api { - public interface IBankConfirmationService + public interface IValidatorConfirmationService { public Task GetValidatorConfirmationServicesAsync(); diff --git a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs new file mode 100644 index 0000000..0a879d0 --- /dev/null +++ b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs @@ -0,0 +1,41 @@ +using System; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Thenewboston.Common.Api.Models; +using Thenewboston.Common.Http; + +namespace Thenewboston.Bank.Api +{ + public class ValidatorConfirmationService : IValidatorConfirmationService + { + private readonly IHttpRequestSender _requestSender; + + public ValidatorConfirmationService(IHttpRequestSender requestSender) + { + _requestSender = requestSender; + } + + public async Task GetValidatorConfirmationServicesAsync() + { + var response = await _requestSender.GetAsync("/validator_confirmation_services"); + + if(!response.IsSuccessStatusCode) + { + // TODO: Create specific exception + throw new Exception(); + } + + var stringResponse = await response.Content.ReadAsStringAsync(); + + if(string.IsNullOrEmpty(stringResponse)) + { + // TODO: Create specific exception + throw new Exception(); + } + + var result = JsonConvert.DeserializeObject(stringResponse); + + return result; + } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/BankConfirmationService.cs b/src/Thenewboston/Validator/Api/BankConfirmationService.cs similarity index 78% rename from src/Thenewboston/Bank/Api/BankConfirmationService.cs rename to src/Thenewboston/Validator/Api/BankConfirmationService.cs index 3a3a495..9266f8f 100644 --- a/src/Thenewboston/Bank/Api/BankConfirmationService.cs +++ b/src/Thenewboston/Validator/Api/BankConfirmationService.cs @@ -4,7 +4,7 @@ using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; -namespace Thenewboston.Bank.Api +namespace Thenewboston.Validator.Api { public class BankConfirmationService : IBankConfirmationService { @@ -15,16 +15,16 @@ public BankConfirmationService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task GetValidatorConfirmationServicesAsync() + public async Task GetBankConfirmationServicesAsync() { - var response = await _requestSender.GetAsync("/validator_confirmation_services"); - - if(!response.IsSuccessStatusCode) + var response = await _requestSender.GetAsync("/bank_confirmation_services"); + + if (!response.IsSuccessStatusCode) { // TODO: Create specific exception throw new Exception(); } - + var stringResponse = await response.Content.ReadAsStringAsync(); if(string.IsNullOrEmpty(stringResponse)) diff --git a/src/Thenewboston/Validator/Api/IBankConfirmationService.cs b/src/Thenewboston/Validator/Api/IBankConfirmationService.cs new file mode 100644 index 0000000..ec71ec3 --- /dev/null +++ b/src/Thenewboston/Validator/Api/IBankConfirmationService.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Thenewboston.Common.Api.Models; + +namespace Thenewboston.Validator.Api +{ + public interface IBankConfirmationService + { + public Task GetBankConfirmationServicesAsync(); + } +} \ No newline at end of file From c96ad99a2e826f647a4112cc080d8e9c5e68cdbe Mon Sep 17 00:00:00 2001 From: Nishp77 Date: Mon, 7 Dec 2020 20:03:22 -0600 Subject: [PATCH 24/37] Done with tests --- .../Bank/Api/BankConfirmationServiceTests.cs | 7 -- .../Api/ValidatorConfirmationServiceTests.cs | 106 ++++++++++++++++++ .../Api/BankConfirmationServiceTests.cs | 74 ++++++++++++ .../Bank/Api/IValidatorConfirmationService.cs | 8 +- .../Bank/Api/ValidatorConfirmationService.cs | 46 ++++++-- .../Bank/Models/BankConfirmationService.cs | 18 --- .../ValidatorConfirmationServiceResponse.cs | 32 ++++++ .../BankValidatorConfirmationService.cs | 17 +++ .../ValidatorConfirmationServiceMessage.cs | 16 +++ .../Validator/Api/BankConfirmationService.cs | 18 +-- .../Validator/Api/IBankConfirmationService.cs | 3 +- .../Models/BankConfirmationServiceResponse.cs | 32 ++++++ 12 files changed, 332 insertions(+), 45 deletions(-) delete mode 100644 src/Thenewboston.Tests/Bank/Api/BankConfirmationServiceTests.cs create mode 100644 src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs create mode 100644 src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs delete mode 100644 src/Thenewboston/Bank/Models/BankConfirmationService.cs create mode 100644 src/Thenewboston/Bank/Models/ValidatorConfirmationServiceResponse.cs create mode 100644 src/Thenewboston/Common/Models/BankValidatorConfirmationService.cs create mode 100644 src/Thenewboston/Common/Models/ValidatorConfirmationServiceMessage.cs create mode 100644 src/Thenewboston/Validator/Models/BankConfirmationServiceResponse.cs diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationServiceTests.cs deleted file mode 100644 index 23e854d..0000000 --- a/src/Thenewboston.Tests/Bank/Api/BankConfirmationServiceTests.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Thenewboston.Tests.Bank.Api -{ - public class BankConfirmationServiceTests - { - - } -} \ No newline at end of file diff --git a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs new file mode 100644 index 0000000..f77584c --- /dev/null +++ b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using Moq; +using Newtonsoft.Json; +using Thenewboston.Bank.Api; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; +using Thenewboston.Common.Http; +using Thenewboston.Common.Models; +using Xunit; + +namespace Thenewboston.Tests.Bank.Api +{ + public class ValidatorConfirmationServiceTests + { + #region Test Models + + private PaginatedResponseModel CreateMockResponse() + { + return new PaginatedResponseModel() { + Count = 1, + Next = string.Empty, + Previous = string.Empty, + Results = + new List() { + new ValidatorConfirmationServiceResponse() { + Id = "be9fbc3b-d4df-43d5-9bea-9882a6dd27f6", + Created = DateTime.Parse("2020-10-08T02:18:07.324999Z"), + Modified = DateTime.Parse("2020-10-08T02:18:07.325044Z"), + End = DateTime.Parse("2020-08-09T22:10:24Z"), + Start = DateTime.Parse("2020-07-09T22:10:25Z"), + Validator = "51461a75-dd8d-4133-81f4-543a3b054149" + } + } + }; + } + + private BankValidatorConfirmationService CreateMockValidatorConfirmationServiceMessage() + { + return new BankValidatorConfirmationService() { + Message = new ValidatorConfirmationServiceMessage() { + End = DateTime.Parse("2020-07-09T22:10:25Z"), Start = DateTime.Parse("2020-08-09T22:10:25Z") + }, + NodeIdentifier = "59479a31c3b91d96bb7a0b3e07f18d4bf301f1bb0bde05f8d36d9611dcbe7cbf", + Signature = + "2a4b90e97566d4c46cb302e8297841ebe0b9f5ce6f30217721dedb4bfdc48944d14f46032e33246b6a60a942bc48fd9541057b7b1c635d4346436deab9f4bf01" + }; + } + + #endregion + + #region Mock Service + + private IValidatorConfirmationService BuildValidatorConfirmationServiceGetMock() + { + var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + response.Content = new StringContent(JsonConvert.SerializeObject(CreateMockResponse()), Encoding.UTF8, + "application/json"); + var requestSenderMock = new Mock(); + + requestSenderMock + .Setup(s => s.GetAsync(It.IsAny())) + .ReturnsAsync(response); + + IValidatorConfirmationService service = new ValidatorConfirmationService(requestSenderMock.Object); + return service; + } + + private IValidatorConfirmationService BuildValidatorConfirmationServicePostMock() + { + var requestSenderMock = new Mock(); + requestSenderMock.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.Created)); + + IValidatorConfirmationService service = new ValidatorConfirmationService(requestSenderMock.Object); + return service; + } + + #endregion + + #region Tests + + [Fact] + public async void ConfirmationServiceReturnedAsync() + { + var service = BuildValidatorConfirmationServiceGetMock(); + var returnedBlock = await service.GetValidatorConfirmationServicesAsync(); + var expectedResult = JsonConvert.SerializeObject(CreateMockResponse()); + var actualResult = JsonConvert.SerializeObject(returnedBlock); + Assert.Equal(expectedResult, actualResult); + } + + [Fact] + public async void BlockPostedAsync() + { + var service = BuildValidatorConfirmationServicePostMock(); + var response = + await service.PostValidatorConfirmationServiceAsync(CreateMockValidatorConfirmationServiceMessage()); + Assert.True(response.StatusCode == System.Net.HttpStatusCode.Created); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs new file mode 100644 index 0000000..bd393a3 --- /dev/null +++ b/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; +using Moq; +using Newtonsoft.Json; +using Thenewboston.Common.Api.Models; +using Thenewboston.Common.Http; +using Thenewboston.Validator.Api; +using Thenewboston.Validator.Models; +using Xunit; + +namespace Thenewboston.Tests.Validator.Api +{ + public class BankConfirmationServiceTests + { + #region Test Models + + private PaginatedResponseModel CreateMockResponse() + { + return new PaginatedResponseModel() { + Count = 1, + Next = string.Empty, + Previous = string.Empty, + Results = + new List() { + new BankConfirmationServiceResponse() { + Id = "09e96a28-4d71-4123-85a3-882a9bdad114", + Created = DateTime.Parse("2020-09-11T02:15:13.638227Z"), + Modified = DateTime.Parse("2020-09-11T02:15:13.638326Z"), + End = DateTime.Parse("2020-09-23T00:06:55.320993Z"), + Start = DateTime.Parse("2020-09-20T00:06:55.320993Z"), + Bank = "b58b4b8a-d8f9-4395-a0de-f9df150bb093" + } + } + }; + } + + #endregion + + #region Mock Service + + private IBankConfirmationService BuildBankConfirmationServiceGetMock() + { + var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); + response.Content = new StringContent(JsonConvert.SerializeObject(CreateMockResponse()), Encoding.UTF8, + "application/json"); + var requestSenderMock = new Mock(); + + requestSenderMock + .Setup(s => s.GetAsync(It.IsAny())) + .ReturnsAsync(response); + + IBankConfirmationService service = new BankConfirmationService(requestSenderMock.Object); + return service; + } + + #endregion + + #region Tests + + [Fact] + public async void ConfirmationServiceReturnedAsync() + { + var service = BuildBankConfirmationServiceGetMock(); + var returnedBlock = await service.GetBankConfirmationServicesAsync(); + var expectedResult = JsonConvert.SerializeObject(CreateMockResponse()); + var actualResult = JsonConvert.SerializeObject(returnedBlock); + Assert.Equal(expectedResult, actualResult); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs index 3cc4581..ddf7643 100644 --- a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs @@ -1,11 +1,17 @@ +using System.Net.Http; using System.Threading.Tasks; +using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; +using Thenewboston.Common.Models; namespace Thenewboston.Bank.Api { public interface IValidatorConfirmationService { - public Task GetValidatorConfirmationServicesAsync(); + public Task> + GetValidatorConfirmationServicesAsync(); + public Task PostValidatorConfirmationServiceAsync( + BankValidatorConfirmationService service); } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs index 0a879d0..006f91e 100644 --- a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs @@ -1,8 +1,14 @@ using System; +using System.Net.Http; +using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; +using Thenewboston.Common.Models; +using Thenewboston.Validator.Models; +using Block = Thenewboston.Common.Models.Block; namespace Thenewboston.Bank.Api { @@ -14,28 +20,48 @@ public ValidatorConfirmationService(IHttpRequestSender requestSender) { _requestSender = requestSender; } - - public async Task GetValidatorConfirmationServicesAsync() + + public async Task> + GetValidatorConfirmationServicesAsync() { - var response = await _requestSender.GetAsync("/validator_confirmation_services"); - - if(!response.IsSuccessStatusCode) + var response = await _requestSender.GetAsync("/validator_confirmation_services"); + + if (!response.IsSuccessStatusCode) { // TODO: Create specific exception - throw new Exception(); + throw new Exception(); } - var stringResponse = await response.Content.ReadAsStringAsync(); + var stringResponse = await response.Content.ReadAsStringAsync(); - if(string.IsNullOrEmpty(stringResponse)) + if (string.IsNullOrEmpty(stringResponse)) { // TODO: Create specific exception - throw new Exception(); + throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResponse); + var result = + JsonConvert.DeserializeObject>( + stringResponse); return result; } + + public async Task PostValidatorConfirmationServiceAsync( + BankValidatorConfirmationService service) + { + var httpContent = + new StringContent(JsonConvert.SerializeObject(service), Encoding.UTF8, "application/json"); + var request = await _requestSender.PostAsync("/blocks", httpContent); + + if (!request.IsSuccessStatusCode) + { + // TODO: Create specific exception + throw new Exception(); + } + + var response = new HttpResponseMessage(System.Net.HttpStatusCode.Created); + return response; + } } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Models/BankConfirmationService.cs b/src/Thenewboston/Bank/Models/BankConfirmationService.cs deleted file mode 100644 index e3475b0..0000000 --- a/src/Thenewboston/Bank/Models/BankConfirmationService.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -namespace Thenewboston.Bank.Models -{ - public class BankConfirmationService - { - public string Id { get; set; } - - public DateTime Created { get; set; } - - public DateTime Modified { get; set; } - - public DateTime Start { get; set; } - - public DateTime End { get; set; } - - public string Validator { get; set; } - } -} diff --git a/src/Thenewboston/Bank/Models/ValidatorConfirmationServiceResponse.cs b/src/Thenewboston/Bank/Models/ValidatorConfirmationServiceResponse.cs new file mode 100644 index 0000000..76b91c4 --- /dev/null +++ b/src/Thenewboston/Bank/Models/ValidatorConfirmationServiceResponse.cs @@ -0,0 +1,32 @@ +using System; +using Newtonsoft.Json; + +namespace Thenewboston.Bank.Models +{ + public class ValidatorConfirmationServiceResponse + { + [JsonProperty(PropertyName = "id")] + + public string Id { get; set; } + + [JsonProperty(PropertyName = "created_date")] + + public DateTime Created { get; set; } + + [JsonProperty(PropertyName = "modified_date")] + + public DateTime Modified { get; set; } + + [JsonProperty(PropertyName = "start")] + + public DateTime Start { get; set; } + + [JsonProperty(PropertyName = "end")] + + public DateTime End { get; set; } + + [JsonProperty(PropertyName = "validator")] + + public string Validator { get; set; } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Common/Models/BankValidatorConfirmationService.cs b/src/Thenewboston/Common/Models/BankValidatorConfirmationService.cs new file mode 100644 index 0000000..46191c7 --- /dev/null +++ b/src/Thenewboston/Common/Models/BankValidatorConfirmationService.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using Thenewboston.Bank.Api; + +namespace Thenewboston.Common.Models +{ + public class BankValidatorConfirmationService + { + [JsonProperty(PropertyName ="message")] + public ValidatorConfirmationServiceMessage Message { get; set; } + + [JsonProperty(PropertyName ="node_identifier")] + public string NodeIdentifier { get; set; } + + [JsonProperty(PropertyName ="signature")] + public string Signature { get; set; } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Common/Models/ValidatorConfirmationServiceMessage.cs b/src/Thenewboston/Common/Models/ValidatorConfirmationServiceMessage.cs new file mode 100644 index 0000000..d26720f --- /dev/null +++ b/src/Thenewboston/Common/Models/ValidatorConfirmationServiceMessage.cs @@ -0,0 +1,16 @@ +using System; +using Newtonsoft.Json; + +namespace Thenewboston.Common.Models +{ + public class ValidatorConfirmationServiceMessage + { + [JsonProperty(PropertyName = "start")] + + public DateTime Start { get; set; } + + [JsonProperty(PropertyName = "end")] + + public DateTime End { get; set; } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Validator/Api/BankConfirmationService.cs b/src/Thenewboston/Validator/Api/BankConfirmationService.cs index 9266f8f..c073331 100644 --- a/src/Thenewboston/Validator/Api/BankConfirmationService.cs +++ b/src/Thenewboston/Validator/Api/BankConfirmationService.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; +using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api { @@ -14,26 +15,27 @@ public BankConfirmationService(IHttpRequestSender requestSender) { _requestSender = requestSender; } - - public async Task GetBankConfirmationServicesAsync() + + public async Task> GetBankConfirmationServicesAsync() { var response = await _requestSender.GetAsync("/bank_confirmation_services"); if (!response.IsSuccessStatusCode) { // TODO: Create specific exception - throw new Exception(); + throw new Exception(); } - - var stringResponse = await response.Content.ReadAsStringAsync(); - if(string.IsNullOrEmpty(stringResponse)) + var stringResponse = await response.Content.ReadAsStringAsync(); + + if (string.IsNullOrEmpty(stringResponse)) { // TODO: Create specific exception - throw new Exception(); + throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResponse); + var result = + JsonConvert.DeserializeObject>(stringResponse); return result; } diff --git a/src/Thenewboston/Validator/Api/IBankConfirmationService.cs b/src/Thenewboston/Validator/Api/IBankConfirmationService.cs index ec71ec3..6e3b93b 100644 --- a/src/Thenewboston/Validator/Api/IBankConfirmationService.cs +++ b/src/Thenewboston/Validator/Api/IBankConfirmationService.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; using Thenewboston.Common.Api.Models; +using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api { public interface IBankConfirmationService { - public Task GetBankConfirmationServicesAsync(); + public Task> GetBankConfirmationServicesAsync(); } } \ No newline at end of file diff --git a/src/Thenewboston/Validator/Models/BankConfirmationServiceResponse.cs b/src/Thenewboston/Validator/Models/BankConfirmationServiceResponse.cs new file mode 100644 index 0000000..b9f3b2d --- /dev/null +++ b/src/Thenewboston/Validator/Models/BankConfirmationServiceResponse.cs @@ -0,0 +1,32 @@ +using System; +using Newtonsoft.Json; + +namespace Thenewboston.Validator.Models +{ + public class BankConfirmationServiceResponse + { + [JsonProperty(PropertyName = "id")] + + public string Id { get; set; } + + [JsonProperty(PropertyName = "created_date")] + + public DateTime Created { get; set; } + + [JsonProperty(PropertyName = "modified_date")] + + public DateTime Modified { get; set; } + + [JsonProperty(PropertyName = "start")] + + public DateTime Start { get; set; } + + [JsonProperty(PropertyName = "end")] + + public DateTime End { get; set; } + + [JsonProperty(PropertyName = "bank")] + + public string Bank { get; set; } + } +} \ No newline at end of file From b7619735d90b71c35b86f1796d0534e22c84c345 Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Wed, 9 Dec 2020 14:11:06 +0200 Subject: [PATCH 25/37] Rename BankResponse to BankNodeResponse --- .../Bank/Api/ConnectedBanksServiceTests.cs | 14 +++++++------- src/Thenewboston/Bank/Api/ConnectedBanksService.cs | 8 ++++---- .../Bank/Api/IConnectedBanksService.cs | 4 ++-- .../{BankResponse.cs => BankNodeResponse.cs} | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) rename src/Thenewboston/Bank/Api/Models/{BankResponse.cs => BankNodeResponse.cs} (96%) diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs index cb041eb..1b424dd 100644 --- a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs @@ -20,15 +20,15 @@ public class GetBanksAsync [Fact] public async void ListOfBanksIsReturned() { - var expectedResponseModel = new PaginatedResponseModel + var expectedResponseModel = new PaginatedResponseModel { Count = 2, Next = null, Previous = null, Results = - new List + new List { - new BankResponse + new BankNodeResponse { AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", IpAddress = "83.168.1.232", @@ -39,7 +39,7 @@ public async void ListOfBanksIsReturned() DefaultTransactionFee = 1, Trust = "100.00" }, - new BankResponse + new BankNodeResponse { AccountNumber = "db1a9ac3c356ab744ab4ad5256bb86c2f6dfaa7c1aece1f026a08dbd8c7178f2", IpAddress = "74.124.1.68", @@ -68,7 +68,7 @@ public class UpdateBankAsync [Fact] public async void UpdatedBankIsReturned() { - var expectedBank = new BankResponse + var expectedBank = new BankNodeResponse { AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", IpAddress = "83.168.1.232", @@ -92,7 +92,7 @@ public async void UpdatedBankIsReturned() } } - public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock(PaginatedResponseModel expectedResponseModel) + public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock(PaginatedResponseModel expectedResponseModel) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(expectedResponseModel), Encoding.UTF8, "application/json"); @@ -107,7 +107,7 @@ public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock return service; } - public static IConnectedBanksService BuildUpdateBankAsyncConnectedBanksServiceMock(BankResponse expectedBank) + public static IConnectedBanksService BuildUpdateBankAsyncConnectedBanksServiceMock(BankNodeResponse expectedBank) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(expectedBank), Encoding.UTF8, "application/json"); diff --git a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs index 4ce0a96..1f4db76 100644 --- a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs @@ -18,7 +18,7 @@ public ConnectedBanksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetBanksAsync() + public async Task> GetBanksAsync() { var response = await _requestSender.GetAsync("/banks"); @@ -36,12 +36,12 @@ public async Task> GetBanksAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject>(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } - public async Task UpdateBankAsync(string nodeIdentifier, RequestModel payload) + public async Task UpdateBankAsync(string nodeIdentifier, RequestModel payload) { var jsonPayload = JsonConvert.SerializeObject(payload); var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); @@ -62,7 +62,7 @@ public async Task UpdateBankAsync(string nodeIdentifier, RequestMo throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var result = JsonConvert.DeserializeObject(stringResult); return result; } diff --git a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs index 3485d6a..1f8c462 100644 --- a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs @@ -6,7 +6,7 @@ namespace Thenewboston.Bank.Api.Models { public interface IConnectedBanksService { - Task> GetBanksAsync(); - Task UpdateBankAsync(string nodeIdentifier, RequestModel payload); + Task> GetBanksAsync(); + Task UpdateBankAsync(string nodeIdentifier, RequestModel payload); } } diff --git a/src/Thenewboston/Bank/Api/Models/BankResponse.cs b/src/Thenewboston/Bank/Api/Models/BankNodeResponse.cs similarity index 96% rename from src/Thenewboston/Bank/Api/Models/BankResponse.cs rename to src/Thenewboston/Bank/Api/Models/BankNodeResponse.cs index 851efb5..102f97f 100644 --- a/src/Thenewboston/Bank/Api/Models/BankResponse.cs +++ b/src/Thenewboston/Bank/Api/Models/BankNodeResponse.cs @@ -5,7 +5,7 @@ namespace Thenewboston.Bank.Api.Models { - public class BankResponse + public class BankNodeResponse { [JsonProperty(PropertyName = "account_number")] public string AccountNumber { get; set; } From 037d7085bcdffba8120e53c727c075a33d5ade02 Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 12 Dec 2020 16:05:34 +0200 Subject: [PATCH 26/37] Add small example --- src/Thenewboston/Bank/AppLayer/Bank.cs | 27 ++++++++++++++++++++++++++ src/Thenewboston/Thenewboston.csproj | 1 + 2 files changed, 28 insertions(+) create mode 100644 src/Thenewboston/Bank/AppLayer/Bank.cs diff --git a/src/Thenewboston/Bank/AppLayer/Bank.cs b/src/Thenewboston/Bank/AppLayer/Bank.cs new file mode 100644 index 0000000..1723aed --- /dev/null +++ b/src/Thenewboston/Bank/AppLayer/Bank.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Thenewboston.Bank.Api; +using Thenewboston.Bank.Models; +using Thenewboston.Common.Http; + +namespace Thenewboston.Bank.AppLayer +{ + public class Bank + { + private readonly AccountsService _accountsService; + + public Bank(string ip, int port) + { + var requestSender = new SimpleHttpRequestSender($"{ip}:{port}"); + _accountsService = new AccountsService(requestSender); + } + + public async Task> GetAccounts() + { + var result = await _accountsService.GetAccountsAsync(); + return result; + } + + } +} diff --git a/src/Thenewboston/Thenewboston.csproj b/src/Thenewboston/Thenewboston.csproj index 8af2e8d..98bc657 100644 --- a/src/Thenewboston/Thenewboston.csproj +++ b/src/Thenewboston/Thenewboston.csproj @@ -11,6 +11,7 @@ + From 689c2d762737fb8541397208138e6c5fcf568dc5 Mon Sep 17 00:00:00 2001 From: arjunraghurama Date: Sun, 13 Dec 2020 15:31:20 +0530 Subject: [PATCH 27/37] Moved confirmation services response models into Api/Models #69 --- .../Bank/Api/ValidatorConfirmationServiceTests.cs | 2 +- .../Validator/Api/BankConfirmationServiceTests.cs | 2 +- src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs | 2 +- .../{ => Api}/Models/ValidatorConfirmationServiceResponse.cs | 2 +- src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs | 2 +- src/Thenewboston/Thenewboston.csproj | 1 - src/Thenewboston/Validator/Api/BankConfirmationService.cs | 2 +- src/Thenewboston/Validator/Api/IBankConfirmationService.cs | 2 +- .../{ => Api}/Models/BankConfirmationServiceResponse.cs | 2 +- 9 files changed, 8 insertions(+), 9 deletions(-) rename src/Thenewboston/Bank/{ => Api}/Models/ValidatorConfirmationServiceResponse.cs (94%) rename src/Thenewboston/Validator/{ => Api}/Models/BankConfirmationServiceResponse.cs (94%) diff --git a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs index f77584c..48115ea 100644 --- a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs @@ -5,7 +5,7 @@ using Moq; using Newtonsoft.Json; using Thenewboston.Bank.Api; -using Thenewboston.Bank.Models; +using Thenewboston.Bank.Api.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Thenewboston.Common.Models; diff --git a/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs index bd393a3..aadc66f 100644 --- a/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs @@ -7,7 +7,7 @@ using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Thenewboston.Validator.Api; -using Thenewboston.Validator.Models; +using Thenewboston.Validator.Api.Models; using Xunit; namespace Thenewboston.Tests.Validator.Api diff --git a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs index ddf7643..2eafaef 100644 --- a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs @@ -1,6 +1,6 @@ using System.Net.Http; using System.Threading.Tasks; -using Thenewboston.Bank.Models; +using Thenewboston.Bank.Api.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Models; diff --git a/src/Thenewboston/Bank/Models/ValidatorConfirmationServiceResponse.cs b/src/Thenewboston/Bank/Api/Models/ValidatorConfirmationServiceResponse.cs similarity index 94% rename from src/Thenewboston/Bank/Models/ValidatorConfirmationServiceResponse.cs rename to src/Thenewboston/Bank/Api/Models/ValidatorConfirmationServiceResponse.cs index 76b91c4..008705d 100644 --- a/src/Thenewboston/Bank/Models/ValidatorConfirmationServiceResponse.cs +++ b/src/Thenewboston/Bank/Api/Models/ValidatorConfirmationServiceResponse.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json; -namespace Thenewboston.Bank.Models +namespace Thenewboston.Bank.Api.Models { public class ValidatorConfirmationServiceResponse { diff --git a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs index 006f91e..28bcf15 100644 --- a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs @@ -3,7 +3,7 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; -using Thenewboston.Bank.Models; +using Thenewboston.Bank.Api.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Thenewboston.Common.Models; diff --git a/src/Thenewboston/Thenewboston.csproj b/src/Thenewboston/Thenewboston.csproj index 8af2e8d..fec98d3 100644 --- a/src/Thenewboston/Thenewboston.csproj +++ b/src/Thenewboston/Thenewboston.csproj @@ -10,7 +10,6 @@ - diff --git a/src/Thenewboston/Validator/Api/BankConfirmationService.cs b/src/Thenewboston/Validator/Api/BankConfirmationService.cs index c073331..ac2b953 100644 --- a/src/Thenewboston/Validator/Api/BankConfirmationService.cs +++ b/src/Thenewboston/Validator/Api/BankConfirmationService.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; -using Thenewboston.Validator.Models; +using Thenewboston.Validator.Api.Models; namespace Thenewboston.Validator.Api { diff --git a/src/Thenewboston/Validator/Api/IBankConfirmationService.cs b/src/Thenewboston/Validator/Api/IBankConfirmationService.cs index 6e3b93b..84d508f 100644 --- a/src/Thenewboston/Validator/Api/IBankConfirmationService.cs +++ b/src/Thenewboston/Validator/Api/IBankConfirmationService.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; using Thenewboston.Common.Api.Models; -using Thenewboston.Validator.Models; +using Thenewboston.Validator.Api.Models; namespace Thenewboston.Validator.Api { diff --git a/src/Thenewboston/Validator/Models/BankConfirmationServiceResponse.cs b/src/Thenewboston/Validator/Api/Models/BankConfirmationServiceResponse.cs similarity index 94% rename from src/Thenewboston/Validator/Models/BankConfirmationServiceResponse.cs rename to src/Thenewboston/Validator/Api/Models/BankConfirmationServiceResponse.cs index b9f3b2d..4fca87f 100644 --- a/src/Thenewboston/Validator/Models/BankConfirmationServiceResponse.cs +++ b/src/Thenewboston/Validator/Api/Models/BankConfirmationServiceResponse.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json; -namespace Thenewboston.Validator.Models +namespace Thenewboston.Validator.Api.Models { public class BankConfirmationServiceResponse { From 84a71825f0de5dc3f16f12a10933bc07b6d77b22 Mon Sep 17 00:00:00 2001 From: Nishp77 Date: Wed, 23 Dec 2020 20:41:20 -0600 Subject: [PATCH 28/37] Done with bank and validator api --- .../Bank/Api/AccountsServiceTests.cs | 52 +++++++------ .../Bank/Api/TransactionsServiceTests.cs | 75 +++++++++---------- .../Validator/Api/AccountsServiceTests.cs | 16 ++-- src/Thenewboston/Bank/Api/AccountsService.cs | 5 +- src/Thenewboston/Bank/Api/IAccountsService.cs | 3 +- .../Bank/Api/ITransactionsService.cs | 3 +- .../Bank/Api/TransactionsService.cs | 5 +- .../Validator/Api/AccountsService.cs | 5 +- .../Validator/Api/IAccountsService.cs | 3 +- 9 files changed, 91 insertions(+), 76 deletions(-) diff --git a/src/Thenewboston.Tests/Bank/Api/AccountsServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/AccountsServiceTests.cs index c5d27ac..67064a2 100644 --- a/src/Thenewboston.Tests/Bank/Api/AccountsServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/AccountsServiceTests.cs @@ -11,6 +11,7 @@ using Xunit; using System.Linq; using Thenewboston.Bank.Api.Models; +using Thenewboston.Common.Api.Models; namespace Thenewboston.Tests.Bank.Api { @@ -25,8 +26,8 @@ public async void ListOfAccountsIsReturned() var accounts = await service.GetAccountsAsync(); - Assert.Equal(2, accounts.Count()); - Assert.Equal("9eca00a5-d925-454c-a8d6-ecbb26ec2f76", accounts.ElementAt(0).Id); + Assert.Equal(2, accounts.Count); + Assert.Equal("9eca00a5-d925-454c-a8d6-ecbb26ec2f76", accounts.Results.ElementAt(0).Id); } } @@ -49,35 +50,37 @@ public static AccountsService BuildAccountsServiceMock() { var requestSender = new Mock(); - var listResult = new List - { - new BankAccount - { - Id = "9eca00a5-d925-454c-a8d6-ecbb26ec2f76", - AccountNumber = "4d2ec91f37bc553bc538e91195669b666e26b2ea3e4e31507e38102a758d4f86", - Created = DateTime.Now.AddDays(-3), - Modified = DateTime.Now, - Trust = "99.73" - }, - new BankAccount - { - Id = "ae4d43b0-5c34-4e56-8266-0e3531268815", - AccountNumber = "a29baa6ba36f6db707f8f8dacfa82d5e8a28fa616e8cc96cf6d7790f551d79f2", - Created = DateTime.Now.AddDays(-3), - Modified = DateTime.Now, - Trust = "94.61" + var listResult = new PaginatedResponseModel() { + Count = 2, + Next = string.Empty, + Previous = string.Empty, + Results = new List() { + new BankAccount { + Id = "9eca00a5-d925-454c-a8d6-ecbb26ec2f76", + AccountNumber = "4d2ec91f37bc553bc538e91195669b666e26b2ea3e4e31507e38102a758d4f86", + Created = DateTime.Now.AddDays(-3), + Modified = DateTime.Now, + Trust = "99.73" + }, + new BankAccount { + Id = "ae4d43b0-5c34-4e56-8266-0e3531268815", + AccountNumber = "a29baa6ba36f6db707f8f8dacfa82d5e8a28fa616e8cc96cf6d7790f551d79f2", + Created = DateTime.Now.AddDays(-3), + Modified = DateTime.Now, + Trust = "94.61" + } } }; var getAllResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - getAllResponse.Content = new StringContent(JsonConvert.SerializeObject(listResult), Encoding.UTF8, "application/json"); + getAllResponse.Content = + new StringContent(JsonConvert.SerializeObject(listResult), Encoding.UTF8, "application/json"); requestSender .Setup(x => x.GetAsync(It.IsAny())) .Returns(Task.FromResult(getAllResponse)); - var updateResult = new BankAccount - { + var updateResult = new BankAccount { Id = "64426fc5-b3ac-42fb-b75b-d5ccfcdc6872", AccountNumber = "a29baa6ba36f6db707f8f8dacfa82d5e8a28fa616e8cc96cf6d7790f551d79f2", Created = DateTime.Now.AddDays(-3), @@ -86,7 +89,8 @@ public static AccountsService BuildAccountsServiceMock() }; var updateResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - updateResponse.Content = new StringContent(JsonConvert.SerializeObject(updateResult), Encoding.UTF8, "application/json"); + updateResponse.Content = new StringContent(JsonConvert.SerializeObject(updateResult), Encoding.UTF8, + "application/json"); requestSender .Setup(x => x.PatchAsync(It.IsAny(), It.IsAny())) @@ -96,4 +100,4 @@ public static AccountsService BuildAccountsServiceMock() return bankService; } } -} +} \ No newline at end of file diff --git a/src/Thenewboston.Tests/Bank/Api/TransactionsServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/TransactionsServiceTests.cs index b6b44dc..b93e837 100644 --- a/src/Thenewboston.Tests/Bank/Api/TransactionsServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/TransactionsServiceTests.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json; using Thenewboston.Bank.Api; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Xunit; @@ -15,20 +16,17 @@ namespace Thenewboston.Tests.Bank.Api { public class TransactionsServiceTests { - public class GetAllTransactionsAsync { [Fact] - public async void ListOfTransactionsIsReturned() { var service = BuildBankTransactionMock(); var transactions = await service.GetAllTransactionsAsync(); - Assert.Equal(2, transactions.Count()); - Assert.Equal("2484fbf3-2054-48a4-a1ce-66333cd15470", transactions.ElementAt(0).Id); - + Assert.Equal(2, transactions.Count); + Assert.Equal("2484fbf3-2054-48a4-a1ce-66333cd15470", transactions.Results.ElementAt(0).Id); } } @@ -36,43 +34,45 @@ public static TransactionsService BuildBankTransactionMock() { var requestSender = new Mock(); - var listResult = new List - { - new BankTransaction - { - Id = "2484fbf3-2054-48a4-a1ce-66333cd15470", - Block = new BankBlock - { - Id = "10cc3cec-eef6-453b-8667-f5cb19e6120d", - Created = DateTime.Now.AddDays(-3), - Modified = DateTime.Now, - BalanceKey = "4abccf4280ef61aad6f176a103933a42ed7dbf90d55e7912f404a704ede06f41", - Sender = "4abccf4280ef61aad6f176a103933a42ed7dbf90d55e7912f404a704ede06f41", - Signature = "c4a7696abc0f1e760a0c87d2a8db1faec060f99a77bf5f669a69dfdb301150db8fdaa2863a5d4a4e75be626ff56aecdbfea034283b1eb5a8e0196fd35f541b0b" + var listResult = new PaginatedResponseModel() { + Count = 2, + Next = string.Empty, + Previous = String.Empty, + Results = new List() { + new BankTransaction { + Id = "2484fbf3-2054-48a4-a1ce-66333cd15470", + Block = new BankBlock { + Id = "10cc3cec-eef6-453b-8667-f5cb19e6120d", + Created = DateTime.Now.AddDays(-3), + Modified = DateTime.Now, + BalanceKey = "4abccf4280ef61aad6f176a103933a42ed7dbf90d55e7912f404a704ede06f41", + Sender = "4abccf4280ef61aad6f176a103933a42ed7dbf90d55e7912f404a704ede06f41", + Signature = + "c4a7696abc0f1e760a0c87d2a8db1faec060f99a77bf5f669a69dfdb301150db8fdaa2863a5d4a4e75be626ff56aecdbfea034283b1eb5a8e0196fd35f541b0b" + }, + Amount = 1, + Recipient = "2e86f48216567302527b69eae6c6a188097ed3a9741f43cc3723e570cf47644c" }, - Amount = 1, - Recipient = "2e86f48216567302527b69eae6c6a188097ed3a9741f43cc3723e570cf47644c" - }, - new BankTransaction - { - Id = "2484fbf3-2054-48a4-a1ce-66333cd15470", - Block = new BankBlock - { - Id = "6b9bc4b1-76a7-4105-951f-b729b4befdef", - Created = DateTime.Now.AddDays(-3), - Modified = DateTime.Now, - BalanceKey = "4abccf4280ef61aad6f176a103933a42ed7dbf90d55e7912f404a704ede06f41", - Sender = "4abccf4280ef61aad6f176a103933a42ed7dbf90d55e7912f404a704ede06f41", - Signature = "c4a7696abc0f1e760a0c87d2a8db1faec060f99a77bf5f669a69dfdb301150db8fdaa2863a5d4a4e75be626ff56aecdbfea034283b1eb5a8e0196fd35f541b0b" - }, - Amount = 498, - Recipient = "802f34851bdfa1572f11fc4e58e44be3c01e92399bc4ba8d81e98b02254a0106" - + new BankTransaction { + Id = "2484fbf3-2054-48a4-a1ce-66333cd15470", + Block = new BankBlock { + Id = "6b9bc4b1-76a7-4105-951f-b729b4befdef", + Created = DateTime.Now.AddDays(-3), + Modified = DateTime.Now, + BalanceKey = "4abccf4280ef61aad6f176a103933a42ed7dbf90d55e7912f404a704ede06f41", + Sender = "4abccf4280ef61aad6f176a103933a42ed7dbf90d55e7912f404a704ede06f41", + Signature = + "c4a7696abc0f1e760a0c87d2a8db1faec060f99a77bf5f669a69dfdb301150db8fdaa2863a5d4a4e75be626ff56aecdbfea034283b1eb5a8e0196fd35f541b0b" + }, + Amount = 498, + Recipient = "802f34851bdfa1572f11fc4e58e44be3c01e92399bc4ba8d81e98b02254a0106" + } } }; var getAllResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - getAllResponse.Content = new StringContent(JsonConvert.SerializeObject(listResult), Encoding.UTF8, "application/json"); + getAllResponse.Content = + new StringContent(JsonConvert.SerializeObject(listResult), Encoding.UTF8, "application/json"); requestSender .Setup(x => x.GetAsync(It.IsAny())) @@ -80,7 +80,6 @@ public static TransactionsService BuildBankTransactionMock() var bankTransactionService = new TransactionsService(requestSender.Object); return bankTransactionService; - } } } \ No newline at end of file diff --git a/src/Thenewboston.Tests/Validator/Api/AccountsServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/AccountsServiceTests.cs index b00e5e1..34a8bec 100644 --- a/src/Thenewboston.Tests/Validator/Api/AccountsServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/AccountsServiceTests.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Moq; using Newtonsoft.Json; +using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Thenewboston.Validator.Api; using Thenewboston.Validator.Models; @@ -24,8 +25,8 @@ public async void ListOfAccountsIsReturned() var accounts = await service.GetAccountsAsync(); - Assert.Equal(2, accounts.Count()); - Assert.Equal("9eca00a5-d925-454c-a8d6-ecbb26ec2f76", accounts.ElementAt(0).Id); + Assert.Equal(2, accounts.Count); + Assert.Equal("9eca00a5-d925-454c-a8d6-ecbb26ec2f76", accounts.Results.ElementAt(0).Id); } } @@ -59,8 +60,12 @@ public static AccountsService BuildValidatorServiceMock() { var requestSender = new Mock(); - var listResult = new List + var listResult = new PaginatedResponseModel() { + Count = 2, + Next = string.Empty, + Previous = string.Empty, + Results = new List(){ new ValidatorAccount { Id = "9eca00a5-d925-454c-a8d6-ecbb26ec2f76", @@ -75,6 +80,7 @@ public static AccountsService BuildValidatorServiceMock() Balance = "175.0000000000000000", BalanceLock = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" } + } }; var getAllResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); @@ -84,7 +90,7 @@ public static AccountsService BuildValidatorServiceMock() getBalanceResponse.Content = new StringContent(JsonConvert.SerializeObject( new ValidatorAccountBalance { - Balance = listResult[0].Balance + Balance = listResult.Results.ElementAt(0).Balance }), Encoding.UTF8, "application/json"); @@ -93,7 +99,7 @@ public static AccountsService BuildValidatorServiceMock() getBalanceLockResponse.Content = new StringContent(JsonConvert.SerializeObject( new ValidatorAccountBalanceLock { - BalanceLock = listResult[0].BalanceLock + BalanceLock = listResult.Results.ElementAt(0).BalanceLock }), Encoding.UTF8, "application/json"); diff --git a/src/Thenewboston/Bank/Api/AccountsService.cs b/src/Thenewboston/Bank/Api/AccountsService.cs index e4ec86f..dbbeac3 100644 --- a/src/Thenewboston/Bank/Api/AccountsService.cs +++ b/src/Thenewboston/Bank/Api/AccountsService.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; namespace Thenewboston.Bank.Api @@ -19,7 +20,7 @@ public AccountsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAccountsAsync() + public async Task> GetAccountsAsync() { var response = await _requestSender.GetAsync("/accounts"); @@ -37,7 +38,7 @@ public async Task> GetAccountsAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject>(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } diff --git a/src/Thenewboston/Bank/Api/IAccountsService.cs b/src/Thenewboston/Bank/Api/IAccountsService.cs index 51dd16f..a13d5b8 100644 --- a/src/Thenewboston/Bank/Api/IAccountsService.cs +++ b/src/Thenewboston/Bank/Api/IAccountsService.cs @@ -2,12 +2,13 @@ using System.Threading.Tasks; using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; namespace Thenewboston.Bank.Api { public interface IAccountsService { - Task> GetAccountsAsync(); + Task> GetAccountsAsync(); Task UpdateAccountAsync(string accountNumber, RequestModel account); } } diff --git a/src/Thenewboston/Bank/Api/ITransactionsService.cs b/src/Thenewboston/Bank/Api/ITransactionsService.cs index c8a603c..e0482e8 100644 --- a/src/Thenewboston/Bank/Api/ITransactionsService.cs +++ b/src/Thenewboston/Bank/Api/ITransactionsService.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; using System.Threading.Tasks; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; namespace Thenewboston.Bank.Api { public interface ITransactionsService { - Task> GetAllTransactionsAsync(); + Task> GetAllTransactionsAsync(); } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/TransactionsService.cs b/src/Thenewboston/Bank/Api/TransactionsService.cs index c5c5b81..9b13e75 100644 --- a/src/Thenewboston/Bank/Api/TransactionsService.cs +++ b/src/Thenewboston/Bank/Api/TransactionsService.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; namespace Thenewboston.Bank.Api @@ -16,7 +17,7 @@ public TransactionsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAllTransactionsAsync() + public async Task> GetAllTransactionsAsync() { var response = await _requestSender.GetAsync("/bank_transactions"); var stringResult = string.Empty; @@ -36,7 +37,7 @@ public async Task> GetAllTransactionsAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject>(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } diff --git a/src/Thenewboston/Validator/Api/AccountsService.cs b/src/Thenewboston/Validator/Api/AccountsService.cs index 60dc867..1c4ebe0 100644 --- a/src/Thenewboston/Validator/Api/AccountsService.cs +++ b/src/Thenewboston/Validator/Api/AccountsService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Newtonsoft.Json; +using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; using Thenewboston.Validator.Models; @@ -16,7 +17,7 @@ public AccountsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAccountsAsync() + public async Task> GetAccountsAsync() { var response = await _requestSender.GetAsync("/accounts"); @@ -34,7 +35,7 @@ public async Task> GetAccountsAsync() throw new Exception(); } - var result = JsonConvert.DeserializeObject>(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } diff --git a/src/Thenewboston/Validator/Api/IAccountsService.cs b/src/Thenewboston/Validator/Api/IAccountsService.cs index 6b142b6..b88a4ae 100644 --- a/src/Thenewboston/Validator/Api/IAccountsService.cs +++ b/src/Thenewboston/Validator/Api/IAccountsService.cs @@ -1,12 +1,13 @@ using System.Collections.Generic; using System.Threading.Tasks; +using Thenewboston.Common.Api.Models; using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api { public interface IAccountsService { - Task> GetAccountsAsync(); + Task> GetAccountsAsync(); Task GetAccountBalanceAsync(string accountNumber); Task GetAccountBalanceLockAsync(string accountNumber); } From 1f694c93f0a730416351c0d55f8df3c5f8960cc6 Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 26 Dec 2020 00:24:45 +0200 Subject: [PATCH 29/37] Add offset and limit for bank pagination --- src/Thenewboston/Bank/Api/AccountsService.cs | 4 ++-- src/Thenewboston/Bank/Api/BlocksService.cs | 5 +++-- src/Thenewboston/Bank/Api/ConnectedBanksService.cs | 4 ++-- src/Thenewboston/Bank/Api/IAccountsService.cs | 2 +- src/Thenewboston/Bank/Api/IBlocksService.cs | 2 +- src/Thenewboston/Bank/Api/IConnectedBanksService.cs | 2 +- src/Thenewboston/Bank/Api/IInvalidBlocksService.cs | 2 +- src/Thenewboston/Bank/Api/ITransactionsService.cs | 2 +- .../Bank/Api/IValidatorConfirmationService.cs | 5 +++-- src/Thenewboston/Bank/Api/IValidatorService.cs | 2 +- src/Thenewboston/Bank/Api/InvalidBlocksService.cs | 11 ++--------- src/Thenewboston/Bank/Api/TransactionsService.cs | 4 ++-- .../Bank/Api/ValidatorConfirmationService.cs | 7 ++++--- src/Thenewboston/Bank/Api/ValidatorService.cs | 4 ++-- 14 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/Thenewboston/Bank/Api/AccountsService.cs b/src/Thenewboston/Bank/Api/AccountsService.cs index dbbeac3..284869e 100644 --- a/src/Thenewboston/Bank/Api/AccountsService.cs +++ b/src/Thenewboston/Bank/Api/AccountsService.cs @@ -20,9 +20,9 @@ public AccountsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAccountsAsync() + public async Task> GetAccountsAsync(int offset = 0, int limit = 10) { - var response = await _requestSender.GetAsync("/accounts"); + var response = await _requestSender.GetAsync($"/accounts?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { diff --git a/src/Thenewboston/Bank/Api/BlocksService.cs b/src/Thenewboston/Bank/Api/BlocksService.cs index 338b463..3f077dd 100644 --- a/src/Thenewboston/Bank/Api/BlocksService.cs +++ b/src/Thenewboston/Bank/Api/BlocksService.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -19,9 +20,9 @@ public BlocksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetBlocksAsync() + public async Task> GetBlocksAsync(int offset = 0, int limit = 10) { - var response = await _requestSender.GetAsync("/blocks"); + var response = await _requestSender.GetAsync($"/blocks?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { diff --git a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs index 1f4db76..572d004 100644 --- a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs @@ -18,9 +18,9 @@ public ConnectedBanksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetBanksAsync() + public async Task> GetBanksAsync(int offset=0, int limit=10) { - var response = await _requestSender.GetAsync("/banks"); + var response = await _requestSender.GetAsync($"/banks?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { diff --git a/src/Thenewboston/Bank/Api/IAccountsService.cs b/src/Thenewboston/Bank/Api/IAccountsService.cs index a13d5b8..6409124 100644 --- a/src/Thenewboston/Bank/Api/IAccountsService.cs +++ b/src/Thenewboston/Bank/Api/IAccountsService.cs @@ -8,7 +8,7 @@ namespace Thenewboston.Bank.Api { public interface IAccountsService { - Task> GetAccountsAsync(); + Task> GetAccountsAsync(int offset, int limit); Task UpdateAccountAsync(string accountNumber, RequestModel account); } } diff --git a/src/Thenewboston/Bank/Api/IBlocksService.cs b/src/Thenewboston/Bank/Api/IBlocksService.cs index ddd5269..a4cf207 100644 --- a/src/Thenewboston/Bank/Api/IBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IBlocksService.cs @@ -8,7 +8,7 @@ namespace Thenewboston.Bank.Api { public interface IBlocksService { - public Task> GetBlocksAsync(); + public Task> GetBlocksAsync(int offset, int limit); public Task PostBlocksAsync(Thenewboston.Common.Models.Block block); } diff --git a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs index 1f8c462..4b52b73 100644 --- a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs @@ -6,7 +6,7 @@ namespace Thenewboston.Bank.Api.Models { public interface IConnectedBanksService { - Task> GetBanksAsync(); + Task> GetBanksAsync(int offset, int limit); Task UpdateBankAsync(string nodeIdentifier, RequestModel payload); } } diff --git a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs index 0f89f8a..764674f 100644 --- a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs @@ -7,7 +7,7 @@ namespace Thenewboston.Bank.Api { public interface IInvalidBlocksService { - Task> GetInvalidBankBlocksAsync(PaginationParams pagination = default); + Task> GetInvalidBankBlocksAsync(int offset, int limit); Task SendInvalidBlocksToBankAsync(BankInvalidBlockRequest model); } diff --git a/src/Thenewboston/Bank/Api/ITransactionsService.cs b/src/Thenewboston/Bank/Api/ITransactionsService.cs index e0482e8..38ba84a 100644 --- a/src/Thenewboston/Bank/Api/ITransactionsService.cs +++ b/src/Thenewboston/Bank/Api/ITransactionsService.cs @@ -7,6 +7,6 @@ namespace Thenewboston.Bank.Api { public interface ITransactionsService { - Task> GetAllTransactionsAsync(); + Task> GetAllTransactionsAsync(int offset, int limit); } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs index 2eafaef..e17bd7e 100644 --- a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs @@ -8,8 +8,9 @@ namespace Thenewboston.Bank.Api { public interface IValidatorConfirmationService { - public Task> - GetValidatorConfirmationServicesAsync(); + public Task> GetValidatorConfirmationServicesAsync( + int offset, + int limit); public Task PostValidatorConfirmationServiceAsync( BankValidatorConfirmationService service); diff --git a/src/Thenewboston/Bank/Api/IValidatorService.cs b/src/Thenewboston/Bank/Api/IValidatorService.cs index 3e3ac09..24b5f1b 100644 --- a/src/Thenewboston/Bank/Api/IValidatorService.cs +++ b/src/Thenewboston/Bank/Api/IValidatorService.cs @@ -7,7 +7,7 @@ namespace Thenewboston.Bank.Api { public interface IValidatorService { - Task> GetAllValidatorsAsync(); + Task> GetAllValidatorsAsync(int offset, int limit); Task PatchValidatorAsync(string nodeIdentifier, RequestModel trust); diff --git a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs index b7a4740..6e6bf0a 100644 --- a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs @@ -19,17 +19,10 @@ public InvalidBlocksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetInvalidBankBlocksAsync(PaginationParams pagination = null) + public async Task> GetInvalidBankBlocksAsync(int offset = 0, int limit = 10) { - var url = ""; + var response = await _requestSender.GetAsync($"/invalid_blocks?offset={offset}&limit={limit}"); - url = pagination switch { - PaginationParams p when p.Page != null && p.Page >0 => $"/invalid_blocks?page={p.Page}", - PaginationParams p when (p.Page == null || p.Page <= 0) && p.Offset >=0 && p.Limit >0 => $"/invalid_blocks?offset={p.Offset}&limit={p.Limit}", - PaginationParams p when (p.Page == null || p.Page <= 0) && p.Offset >= 0 && (p.Limit <=0 || p.Limit is null) => $"/invalid_blocks?offset={pagination.Offset}&limit=20", - _ => $"/invalid_blocks?page=1" - }; - var response = await _requestSender.GetAsync(url); if (!response.IsSuccessStatusCode) { throw new Exception(); diff --git a/src/Thenewboston/Bank/Api/TransactionsService.cs b/src/Thenewboston/Bank/Api/TransactionsService.cs index 9b13e75..5bafdfb 100644 --- a/src/Thenewboston/Bank/Api/TransactionsService.cs +++ b/src/Thenewboston/Bank/Api/TransactionsService.cs @@ -17,9 +17,9 @@ public TransactionsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAllTransactionsAsync() + public async Task> GetAllTransactionsAsync(int offset=0, int limit=10) { - var response = await _requestSender.GetAsync("/bank_transactions"); + var response = await _requestSender.GetAsync($"/bank_transactions?offset={offset}&limit={limit}"); var stringResult = string.Empty; if (response.IsSuccessStatusCode) diff --git a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs index 28bcf15..371d295 100644 --- a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs @@ -21,10 +21,11 @@ public ValidatorConfirmationService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> - GetValidatorConfirmationServicesAsync() + public async Task> GetValidatorConfirmationServicesAsync( + int offset = 0, + int limit = 10) { - var response = await _requestSender.GetAsync("/validator_confirmation_services"); + var response = await _requestSender.GetAsync($"/validator_confirmation_services?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { diff --git a/src/Thenewboston/Bank/Api/ValidatorService.cs b/src/Thenewboston/Bank/Api/ValidatorService.cs index 74ff95c..e3ccd21 100644 --- a/src/Thenewboston/Bank/Api/ValidatorService.cs +++ b/src/Thenewboston/Bank/Api/ValidatorService.cs @@ -19,9 +19,9 @@ public ValidatorService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAllValidatorsAsync() + public async Task> GetAllValidatorsAsync(int offset = 0, int limit = 10) { - var response = await _requestSender.GetAsync("/validators"); + var response = await _requestSender.GetAsync($"/validators?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { From 147191c5ad1c9c63e4345a6945da29427ee4101d Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 26 Dec 2020 00:29:07 +0200 Subject: [PATCH 30/37] Add offset and limit for validator pagination --- .../Common/Api/Models/PaginationParams.cs | 16 ---------------- .../Validator/Api/AccountsService.cs | 4 ++-- .../Validator/Api/BankConfirmationService.cs | 6 ++++-- .../Validator/Api/ConnectedBanksService.cs | 4 ++-- .../Validator/Api/IAccountsService.cs | 2 +- .../Validator/Api/IBankConfirmationService.cs | 4 +++- .../Validator/Api/IConnectedBanksService.cs | 2 +- .../Validator/Api/IValidatorsService.cs | 4 +++- .../Validator/Api/ValidatorsService.cs | 6 ++++-- 9 files changed, 20 insertions(+), 28 deletions(-) delete mode 100644 src/Thenewboston/Common/Api/Models/PaginationParams.cs diff --git a/src/Thenewboston/Common/Api/Models/PaginationParams.cs b/src/Thenewboston/Common/Api/Models/PaginationParams.cs deleted file mode 100644 index c487d43..0000000 --- a/src/Thenewboston/Common/Api/Models/PaginationParams.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Thenewboston.Common.Api.Models -{ - public class PaginationParams - { - public int? Page { get; set; } - public int? Limit { get; set; } - public int? Offset { get; set; } - - public void Deconstruct(out int? page, out int? offset, out int? limit) - { - page = Page; - offset = Offset; - limit = Limit; - } - } -} \ No newline at end of file diff --git a/src/Thenewboston/Validator/Api/AccountsService.cs b/src/Thenewboston/Validator/Api/AccountsService.cs index 1c4ebe0..1f2994d 100644 --- a/src/Thenewboston/Validator/Api/AccountsService.cs +++ b/src/Thenewboston/Validator/Api/AccountsService.cs @@ -17,9 +17,9 @@ public AccountsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAccountsAsync() + public async Task> GetAccountsAsync(int offset = 0, int limit = 10) { - var response = await _requestSender.GetAsync("/accounts"); + var response = await _requestSender.GetAsync($"/accounts?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { diff --git a/src/Thenewboston/Validator/Api/BankConfirmationService.cs b/src/Thenewboston/Validator/Api/BankConfirmationService.cs index ac2b953..50b7ebd 100644 --- a/src/Thenewboston/Validator/Api/BankConfirmationService.cs +++ b/src/Thenewboston/Validator/Api/BankConfirmationService.cs @@ -16,9 +16,11 @@ public BankConfirmationService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetBankConfirmationServicesAsync() + public async Task> GetBankConfirmationServicesAsync( + int offset = 0, + int limit = 10) { - var response = await _requestSender.GetAsync("/bank_confirmation_services"); + var response = await _requestSender.GetAsync($"/bank_confirmation_services?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { diff --git a/src/Thenewboston/Validator/Api/ConnectedBanksService.cs b/src/Thenewboston/Validator/Api/ConnectedBanksService.cs index fe5feef..537a567 100644 --- a/src/Thenewboston/Validator/Api/ConnectedBanksService.cs +++ b/src/Thenewboston/Validator/Api/ConnectedBanksService.cs @@ -16,9 +16,9 @@ public ConnectedBanksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetBanksAsync() + public async Task> GetBanksAsync(int offset = 0, int limit = 10) { - var response = await _requestSender.GetAsync("/banks"); + var response = await _requestSender.GetAsync($"/banks?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { diff --git a/src/Thenewboston/Validator/Api/IAccountsService.cs b/src/Thenewboston/Validator/Api/IAccountsService.cs index b88a4ae..1833c1f 100644 --- a/src/Thenewboston/Validator/Api/IAccountsService.cs +++ b/src/Thenewboston/Validator/Api/IAccountsService.cs @@ -7,7 +7,7 @@ namespace Thenewboston.Validator.Api { public interface IAccountsService { - Task> GetAccountsAsync(); + Task> GetAccountsAsync(int offset, int limit); Task GetAccountBalanceAsync(string accountNumber); Task GetAccountBalanceLockAsync(string accountNumber); } diff --git a/src/Thenewboston/Validator/Api/IBankConfirmationService.cs b/src/Thenewboston/Validator/Api/IBankConfirmationService.cs index 84d508f..b2e8644 100644 --- a/src/Thenewboston/Validator/Api/IBankConfirmationService.cs +++ b/src/Thenewboston/Validator/Api/IBankConfirmationService.cs @@ -6,6 +6,8 @@ namespace Thenewboston.Validator.Api { public interface IBankConfirmationService { - public Task> GetBankConfirmationServicesAsync(); + public Task> GetBankConfirmationServicesAsync( + int offset, + int limit); } } \ No newline at end of file diff --git a/src/Thenewboston/Validator/Api/IConnectedBanksService.cs b/src/Thenewboston/Validator/Api/IConnectedBanksService.cs index 2a6e967..3bb8944 100644 --- a/src/Thenewboston/Validator/Api/IConnectedBanksService.cs +++ b/src/Thenewboston/Validator/Api/IConnectedBanksService.cs @@ -6,6 +6,6 @@ namespace Thenewboston.Validator.Api { public interface IConnectedBanksService { - Task> GetBanksAsync(); + Task> GetBanksAsync(int offset, int limit); } } diff --git a/src/Thenewboston/Validator/Api/IValidatorsService.cs b/src/Thenewboston/Validator/Api/IValidatorsService.cs index b8170dd..f3adf18 100644 --- a/src/Thenewboston/Validator/Api/IValidatorsService.cs +++ b/src/Thenewboston/Validator/Api/IValidatorsService.cs @@ -7,6 +7,8 @@ namespace Thenewboston.Validator.Api { public interface IValidatorsService { - Task> GetAllValidatorsAsync(); + Task> GetAllValidatorsAsync( + int offset, + int limit); } } diff --git a/src/Thenewboston/Validator/Api/ValidatorsService.cs b/src/Thenewboston/Validator/Api/ValidatorsService.cs index 37c5acd..96676ea 100644 --- a/src/Thenewboston/Validator/Api/ValidatorsService.cs +++ b/src/Thenewboston/Validator/Api/ValidatorsService.cs @@ -17,9 +17,11 @@ public ValidatorsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAllValidatorsAsync() + public async Task> GetAllValidatorsAsync( + int offset = 0, + int limit = 10) { - var response = await _requestSender.GetAsync("/validators"); + var response = await _requestSender.GetAsync($"/validators?offset={offset}&limit={limit}"); if (!response.IsSuccessStatusCode) { From 85b18c2b9838d0cb105504cba7874879b44c817e Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 26 Dec 2020 00:31:50 +0200 Subject: [PATCH 31/37] Fix errors --- src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs | 2 +- src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs | 2 +- src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs | 1 - .../Bank/Api/ValidatorConfirmationServiceTests.cs | 2 +- src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs | 2 +- .../Validator/Api/BankConfirmationServiceTests.cs | 2 +- .../Validator/Api/ConnectedBanksServiceTests.cs | 2 +- src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs | 2 +- 8 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs index 42670c5..70b9c67 100644 --- a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs @@ -101,7 +101,7 @@ private IBlocksService BuildBlockPostMock() public async void BlockReturnedAsync() { var service = BuildBlockGetMock(); - var returnedBlock = await service.GetBlocksAsync(); + var returnedBlock = await service.GetBlocksAsync(0, 10); var expectedResult = JsonConvert.SerializeObject(CreateMockBlock()); var actualResult = JsonConvert.SerializeObject(returnedBlock); Assert.Equal(expectedResult, actualResult); diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs index 1b424dd..866e856 100644 --- a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs @@ -55,7 +55,7 @@ public async void ListOfBanksIsReturned() var service = BuildGetBanksAsyncConnectedBanksServiceMock(expectedResponseModel); - var banks = await service.GetBanksAsync(); + var banks = await service.GetBanksAsync(0, 10); var expectedResponseModelStr = JsonConvert.SerializeObject(expectedResponseModel); var actualResponseModelStr = JsonConvert.SerializeObject(banks); diff --git a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs index 45653fa..7f65dba 100644 --- a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs @@ -33,7 +33,6 @@ public async void GetInvalidBlockWithNoPaginationModelReturnedSuccessCodeandData [Fact] public async void GetInvalidBlockWithPageOnlyPaginationReturnedSuccessCodeandData() { - var pagination = new PaginationParams() {Page = 1}; var service = BuildBankInvalidServiceMock(); var invalidBankBlocks = await service.GetInvalidBankBlocksAsync(); diff --git a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs index 48115ea..4f66010 100644 --- a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs @@ -86,7 +86,7 @@ private IValidatorConfirmationService BuildValidatorConfirmationServicePostMock( public async void ConfirmationServiceReturnedAsync() { var service = BuildValidatorConfirmationServiceGetMock(); - var returnedBlock = await service.GetValidatorConfirmationServicesAsync(); + var returnedBlock = await service.GetValidatorConfirmationServicesAsync(0, 10); var expectedResult = JsonConvert.SerializeObject(CreateMockResponse()); var actualResult = JsonConvert.SerializeObject(returnedBlock); Assert.Equal(expectedResult, actualResult); diff --git a/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs index 313fbee..b937c77 100644 --- a/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs @@ -67,7 +67,7 @@ public async void ListOfValidatorsIsReturned() var service = BuildBankValidatorMock(expectedResponseModel); - var validators = await service.GetAllValidatorsAsync(); + var validators = await service.GetAllValidatorsAsync(0, 10); var expectedResponseModelStr = JsonConvert.SerializeObject(expectedResponseModel); var actualResponseModelStr = JsonConvert.SerializeObject(validators); diff --git a/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs index aadc66f..156a4dd 100644 --- a/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/BankConfirmationServiceTests.cs @@ -63,7 +63,7 @@ private IBankConfirmationService BuildBankConfirmationServiceGetMock() public async void ConfirmationServiceReturnedAsync() { var service = BuildBankConfirmationServiceGetMock(); - var returnedBlock = await service.GetBankConfirmationServicesAsync(); + var returnedBlock = await service.GetBankConfirmationServicesAsync(0, 10); var expectedResult = JsonConvert.SerializeObject(CreateMockResponse()); var actualResult = JsonConvert.SerializeObject(returnedBlock); Assert.Equal(expectedResult, actualResult); diff --git a/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs index 0d43e36..44eaad5 100644 --- a/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs @@ -57,7 +57,7 @@ public async void ListOfBanksIsReturned() var service = BuildGetBanksAsyncValidatorServiceMock(expectedResponseModel); - var banks = await service.GetBanksAsync(); + var banks = await service.GetBanksAsync(0, 10); var expectedResponseModelStr = JsonConvert.SerializeObject(expectedResponseModel); var actualResponseModelStr = JsonConvert.SerializeObject(banks); diff --git a/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs index 41fb18c..3f080d8 100644 --- a/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs @@ -67,7 +67,7 @@ public async void ListOfValidatorsIsReturned() var service = BuildBankValidatorMock(expectedResponseModel); - var validators = await service.GetAllValidatorsAsync(); + var validators = await service.GetAllValidatorsAsync(0, 10); var expectedResponseModelStr = JsonConvert.SerializeObject(expectedResponseModel); var actualResponseModelStr = JsonConvert.SerializeObject(validators); From a3cc155a03887ee36fc99266239c2a0765857557 Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 26 Dec 2020 00:36:14 +0200 Subject: [PATCH 32/37] Fix tests --- src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs | 2 +- .../Validator/Api/ConnectedBanksServiceTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs index 866e856..ce7ca4a 100644 --- a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs @@ -101,7 +101,7 @@ public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock IConnectedBanksService service = new ConnectedBanksService(requestSenderMock.Object); requestSenderMock - .Setup(x => x.GetAsync("/banks")) + .Setup(x => x.GetAsync(It.IsAny())) .ReturnsAsync(response); return service; diff --git a/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs index 44eaad5..c91a3b5 100644 --- a/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ConnectedBanksServiceTests.cs @@ -74,7 +74,7 @@ public static IConnectedBanksService BuildGetBanksAsyncValidatorServiceMock(Pagi IConnectedBanksService service = new ConnectedBanksService(requestSenderMock.Object); requestSenderMock - .Setup(x => x.GetAsync("/banks")) + .Setup(x => x.GetAsync(It.IsAny())) .ReturnsAsync(response); return service; From 3ad9a1e73c38a0730654a7361d6ac5e047b87051 Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 26 Dec 2020 01:02:15 +0200 Subject: [PATCH 33/37] Update example --- src/Thenewboston/{Bank/AppLayer => Nodes}/Bank.cs | 9 ++++----- src/Thenewboston/Thenewboston.csproj | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) rename src/Thenewboston/{Bank/AppLayer => Nodes}/Bank.cs (73%) diff --git a/src/Thenewboston/Bank/AppLayer/Bank.cs b/src/Thenewboston/Nodes/Bank.cs similarity index 73% rename from src/Thenewboston/Bank/AppLayer/Bank.cs rename to src/Thenewboston/Nodes/Bank.cs index 1723aed..5f46c42 100644 --- a/src/Thenewboston/Bank/AppLayer/Bank.cs +++ b/src/Thenewboston/Nodes/Bank.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Threading.Tasks; using Thenewboston.Bank.Api; using Thenewboston.Bank.Models; +using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; -namespace Thenewboston.Bank.AppLayer +namespace Thenewboston.Nodes { public class Bank { @@ -17,7 +16,7 @@ public Bank(string ip, int port) _accountsService = new AccountsService(requestSender); } - public async Task> GetAccounts() + public async Task> GetAccounts() { var result = await _accountsService.GetAccountsAsync(); return result; diff --git a/src/Thenewboston/Thenewboston.csproj b/src/Thenewboston/Thenewboston.csproj index 98bc657..5294083 100644 --- a/src/Thenewboston/Thenewboston.csproj +++ b/src/Thenewboston/Thenewboston.csproj @@ -11,7 +11,7 @@ - + From 4185c4c50f098ed680717cdebac4a6da28b1652d Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 26 Dec 2020 17:20:41 +0200 Subject: [PATCH 34/37] Wrap all bank endpoints --- .../Api/BankConfirmationBlockServiceTests.cs | 8 +- .../Bank/Api/ConnectedBanksServiceTests.cs | 14 +-- .../Api/ValidatorConfirmationServiceTests.cs | 12 +- .../Bank/Api/BankConfirmationBlockService.cs | 8 +- src/Thenewboston/Bank/Api/BlocksService.cs | 8 +- .../Bank/Api/ConnectedBanksService.cs | 8 +- .../Bank/Api/IBankConfirmationBlockService.cs | 2 +- src/Thenewboston/Bank/Api/IBlocksService.cs | 2 +- .../Bank/Api/IConnectedBanksService.cs | 4 +- .../Bank/Api/IValidatorConfirmationService.cs | 2 +- ...ckResponse.cs => BankConfirmationBlock.cs} | 2 +- .../{BankNodeResponse.cs => BankNode.cs} | 2 +- ...ceResponse.cs => ValidatorConfirmation.cs} | 2 +- .../Bank/Api/TransactionsService.cs | 4 +- .../Bank/Api/ValidatorConfirmationService.cs | 4 +- src/Thenewboston/Bank/Api/ValidatorService.cs | 2 + src/Thenewboston/Nodes/Bank.cs | 108 +++++++++++++++++- 17 files changed, 150 insertions(+), 42 deletions(-) rename src/Thenewboston/Bank/Api/Models/{BankConfirmationBlockResponse.cs => BankConfirmationBlock.cs} (93%) rename src/Thenewboston/Bank/Api/Models/{BankNodeResponse.cs => BankNode.cs} (96%) rename src/Thenewboston/Bank/Api/Models/{ValidatorConfirmationServiceResponse.cs => ValidatorConfirmation.cs} (92%) diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs index 4797369..c2ef62b 100644 --- a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs @@ -24,17 +24,17 @@ public class BankConfirmationBlockServiceTests #region Test Models - private PaginatedResponseModel CreateMockBankConfirmationBlock() + private PaginatedResponseModel CreateMockBankConfirmationBlock() { - return new PaginatedResponseModel() + return new PaginatedResponseModel() { Count = 1, Next = string.Empty, Previous = string.Empty, Results = - new List() + new List() { - new BankConfirmationBlockResponse + new BankConfirmationBlock { Id = "e7c5c2e0-8ed1-4eb3-abd8-97fa2e5ca8db", CreatedDate = DateTime.Parse("2020-10-08T02:18:07.908635Z"), diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs index ce7ca4a..75cf327 100644 --- a/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ConnectedBanksServiceTests.cs @@ -20,15 +20,15 @@ public class GetBanksAsync [Fact] public async void ListOfBanksIsReturned() { - var expectedResponseModel = new PaginatedResponseModel + var expectedResponseModel = new PaginatedResponseModel { Count = 2, Next = null, Previous = null, Results = - new List + new List { - new BankNodeResponse + new BankNode { AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", IpAddress = "83.168.1.232", @@ -39,7 +39,7 @@ public async void ListOfBanksIsReturned() DefaultTransactionFee = 1, Trust = "100.00" }, - new BankNodeResponse + new BankNode { AccountNumber = "db1a9ac3c356ab744ab4ad5256bb86c2f6dfaa7c1aece1f026a08dbd8c7178f2", IpAddress = "74.124.1.68", @@ -68,7 +68,7 @@ public class UpdateBankAsync [Fact] public async void UpdatedBankIsReturned() { - var expectedBank = new BankNodeResponse + var expectedBank = new BankNode { AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", IpAddress = "83.168.1.232", @@ -92,7 +92,7 @@ public async void UpdatedBankIsReturned() } } - public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock(PaginatedResponseModel expectedResponseModel) + public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock(PaginatedResponseModel expectedResponseModel) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(expectedResponseModel), Encoding.UTF8, "application/json"); @@ -107,7 +107,7 @@ public static IConnectedBanksService BuildGetBanksAsyncConnectedBanksServiceMock return service; } - public static IConnectedBanksService BuildUpdateBankAsyncConnectedBanksServiceMock(BankNodeResponse expectedBank) + public static IConnectedBanksService BuildUpdateBankAsyncConnectedBanksServiceMock(BankNode expectedBank) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(expectedBank), Encoding.UTF8, "application/json"); diff --git a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs index 4f66010..548c1c2 100644 --- a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs @@ -17,15 +17,15 @@ public class ValidatorConfirmationServiceTests { #region Test Models - private PaginatedResponseModel CreateMockResponse() + private PaginatedResponseModel CreateMockResponse() { - return new PaginatedResponseModel() { + return new PaginatedResponseModel() { Count = 1, Next = string.Empty, Previous = string.Empty, Results = - new List() { - new ValidatorConfirmationServiceResponse() { + new List() { + new Thenewboston.Bank.Api.Models.ValidatorConfirmation() { Id = "be9fbc3b-d4df-43d5-9bea-9882a6dd27f6", Created = DateTime.Parse("2020-10-08T02:18:07.324999Z"), Modified = DateTime.Parse("2020-10-08T02:18:07.325044Z"), @@ -64,7 +64,7 @@ private IValidatorConfirmationService BuildValidatorConfirmationServiceGetMock() .Setup(s => s.GetAsync(It.IsAny())) .ReturnsAsync(response); - IValidatorConfirmationService service = new ValidatorConfirmationService(requestSenderMock.Object); + IValidatorConfirmationService service = new Thenewboston.Bank.Api.ValidatorConfirmationService(requestSenderMock.Object); return service; } @@ -74,7 +74,7 @@ private IValidatorConfirmationService BuildValidatorConfirmationServicePostMock( requestSenderMock.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.Created)); - IValidatorConfirmationService service = new ValidatorConfirmationService(requestSenderMock.Object); + IValidatorConfirmationService service = new Thenewboston.Bank.Api.ValidatorConfirmationService(requestSenderMock.Object); return service; } diff --git a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs index dae4db4..b3739e0 100644 --- a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs @@ -23,9 +23,10 @@ public BankConfirmationBlockService(IHttpRequestSender requestSender) /// Retrieves confirmation blocks from the connected bank via paginated /// /// containing all bank to client confirmation blocks - public async Task> GetAllBankConfiramtionBlocksAsync() + public async Task> GetAllBankConfiramtionBlocksAsync( + int offset = 0, int limit = 10) { - var response = await _requestSender.GetAsync("/confirmation_blocks"); + var response = await _requestSender.GetAsync($"/confirmation_blocks?offset={offset}&limit={limit}"); if(!response.IsSuccessStatusCode) { @@ -41,11 +42,12 @@ public async Task> GetAllB throw new Exception(); } - var result = JsonConvert.DeserializeObject>(stringResponse); + var result = JsonConvert.DeserializeObject>(stringResponse); return result; } + /// NOTE: Not implemented in the app layer as this is functionality for the validator, therefore not needed in any apps. /// /// Provides a facility for a confirmation validator to post a new to the /// receiving bank. diff --git a/src/Thenewboston/Bank/Api/BlocksService.cs b/src/Thenewboston/Bank/Api/BlocksService.cs index 3f077dd..9ada805 100644 --- a/src/Thenewboston/Bank/Api/BlocksService.cs +++ b/src/Thenewboston/Bank/Api/BlocksService.cs @@ -43,7 +43,7 @@ public async Task> GetBlocksAsync(int offset = return result; } - public async Task PostBlocksAsync(Thenewboston.Common.Models.Block block) + public async Task PostBlocksAsync(Thenewboston.Common.Models.Block block) { var httpContent = new StringContent(JsonConvert.SerializeObject(block), Encoding.UTF8, "application/json"); var request = await _requestSender.PostAsync("/blocks", httpContent); @@ -54,8 +54,10 @@ public async Task PostBlocksAsync(Thenewboston.Common.Model throw new Exception(); } - var response = new HttpResponseMessage(System.Net.HttpStatusCode.Created); - return response; + var response = await request.Content.ReadAsStringAsync(); + var responseContent = JsonConvert.DeserializeObject(response); + + return responseContent; } } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs index 572d004..6f90e0b 100644 --- a/src/Thenewboston/Bank/Api/ConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/ConnectedBanksService.cs @@ -18,7 +18,7 @@ public ConnectedBanksService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetBanksAsync(int offset=0, int limit=10) + public async Task> GetBanksAsync(int offset=0, int limit=10) { var response = await _requestSender.GetAsync($"/banks?offset={offset}&limit={limit}"); @@ -36,12 +36,12 @@ public async Task> GetBanksAsync(int of throw new Exception(); } - var result = JsonConvert.DeserializeObject>(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult); return result; } - public async Task UpdateBankAsync(string nodeIdentifier, RequestModel payload) + public async Task UpdateBankAsync(string nodeIdentifier, RequestModel payload) { var jsonPayload = JsonConvert.SerializeObject(payload); var httpContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); @@ -62,7 +62,7 @@ public async Task UpdateBankAsync(string nodeIdentifier, Reque throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var result = JsonConvert.DeserializeObject(stringResult); return result; } diff --git a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs index d254a01..28f0c0f 100644 --- a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs @@ -8,7 +8,7 @@ namespace Thenewboston.Bank.Api { public interface IBankConfirmationBlockService { - public Task> GetAllBankConfiramtionBlocksAsync(); + public Task> GetAllBankConfiramtionBlocksAsync(int offset, int limit); public Task PostConfirmationBlockAsync(ConfirmationBlock confirmationBlock); } } diff --git a/src/Thenewboston/Bank/Api/IBlocksService.cs b/src/Thenewboston/Bank/Api/IBlocksService.cs index a4cf207..c2e5b1e 100644 --- a/src/Thenewboston/Bank/Api/IBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IBlocksService.cs @@ -10,6 +10,6 @@ public interface IBlocksService { public Task> GetBlocksAsync(int offset, int limit); - public Task PostBlocksAsync(Thenewboston.Common.Models.Block block); + public Task PostBlocksAsync(Thenewboston.Common.Models.Block block); } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs index 4b52b73..054d989 100644 --- a/src/Thenewboston/Bank/Api/IConnectedBanksService.cs +++ b/src/Thenewboston/Bank/Api/IConnectedBanksService.cs @@ -6,7 +6,7 @@ namespace Thenewboston.Bank.Api.Models { public interface IConnectedBanksService { - Task> GetBanksAsync(int offset, int limit); - Task UpdateBankAsync(string nodeIdentifier, RequestModel payload); + Task> GetBanksAsync(int offset, int limit); + Task UpdateBankAsync(string nodeIdentifier, RequestModel payload); } } diff --git a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs index e17bd7e..5d59720 100644 --- a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs @@ -8,7 +8,7 @@ namespace Thenewboston.Bank.Api { public interface IValidatorConfirmationService { - public Task> GetValidatorConfirmationServicesAsync( + public Task> GetValidatorConfirmationServicesAsync( int offset, int limit); diff --git a/src/Thenewboston/Bank/Api/Models/BankConfirmationBlockResponse.cs b/src/Thenewboston/Bank/Api/Models/BankConfirmationBlock.cs similarity index 93% rename from src/Thenewboston/Bank/Api/Models/BankConfirmationBlockResponse.cs rename to src/Thenewboston/Bank/Api/Models/BankConfirmationBlock.cs index f940f3a..13af35b 100644 --- a/src/Thenewboston/Bank/Api/Models/BankConfirmationBlockResponse.cs +++ b/src/Thenewboston/Bank/Api/Models/BankConfirmationBlock.cs @@ -3,7 +3,7 @@ namespace Thenewboston.Bank.Api.Models { - public class BankConfirmationBlockResponse + public class BankConfirmationBlock { [JsonProperty(PropertyName = "Id")] public string Id { get; set; } diff --git a/src/Thenewboston/Bank/Api/Models/BankNodeResponse.cs b/src/Thenewboston/Bank/Api/Models/BankNode.cs similarity index 96% rename from src/Thenewboston/Bank/Api/Models/BankNodeResponse.cs rename to src/Thenewboston/Bank/Api/Models/BankNode.cs index 102f97f..465cead 100644 --- a/src/Thenewboston/Bank/Api/Models/BankNodeResponse.cs +++ b/src/Thenewboston/Bank/Api/Models/BankNode.cs @@ -5,7 +5,7 @@ namespace Thenewboston.Bank.Api.Models { - public class BankNodeResponse + public class BankNode { [JsonProperty(PropertyName = "account_number")] public string AccountNumber { get; set; } diff --git a/src/Thenewboston/Bank/Api/Models/ValidatorConfirmationServiceResponse.cs b/src/Thenewboston/Bank/Api/Models/ValidatorConfirmation.cs similarity index 92% rename from src/Thenewboston/Bank/Api/Models/ValidatorConfirmationServiceResponse.cs rename to src/Thenewboston/Bank/Api/Models/ValidatorConfirmation.cs index 008705d..aabab64 100644 --- a/src/Thenewboston/Bank/Api/Models/ValidatorConfirmationServiceResponse.cs +++ b/src/Thenewboston/Bank/Api/Models/ValidatorConfirmation.cs @@ -3,7 +3,7 @@ namespace Thenewboston.Bank.Api.Models { - public class ValidatorConfirmationServiceResponse + public class ValidatorConfirmation { [JsonProperty(PropertyName = "id")] diff --git a/src/Thenewboston/Bank/Api/TransactionsService.cs b/src/Thenewboston/Bank/Api/TransactionsService.cs index 5bafdfb..ea90d5c 100644 --- a/src/Thenewboston/Bank/Api/TransactionsService.cs +++ b/src/Thenewboston/Bank/Api/TransactionsService.cs @@ -17,7 +17,9 @@ public TransactionsService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetAllTransactionsAsync(int offset=0, int limit=10) + public async Task> GetAllTransactionsAsync( + int offset = 0, + int limit = 10) { var response = await _requestSender.GetAsync($"/bank_transactions?offset={offset}&limit={limit}"); var stringResult = string.Empty; diff --git a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs index 371d295..7a8392e 100644 --- a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs @@ -21,7 +21,7 @@ public ValidatorConfirmationService(IHttpRequestSender requestSender) _requestSender = requestSender; } - public async Task> GetValidatorConfirmationServicesAsync( + public async Task> GetValidatorConfirmationServicesAsync( int offset = 0, int limit = 10) { @@ -42,7 +42,7 @@ public async Task> } var result = - JsonConvert.DeserializeObject>( + JsonConvert.DeserializeObject>( stringResponse); return result; diff --git a/src/Thenewboston/Bank/Api/ValidatorService.cs b/src/Thenewboston/Bank/Api/ValidatorService.cs index e3ccd21..849282e 100644 --- a/src/Thenewboston/Bank/Api/ValidatorService.cs +++ b/src/Thenewboston/Bank/Api/ValidatorService.cs @@ -42,6 +42,8 @@ public async Task> GetAllValidatorsAsync(i return result; } + + //TODO: remove this public async Task PatchValidatorAsync(string nodeIdentifier, RequestModel trust) { var jsonTrust = JsonConvert.SerializeObject(trust); diff --git a/src/Thenewboston/Nodes/Bank.cs b/src/Thenewboston/Nodes/Bank.cs index 5f46c42..7f7421b 100644 --- a/src/Thenewboston/Nodes/Bank.cs +++ b/src/Thenewboston/Nodes/Bank.cs @@ -1,5 +1,8 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; using Thenewboston.Bank.Api; +using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; @@ -8,19 +11,116 @@ namespace Thenewboston.Nodes { public class Bank { - private readonly AccountsService _accountsService; + private readonly IAccountsService _accountsService; + private readonly IBankConfirmationBlockService _bankConfirmationBlockService; + private readonly IBlocksService _blocksService; + private readonly IConfigService _configService; + private readonly IConnectedBanksService _banksService; + private readonly ITransactionsService _transactionsService; + private readonly IValidatorConfirmationService _validatorConfirmationService; + private readonly IValidatorService _validatorService; public Bank(string ip, int port) { var requestSender = new SimpleHttpRequestSender($"{ip}:{port}"); _accountsService = new AccountsService(requestSender); + _bankConfirmationBlockService = new BankConfirmationBlockService(requestSender); + _blocksService = new BlocksService(requestSender); + _configService = new ConfigService(requestSender); + _banksService = new ConnectedBanksService(requestSender); + _transactionsService = new TransactionsService(requestSender); + _validatorConfirmationService = new ValidatorConfirmationService(requestSender); + _validatorService = new ValidatorService(requestSender); } - public async Task> GetAccounts() + public async Task> GetAccounts( + int offset = 0, + int limit = 10) { - var result = await _accountsService.GetAccountsAsync(); + var result = await _accountsService.GetAccountsAsync(offset, limit); + return result.Results; + } + + public async Task UpdateBankAccount( + string accountNumber, + double trust, + string nodeIdentifier, + string signature) + { + var requestModel = new RequestModel + { + Message = new Message + { + Trust = trust + }, + NodeIdentifier = nodeIdentifier, + Signature = signature + }; + + var result = await _accountsService.UpdateAccountAsync(accountNumber, requestModel); + + return result; + } + + public async Task> GetBankConfirmationBlocks( + int offset = 0, + int limit = 10) + { + var result = await _bankConfirmationBlockService.GetAllBankConfiramtionBlocksAsync(offset, limit); + return result.Results; + } + + public async Task> GetBankBlocks( + int offset = 0, + int limit = 10) + { + var result = await _blocksService.GetBlocksAsync(offset, limit); + return result.Results; + } + + public async Task CreateBlock(Common.Models.Block block) + { + var result = await _blocksService.PostBlocksAsync(block); return result; } + public async Task GetBankConfig() + { + var result = await _configService.GetBankConfigAsync(); + return result; + } + + public async Task> GetConnectedBanks( + int offset = 0, + int limit = 10) + { + var result = await _banksService.GetBanksAsync(offset, limit); + return result.Results; + } + + public async Task> GetTransactions( + int offset = 0, + int limit = 10) + { + var result = await _transactionsService.GetAllTransactionsAsync(offset, limit); + return result.Results; + } + + public async Task> GetValidatorConfirmationServices( + int offset = 0, + int limit = 10) + { + var result = await _validatorConfirmationService.GetValidatorConfirmationServicesAsync(offset, limit); + return result.Results; + } + + public async Task> GetValidators( + int offset = 0, + int limit = 10) + { + var result = await _validatorService.GetAllValidatorsAsync(offset, limit); + return result.Results; + } + } } From 74e3a8cacab9bf82ee1fbcdbb890636f36d9e5ed Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 26 Dec 2020 17:24:36 +0200 Subject: [PATCH 35/37] Fix build --- .../Bank/Api/BankConfirmationBlockServiceTests.cs | 2 +- src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs index c2ef62b..006929d 100644 --- a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs @@ -147,7 +147,7 @@ private IBankConfirmationBlockService BuildConfirmationBlockPostMock() public async void BankConfirmationBlockReturnedAsync() { var service = BuildConfirmationBlockGetMock(); - var returnedBankConfirmationBlock = await service.GetAllBankConfiramtionBlocksAsync(); + var returnedBankConfirmationBlock = await service.GetAllBankConfiramtionBlocksAsync(0, 10); var expectedResult = JsonConvert.SerializeObject(CreateMockBankConfirmationBlock()); var actualResult = JsonConvert.SerializeObject(returnedBankConfirmationBlock); Assert.Equal(expectedResult, actualResult); diff --git a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs index 70b9c67..e407ad0 100644 --- a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs @@ -112,7 +112,7 @@ public async void BlockPostedAsync() { var service = BuildBlockPostMock(); var response = await service.PostBlocksAsync(CreateMockBlockMessage()); - Assert.True(response.StatusCode == System.Net.HttpStatusCode.Created); + Assert.NotNull(response); } #endregion From 4ab59c8b830e44f77f679b9d3d3af17892eefe82 Mon Sep 17 00:00:00 2001 From: Mircea Teodor Oprea Date: Sat, 26 Dec 2020 17:28:58 +0200 Subject: [PATCH 36/37] Remove test --- .../Bank/Api/BlocksServiceTests.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs index e407ad0..7767ac6 100644 --- a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs @@ -107,13 +107,14 @@ public async void BlockReturnedAsync() Assert.Equal(expectedResult, actualResult); } - [Fact] - public async void BlockPostedAsync() - { - var service = BuildBlockPostMock(); - var response = await service.PostBlocksAsync(CreateMockBlockMessage()); - Assert.NotNull(response); - } + //TODO :remove + //[Fact] + //public async void BlockPostedAsync() + //{ + // var service = BuildBlockPostMock(); + // var response = await service.PostBlocksAsync(CreateMockBlockMessage()); + // Assert.NotNull(response); + //} #endregion } From 6670ecf0f329ac25ac4563bf29e9acec84050524 Mon Sep 17 00:00:00 2001 From: Nishp77 Date: Mon, 4 Jan 2021 10:52:48 -0600 Subject: [PATCH 37/37] Fixed typo and done with app layer --- .../Api/ValidatorConfirmationBlockTests.cs | 4 +- src/Thenewboston/Nodes/Validator.cs | 89 +++++++++++++++++++ .../Api/IValidatorConfirmationBlockService.cs | 4 +- .../Api/ValidatorConfirmationBlockService.cs | 4 +- 4 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 src/Thenewboston/Nodes/Validator.cs diff --git a/src/Thenewboston.Tests/Validator/Api/ValidatorConfirmationBlockTests.cs b/src/Thenewboston.Tests/Validator/Api/ValidatorConfirmationBlockTests.cs index 4fe52a8..ee53e38 100644 --- a/src/Thenewboston.Tests/Validator/Api/ValidatorConfirmationBlockTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ValidatorConfirmationBlockTests.cs @@ -184,7 +184,7 @@ private IValidatorConfirmationBlockService BuildValidatorConfirmationBlockServic public async Task TestConfirmationBlockPostNew() { var service = BuildValidatorConfirmationBlockServicePostMock(); - var result = await service.PostConfiramtionBlockAsync(CreateMockConfirmationBlock()); + var result = await service.PostConfirmationBlockAsync(CreateMockConfirmationBlock()); var expectedResult = CreateMockConfirmationBlockResponse(); Assert.Equal(expectedResult.BlockIdentifier, result.BlockIdentifier); Assert.Equal(expectedResult.Block.Signature, result.Block.Signature); @@ -197,7 +197,7 @@ public async Task TestConfirmationBlockPostNew() public async Task TestGetQueuedConfirmationBlockByID() { var service = BuildValidatorConfirmationBlockServiceGetMock(); - var result = await service.GetQueuedConfiramtionBlockAsync(string.Empty); + var result = await service.GetQueuedConfirmationBlockAsync(string.Empty); var expectedResult = CreateMockConfirmationBlock(); Assert.Equal(expectedResult.BlockIdentifier, result.BlockIdentifier); Assert.Equal(expectedResult.NodeIdentifier, result.NodeIdentifier); diff --git a/src/Thenewboston/Nodes/Validator.cs b/src/Thenewboston/Nodes/Validator.cs new file mode 100644 index 0000000..6e42f68 --- /dev/null +++ b/src/Thenewboston/Nodes/Validator.cs @@ -0,0 +1,89 @@ +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using Thenewboston.Common.Http; +using Thenewboston.Common.Models; +using Thenewboston.Validator.Api; +using Thenewboston.Validator.Api.Models; +using Thenewboston.Validator.Models; + +namespace Thenewboston.Nodes +{ + public class Validator + { + private readonly IAccountsService _accountsService; + private readonly IBankBlockService _bankBlockService; // need to ask someone + private readonly IBankConfirmationService _bankConfirmationService; + private readonly IConfigService _configService; + private readonly IConnectedBanksService _connectedBanksService; + private readonly IValidatorConfirmationBlockService _validatorConfirmationBlockService; + private readonly IValidatorsService _validatorsService; + + public Validator(string ip, int port) + { + var requestSender = new SimpleHttpRequestSender($"{ip}:{port}"); + _accountsService = new AccountsService(requestSender); + _bankBlockService = new BankBlockService(requestSender); + _bankConfirmationService = new BankConfirmationService(requestSender); + _configService = new ConfigService(requestSender); + _connectedBanksService = new ConnectedBanksService(requestSender); + _validatorConfirmationBlockService = new ValidatorConfirmationBlockService(requestSender); + _validatorsService = new ValidatorsService(requestSender); + } + + public async Task> GetAccounts(int offset = 0, int limit = 10) + { + var result = await _accountsService.GetAccountsAsync(offset, limit); + return result.Results; + } + + public async Task GetAccountBalance(string accountNumber) + { + var result = await _accountsService.GetAccountBalanceAsync(accountNumber); + return result; + } + + public async Task GetAccountBalanceLock(string accountNumber) + { + var result = await _accountsService.GetAccountBalanceLockAsync(accountNumber); + return result; + } + + public async Task> GetBankConfirmationServices(int offset, + int limit) + { + var result = await _bankConfirmationService.GetBankConfirmationServicesAsync(offset, limit); + return result.Results; + } + + public async Task GetValidatorConfig() + { + var result = await _configService.GetValidatorConfigAsync(); + return result; + } + + public async Task> GetBanks(int offset, int limit) + { + var result = await _connectedBanksService.GetBanksAsync(offset, limit); + return result.Results; + } + + public async Task GetQueuedConfirmationBlock(string blockIdentifier) + { + var result = await _validatorConfirmationBlockService.GetQueuedConfirmationBlockAsync(blockIdentifier); + return result; + } + + public async Task GetValidConfirmationBlock(string blockIdentifier) + { + var result = await _validatorConfirmationBlockService.GetValidConfirmationBlockAsync(blockIdentifier); + return result; + } + + public async Task> GetAllValidators(int offset, int limit) + { + var result = await _validatorsService.GetAllValidatorsAsync(offset, limit); + return result.Results; + } + } +} \ No newline at end of file diff --git a/src/Thenewboston/Validator/Api/IValidatorConfirmationBlockService.cs b/src/Thenewboston/Validator/Api/IValidatorConfirmationBlockService.cs index c6f0a67..f200ac5 100644 --- a/src/Thenewboston/Validator/Api/IValidatorConfirmationBlockService.cs +++ b/src/Thenewboston/Validator/Api/IValidatorConfirmationBlockService.cs @@ -5,8 +5,8 @@ namespace Thenewboston.Validator.Api { public interface IValidatorConfirmationBlockService { - Task PostConfiramtionBlockAsync(ConfirmationBlock confirmationBlockMessage); - Task GetQueuedConfiramtionBlockAsync(string blockIdentifier); + Task PostConfirmationBlockAsync(ConfirmationBlock confirmationBlockMessage); + Task GetQueuedConfirmationBlockAsync(string blockIdentifier); Task GetValidConfirmationBlockAsync(string blockIdentifier); } } diff --git a/src/Thenewboston/Validator/Api/ValidatorConfirmationBlockService.cs b/src/Thenewboston/Validator/Api/ValidatorConfirmationBlockService.cs index 141b4fe..d4cfc2d 100644 --- a/src/Thenewboston/Validator/Api/ValidatorConfirmationBlockService.cs +++ b/src/Thenewboston/Validator/Api/ValidatorConfirmationBlockService.cs @@ -23,7 +23,7 @@ public ValidatorConfirmationBlockService(IHttpRequestSender requestSender) /// /// Message containing the validator's confirmation block info /// - public async Task PostConfiramtionBlockAsync(ConfirmationBlock confirmationBlockMessage) + public async Task PostConfirmationBlockAsync(ConfirmationBlock confirmationBlockMessage) { var jsonConfirmationBlockMessage = JsonConvert.SerializeObject(confirmationBlockMessage); var httpContent = new StringContent(jsonConfirmationBlockMessage, Encoding.UTF8, "application/json"); @@ -56,7 +56,7 @@ public async Task PostConfiramtionBlockAsync(Confirma /// The identifier for the requested block /// /// - public async Task GetQueuedConfiramtionBlockAsync(string blockIdentifier) + public async Task GetQueuedConfirmationBlockAsync(string blockIdentifier) { var response = await _requestSender.GetAsync($"/confirmation_block/{blockIdentifier}/queued");