Skip to content

Commit

Permalink
Merge branch 'main' into ProductTestIssue
Browse files Browse the repository at this point in the history
  • Loading branch information
Atralupus authored Dec 4, 2024
2 parents 19c6c98 + 53582d3 commit b65141d
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Mimir.MongoDB/Bson/PledgeDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

1 change: 0 additions & 1 deletion Mimir.MongoDB/Repositories/ActionPointRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public interface IActionPointRepository
{
Task<ActionPointDocument> GetByAddressAsync(Address address);
}

public class ActionPointRepository(IMongoDbService dbService) : IActionPointRepository
{
public virtual async Task<ActionPointDocument> GetByAddressAsync(Address address)
Expand Down
7 changes: 6 additions & 1 deletion Mimir.MongoDB/Repositories/PledgeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
using MongoDB.Driver;

namespace Mimir.MongoDB.Repositories;
public interface IPledgeRepository
{
Task<PledgeDocument> GetByAddressAsync(Address address);
}


public class PledgeRepository(IMongoDbService dbService)
public class PledgeRepository(IMongoDbService dbService) : IPledgeRepository
{
public async Task<PledgeDocument> GetByAddressAsync(Address address)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"data": {
"pledge": {
"address": "0x0000000000000000000000000000000000000000",
"contractAddress": "0x0000000000000000000000000000000000000000",
"contracted": true,
"id": "0000000000000000000000000000000000000000",
"refillMead": 10,
"storedBlockIndex": 10000,
"metadata": {
"schemaVersion": 1,
"storedBlockIndex": 10000
}
}
}
}
43 changes: 43 additions & 0 deletions Mimir.Tests/QueryTests/PledgeTest.cs
Original file line number Diff line number Diff line change
@@ -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<IPledgeRepository>();
mockRepo
.Setup(repo => repo.GetByAddressAsync(It.IsAny<Address>()))
.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);
}
}
2 changes: 1 addition & 1 deletion Mimir/GraphQL/Queries/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task<PetState> GetPetAsync(Address avatarAddress, [Service] PetRepo
/// <summary>
/// Get the pledge state for a given agent address.
/// </summary>
public async Task<PledgeDocument> GetPledgeAsync(Address agentAddress, [Service] PledgeRepository repo) =>
public async Task<PledgeDocument> GetPledgeAsync(Address agentAddress, [Service] IPledgeRepository repo) =>
await repo.GetByAddressAsync(agentAddress.GetPledgeAddress());

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Mimir/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
builder.Services.AddSingleton<ItemSlotRepository>();
builder.Services.AddSingleton<IMetadataRepository,MetadataRepository>();
builder.Services.AddSingleton<PetRepository>();
builder.Services.AddSingleton<PledgeRepository>();
builder.Services.AddSingleton<IProductRepository, ProductRepository>();
builder.Services.AddSingleton<IPledgeRepository, PledgeRepository>();
builder.Services.AddSingleton<IProductsRepository, ProductsRepository>();
builder.Services.AddSingleton<IStakeRepository, StakeRepository>();
builder.Services.AddSingleton<TableSheetsRepository>();
Expand Down

0 comments on commit b65141d

Please sign in to comment.