From 5531ff9ad62c157f6ffef2040406e31ef9b0b396 Mon Sep 17 00:00:00 2001 From: hyeon Date: Wed, 19 Jun 2024 14:32:02 +0900 Subject: [PATCH] Check staking level from latest stake policy --- .../Action/AdventureBoss/WantedTest.cs | 30 ++++++++++++++----- Lib9c/Action/AdventureBoss/Wanted.cs | 17 +++++++++-- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.Lib9c.Tests/Action/AdventureBoss/WantedTest.cs b/.Lib9c.Tests/Action/AdventureBoss/WantedTest.cs index f18ba07e5e..a05eb5a128 100644 --- a/.Lib9c.Tests/Action/AdventureBoss/WantedTest.cs +++ b/.Lib9c.Tests/Action/AdventureBoss/WantedTest.cs @@ -341,10 +341,13 @@ public void CannotCreateFutureSeason(int latestSeason, int targetSeason) ); } - [Fact] - public void InsufficientStaking() + [Theory] + [InlineData(50, true)] // Min. staking amount + [InlineData(4999, true)] // Staking 3 level -1 + [InlineData(5000, false)] + public void InsufficientStaking(int staking, bool err) { - var state = Stake(_initialState, 100); + var state = Stake(_initialState, staking); var gameConfig = state.GetGameConfigState(); // Set active season var seasonInfo = new SeasonInfo( @@ -363,14 +366,27 @@ public void InsufficientStaking() AvatarAddress = AvatarAddress, Bounty = gameConfig.AdventureBossMinBounty * NCG, }; - Assert.Throws(() => action.Execute( - new ActionContext + + if (err) + { + Assert.Throws(() => action.Execute( + new ActionContext + { + PreviousState = state, + Signer = AgentAddress, + BlockIndex = 100L, + } + )); + } + else + { + action.Execute(new ActionContext { PreviousState = state, Signer = AgentAddress, BlockIndex = 100L, - } - )); + }); + } } [Fact] diff --git a/Lib9c/Action/AdventureBoss/Wanted.cs b/Lib9c/Action/AdventureBoss/Wanted.cs index 15a26c2646..3a37ef2a06 100644 --- a/Lib9c/Action/AdventureBoss/Wanted.cs +++ b/Lib9c/Action/AdventureBoss/Wanted.cs @@ -6,12 +6,14 @@ using Libplanet.Crypto; using Libplanet.Types.Assets; using Nekoyume.Action.Exceptions.AdventureBoss; +using Nekoyume.Exceptions; using Nekoyume.Helper; using Nekoyume.Model.AdventureBoss; using Nekoyume.Model.State; using Nekoyume.Module; using Nekoyume.TableData; using Nekoyume.TableData.AdventureBoss; +using Nekoyume.TableData.Stake; namespace Nekoyume.Action.AdventureBoss { @@ -97,10 +99,19 @@ public override IWorld Execute(IActionContext context) throw new InvalidAddressException(); } - var RequiredStakingLevel = + var requiredStakingLevel = states.GetGameConfigState().AdventureBossWantedRequiredStakingLevel; - var requiredStakingAmount = states.GetSheet() - .OrderedList.First(row => row.Level == RequiredStakingLevel).RequiredGold; + var currentStakeRegularRewardSheetAddr = Addresses.GetSheetAddress( + states.GetSheet().StakeRegularRewardSheetValue); + if (!states.TryGetSheet( + currentStakeRegularRewardSheetAddr, + out var stakeRegularRewardSheet)) + { + throw new StateNullException(ReservedAddresses.LegacyAccount, + currentStakeRegularRewardSheetAddr); + } + + var requiredStakingAmount = stakeRegularRewardSheet[requiredStakingLevel].RequiredGold; var stakedAmount = states.GetStakedAmount(states.GetAvatarState(AvatarAddress).agentAddress); if (stakedAmount < requiredStakingAmount * currency)