-
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
4 changed files
with
177 additions
and
7 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
NineChronicles.Headless.Tests/GraphTypes/DelegatorTypeTest.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,45 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Numerics; | ||
using System.Threading.Tasks; | ||
using GraphQL.Execution; | ||
using Lib9c; | ||
using Libplanet.Types.Tx; | ||
using Nekoyume.ValidatorDelegation; | ||
using NineChronicles.Headless.GraphTypes; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace NineChronicles.Headless.Tests.GraphTypes | ||
{ | ||
public class DelegatorTypeTest | ||
{ | ||
[Fact] | ||
public async Task ExecuteQuery() | ||
{ | ||
var lastDistributeHeight = 1L; | ||
var share = new BigInteger(1000000000000000000) * 10; | ||
var fav = Currencies.GuildGold * 10; | ||
|
||
var result = await GraphQLTestUtils.ExecuteQueryAsync<DelegatorType>( | ||
"{ lastDistributeHeight share fav { currency quantity } }", | ||
source: new DelegatorType | ||
{ | ||
LastDistributeHeight = lastDistributeHeight, | ||
Share = share, | ||
Fav = fav, | ||
} | ||
); | ||
|
||
// Then | ||
var data = (Dictionary<string, object>)((ExecutionNode)result.Data!).ToValue()!; | ||
|
||
Assert.Equal(lastDistributeHeight, data["lastDistributeHeight"]); | ||
Assert.Equal(share.ToString("N0"), data["share"]); | ||
|
||
var favResult = (Dictionary<string, object>)data["fav"]; | ||
Assert.Equal(fav.Currency.Ticker, favResult["currency"]); | ||
Assert.Equal(fav.GetQuantityString(minorUnit: true), favResult["quantity"]); | ||
} | ||
} | ||
} |
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,30 @@ | ||
using System.Numerics; | ||
using GraphQL.Types; | ||
using Libplanet.Types.Assets; | ||
|
||
namespace NineChronicles.Headless.GraphTypes; | ||
|
||
public class DelegatorType : ObjectGraphType<DelegatorType> | ||
{ | ||
public long LastDistributeHeight { get; set; } | ||
|
||
public BigInteger Share { get; set; } | ||
|
||
public FungibleAssetValue Fav { get; set; } | ||
|
||
public DelegatorType() | ||
{ | ||
Field<NonNullGraphType<LongGraphType>>( | ||
nameof(LastDistributeHeight), | ||
description: "LastDistributeHeight of delegator", | ||
resolve: context => context.Source.LastDistributeHeight); | ||
Field<NonNullGraphType<StringGraphType>>( | ||
nameof(Share), | ||
description: "Share of delegator", | ||
resolve: context => context.Source.Share.ToString("N0")); | ||
Field<NonNullGraphType<FungibleAssetValueType>>( | ||
nameof(Fav), | ||
description: "Delegated FAV calculated based on Share value", | ||
resolve: context => context.Source.Fav); | ||
} | ||
} |
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,38 @@ | ||
using GraphQL.Types; | ||
using Libplanet.Crypto; | ||
using Libplanet.Explorer.GraphTypes; | ||
using Nekoyume.Model.Guild; | ||
|
||
namespace NineChronicles.Headless.GraphTypes; | ||
|
||
public class GuildType : ObjectGraphType<GuildType> | ||
{ | ||
public Address Address { get; set; } | ||
|
||
public Address ValidatorAddress { get; set; } | ||
|
||
public Address GuildMasterAddress { get; set; } | ||
|
||
public GuildType() | ||
{ | ||
Field<NonNullGraphType<AddressType>>( | ||
nameof(Address), | ||
description: "Address of the guild", | ||
resolve: context => context.Source.Address); | ||
Field<NonNullGraphType<AddressType>>( | ||
nameof(ValidatorAddress), | ||
description: "Validator address of the guild", | ||
resolve: context => context.Source.ValidatorAddress); | ||
Field<NonNullGraphType<AddressType>>( | ||
nameof(GuildMasterAddress), | ||
description: "Guild master address of the guild", | ||
resolve: context => context.Source.GuildMasterAddress); | ||
} | ||
|
||
public static GuildType FromDelegatee(Guild guild) => new GuildType | ||
{ | ||
Address = guild.Address, | ||
ValidatorAddress = guild.ValidatorAddress, | ||
GuildMasterAddress = guild.GuildMasterAddress, | ||
}; | ||
} |
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