Skip to content

Commit

Permalink
Merge pull request #3096 from planetarium/release/1.21.0
Browse files Browse the repository at this point in the history
Release/1.21.0 to main
  • Loading branch information
Atralupus authored Dec 19, 2024
2 parents 36447a9 + 40e9864 commit e639502
Show file tree
Hide file tree
Showing 110 changed files with 11,748 additions and 871 deletions.
22 changes: 18 additions & 4 deletions .Lib9c.Plugin/PluginActionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Libplanet.Store;
using Nekoyume.Action;
using Nekoyume.Action.Loader;
using Nekoyume.Action.ValidatorDelegation;

namespace Lib9c.Plugin
{
Expand All @@ -19,10 +20,23 @@ public PluginActionEvaluator(IPluginKeyValueStore keyValueStore)
var stateStore = new TrieStateStore(new WrappedKeyValueStore(keyValueStore));
_actionEvaluator = new ActionEvaluator(
new PolicyActionsRegistry(
beginBlockActions: ImmutableArray<IAction>.Empty,
endBlockActions: new IAction[] { new RewardGold() }.ToImmutableArray(),
beginTxActions: ImmutableArray<IAction>.Empty,
endTxActions: ImmutableArray<IAction>.Empty),
beginBlockActions: new IAction[] {
new SlashValidator(),
new AllocateGuildReward(),
new AllocateReward(),
}.ToImmutableArray(),
endBlockActions: new IAction[] {
new UpdateValidators(),
new RecordProposer(),
new RewardGold(),
new ReleaseValidatorUnbondings(),
}.ToImmutableArray(),
beginTxActions: new IAction[] {
new Mortgage(),
}.ToImmutableArray(),
endTxActions: new IAction[] {
new Reward(), new Refund(),
}.ToImmutableArray()),
stateStore,
new NCActionLoader());
}
Expand Down
64 changes: 64 additions & 0 deletions .Lib9c.Tests/Action/BattleArenaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,70 @@ public void Execute_ValidateDuplicateTicketPurchaseException()
}));
}

[Fact]
public void ExecuteRuneNotFoundException()
{
var previousStates = _initialStates;
var context = new ActionContext();
Assert.True(
previousStates.GetSheet<ArenaSheet>().TryGetValue(
1,
out var row));

if (!row.TryGetRound(1, out var roundData))
{
throw new RoundNotFoundException(
$"[{nameof(BattleArena)}] ChampionshipId({row.ChampionshipId}) - round({1})");
}

if (roundData.ArenaType != ArenaType.OffSeason)
{
throw new InvalidSeasonException(
$"[{nameof(BattleArena)}] This test is only for OffSeason. ArenaType : {roundData.ArenaType}");
}

var random = new TestRandom();
previousStates = JoinArena(
context,
previousStates,
_agent1Address,
_avatar1Address,
roundData.StartBlockIndex,
1,
1,
random);
previousStates = JoinArena(
context,
previousStates,
_agent2Address,
_avatar2Address,
roundData.StartBlockIndex,
1,
1,
random);

var action = new BattleArena
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
championshipId = 1,
round = 1,
ticket = 1,
costumes = new List<Guid>(),
equipments = new List<Guid>(),
runeInfos = new List<RuneSlotInfo> { new (0, 10035), },
};
Assert.Throws<RuneNotFoundException>(
() => action.Execute(
new ActionContext
{
BlockIndex = roundData.StartBlockIndex + 1,
PreviousState = previousStates,
Signer = _agent1Address,
RandomSeed = 0,
}));
}

[Theory]
[InlineData(8, null)]
[InlineData(100, null)]
Expand Down
29 changes: 29 additions & 0 deletions .Lib9c.Tests/Action/ClaimStakeRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,35 @@ public void Execute_V6()
}
}

[Fact]
public void Execute_Throw_When_Validator_Tries_To_Claim()
{
// When
var world = _initialState;
var validatorKey = new PrivateKey().PublicKey;
var validatorAddress = validatorKey.Address;
var height = 0L;
world = DelegationUtil.EnsureValidatorPromotionReady(world, validatorKey, height);
var stakeAddr = StakeState.DeriveAddress(AgentAddr);
var stakeStateV2 = PrepareStakeStateV2(
_stakePolicySheet,
0,
LegacyStakeState.RewardInterval);
var action = new ClaimStakeReward(validatorAddress);
var actionContext = new ActionContext
{
PreviousState = world,
Signer = validatorAddress,
BlockIndex = height,
};

// When
var e = Assert.Throws<InvalidOperationException>(() => action.Execute(actionContext));

// Then
Assert.Equal("The validator cannot claim the stake reward.", e.Message);
}

private static StakeState PrepareStakeStateV2(
StakePolicySheet stakePolicySheet,
long startedBlockIndex,
Expand Down
Loading

0 comments on commit e639502

Please sign in to comment.