Skip to content

Commit

Permalink
Merge pull request #2778 from planetarium/feature/add-testcase-to-rap…
Browse files Browse the repository at this point in the history
…id-combination

Feature/add testcase to rapid combination
  • Loading branch information
eugene-doobu authored Sep 4, 2024
2 parents c0657c6 + 41675cf commit 1883e59
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 6 deletions.
90 changes: 85 additions & 5 deletions .Lib9c.Tests/Action/RapidCombinationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ public void Execute()
result.id = mail.id;
avatarState.Update2(mail);

var slotAddress = _avatarAddress.Derive(string.Format(
CultureInfo.InvariantCulture,
CombinationSlotState.DeriveFormat,
0));
var allSlotState = new AllCombinationSlotState();
allSlotState.AddSlot(slotAddress);
allSlotState.AddSlot(_avatarAddress);
var slotState = allSlotState.GetSlot(0);
slotState.Update(result, 0, requiredBlockIndex);

Expand Down Expand Up @@ -163,6 +159,90 @@ public void Execute()
Assert.Equal(51, item.RequiredBlockIndex);
}

[Fact]
public void Execute_Many()
{
const int slotStateUnlockStage = 1;

var avatarState = _initialState.GetAvatarState(_avatarAddress);
avatarState.worldInformation = new WorldInformation(
0,
_initialState.GetSheet<WorldSheet>(),
slotStateUnlockStage);

var row = _tableSheets.MaterialItemSheet.Values.First(r =>
r.ItemSubType == ItemSubType.Hourglass);

var numOfHourglass = 83 * AvatarState.DefaultCombinationSlotCount;
avatarState.inventory.AddItem(ItemFactory.CreateMaterial(row), numOfHourglass);

var numOfTradableHourglass = 100 * AvatarState.DefaultCombinationSlotCount;
avatarState.inventory.AddItem(ItemFactory.CreateTradableMaterial(row), numOfTradableHourglass);

Assert.True(avatarState.inventory.HasFungibleItem(row.ItemId, 0, numOfHourglass + numOfTradableHourglass));

var firstEquipmentRow = _tableSheets.EquipmentItemSheet.First;
Assert.NotNull(firstEquipmentRow);

var gameConfigState = _initialState.GetGameConfigState();
var requiredBlockIndex = gameConfigState.HourglassPerBlock * 200;
var equipment = (Equipment)ItemFactory.CreateItemUsable(
firstEquipmentRow,
Guid.NewGuid(),
requiredBlockIndex);
avatarState.inventory.AddItem(equipment);

var targetState = _initialState;
var allSlotState = new AllCombinationSlotState();
for (var i = 0; i < AvatarState.DefaultCombinationSlotCount; ++i)
{
var result = new CombinationConsumable5.ResultModel
{
actionPoint = 0,
gold = 0,
materials = new Dictionary<Material, int>(),
itemUsable = equipment,
recipeId = 0,
itemType = ItemType.Equipment,
};

var mail = new CombinationMail(result, 0, default, requiredBlockIndex);
result.id = mail.id;
avatarState.Update2(mail);

targetState = targetState
.SetAvatarState(_avatarAddress, avatarState);

allSlotState.AddSlot(_avatarAddress, i);
var slotState = allSlotState.GetSlot(i);
slotState.Update(result, 0, requiredBlockIndex);
}

targetState = targetState
.SetCombinationSlotState(_avatarAddress, allSlotState);

var slotIndexList = Enumerable.Range(0, AvatarState.DefaultCombinationSlotCount).ToList();
var action = new RapidCombination
{
avatarAddress = _avatarAddress,
slotIndexList = slotIndexList,
};

var nextState = action.Execute(new ActionContext
{
PreviousState = targetState,
Signer = _agentAddress,
BlockIndex = 51,
});

var nextAvatarState = nextState.GetAvatarState(_avatarAddress);
var item = nextAvatarState.inventory.Equipments.First();

Assert.Empty(nextAvatarState.inventory.Materials.Select(r => r.ItemSubType == ItemSubType.Hourglass));
Assert.Equal(equipment.ItemId, item.ItemId);
Assert.Equal(51, item.RequiredBlockIndex);
}

[Fact]
public void Execute_Throw_CombinationSlotResultNullException()
{
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Model/State/AllCombinationSlotState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public CombinationSlotState GetSlot(int slotStateIndex)
{
return CombinationSlots.TryGetValue(slotStateIndex, out var combinationSlotState)
? combinationSlotState
: throw new CombinationSlotNotFoundException($"Rune {slotStateIndex} not found in AllCombinationSlotState");
: throw new CombinationSlotNotFoundException($"CombinationSlot {slotStateIndex} not found in AllCombinationSlotState");
}

public void AddSlot(Address address, int index = 0)
Expand Down

0 comments on commit 1883e59

Please sign in to comment.