Skip to content

Commit

Permalink
Merge pull request #2686 from Atralupus/development-to-release-240
Browse files Browse the repository at this point in the history
Development to release 240
  • Loading branch information
Atralupus authored Jan 17, 2025
2 parents 948876b + 5762224 commit 5137098
Show file tree
Hide file tree
Showing 34 changed files with 840 additions and 132 deletions.
1 change: 0 additions & 1 deletion .github/auto_assign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ addAssignees: author
reviewers:
- ipdae
- area363
- moreal
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: dotnet format
run: dotnet format --exclude Lib9c --exclude NineChronicles.RPC.Shared -v=d --no-restore --verify-no-changes
validate-appsettings-json:
Expand Down
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 168 files
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Lib9c\.Lib9c.ActionEvaluatorCommonComponents\Lib9c.ActionEvaluatorCommonComponents.csproj" />
<ProjectReference Include="..\Lib9c\.Lib9c.Plugin.Shared\Lib9c.Plugin.Shared.csproj" />
<ProjectReference Include="..\Lib9c\.Libplanet.Extensions.ActionEvaluatorCommonComponents\Libplanet.Extensions.ActionEvaluatorCommonComponents.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Reflection;
using System.Security.Cryptography;
using Lib9c.ActionEvaluatorCommonComponents;
using Lib9c.Plugin.Shared;
using Libplanet.Action;
using Libplanet.Action.Loader;
using Libplanet.Common;
using Libplanet.Extensions.ActionEvaluatorCommonComponents;
using Libplanet.Store.Trie;
using Libplanet.Types.Blocks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public void TransferAsset(
public void Stake()
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var resultCode = _command.Stake(1, filePath);
var resultCode = _command.Stake(
1, new Address("0xab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d"), filePath);
Assert.Equal(0, resultCode);
var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ public class TxCommandTest
private readonly StringIOConsole _console;
private readonly TxCommand _command;
private readonly PrivateKey _privateKey;
private readonly Address _avatarAddress;
private readonly BlockHash _blockHash;

public TxCommandTest()
{
_console = new StringIOConsole();
_command = new TxCommand(_console);
_privateKey = new PrivateKey();
_avatarAddress = new PrivateKey().Address;
_blockHash = BlockHash.FromHashDigest(default);
}

Expand All @@ -54,7 +56,7 @@ public void Sign_Stake(bool gas)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var actionCommand = new ActionCommand(_console);
actionCommand.Stake(1, filePath);
actionCommand.Stake(1, _avatarAddress, filePath);
Assert_Tx(1, filePath, gas);
}

