diff --git a/Mimir.MongoDB/Bson/PledgeDocument.cs b/Mimir.MongoDB/Bson/PledgeDocument.cs index 5b4e41cb..7f3523b0 100644 --- a/Mimir.MongoDB/Bson/PledgeDocument.cs +++ b/Mimir.MongoDB/Bson/PledgeDocument.cs @@ -11,4 +11,5 @@ public record PledgeDocument( Address ContractAddress, bool Contracted, int RefillMead -) : MimirBsonDocument(Address.ToHex(), new DocumentMetadata(1, StoredBlockIndex)) { } +) : MimirBsonDocument(Address.ToHex(), new DocumentMetadata(1, StoredBlockIndex)); + diff --git a/Mimir.MongoDB/Repositories/ActionPointRepository.cs b/Mimir.MongoDB/Repositories/ActionPointRepository.cs index f909024b..8bc47994 100644 --- a/Mimir.MongoDB/Repositories/ActionPointRepository.cs +++ b/Mimir.MongoDB/Repositories/ActionPointRepository.cs @@ -10,7 +10,6 @@ public interface IActionPointRepository { Task GetByAddressAsync(Address address); } - public class ActionPointRepository(IMongoDbService dbService) : IActionPointRepository { public virtual async Task GetByAddressAsync(Address address) diff --git a/Mimir.MongoDB/Repositories/PledgeRepository.cs b/Mimir.MongoDB/Repositories/PledgeRepository.cs index c28032a3..6f3626e3 100644 --- a/Mimir.MongoDB/Repositories/PledgeRepository.cs +++ b/Mimir.MongoDB/Repositories/PledgeRepository.cs @@ -5,8 +5,13 @@ using MongoDB.Driver; namespace Mimir.MongoDB.Repositories; +public interface IPledgeRepository +{ + Task GetByAddressAsync(Address address); +} + -public class PledgeRepository(IMongoDbService dbService) +public class PledgeRepository(IMongoDbService dbService) : IPledgeRepository { public async Task GetByAddressAsync(Address address) { diff --git a/Mimir.Tests/QueryTests/PledgeTest.GraphQL_Query_Pledge_Returns_CorrectValue.verified.txt b/Mimir.Tests/QueryTests/PledgeTest.GraphQL_Query_Pledge_Returns_CorrectValue.verified.txt new file mode 100644 index 00000000..97626671 --- /dev/null +++ b/Mimir.Tests/QueryTests/PledgeTest.GraphQL_Query_Pledge_Returns_CorrectValue.verified.txt @@ -0,0 +1,16 @@ +{ + "data": { + "pledge": { + "address": "0x0000000000000000000000000000000000000000", + "contractAddress": "0x0000000000000000000000000000000000000000", + "contracted": true, + "id": "0000000000000000000000000000000000000000", + "refillMead": 10, + "storedBlockIndex": 10000, + "metadata": { + "schemaVersion": 1, + "storedBlockIndex": 10000 + } + } + } +} \ No newline at end of file diff --git a/Mimir.Tests/QueryTests/PledgeTest.cs b/Mimir.Tests/QueryTests/PledgeTest.cs new file mode 100644 index 00000000..e9d5a777 --- /dev/null +++ b/Mimir.Tests/QueryTests/PledgeTest.cs @@ -0,0 +1,43 @@ +using Libplanet.Crypto; +using Mimir.MongoDB.Bson; +using Mimir.MongoDB.Repositories; +using Mimir.Tests; +using Moq; + +public class PledgeTest +{ + [Fact] + public async Task GraphQL_Query_Pledge_Returns_CorrectValue() + { + var mockRepo = new Mock(); + mockRepo + .Setup(repo => repo.GetByAddressAsync(It.IsAny
())) + .ReturnsAsync(new PledgeDocument(10000, default, default, true, 10)); + + var serviceProvider = TestServices.Builder + .With(mockRepo.Object) + .Build(); + + var address = "0x0000008001000000000200000000030000000004"; + var query = $$""" + query { + pledge(agentAddress: "{{address}}") { + address + contractAddress + contracted + id + refillMead + storedBlockIndex + metadata { + schemaVersion + storedBlockIndex + } + } + } + """; + + var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetDocument(query)); + + await Verify(result); + } +} \ No newline at end of file diff --git a/Mimir/GraphQL/Queries/Query.cs b/Mimir/GraphQL/Queries/Query.cs index 0a2a71bd..7b66e1b4 100644 --- a/Mimir/GraphQL/Queries/Query.cs +++ b/Mimir/GraphQL/Queries/Query.cs @@ -128,7 +128,7 @@ public async Task GetPetAsync(Address avatarAddress, [Service] PetRepo /// /// Get the pledge state for a given agent address. /// - public async Task GetPledgeAsync(Address agentAddress, [Service] PledgeRepository repo) => + public async Task GetPledgeAsync(Address agentAddress, [Service] IPledgeRepository repo) => await repo.GetByAddressAsync(agentAddress.GetPledgeAddress()); /// diff --git a/Mimir/Program.cs b/Mimir/Program.cs index 9e609fcd..e4d76128 100644 --- a/Mimir/Program.cs +++ b/Mimir/Program.cs @@ -49,8 +49,8 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); -builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton();