Skip to content

Commit

Permalink
hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
area363 committed May 1, 2024
1 parent e7ff372 commit 0bd6300
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,39 @@ public async Task QueryWithCombinationSlotState(AvatarState avatarState, Diction
Assert.Equal(expected, data);
}

[Theory]
[MemberData(nameof(ActionPointMembers))]
public async Task QueryActionPoint(bool modern, Dictionary<string, object> expected)
{
const string query = @"
{
actionPoint
dailyRewardReceivedIndex
}";
IWorld mockWorld = new World(MockWorldState.CreateModern());
mockWorld = mockWorld.SetAvatarState(
Fixtures.AvatarAddress,
Fixtures.AvatarStateFX,
true,
true,
true,
true);
mockWorld = mockWorld.SetAgentState(Fixtures.UserAddress, Fixtures.AgentStateFx);
if (modern)
{
mockWorld = mockWorld.SetDailyRewardReceivedBlockIndex(Fixtures.AvatarAddress, 1L)
.SetActionPoint(Fixtures.AvatarAddress, 5);
}
var queryResult = await ExecuteQueryAsync<AvatarStateType>(
query,
source: new AvatarStateType.AvatarStateContext(
Fixtures.AvatarStateFX,
mockWorld,
0, new StateMemoryCache()));
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
Assert.Equal(expected, data);
}

public static IEnumerable<object[]> Members => new List<object[]>
{
new object[]
Expand Down Expand Up @@ -128,5 +161,27 @@ public async Task QueryWithCombinationSlotState(AvatarState avatarState, Diction
}
}
};

public static IEnumerable<object[]> ActionPointMembers = new List<object[]>()
{
new object[]
{
false,
new Dictionary<string, object>
{
["actionPoint"] = Fixtures.AvatarStateFX.actionPoint,
["dailyRewardReceivedIndex"] = Fixtures.AvatarStateFX.dailyRewardReceivedIndex,
}
},
new object[]
{
true,
new Dictionary<string, object>
{
["actionPoint"] = 5,
["dailyRewardReceivedIndex"] = 1L,
}
}
};
}
}
25 changes: 23 additions & 2 deletions NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ public AvatarStateType()
Field<NonNullGraphType<LongGraphType>>(
nameof(AvatarState.dailyRewardReceivedIndex),
description: "Block index at the DailyReward execution.",
resolve: context => context.Source.AvatarState.dailyRewardReceivedIndex);
resolve: context =>
{
try
{
return context.Source.WorldState.GetDailyRewardReceivedBlockIndex(context.Source.AvatarState
.address);
}
catch (FailedLoadStateException)
{
return context.Source.AvatarState.dailyRewardReceivedIndex;
}
});
Field<NonNullGraphType<AddressType>>(
nameof(AvatarState.agentAddress),
description: "Address of agent.",
Expand Down Expand Up @@ -86,7 +97,17 @@ public AvatarStateType()
Field<NonNullGraphType<IntGraphType>>(
nameof(AvatarState.actionPoint),
description: "Current ActionPoint.",
resolve: context => context.Source.AvatarState.actionPoint);
resolve: context =>
{
try
{
return context.Source.WorldState.GetActionPoint(context.Source.AvatarState.address);
}
catch (FailedLoadStateException)
{
return context.Source.AvatarState.actionPoint;
}
});
Field<NonNullGraphType<IntGraphType>>(
nameof(AvatarState.ear),
description: "Index of ear color.",
Expand Down

0 comments on commit 0bd6300

Please sign in to comment.