From bf10b2e4e4d89196bec651d6b3024887fca01c31 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Thu, 7 Mar 2024 21:33:15 +0900 Subject: [PATCH] Fix tests --- .Lib9c.Tests/Action/HackAndSlashTest.cs | 219 ++++++------------------ 1 file changed, 51 insertions(+), 168 deletions(-) diff --git a/.Lib9c.Tests/Action/HackAndSlashTest.cs b/.Lib9c.Tests/Action/HackAndSlashTest.cs index 133154d558..b99f062702 100644 --- a/.Lib9c.Tests/Action/HackAndSlashTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashTest.cs @@ -83,11 +83,8 @@ public HackAndSlashTest() _initialState = _initialState .SetLegacyState(Addresses.GoldCurrency, goldCurrencyState.Serialize()) .SetLegacyState(_weeklyArenaState.address, _weeklyArenaState.Serialize()) - .SetLegacyState(_agentAddress, agentState.SerializeV2()) - .SetLegacyState(_avatarAddress, _avatarState.SerializeV2()) - .SetLegacyState(_inventoryAddress, _avatarState.inventory.Serialize()) - .SetLegacyState(_worldInformationAddress, _avatarState.worldInformation.Serialize()) - .SetLegacyState(_questListAddress, _avatarState.questList.Serialize()) + .SetAgentState(_agentAddress, agentState) + .SetAvatarState(_avatarAddress, _avatarState) .SetLegacyState(gameConfigState.address, gameConfigState.Serialize()); foreach (var (key, value) in _sheets) @@ -106,17 +103,14 @@ public HackAndSlashTest() } [Theory] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, false, false, true)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, false, true, true)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, true, false, true)] - [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false, false, true)] - [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, true, false, true)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false, false, false)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false, true, false)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, true, false, false)] - [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false, false, false)] - [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, true, false, false)] - public void Execute(int avatarLevel, int worldId, int stageId, bool backward, bool isWeaponLock, bool isClearedBefore) + [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, false, true)] + [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, true, true)] + [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false, true)] + [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false, true)] + [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false, false)] + [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, true, false)] + [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false, false)] + public void Execute(int avatarLevel, int worldId, int stageId, bool isWeaponLock, bool isClearedBefore) { Assert.True(_tableSheets.WorldSheet.TryGetValue(worldId, out var worldRow)); Assert.True(stageId >= worldRow.StageBegin); @@ -174,24 +168,11 @@ public void Execute(int avatarLevel, int worldId, int stageId, bool backward, bo previousAvatarState.Update(mail); } - IWorld state; - if (backward) - { - state = _initialState.SetLegacyState(_avatarAddress, previousAvatarState.Serialize()); - } - else - { - state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState(_avatarAddress.Derive(LegacyInventoryKey), previousAvatarState.inventory.Serialize()) - .SetLegacyState(_avatarAddress.Derive(LegacyWorldInformationKey), previousAvatarState.worldInformation.Serialize()) - .SetLegacyState(_avatarAddress.Derive(LegacyQuestListKey), previousAvatarState.questList.Serialize()); - } - - state = state.SetLegacyState( - _avatarAddress.Derive("world_ids"), - List.Empty.Add(worldId.Serialize()) - ); + IWorld state = _initialState + .SetAvatarState(_avatarAddress, previousAvatarState) + .SetLegacyState( + _avatarAddress.Derive("world_ids"), + List.Empty.Add(worldId.Serialize())); var action = new HackAndSlash { @@ -249,10 +230,7 @@ public void Execute_With_UpdateQuestList(int worldId, int stageId) } state = state - .SetLegacyState(avatarState.address, avatarState.SerializeV2()) - .SetLegacyState(_inventoryAddress, avatarState.inventory.Serialize()) - .SetLegacyState(_worldInformationAddress, avatarState.worldInformation.Serialize()) - .SetLegacyState(_questListAddress, avatarState.questList.Serialize()); + .SetAvatarState(avatarState.address, avatarState); Assert.Equal(400, avatarState.level); Assert.True(avatarState.worldInformation.IsWorldUnlocked(worldId)); Assert.True(avatarState.worldInformation.IsStageCleared(stageId)); @@ -334,7 +312,7 @@ public void MaxLevelTest() _tableSheets.WorldSheet, Math.Max(_tableSheets.StageSheet.First?.Id ?? 1, stageId)); - var state = _initialState.SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()); + var state = _initialState.SetAvatarState(_avatarAddress, previousAvatarState); var action = new HackAndSlash { @@ -393,9 +371,7 @@ public void MultipleEquipmentTest(ItemSubType type, int maxCount) previousAvatarState.inventory.AddItem(equipment); } - var state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState(_inventoryAddress, previousAvatarState.inventory.Serialize()); + var state = _initialState.SetAvatarState(_avatarAddress, previousAvatarState); var action = new HackAndSlash { @@ -421,7 +397,7 @@ public void MultipleEquipmentTest(ItemSubType type, int maxCount) [Theory] [InlineData(true)] [InlineData(false)] - public void Execute_Throw_FailedLoadStateException(bool backward) + public void Execute_Throw_FailedLoadStateException(bool empty) { var action = new HackAndSlash { @@ -434,19 +410,11 @@ public void Execute_Throw_FailedLoadStateException(bool backward) AvatarAddress = _avatarAddress, }; - IWorld state = backward ? new World(new MockWorldState()) : _initialState; - if (!backward) - { - state = _initialState - .SetLegacyState(_avatarAddress, _avatarState.SerializeV2()) - .SetAccount( - ReservedAddresses.LegacyAccount, - _initialState - .GetAccount(ReservedAddresses.LegacyAccount) - .SetNull(_avatarAddress.Derive(LegacyInventoryKey)) - .SetNull(_avatarAddress.Derive(LegacyWorldInformationKey)) - .SetNull(_avatarAddress.Derive(LegacyQuestListKey))); - } + IWorld state = empty + ? new World(new MockWorldState()) + : _initialState + .SetAvatarState(_avatarAddress, _avatarState) + .SetAccount(Addresses.Inventory, new Account(new MockAccountState())); var exec = Assert.Throws(() => action.Execute(new ActionContext { @@ -532,7 +500,7 @@ public void ExecuteThrowFailedAddWorldException() { worldInformation = new WorldInformation(0, worldSheet, false), }; - state = state.SetLegacyState(_worldInformationAddress, avatarState.worldInformation.Serialize()); + state = state.SetAvatarState(_avatarAddress, avatarState); Assert.False(avatarState.worldInformation.IsStageCleared(0)); @@ -613,7 +581,7 @@ public void ExecuteThrowInvalidStageException() Assert.True(avatarState.worldInformation.IsWorldUnlocked(1)); var state = _initialState; - state = state.SetLegacyState(_avatarAddress, avatarState.SerializeV2()); + state = state.SetAvatarState(_avatarAddress, avatarState); var exec = Assert.Throws(() => action.Execute(new ActionContext { @@ -679,9 +647,7 @@ public void ExecuteThrowInvalidEquipmentException(ItemSubType itemSubType) AvatarAddress = _avatarAddress, }; - var state = _initialState - .SetLegacyState(_avatarAddress, avatarState.SerializeV2()) - .SetLegacyState(_inventoryAddress, avatarState.inventory.Serialize()); + var state = _initialState.SetAvatarState(_avatarAddress, avatarState); var exec = Assert.Throws(() => action.Execute(new ActionContext { @@ -706,12 +672,12 @@ public void ExecuteThrowEquipmentSlotUnlockException(ItemSubType itemSubType) { level = 0, }; - state = state.SetLegacyState(_avatarAddress, avatarState.SerializeV2()); + state = state.SetAvatarState(_avatarAddress, avatarState); var equipRow = _tableSheets.EquipmentItemSheet.Values.First(r => r.ItemSubType == itemSubType); var equipment = ItemFactory.CreateItemUsable(equipRow, Guid.NewGuid(), 0); avatarState.inventory.AddItem(equipment); - state = state.SetLegacyState(_inventoryAddress, avatarState.inventory.Serialize()); + state = state.SetAvatarState(_avatarAddress, avatarState); var action = new HackAndSlash { @@ -761,7 +727,7 @@ public void ExecuteThrowNotEnoughActionPointException(int ap, int playCount = 1) }; var state = _initialState; - state = state.SetLegacyState(_avatarAddress, avatarState.SerializeV2()); + state = state.SetAvatarState(_avatarAddress, avatarState); var exec = Assert.Throws(() => action.Execute(new ActionContext { @@ -804,17 +770,7 @@ public void ExecuteWithoutPlayCount() previousAvatarState.Update(mail); } - IWorld state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState( - _avatarAddress.Derive(LegacyInventoryKey), - previousAvatarState.inventory.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyWorldInformationKey), - previousAvatarState.worldInformation.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyQuestListKey), - previousAvatarState.questList.Serialize()); + IWorld state = _initialState.SetAvatarState(_avatarAddress, previousAvatarState); var action = new HackAndSlash { @@ -880,10 +836,7 @@ public void Execute_Throw_NotEnoughAvatarLevelException(int avatarLevel) costumes.Add(((INonFungibleItem)costume).NonFungibleId); } - state = state.SetLegacyState(avatarState.address, avatarState.SerializeV2()) - .SetLegacyState( - avatarState.address.Derive(LegacyInventoryKey), - avatarState.inventory.Serialize()); + state = state.SetAvatarState(avatarState.address, avatarState); var action = new HackAndSlash { @@ -1033,15 +986,11 @@ public void ExecuteThrowNotEnoughMaterialException() } [Theory] - [InlineData(true, 1, 15)] - [InlineData(true, 2, 55)] - [InlineData(true, 3, 111)] - [InlineData(true, 4, 189)] - [InlineData(false, 1, 15)] - [InlineData(false, 2, 55)] - [InlineData(false, 3, 111)] - [InlineData(false, 4, 189)] - public void CheckRewardItems(bool backward, int worldId, int stageId) + [InlineData(1, 15)] + [InlineData(2, 55)] + [InlineData(3, 111)] + [InlineData(4, 189)] + public void CheckRewardItems(int worldId, int stageId) { Assert.True(_tableSheets.WorldSheet.TryGetValue(worldId, out var worldRow)); Assert.True(stageId >= worldRow.StageBegin); @@ -1092,30 +1041,11 @@ public void CheckRewardItems(bool backward, int worldId, int stageId) previousAvatarState.Update(mail); } - IWorld state; - if (backward) - { - state = _initialState.SetLegacyState(_avatarAddress, previousAvatarState.Serialize()); - } - else - { - state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState( - _avatarAddress.Derive(LegacyInventoryKey), - previousAvatarState.inventory.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyWorldInformationKey), - previousAvatarState.worldInformation.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyQuestListKey), - previousAvatarState.questList.Serialize()); - } - - state = state.SetLegacyState( - _avatarAddress.Derive("world_ids"), - Enumerable.Range(1, worldId).ToList().Select(i => i.Serialize()).Serialize() - ); + IWorld state = _initialState + .SetAvatarState(_avatarAddress, previousAvatarState) + .SetLegacyState( + _avatarAddress.Derive("world_ids"), + Enumerable.Range(1, worldId).ToList().Select(i => i.Serialize()).Serialize()); var action = new HackAndSlash { @@ -1238,17 +1168,7 @@ public void CheckCrystalRandomSkillState( previousAvatarState.Update(mail); } - var state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState( - _avatarAddress.Derive(LegacyInventoryKey), - previousAvatarState.inventory.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyWorldInformationKey), - previousAvatarState.worldInformation.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyQuestListKey), - previousAvatarState.questList.Serialize()); + var state = _initialState.SetAvatarState(_avatarAddress, previousAvatarState); state = state.SetLegacyState( _avatarAddress.Derive("world_ids"), @@ -1387,16 +1307,7 @@ public void CheckUsedApByStaking(int level, int playCount) .FirstOrDefault(r => r.Level == level)?.RequiredGold ?? 0; var context = new ActionContext(); var state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState( - _avatarAddress.Derive(LegacyInventoryKey), - previousAvatarState.inventory.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyWorldInformationKey), - previousAvatarState.worldInformation.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyQuestListKey), - previousAvatarState.questList.Serialize()) + .SetAvatarState(_avatarAddress, previousAvatarState) .SetLegacyState(stakeStateAddress, stakeState.SerializeV2()) .SetLegacyState( _avatarAddress.Derive("world_ids"), @@ -1465,16 +1376,7 @@ public void CheckUsingApStoneWithStaking(int level, int apStoneCount, int totalR .FirstOrDefault(r => r.Level == level)?.RequiredGold ?? 0; var context = new ActionContext(); var state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState( - _avatarAddress.Derive(LegacyInventoryKey), - previousAvatarState.inventory.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyWorldInformationKey), - previousAvatarState.worldInformation.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyQuestListKey), - previousAvatarState.questList.Serialize()) + .SetAvatarState(_avatarAddress, previousAvatarState) .SetLegacyState(stakeStateAddress, stakeState.SerializeV2()) .SetLegacyState( _avatarAddress.Derive("world_ids"), @@ -1525,17 +1427,7 @@ public void ExecuteThrowInvalidRepeatPlayException() r.ItemSubType == ItemSubType.ApStone); var apStone = ItemFactory.CreateTradableMaterial(apStoneRow); avatarState.inventory.AddItem(apStone); - var state = _initialState - .SetLegacyState(_avatarAddress, avatarState.SerializeV2()) - .SetLegacyState( - _avatarAddress.Derive(LegacyInventoryKey), - avatarState.inventory.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyWorldInformationKey), - avatarState.worldInformation.Serialize()) - .SetLegacyState( - _avatarAddress.Derive(LegacyQuestListKey), - avatarState.questList.Serialize()); + var state = _initialState.SetAvatarState(_avatarAddress, avatarState); var action = new HackAndSlash { Costumes = new List(), @@ -1619,15 +1511,10 @@ public void ExecuteTwoRepetitions() } var state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState(_avatarAddress.Derive(LegacyInventoryKey), previousAvatarState.inventory.Serialize()) - .SetLegacyState(_avatarAddress.Derive(LegacyWorldInformationKey), previousAvatarState.worldInformation.Serialize()) - .SetLegacyState(_avatarAddress.Derive(LegacyQuestListKey), previousAvatarState.questList.Serialize()); - - state = state.SetLegacyState( - _avatarAddress.Derive("world_ids"), - List.Empty.Add(worldId.Serialize()) - ); + .SetAvatarState(_avatarAddress, previousAvatarState) + .SetLegacyState( + _avatarAddress.Derive("world_ids"), + List.Empty.Add(worldId.Serialize())); var action = new HackAndSlash { @@ -1738,11 +1625,7 @@ public void ExecuteDuplicatedException(int slotIndex, int runeId, int slotIndex2 } var context = new ActionContext(); - var state = _initialState - .SetLegacyState(_avatarAddress, previousAvatarState.SerializeV2()) - .SetLegacyState(_avatarAddress.Derive(LegacyInventoryKey), previousAvatarState.inventory.Serialize()) - .SetLegacyState(_avatarAddress.Derive(LegacyWorldInformationKey), previousAvatarState.worldInformation.Serialize()) - .SetLegacyState(_avatarAddress.Derive(LegacyQuestListKey), previousAvatarState.questList.Serialize()); + var state = _initialState.SetAvatarState(_avatarAddress, previousAvatarState); state = state.SetLegacyState( _avatarAddress.Derive("world_ids"),