Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIMIR_ISSUE446] Implement e2e tests for the stake state #451

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Mimir.E2ETests/MimirGQL/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ query GetInventory($avatarAddress: Address!) {
}
}
}

query GetStake($agentAddress: Address!) {
stake(address: $agentAddress) {
receivedBlockIndex
startedBlockIndex
}
}
62 changes: 62 additions & 0 deletions Mimir.E2ETests/StackTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Bencodex.Types;
using HeadlessGQL;
using Lib9c.Models.States;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Microsoft.Extensions.DependencyInjection;
using MimirGQL;

namespace Mimir.E2ETests;

public class StakeTests : IClassFixture<GraphQLClientFixture>
{
private readonly IMimirClient mimirClient;
private readonly IHeadlessClient headlessClient;

public StakeTests(GraphQLClientFixture fixture)
{
mimirClient = fixture.ServiceProvider.GetRequiredService<IMimirClient>();
headlessClient = fixture.ServiceProvider.GetRequiredService<IHeadlessClient>();
}

[Theory]
[InlineData("0x08eB36BB2B46073149fE9DaCB9706d2b49Fa6115")]
[InlineData("0x2EB4c1C19E5664feC2eb722FB01df6eBdf5014e2")]
public async Task CompareStakeDataFromDifferentServices_ShouldMatch(string address)
{
var agentDataFromMimir = await GetMimirStakeData(new Address(address));

var stakeAddress = Nekoyume.Model.State.StakeState.DeriveAddress(new Address(address));
var agentDataFromHeadless = await GetHeadlessStakeData(stakeAddress);
if (agentDataFromMimir == null)
{
// FIXME; if agentDataFromMimir is null, stakeAddress should be null as well, but now it isn't
return;
}

Assert.Equal(agentDataFromMimir.StartedBlockIndex, agentDataFromHeadless.StartedBlockIndex);
}

private async Task<IGetStake_Stake> GetMimirStakeData(Address address)
{
var agentResponse = await mimirClient.GetStake.ExecuteAsync(address.ToString());
var agentData = agentResponse.Data.Stake;

return agentData;
}

private async Task<StakeState?> GetHeadlessStakeData(Address address)
{
var stateResponse = await headlessClient.GetState.ExecuteAsync(
ReservedAddresses.LegacyAccount.ToString(),
address.ToString()
);
var result = CodecUtil.DecodeState(stateResponse.Data.State);
if (result.Kind == ValueKind.Null)
{
return null;
}

return new StakeState(result);
}
}
Loading