Skip to content

Commit

Permalink
Merge branch 'development' into release/1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
greymistcube committed Nov 7, 2023
2 parents aa95dcf + 0411bb7 commit f8d681a
Show file tree
Hide file tree
Showing 182 changed files with 14,171 additions and 3,683 deletions.
45 changes: 30 additions & 15 deletions .Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using Bencodex.Types;
using Lib9c.DevExtensions.Action;
using Lib9c.Tests;
using Lib9c.Tests.Action;
using Libplanet.Action.State;
using Libplanet.Crypto;
Expand All @@ -24,6 +25,7 @@ namespace Lib9c.DevExtensions.Tests.Action
public class CreateOrReplaceAvatarTest
{
private readonly IAccount _initialStates;
private readonly TableSheets _tableSheets;

public CreateOrReplaceAvatarTest()
{
Expand All @@ -36,6 +38,7 @@ public CreateOrReplaceAvatarTest()
GoldCurrencyState.Address,
new GoldCurrencyState(ncgCurrency).Serialize());
var sheets = TableSheetsImporter.ImportSheets();
_tableSheets = new TableSheets(sheets);
foreach (var (key, value) in sheets)
{
_initialStates = _initialStates.SetState(
Expand Down Expand Up @@ -69,16 +72,8 @@ public CreateOrReplaceAvatarTest()
int.MaxValue,
new[]
{
(10111000, 0),
(10111000, 21), // 21: See also EnhancementCostSheetV2.csv
(10211000, 0),
(10211000, 21),
(10311000, 0),
(10311000, 21),
(10411000, 0),
(10411000, 21),
(10511000, 0),
(10511000, 21),
(ItemSubType.Weapon, 0),
(ItemSubType.Weapon, 21), // 21: See also EnhancementCostSheetV2.csv
},
new[]
{
Expand Down Expand Up @@ -291,12 +286,22 @@ public void Serialize(
int ear,
int tail,
int level,
(int equipmentId, int level)[]? equipments,
(ItemSubType itemSubType, int level)[]? equipmentData,
(int consumableId, int count)[]? foods,
int[]? costumeIds,
(int runeId, int level)[]? runes,
(int stageId, int[] crystalRandomBuffIds)? crystalRandomBuff)
{
var equipments = new List<(int, int)>();
if (!(equipmentData is null))
{
foreach (var data in equipmentData)
{
var row = _tableSheets.EquipmentItemRecipeSheet.Values.First(r =>
r.ItemSubType == data.itemSubType);
equipments.Add((row.ResultEquipmentId, data.level));
}
}
var action = new CreateOrReplaceAvatar(
avatarIndex,
name,
Expand All @@ -305,7 +310,7 @@ public void Serialize(
ear,
tail,
level,
equipments,
equipments.ToArray(),
foods,
costumeIds,
runes,
Expand Down Expand Up @@ -348,12 +353,22 @@ public void Execute_Success(
int ear,
int tail,
int level,
(int equipmentId, int level)[]? equipments,
(ItemSubType itemSubType, int level)[]? equipmentData,
(int consumableId, int count)[]? foods,
int[]? costumeIds,
(int runeId, int level)[]? runes,
(int stageId, int[] crystalRandomBuffIds)? crystalRandomBuff)
{
var equipments = new List<(int, int)>();
if (!(equipmentData is null))
{
foreach (var data in equipmentData)
{
var row = _tableSheets.EquipmentItemRecipeSheet.Values.First(r =>
r.ItemSubType == data.itemSubType);
equipments.Add((row.ResultEquipmentId, data.level));
}
}
var agentAddr = new PrivateKey().ToAddress();
Execute(
_initialStates,
Expand All @@ -366,7 +381,7 @@ public void Execute_Success(
ear,
tail,
level,
equipments,
equipments.ToArray(),
foods,
costumeIds,
runes,
Expand Down Expand Up @@ -478,7 +493,7 @@ private static void Execute(
var recipe = equipmentItemRecipeSheet.OrderedList!.First(r =>
r.ResultEquipmentId == equipment.Id);
Assert.NotNull(recipe);
Assert.Equal(3, recipe.SubRecipeIds.Count);
Assert.Equal(2, recipe.SubRecipeIds.Count);
Assert.True(equipmentItemSubRecipeSheetV2.TryGetValue(
recipe.SubRecipeIds[1],
out var subRecipe));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Linq;
using Lib9c.DevExtensions.Action.Factory;
using Lib9c.Tests;
using Nekoyume.Model.Item;
using Xunit;

namespace Lib9c.DevExtensions.Tests.Action.Factory
{
public class CreateOrReplaceAvatarFactoryTest
{
private readonly TableSheets _tableSheets;

public CreateOrReplaceAvatarFactoryTest()
{
_tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
}

[Theory]
[MemberData(
nameof(CreateOrReplaceAvatarTest.Get_Execute_Success_MemberData),
Expand All @@ -22,12 +32,23 @@ public void TryGetByBlockIndex_Success(
int ear,
int tail,
int level,
(int equipmentId, int level)[]? equipments,
(ItemSubType itemSubType, int level)[]? equipmentData,
(int consumableId, int count)[]? foods,
int[]? costumeIds,
(int runeId, int level)[]? runes,
(int stageId, int[] crystalRandomBuffIds)? crystalRandomBuff)
{
var equipments = new List<(int, int)>();
if (!(equipmentData is null))
{
foreach (var data in equipmentData)
{
var row = _tableSheets.EquipmentItemRecipeSheet.Values.First(r =>
r.ItemSubType == data.itemSubType);
equipments.Add((row.ResultEquipmentId, data.level));
}
}

var (e, r) = CreateOrReplaceAvatarFactory
.TryGetByBlockIndex(
blockIndex,
Expand All @@ -38,7 +59,7 @@ public void TryGetByBlockIndex_Success(
ear,
tail,
level,
equipments,
equipments.ToArray(),
foods,
costumeIds,
runes,
Expand Down
36 changes: 18 additions & 18 deletions .Lib9c.Tests/Action/BattleArena13Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void Execute_Backward_Compatibility_Success()
[Fact]
public void Execute_InvalidAddressException()
{
var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar1Address,
Expand All @@ -218,7 +218,7 @@ public void Execute_InvalidAddressException()
[Fact]
public void Execute_FailedLoadStateException()
{
var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar2Address,
enemyAvatarAddress = _avatar1Address,
Expand All @@ -241,7 +241,7 @@ public void Execute_FailedLoadStateException()
[Fact]
public void Execute_NotEnoughClearedStageLevelException()
{
var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar4Address,
enemyAvatarAddress = _avatar2Address,
Expand All @@ -266,7 +266,7 @@ public void Execute_NotEnoughClearedStageLevelException()
[Fact]
public void Execute_SheetRowNotFoundException()
{
var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand All @@ -289,7 +289,7 @@ public void Execute_SheetRowNotFoundException()
[Fact]
public void Execute_ThisArenaIsClosedException()
{
var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand All @@ -313,7 +313,7 @@ public void Execute_ThisArenaIsClosedException()
[Fact]
public void Execute_ArenaParticipantsNotFoundException()
{
var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -374,7 +374,7 @@ public void Execute_AddressNotFoundInArenaParticipantsException(bool excludeMe)
round,
random);

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -444,7 +444,7 @@ public void Execute_ValidateScoreDifferenceException(bool isSigner)
arenaScore.AddScore(900);
previousStates = previousStates.SetState(arenaScoreAdr, arenaScore.Serialize());

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -513,7 +513,7 @@ public void Execute_InsufficientBalanceException()
beforeInfo.UseTicket(beforeInfo.Ticket);
previousStates = previousStates.SetState(arenaInfoAdr, beforeInfo.Serialize());

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -579,7 +579,7 @@ public void Execute_ExceedPlayCountException()
throw new ArenaInformationNotFoundException($"arenaInfoAdr : {arenaInfoAdr}");
}

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -659,7 +659,7 @@ public void Execute_ExceedTicketPurchaseLimitException()
previousStates.GetGoldCurrency());
previousStates = previousStates.MintAsset(context, _agent1Address, price);

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -732,7 +732,7 @@ public void Execute_ExceedTicketPurchaseLimitDuringIntervalException()
beforeInfo.BuyTicket(roundData.MaxPurchaseCount);
}

var purchasedCountDuringInterval = arenaInfoAdr.Derive(BattleArena.PurchasedCountKey);
var purchasedCountDuringInterval = arenaInfoAdr.Derive(BattleArena13.PurchasedCountKey);
previousStates = previousStates
.SetState(arenaInfoAdr, beforeInfo.Serialize())
.SetState(
Expand All @@ -744,7 +744,7 @@ public void Execute_ExceedTicketPurchaseLimitDuringIntervalException()
previousStates.GetGoldCurrency());
previousStates = previousStates.MintAsset(context, _agent1Address, price);

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -823,7 +823,7 @@ public void Execute_CoolDownBlockException()
beforeInfo.BuyTicket(roundData.MaxPurchaseCount);
}

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -922,7 +922,7 @@ public void ExecuteDuplicatedException(int slotIndex, int runeId, int slotIndex2
RandomSeed = 0,
});

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -1029,7 +1029,7 @@ public void Execute_ValidateDuplicateTicketPurchaseException()

beforeInfo.UseTicket(ArenaInformation.MaxTicketCount);

var purchasedCountDuringInterval = arenaInfoAdr.Derive(BattleArena.PurchasedCountKey);
var purchasedCountDuringInterval = arenaInfoAdr.Derive(BattleArena13.PurchasedCountKey);
previousStates = previousStates
.SetState(arenaInfoAdr, beforeInfo.Serialize())
.SetState(
Expand All @@ -1041,7 +1041,7 @@ public void Execute_ValidateDuplicateTicketPurchaseException()
previousStates.GetGoldCurrency());
previousStates = previousStates.MintAsset(context, _agent1Address, price);

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
Expand Down Expand Up @@ -1157,7 +1157,7 @@ private void Execute(
}
}

var action = new BattleArena
var action = new BattleArena13
{
myAvatarAddress = myAvatarAddress,
enemyAvatarAddress = enemyAvatarAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Lib9c.Tests.Action
using Xunit;
using Xunit.Abstractions;

public class BuyProductTest
public class BuyProduct2Test
{
private static readonly Address BuyerAgentAddress = new Address("47d082a115c63e7b58b1532d20e631538eafadde");
private static readonly Address BuyerAvatarAddress = new Address("340f110b91d0577a9ae0ea69ce15269436f217da");
Expand All @@ -37,7 +37,7 @@ public class BuyProductTest
private readonly Guid _orderId;
private IAccount _initialState;

public BuyProductTest(ITestOutputHelper outputHelper)
public BuyProduct2Test(ITestOutputHelper outputHelper)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
Expand Down Expand Up @@ -296,7 +296,7 @@ public void Execute_Throw_Exception(params ExecuteMember[] validateMembers)

foreach (var productInfo in validateMember.ProductInfos)
{
var action = new BuyProduct
var action = new BuyProduct2
{
AvatarAddress = BuyerAvatarAddress,
ProductInfos = new[] { productInfo },
Expand All @@ -315,12 +315,12 @@ public void Execute_Throw_Exception(params ExecuteMember[] validateMembers)
public void Execute_Throw_ArgumentOutOfRangeException()
{
var productInfos = new List<ItemProductInfo>();
for (int i = 0; i < BuyProduct.Capacity + 1; i++)
for (int i = 0; i < BuyProduct2.Capacity + 1; i++)
{
productInfos.Add(new ItemProductInfo());
}

var action = new BuyProduct
var action = new BuyProduct2
{
AvatarAddress = _sellerAvatarAddress2,
ProductInfos = productInfos,
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/BuyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public void Execute(params OrderData[] orderDataList)
Signer = _buyerAgentAddress,
});

var buyProductAction = new BuyProduct
var buyProductAction = new BuyProduct2
{
AvatarAddress = _buyerAvatarAddress,
ProductInfos = productInfos,
Expand Down Expand Up @@ -630,7 +630,7 @@ public void Execute_ErrorCode(ErrorCodeMember errorCodeMember)
action.errors.Select(r => r.errorCode)
);

var buyProductAction = new BuyProduct
var buyProductAction = new BuyProduct2
{
AvatarAddress = _buyerAvatarAddress,
ProductInfos = new[] { productInfo },
Expand Down
Loading

0 comments on commit f8d681a

Please sign in to comment.