-
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.
Merge pull request #2686 from Atralupus/development-to-release-240
Development to release 240
- Loading branch information
Showing
34 changed files
with
840 additions
and
132 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,4 +4,3 @@ addAssignees: author | |
reviewers: | ||
- ipdae | ||
- area363 | ||
- moreal |
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
2 changes: 1 addition & 1 deletion
2
Libplanet.Extensions.PluggedActionEvaluator/PluggedActionEvaluator.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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,87 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using Bencodex.Types; | ||
using Lib9c.Renderers; | ||
using Libplanet.Blockchain; | ||
using Libplanet.Blockchain.Policies; | ||
using Libplanet.Crypto; | ||
using Libplanet.Headless.Hosting; | ||
using Libplanet.Mocks; | ||
using Libplanet.Types.Tx; | ||
using Moq; | ||
using Nekoyume.Action; | ||
using NineChronicles.Headless.Repositories.BlockChain; | ||
using NineChronicles.Headless.Repositories.Swarm; | ||
using NineChronicles.Headless.Repositories.Transaction; | ||
using NineChronicles.Headless.Repositories.WorldState; | ||
using Xunit; | ||
|
||
namespace NineChronicles.Headless.Tests | ||
{ | ||
public class BlockChainServiceTest | ||
{ | ||
// FIXME 의미 있는 테스트를 추가해야 합니다. | ||
[Fact] | ||
public void Constructor() | ||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public async Task PutTransaction(bool stageResult) | ||
{ | ||
// Arrange | ||
var mockBlockChain = new Mock<IBlockChainRepository>(); | ||
var mockTransaction = new Mock<ITransactionRepository>(); | ||
var mockWorld = new Mock<IWorldStateRepository>(); | ||
var mockSwarm = new Mock<ISwarmRepository>(); | ||
var mockRpcContext = new Mock<RpcContext>(); | ||
var mockProperties = new Mock<LibplanetNodeServiceProperties>(); | ||
var mockCache = new Mock<StateMemoryCache>(); | ||
var mockPolicy = new Mock<IBlockPolicy>(); | ||
|
||
// Mocking dependencies | ||
mockPolicy | ||
.Setup(bc => bc.ValidateNextBlockTx(It.IsAny<BlockChain>(), It.IsAny<Transaction>())) | ||
.Returns((TxPolicyViolationException?)null); | ||
mockBlockChain | ||
.Setup(bc => bc.StageTransaction(It.IsAny<Transaction>())) | ||
.Returns(stageResult); | ||
mockBlockChain | ||
.Setup(bc => bc.GetStagedTransactionIds()) | ||
.Returns(ImmutableHashSet<TxId>.Empty); | ||
|
||
var service = new BlockChainService( | ||
mockBlockChain.Object, | ||
mockTransaction.Object, | ||
mockWorld.Object, | ||
mockSwarm.Object, | ||
mockRpcContext.Object, | ||
mockProperties.Object, | ||
new ActionEvaluationPublisher( | ||
new BlockRenderer(), | ||
new ActionRenderer(), | ||
new ExceptionRenderer(), | ||
new NodeStatusRenderer(), | ||
new MockBlockChainStates(), | ||
"", | ||
0, | ||
new RpcContext(), | ||
new StateMemoryCache() | ||
), | ||
mockCache.Object); | ||
|
||
var tx = Transaction.Create(0, new PrivateKey(), null, new List<IValue> | ||
{ | ||
new DailyReward | ||
{ | ||
avatarAddress = new Address(), | ||
}.PlainValue, | ||
}); // Create a valid transaction | ||
|
||
// Act | ||
var result = await service.PutTransaction(tx.Serialize()); | ||
|
||
// Assert | ||
Assert.Equal(stageResult, result); | ||
mockBlockChain.Verify(bc => bc.StageTransaction(It.IsAny<Transaction>()), Times.Once); | ||
mockSwarm.Verify(s => s.BroadcastTxs(It.IsAny<Transaction[]>()), Times.Once); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.