From 01c3adce9932a4d5bff1c78d242d0279b0c7b155 Mon Sep 17 00:00:00 2001 From: woojihye Date: Sun, 27 Oct 2024 16:44:47 +0900 Subject: [PATCH] feat: add stack e2e test - ref: https://github.com/planetarium/mimir/issues/446 --- Mimir.E2ETests/MimirGQL/query.graphql | 7 +++ Mimir.E2ETests/StackTests.cs | 62 +++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 Mimir.E2ETests/StackTests.cs diff --git a/Mimir.E2ETests/MimirGQL/query.graphql b/Mimir.E2ETests/MimirGQL/query.graphql index a486787a..0b1d0151 100644 --- a/Mimir.E2ETests/MimirGQL/query.graphql +++ b/Mimir.E2ETests/MimirGQL/query.graphql @@ -34,3 +34,10 @@ query GetInventory($avatarAddress: Address!) { } } } + +query GetStake($agentAddress: Address!) { + stake(address: $agentAddress) { + receivedBlockIndex + startedBlockIndex + } +} \ No newline at end of file diff --git a/Mimir.E2ETests/StackTests.cs b/Mimir.E2ETests/StackTests.cs new file mode 100644 index 00000000..312ae19c --- /dev/null +++ b/Mimir.E2ETests/StackTests.cs @@ -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 +{ + private readonly IMimirClient mimirClient; + private readonly IHeadlessClient headlessClient; + + public StakeTests(GraphQLClientFixture fixture) + { + mimirClient = fixture.ServiceProvider.GetRequiredService(); + headlessClient = fixture.ServiceProvider.GetRequiredService(); + } + + [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 GetMimirStakeData(Address address) + { + var agentResponse = await mimirClient.GetStake.ExecuteAsync(address.ToString()); + var agentData = agentResponse.Data.Stake; + + return agentData; + } + + private async Task 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); + } +} \ No newline at end of file