Skip to content

Commit

Permalink
Merge pull request #2638 from planetarium/bugfix/adv-boss/staking-level
Browse files Browse the repository at this point in the history
Check staking required level from latest staking policy
  • Loading branch information
U-lis authored Jun 19, 2024
2 parents ce48094 + 5531ff9 commit 44785fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
30 changes: 23 additions & 7 deletions .Lib9c.Tests/Action/AdventureBoss/WantedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -363,14 +366,27 @@ public void InsufficientStaking()
AvatarAddress = AvatarAddress,
Bounty = gameConfig.AdventureBossMinBounty * NCG,
};
Assert.Throws<InsufficientStakingException>(() => action.Execute(
new ActionContext

if (err)
{
Assert.Throws<InsufficientStakingException>(() => action.Execute(
new ActionContext
{
PreviousState = state,
Signer = AgentAddress,
BlockIndex = 100L,
}
));
}
else
{
action.Execute(new ActionContext
{
PreviousState = state,
Signer = AgentAddress,
BlockIndex = 100L,
}
));
});
}
}

[Fact]
Expand Down
17 changes: 14 additions & 3 deletions Lib9c/Action/AdventureBoss/Wanted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -97,10 +99,19 @@ public override IWorld Execute(IActionContext context)
throw new InvalidAddressException();
}

var RequiredStakingLevel =
var requiredStakingLevel =
states.GetGameConfigState().AdventureBossWantedRequiredStakingLevel;
var requiredStakingAmount = states.GetSheet<MonsterCollectionSheet>()
.OrderedList.First(row => row.Level == RequiredStakingLevel).RequiredGold;
var currentStakeRegularRewardSheetAddr = Addresses.GetSheetAddress(
states.GetSheet<StakePolicySheet>().StakeRegularRewardSheetValue);
if (!states.TryGetSheet<StakeRegularRewardSheet>(
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)
Expand Down

0 comments on commit 44785fd

Please sign in to comment.