-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
184 additions
and
8 deletions.
There are no files selected for viewing
Submodule Lib9c
updated
2 files
+19 −104 | Lib9c/Action/ClaimStakeReward.cs | |
+127 −0 | Lib9c/Model/State/StakeRewardCalculator.cs |
50 changes: 50 additions & 0 deletions
50
NineChronicles.Headless.Tests/GraphTypes/Abstractions/CalculatedStakeRewardsTypeTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using GraphQL.Execution; | ||
using Lib9c; | ||
using Libplanet.Types.Assets; | ||
using Nekoyume.Model.Item; | ||
using NineChronicles.Headless.GraphTypes.Abstractions; | ||
using Xunit; | ||
using static NineChronicles.Headless.Tests.GraphQLTestUtils; | ||
|
||
namespace NineChronicles.Headless.Tests.GraphTypes.Abstractions | ||
{ | ||
public class CalculatedStakeRewardsTypeTest | ||
{ | ||
[Fact] | ||
public async Task Query() | ||
{ | ||
const string query = @" | ||
{ | ||
favs { | ||
quantity | ||
currency | ||
} | ||
items { | ||
count | ||
fungibleItemId | ||
} | ||
}"; | ||
var materialItemSheet = Fixtures.TableSheetsFX.MaterialItemSheet; | ||
var row = materialItemSheet.First; | ||
var item = ItemFactory.CreateMaterial(row); | ||
var fav = 1 * Currencies.Crystal; | ||
var itemResult = new Dictionary<ItemBase, int> | ||
{ | ||
[item] = 2 | ||
}; | ||
var favs = new List<FungibleAssetValue> | ||
{ | ||
fav, | ||
fav, | ||
}; | ||
var queryResult = await ExecuteQueryAsync<CalculatedStakeRewardsType>( | ||
query, | ||
source: (itemResult, favs)); | ||
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!; | ||
Assert.NotEmpty(data); | ||
Assert.Null(queryResult.Errors); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
NineChronicles.Headless/GraphTypes/Abstractions/CalculatedStakeRewardsType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Collections.Generic; | ||
using GraphQL.Types; | ||
using Libplanet.Types.Assets; | ||
using Nekoyume.Model.Item; | ||
using NineChronicles.Headless.GraphTypes.States.Models.Item; | ||
|
||
namespace NineChronicles.Headless.GraphTypes.Abstractions | ||
{ | ||
public class CalculatedStakeRewardsType : ObjectGraphType<(Dictionary<ItemBase, int> itemResult, List<FungibleAssetValue> favs)> | ||
{ | ||
public CalculatedStakeRewardsType() | ||
{ | ||
Field<ListGraphType<FungibleAssetValueType>>( | ||
"favs", | ||
resolve: context => context.Source.favs); | ||
Field<ListGraphType<InventoryItemType>>( | ||
"items", | ||
resolve: context => | ||
{ | ||
var result = new List<Inventory.Item>(); | ||
foreach (var pair in context.Source.itemResult) | ||
{ | ||
var item = new Inventory.Item(pair.Key, pair.Value); | ||
result.Add(item); | ||
} | ||
|
||
return result; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters