From 8079d00f30679e55b9c905f9b40b8db9659e2d65 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 5 Apr 2024 15:53:41 +0900 Subject: [PATCH 1/5] Bump to libplanet 4.3.0 candidate --- .Libplanet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.Libplanet b/.Libplanet index 81ddb0a52b..fe11701ea0 160000 --- a/.Libplanet +++ b/.Libplanet @@ -1 +1 @@ -Subproject commit 81ddb0a52b2ea66034848270f3d8a6630432585b +Subproject commit fe11701ea051dfc4363e2f2e738914a6e74bf17a From 87de9dabf797222f736f8caa29a194f4fd8c6cdf Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 5 Apr 2024 16:29:47 +0900 Subject: [PATCH 2/5] Build fix --- .Lib9c.Tests/Action/ActionContext.cs | 3 +++ Lib9c/Action/RewardGold.cs | 12 ++++++------ Lib9c/Module/LegacyModule.cs | 3 +-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.Lib9c.Tests/Action/ActionContext.cs b/.Lib9c.Tests/Action/ActionContext.cs index 9c157693b4..264281c541 100644 --- a/.Lib9c.Tests/Action/ActionContext.cs +++ b/.Lib9c.Tests/Action/ActionContext.cs @@ -1,5 +1,6 @@ namespace Lib9c.Tests.Action { + using System.Collections.Generic; using System.Security.Cryptography; using Libplanet.Action; using Libplanet.Action.State; @@ -36,6 +37,8 @@ public class ActionContext : IActionContext public bool BlockAction { get; } + public IReadOnlyList Txs { get; set; } + public void UseGas(long gas) { _gasUsed += gas; diff --git a/Lib9c/Action/RewardGold.cs b/Lib9c/Action/RewardGold.cs index a4fcebbb71..6d88760249 100644 --- a/Lib9c/Action/RewardGold.cs +++ b/Lib9c/Action/RewardGold.cs @@ -307,12 +307,12 @@ public IWorld MinerReward(IActionContext ctx, IWorld states) public static IWorld TransferMead(IActionContext context, IWorld states) { -#pragma warning disable LAA1002 - var targetAddresses = states.TotalUpdatedFungibleAssets -#pragma warning restore LAA1002 - .Where(pair => pair.Item2.Equals(Currencies.Mead)) - .Select(pair => pair.Item1) - .Distinct(); + var targetAddresses = context.Txs is { } txs + ? txs + .Where(tx => tx.MaxGasPrice is { } price && price.Currency.Equals(Currencies.Mead)) + .Select(tx => tx.Signer) + .Distinct() + : throw new NullReferenceException(); foreach (var address in targetAddresses) { var contractAddress = address.GetPledgeAddress(); diff --git a/Lib9c/Module/LegacyModule.cs b/Lib9c/Module/LegacyModule.cs index 044d356fe0..d6201363b4 100644 --- a/Lib9c/Module/LegacyModule.cs +++ b/Lib9c/Module/LegacyModule.cs @@ -68,8 +68,7 @@ params Address[] accounts context, accounts[i - 1], accounts[i], - currency * 1, - true); + currency * 1); } return world; From 98a83ad27e627d1b75a7f3c376e817ce09f1c34a Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Mon, 8 Apr 2024 16:16:11 +0900 Subject: [PATCH 3/5] Fixed tests --- .Lib9c.Tests/Action/ActionContext.cs | 9 +++++++- .Lib9c.Tests/Action/RewardGoldTest.cs | 18 +++++++++++++-- .../Action/Scenario/MeadScenarioTest.cs | 23 +++++++++++++++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/.Lib9c.Tests/Action/ActionContext.cs b/.Lib9c.Tests/Action/ActionContext.cs index 264281c541..6c9ad64c63 100644 --- a/.Lib9c.Tests/Action/ActionContext.cs +++ b/.Lib9c.Tests/Action/ActionContext.cs @@ -1,6 +1,7 @@ namespace Lib9c.Tests.Action { using System.Collections.Generic; + using System.Collections.Immutable; using System.Security.Cryptography; using Libplanet.Action; using Libplanet.Action.State; @@ -15,6 +16,8 @@ public class ActionContext : IActionContext private IRandom _random = null; + private IReadOnlyList _txs = null; + public BlockHash? GenesisHash { get; set; } public Address Signer { get; set; } @@ -37,7 +40,11 @@ public class ActionContext : IActionContext public bool BlockAction { get; } - public IReadOnlyList Txs { get; set; } + public IReadOnlyList Txs + { + get => _txs ?? ImmutableList.Empty; + set => _txs = value; + } public void UseGas(long gas) { diff --git a/.Lib9c.Tests/Action/RewardGoldTest.cs b/.Lib9c.Tests/Action/RewardGoldTest.cs index abe9c18f30..f62a615f3a 100644 --- a/.Lib9c.Tests/Action/RewardGoldTest.cs +++ b/.Lib9c.Tests/Action/RewardGoldTest.cs @@ -580,10 +580,24 @@ public async Task Genesis_StateRootHash(bool mainnet) [InlineData(1, 0)] public void TransferMead(int patronMead, int balance) { - var agentAddress = new PrivateKey().Address; + var agentKey = new PrivateKey(); + var agentAddress = agentKey.Address; var patronAddress = new PrivateKey().Address; var contractAddress = agentAddress.GetPledgeAddress(); - IActionContext context = new ActionContext(); + IActionContext context = new ActionContext() + { + Txs = ImmutableList.Create( + new Transaction( + new UnsignedTx( + new TxInvoice( + null, + DateTimeOffset.UtcNow, + new TxActionList(new List()), + maxGasPrice: Currencies.Mead * 4, + gasLimit: 4), + new TxSigningMetadata(agentKey.PublicKey, 0)), + agentKey)), + }; IWorld states = new World(MockUtil.MockModernWorldState) .MintAsset(context, patronAddress, patronMead * Currencies.Mead) .TransferAsset(context, patronAddress, agentAddress, 1 * Currencies.Mead) diff --git a/.Lib9c.Tests/Action/Scenario/MeadScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/MeadScenarioTest.cs index ac56297807..0bf467e478 100644 --- a/.Lib9c.Tests/Action/Scenario/MeadScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/MeadScenarioTest.cs @@ -1,13 +1,17 @@ namespace Lib9c.Tests.Action.Scenario { using System; + using System.Collections.Generic; + using System.Collections.Immutable; using System.Linq; using System.Reflection; + using Bencodex.Types; using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; using Libplanet.Mocks; using Libplanet.Types.Assets; + using Libplanet.Types.Tx; using Nekoyume; using Nekoyume.Action; using Nekoyume.Module; @@ -20,10 +24,25 @@ public void Contract() { Currency mead = Currencies.Mead; var patron = new PrivateKey().Address; - IActionContext context = new ActionContext(); + var agentKey = new PrivateKey(); + var agentAddress = agentKey.Address; + + IActionContext context = new ActionContext() + { + Txs = ImmutableList.Create( + new Transaction( + new UnsignedTx( + new TxInvoice( + null, + DateTimeOffset.UtcNow, + new TxActionList(new List()), + maxGasPrice: Currencies.Mead * 4, + gasLimit: 4), + new TxSigningMetadata(agentKey.PublicKey, 0)), + agentKey)), + }; IWorld states = new World(MockUtil.MockModernWorldState).MintAsset(context, patron, 10 * mead); - var agentAddress = new PrivateKey().Address; var requestPledge = new RequestPledge { AgentAddress = agentAddress, From 22d829e115f09f7509f300c341612b589f71ea34 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Mon, 8 Apr 2024 17:56:51 +0900 Subject: [PATCH 4/5] Bump to libplanet 4.3.0 --- .Libplanet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.Libplanet b/.Libplanet index fe11701ea0..8874c899af 160000 --- a/.Libplanet +++ b/.Libplanet @@ -1 +1 @@ -Subproject commit fe11701ea051dfc4363e2f2e738914a6e74bf17a +Subproject commit 8874c899afca340a0876b8418eea63d339bc9f90 From 01114831e40dd75fcb62809c382639afd182e5ab Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 12 Apr 2024 10:36:10 +0900 Subject: [PATCH 5/5] Minor cleanup --- Lib9c/Action/RewardGold.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib9c/Action/RewardGold.cs b/Lib9c/Action/RewardGold.cs index 6d88760249..a4a60fcafb 100644 --- a/Lib9c/Action/RewardGold.cs +++ b/Lib9c/Action/RewardGold.cs @@ -307,12 +307,10 @@ public IWorld MinerReward(IActionContext ctx, IWorld states) public static IWorld TransferMead(IActionContext context, IWorld states) { - var targetAddresses = context.Txs is { } txs - ? txs - .Where(tx => tx.MaxGasPrice is { } price && price.Currency.Equals(Currencies.Mead)) - .Select(tx => tx.Signer) - .Distinct() - : throw new NullReferenceException(); + var targetAddresses = context.Txs + .Where(tx => tx.MaxGasPrice is { } price && price.Currency.Equals(Currencies.Mead)) + .Select(tx => tx.Signer) + .Distinct(); foreach (var address in targetAddresses) { var contractAddress = address.GetPledgeAddress();