Skip to content

Commit

Permalink
Merge pull request #2313 from planetarium/feature/claim-items-memo
Browse files Browse the repository at this point in the history
Add memo to claimItems GQL
  • Loading branch information
U-lis authored Nov 18, 2023
2 parents c744af0 + 3660e91 commit e54343b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
33 changes: 27 additions & 6 deletions NineChronicles.Headless.Tests/GraphTypes/ActionQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,16 +1343,21 @@ public async Task AuraSummon()
}

[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(10)]
[InlineData(100)]
public async Task ClaimItems(int claimDataCount)
[InlineData(1, false)]
[InlineData(2, false)]
[InlineData(10, false)]
[InlineData(100, false)]
[InlineData(1, true)]
[InlineData(2, true)]
[InlineData(10, true)]
[InlineData(100, true)]
public async Task ClaimItems(int claimDataCount, bool hasMemo)
{
var random = new Random();
var tickerList = new List<string> { "Item_T_500000", "Item_T_400000", "Item_T_800201", "Item_NT_49900011" };
var claimDataList = new List<(Address, List<FungibleAssetValue>)>();
var queryBuilder = new StringBuilder().Append("{claimItems(claimData: [");
var expectedMemo = "This is test memo";
for (var i = 0; i < claimDataCount; i++)
{
var avatarAddress = new PrivateKey().ToAddress();
Expand Down Expand Up @@ -1395,7 +1400,14 @@ public async Task ClaimItems(int claimDataCount)
}
}

queryBuilder.Append("])}");
queryBuilder.Append("]");

if (hasMemo)
{
queryBuilder.Append($", memo: \"{expectedMemo}\"");
}

queryBuilder.Append(")}");

var queryResult =
await ExecuteQueryAsync<ActionQuery>(queryBuilder.ToString(), standaloneContext: _standaloneContext);
Expand Down Expand Up @@ -1425,6 +1437,15 @@ public async Task ClaimItems(int claimDataCount)
Assert.Equal(expectedFavList[j].RawValue, actualFavList[j].RawValue);
}
}

if (hasMemo)
{
Assert.Equal(expectedMemo, action.Memo);
}
else
{
Assert.Null(action.Memo);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ private void RegisterClaimItems()
{
Name = "claimData",
Description = "List of pair of avatar address, List<FAV> to claim."
},
new QueryArgument<StringGraphType>
{
Name = "memo",
Description = "Memo to attach to this action."
}
),
resolve: context =>
Expand All @@ -28,7 +33,8 @@ private void RegisterClaimItems()
context.GetArgument<
List<(Address avataAddress, IReadOnlyList<FungibleAssetValue> fungibleAssetValues)>
>("claimData").AsReadOnly();
ActionBase action = new ClaimItems(claimData);
var memo = context.GetArgument<string?>("memo");
ActionBase action = new ClaimItems(claimData, memo);
return Encode(context, action);
}
);
Expand Down

0 comments on commit e54343b

Please sign in to comment.