Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent to add item with 0 quantity #1080 #2939

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static IEnumerable<object[]> GetExecuteMemberData()
};
yield return new object[]
{
1, 0, 0, typeof(NotEnoughMaterialException), null,
1, 1, 1, typeof(NotEnoughMaterialException), null,
};
yield return new object[]
{
Expand Down
14 changes: 7 additions & 7 deletions .Lib9c.Tests/Action/Summon/AuraSummonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void CumulativeRatio(string version, int groupId)
9,
800201,
9,
0,
2,
new[] { 10610000, 10610000, 10610000, 10610000, 10610000, 10610000, 10620000, 10620000, 10620000, },
null
)]
Expand All @@ -144,7 +144,7 @@ public void CumulativeRatio(string version, int groupId)
9,
600201,
9,
0,
1,
new[] { 10620001, 10620001, 10620001, 10620001, 10620001, 10630001, 10630001, 10630001, 10630001, },
null
)]
Expand All @@ -155,7 +155,7 @@ public void CumulativeRatio(string version, int groupId)
10,
800201,
10,
0,
1,
new[] { 10610000, 10610000, 10610000, 10610000, 10610000, 10610000, 10610000, 10610000, 10620000, 10620000, 10620000, },
null
)]
Expand All @@ -165,15 +165,15 @@ public void CumulativeRatio(string version, int groupId)
10,
600201,
10,
0,
2,
new[] { 10620001, 10620001, 10620001, 10620001, 10620001, 10620001, 10630001, 10620001, 10630001, 10630001, 10630001, },
null
)]
// fail by invalid group
[InlineData("V1", 100003, 1, null, 0, 0, new int[] { }, typeof(RowNotInTableException))]
[InlineData("V1", 100003, 1, null, 0, 1, new int[] { }, typeof(RowNotInTableException))]
// fail by not enough material
[InlineData("V1", 10001, 1, 800201, 0, 0, new int[] { }, typeof(NotEnoughMaterialException))]
[InlineData("V1", 10001, 2, 800201, 0, 0, new int[] { }, typeof(NotEnoughMaterialException))]
[InlineData("V1", 10001, 1, 800201, 0, 2, new int[] { }, typeof(NotEnoughMaterialException))]
[InlineData("V1", 10001, 2, 800201, 0, 1, new int[] { }, typeof(NotEnoughMaterialException))]
// Fail by exceeding summon limit
[InlineData("V1", 10001, 11, 800201, 22, 1, new int[] { }, typeof(InvalidSummonCountException))]
// 15 recipes
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/Summon/RuneSummonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private class ExecuteMemeber : IEnumerable<object[]>
9,
600201,
9,
0,
2,
null,
},
// Ten plus one
Expand All @@ -218,7 +218,7 @@ private class ExecuteMemeber : IEnumerable<object[]>
10,
600201,
10,
0,
1,
null,
},
// fail by invalid group
Expand Down
14 changes: 14 additions & 0 deletions .Lib9c.Tests/Model/Item/InventoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using Lib9c.Tests.Action;
using Nekoyume.Action;
using Nekoyume.Model.Item;
using Nekoyume.TableData;
using Xunit;
Expand Down Expand Up @@ -34,6 +35,19 @@ public void Serialize()
}

// Add
[Fact]
public void AddItemZero()
{
var item = GetFirstConsumable();
var inventory = new Inventory();
Assert.Empty(inventory.Items);

Assert.Throws<InvalidItemCountException>(() =>
{
inventory.AddItem(item, 0);
});
}

[Fact]
public Inventory AddItem_Consumable()
{
Expand Down
5 changes: 5 additions & 0 deletions Lib9c/Model/Item/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ public object Clone()

public KeyValuePair<int, int> AddItem(ItemBase itemBase, int count = 1, ILock iLock = null)
{
if(count == 0)
{
throw new InvalidItemCountException();
}

switch (itemBase.ItemType)
{
case ItemType.Consumable:
Expand Down