Expand Down
40 changes: 20 additions & 20 deletions NineChronicles.Headless.Executable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.Forkab
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.ForkableActionEvaluator.Tests", "Libplanet.Extensions.ForkableActionEvaluator.Tests\Libplanet.Extensions.ForkableActionEvaluator.Tests.csproj", "{490D20B6-FC0C-4459-8412-17777DB95931}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.ActionEvaluatorCommonComponents", "Lib9c\.Libplanet.Extensions.ActionEvaluatorCommonComponents\Libplanet.Extensions.ActionEvaluatorCommonComponents.csproj", "{A6922395-36E5-4B0A-BEBD-9BCE34D08722}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NineChronicles.Headless.AccessControlCenter", "NineChronicles.Headless.AccessControlCenter\NineChronicles.Headless.AccessControlCenter.csproj", "{162C0F4B-A1D9-4132-BC34-31F1247BC26B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.PluggedActionEvaluator", "Libplanet.Extensions.PluggedActionEvaluator\Libplanet.Extensions.PluggedActionEvaluator.csproj", "{DE91C36D-3999-47B6-A0BD-848C8EBA2A76}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.Plugin.Shared", "Lib9c\.Lib9c.Plugin.Shared\Lib9c.Plugin.Shared.csproj", "{3D32DA34-E619-429F-8421-848FF4F14417}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.ActionEvaluatorCommonComponents", "Lib9c\.Lib9c.ActionEvaluatorCommonComponents\Lib9c.ActionEvaluatorCommonComponents.csproj", "{0F29AB64-E2A9-4B32-96E9-291D47294A94}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -389,24 +389,6 @@ Global
{490D20B6-FC0C-4459-8412-17777DB95931}.Release|x64.Build.0 = Release|Any CPU
{490D20B6-FC0C-4459-8412-17777DB95931}.Release|x86.ActiveCfg = Release|Any CPU
{490D20B6-FC0C-4459-8412-17777DB95931}.Release|x86.Build.0 = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Debug|x64.ActiveCfg = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Debug|x64.Build.0 = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Debug|x86.ActiveCfg = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Debug|x86.Build.0 = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.DevEx|Any CPU.ActiveCfg = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.DevEx|Any CPU.Build.0 = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.DevEx|x64.ActiveCfg = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.DevEx|x64.Build.0 = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.DevEx|x86.ActiveCfg = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.DevEx|x86.Build.0 = Debug|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|Any CPU.Build.0 = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x64.ActiveCfg = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x64.Build.0 = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x86.ActiveCfg = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x86.Build.0 = Release|Any CPU
{162C0F4B-A1D9-4132-BC34-31F1247BC26B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{162C0F4B-A1D9-4132-BC34-31F1247BC26B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{162C0F4B-A1D9-4132-BC34-31F1247BC26B}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -461,6 +443,24 @@ Global
{3D32DA34-E619-429F-8421-848FF4F14417}.Release|x64.Build.0 = Release|Any CPU
{3D32DA34-E619-429F-8421-848FF4F14417}.Release|x86.ActiveCfg = Release|Any CPU
{3D32DA34-E619-429F-8421-848FF4F14417}.Release|x86.Build.0 = Release|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Debug|x64.ActiveCfg = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Debug|x64.Build.0 = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Debug|x86.ActiveCfg = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Debug|x86.Build.0 = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.DevEx|Any CPU.ActiveCfg = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.DevEx|Any CPU.Build.0 = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.DevEx|x64.ActiveCfg = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.DevEx|x64.Build.0 = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.DevEx|x86.ActiveCfg = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.DevEx|x86.Build.0 = Debug|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Release|Any CPU.Build.0 = Release|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Release|x64.ActiveCfg = Release|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Release|x64.Build.0 = Release|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Release|x86.ActiveCfg = Release|Any CPU
{0F29AB64-E2A9-4B32-96E9-291D47294A94}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 2 additions & 1 deletion NineChronicles.Headless.Executable/Commands/ActionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ public int TransferAsset(
[Command(Description = "Create Stake action.")]
public int Stake(
long amount,
Address avatarAddress,
[Argument("PATH", Description = "A file path of base64 encoded action.")]
string? filePath = null
)
{
try
{
Nekoyume.Action.Stake action = new Stake(amount);
Nekoyume.Action.Stake action = new Stake(amount, avatarAddress);
byte[] raw = Codec.Encode(new List(
new[]
{
Expand Down
2 changes: 1 addition & 1 deletion NineChronicles.Headless.Tests/Action/ActionContext.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using Lib9c.ActionEvaluatorCommonComponents;
using Libplanet.Action;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Extensions.ActionEvaluatorCommonComponents;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Evidence;
Expand Down
80 changes: 77 additions & 3 deletions NineChronicles.Headless.Tests/BlockChainServiceTest.cs
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);
}
}
}
8 changes: 5 additions & 3 deletions NineChronicles.Headless.Tests/GraphTypes/ActionQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public ActionQueryTest()

[Theory]
[ClassData(typeof(StakeFixture))]
public async Task Stake(BigInteger amount)
public async Task Stake(BigInteger amount, Address avatarAddress)
{
string query = $@"
{{
stake(amount: {amount})
stake(amount: {amount}, avatarAddress: ""{avatarAddress.ToString()}"")
}}";

var queryResult = await ExecuteQueryAsync<ActionQuery>(query, standaloneContext: _standaloneContext);
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
ActionBase action = new Stake(amount);
ActionBase action = new Stake(amount, avatarAddress);
var expected = new Dictionary<string, object>()
{
["stake"] = ByteUtil.Hex(_codec.Encode(action.PlainValue)),
Expand Down Expand Up @@ -134,10 +134,12 @@ private class StakeFixture : IEnumerable<object[]>
new object[]
{
new BigInteger(1),
new Address("0xD84F1893A1912DEC1834A31a43f5619e0b2D5915")
},
new object[]
{
new BigInteger(100),
new Address("0x35FdEee2fABE6aa916a36620E104a3E9433E4698")
},
};

Expand Down
45 changes: 45 additions & 0 deletions NineChronicles.Headless.Tests/GraphTypes/DelegatorTypeTest.cs
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"]);
}
}
}
6 changes: 3 additions & 3 deletions NineChronicles.Headless.Tests/GraphTypes/SignScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public async Task SignTransaction_CreatePledge()
Assert.Equal(sender, action.AgentAddresses.Single().Item1);
Assert.Equal(MeadConfig.PatronAddress, action.PatronAddress);
Assert.Equal(1, signedTx.GasLimit);
Assert.Equal(1 * Currencies.Mead, signedTx.MaxGasPrice);
Assert.Equal(FungibleAssetValue.FromRawValue(Currencies.Mead, 10000000000000), signedTx.MaxGasPrice);
await StageTransaction(signedTx, hex);
}

Expand Down Expand Up @@ -206,7 +206,7 @@ private async Task<object> GetAction(string actionName, string queryArgs)

// Create unsigned Transaction.
var unsignedQuery = gas ? $@"query {{
unsignedTransaction(publicKey: ""{hexedPublicKey}"", plainValue: ""{plainValue}"", nonce: {nonce}, maxGasPrice: {{ quantity: 1, decimalPlaces: 18, ticker: ""Mead"" }})
unsignedTransaction(publicKey: ""{hexedPublicKey}"", plainValue: ""{plainValue}"", nonce: {nonce}, maxGasPrice: {{ quantity: ""0.00001"", decimalPlaces: 18, ticker: ""Mead"" }})
}}" : $@"query {{
unsignedTransaction(publicKey: ""{hexedPublicKey}"", plainValue: ""{plainValue}"", nonce: {nonce})
}}";
Expand Down Expand Up @@ -249,7 +249,7 @@ private async Task<object> GetAction(string actionName, string queryArgs)
Assert.Single(unsignedTx.Actions);
Assert.Single(signedTx.Actions!);
Assert.Equal(expectedGasLimit, signedTx.GasLimit);
Assert.Equal(1 * Currencies.Mead, signedTx.MaxGasPrice);
Assert.Equal(FungibleAssetValue.FromRawValue(Currencies.Mead, 10000000000000), signedTx.MaxGasPrice);
return (signedTx, hex);
}

Expand Down
Loading

0 comments on commit 5137098

Please sign in to comment.