Skip to content

Commit

Permalink
Merge pull request #3081 from planetarium/validate/rune-slot
Browse files Browse the repository at this point in the history
validate RuneSlotInfo with AllRuneState at BattleArena
  • Loading branch information
ipdae authored Dec 11, 2024
2 parents 4b5d212 + eb294fb commit 487fca8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
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
6 changes: 6 additions & 0 deletions Lib9c/Action/BattleArena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ public override IWorld Execute(IActionContext context)
states = states.SetRuneState(myAvatarAddress, myRuneStates);
}

// just validate
foreach (var runeSlotInfo in runeInfos)
{
myRuneStates.GetRuneState(runeSlotInfo.RuneId);
}

// get enemy equipped items
var enemyItemSlotStateAddress = ItemSlotState.DeriveAddress(enemyAvatarAddress, BattleType.Arena);
var enemyItemSlotState = states.TryGetLegacyState(enemyItemSlotStateAddress, out List rawEnemyItemSlotState)
Expand Down

0 comments on commit 487fca8

Please sign in to comment.