-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: StateQuery test code for validator
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
NineChronicles.Headless.Tests/GraphTypes/ValidatorTypeTest.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,78 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using GraphQL.Execution; | ||
using Libplanet.Types.Tx; | ||
using Nekoyume.ValidatorDelegation; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace NineChronicles.Headless.Tests.GraphTypes | ||
{ | ||
public class ValidatorTypeTest : GraphQLTestBase | ||
{ | ||
public ValidatorTypeTest(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task ExecuteQuery() | ||
{ | ||
// Given | ||
var block = BlockChain.Tip; | ||
var blockHeight = 0L; | ||
var tip = new Domain.Model.BlockChain.Block( | ||
Hash: block.Hash, | ||
PreviousHash: null, | ||
Miner: ProposerPrivateKey.Address, | ||
Index: blockHeight, | ||
Timestamp: block.Timestamp, | ||
StateRootHash: block.StateRootHash, | ||
Transactions: ImmutableArray<Transaction>.Empty); | ||
var worldState = BlockChain.GetNextWorldState(); | ||
var stateRootHash = block.StateRootHash; | ||
var validatorAddress = ProposerPrivateKey.Address.ToHex(); | ||
var query = | ||
$"query {{\n" + | ||
$" stateQuery(index: 0) {{\n" + | ||
$" validator(validatorAddress: \"{validatorAddress}\") {{\n" + | ||
$" power\n" + | ||
$" isActive\n" + | ||
$" totalShares\n" + | ||
$" jailed\n" + | ||
$" jailedUntil\n" + | ||
$" tombstoned\n" + | ||
$" commissionPercentage\n" + | ||
$" totalDelegated {{\n" + | ||
$" currency\n" + | ||
$" quantity\n" + | ||
$" }}\n" + | ||
$" }}\n" + | ||
$" }}\n" + | ||
$"}}\n"; | ||
|
||
BlockChainRepository.Setup(repository => repository.GetBlock(blockHeight)).Returns(tip); | ||
WorldStateRepository.Setup(repository => repository.GetWorldState(stateRootHash)).Returns(worldState); | ||
|
||
// When | ||
var result = await ExecuteQueryAsync(query); | ||
|
||
// Then | ||
var data = (Dictionary<string, object>)((ExecutionNode)result.Data!).ToValue()!; | ||
var stateQueryResult = (Dictionary<string, object>)data["stateQuery"]; | ||
var validatorResult = (Dictionary<string, object>)stateQueryResult["validator"]; | ||
|
||
Assert.Equal("10,000,000,000,000,000,000", validatorResult["power"]); | ||
Assert.Equal(true, validatorResult["isActive"]); | ||
Assert.Equal("10,000,000,000,000,000,000", validatorResult["totalShares"]); | ||
Assert.Equal(false, validatorResult["jailed"]); | ||
Assert.Equal(-1L, validatorResult["jailedUntil"]); | ||
Assert.Equal(false, validatorResult["tombstoned"]); | ||
Assert.Equal($"{ValidatorDelegatee.DefaultCommissionPercentage}", validatorResult["commissionPercentage"]); | ||
|
||
var totalDelegatedResult = (Dictionary<string, object>)validatorResult["totalDelegated"]; | ||
Assert.Equal("GUILD_GOLD", totalDelegatedResult["currency"]); | ||
Assert.Equal("10.000000000000000000", totalDelegatedResult["quantity"]); | ||
} | ||
} | ||
} |