Skip to content

Commit

Permalink
Merge pull request #2096 from planetarium/revert-itradable
Browse files Browse the repository at this point in the history
Revert "Move ITradableItem from ItemUsable to each items"
  • Loading branch information
ipdae authored Aug 24, 2023
2 parents 8dd516f + 6c8e965 commit 0e4f6bc
Show file tree
Hide file tree
Showing 70 changed files with 143 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Buy10Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void Execute(params OrderData[] orderDataList)
_tableSheets.EquipmentItemSheet.First,
itemId,
0);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
}
else if (orderData.ItemType == ItemType.Costume)
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Buy11Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void Execute(params OrderData[] orderDataList)
_tableSheets.EquipmentItemSheet.First,
itemId,
0);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
}
else if (orderData.ItemType == ItemType.Costume)
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Buy2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Buy2Test(ITestOutputHelper outputHelper)
_sellerAvatarAddress,
Guid.NewGuid(),
new FungibleAssetValue(_goldCurrencyState.Currency, 100, 0),
(ITradableItem)equipment));
equipment));

var result = new CombinationConsumable5.ResultModel()
{
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/Buy3Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ public Buy3Test(ITestOutputHelper outputHelper)
_sellerAvatarAddress,
Guid.NewGuid(),
new FungibleAssetValue(_goldCurrencyState.Currency, ProductPrice, 0),
(ITradableItem)equipment));
equipment));

shopState.Register(new ShopItem(
_sellerAgentAddress,
_sellerAvatarAddress,
Guid.NewGuid(),
new FungibleAssetValue(_goldCurrencyState.Currency, ProductPrice, 0),
(ITradableItem)consumable));
consumable));

shopState.Register(new ShopItem(
_sellerAgentAddress,
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/Buy4Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ public Buy4Test(ITestOutputHelper outputHelper)
_sellerAvatarAddress,
Guid.NewGuid(),
new FungibleAssetValue(_goldCurrencyState.Currency, ProductPrice, 0),
(ITradableItem)equipment));
equipment));

shopState.Register(new ShopItem(
_sellerAgentAddress,
_sellerAvatarAddress,
Guid.NewGuid(),
new FungibleAssetValue(_goldCurrencyState.Currency, ProductPrice, 0),
(ITradableItem)consumable));
consumable));

shopState.Register(new ShopItem(
_sellerAgentAddress,
Expand Down
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/Buy5Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void Execute(params ShopItemData[] shopItemMembers)
productId,
new FungibleAssetValue(_goldCurrencyState.Currency, shopItemData.Price, 0),
requiredBlockIndex,
(ITradableItem)nonFungibleItem);
nonFungibleItem);

// Case for backward compatibility.
if (shopItemData.ContainsInInventory)
Expand Down Expand Up @@ -454,7 +454,7 @@ public void Execute_ErrorCode_InsufficientBalance()
_productId,
new FungibleAssetValue(_goldCurrencyState.Currency, 100, 0),
Sell6.ExpiredBlockIndex,
(ITradableItem)itemUsable);
itemUsable);

ShardedShopState shopState = new ShardedShopState(shardedShopAddress);
shopState.Register(shopItem);
Expand Down Expand Up @@ -506,7 +506,7 @@ public void Execute_ErrorCode_ItemDoesNotExist_By_SellerAvatar()
_productId,
new FungibleAssetValue(_goldCurrencyState.Currency, 100, 0),
Sell6.ExpiredBlockIndex,
(ITradableItem)itemUsable);
itemUsable);

ShardedShopState shopState = new ShardedShopState(shardedShopAddress);
shopState.Register(shopItem);
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/Buy6Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void Execute(params ShopItemData[] shopItemMembers)
_tableSheets.EquipmentItemSheet.First,
itemId,
requiredBlockIndex);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
}
else if (shopItemData.ItemType == ItemType.Costume)
Expand Down Expand Up @@ -581,7 +581,7 @@ public void Execute_ErrorCode_InsufficientBalance()
_productId,
new FungibleAssetValue(_goldCurrencyState.Currency, 100, 0),
Sell6.ExpiredBlockIndex,
(ITradableItem)itemUsable);
itemUsable);

ShardedShopState shopState = new ShardedShopState(shardedShopAddress);
shopState.Register(shopItem);
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/Buy7Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void Execute(params ShopItemData[] shopItemMembers)
_tableSheets.EquipmentItemSheet.First,
itemId,
requiredBlockIndex);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
}
else if (shopItemData.ItemType == ItemType.Costume)
Expand Down Expand Up @@ -652,7 +652,7 @@ public void Execute_ErrorCode_InsufficientBalance()
_productId,
new FungibleAssetValue(_goldCurrencyState.Currency, 100, 0),
Sell6.ExpiredBlockIndex,
(ITradableItem)itemUsable);
itemUsable);

ShardedShopState shopState = new ShardedShopState(shardedShopAddress);
shopState.Register(shopItem);
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Buy8Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void Execute(params OrderData[] orderDataList)
_tableSheets.EquipmentItemSheet.First,
itemId,
0);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
}
else if (orderData.ItemType == ItemType.Costume)
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Buy9Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void Execute(params OrderData[] orderDataList)
_tableSheets.EquipmentItemSheet.First,
itemId,
0);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
}
else if (orderData.ItemType == ItemType.Costume)
Expand Down
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/BuyMultipleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void Execute(params ShopItemData[] productDatas)
shopItemId,
new FungibleAssetValue(_goldCurrencyState.Currency, product.Price, 0),
product.RequiredBlockIndex,
(ITradableItem)nonFungibleItem);
nonFungibleItem);
shopState.Register(shopItem);

if (product.Buy)
Expand Down Expand Up @@ -504,7 +504,7 @@ public void ExecuteInsufficientBalanceError()
Guid.NewGuid(),
new FungibleAssetValue(_goldCurrencyState.Currency, 1, 0),
100,
(ITradableItem)equipment));
equipment));

var costume = ItemFactory.CreateCostume(
_tableSheets.CostumeItemSheet.First,
Expand Down Expand Up @@ -574,7 +574,7 @@ public void ExecuteThrowShopItemExpiredError()
productId,
new FungibleAssetValue(_goldCurrencyState.Currency, 100, 0),
10,
(ITradableItem)equipment));
equipment));

previousStates = previousStates
.SetState(Addresses.Shop, shopState.Serialize());
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/BuyProduct0Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BuyProduct0Test
private static readonly Currency Gold = Currency.Legacy("NCG", 2, null);
private static readonly TableSheets TableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
private static readonly ITradableItem TradableItem =
(ITradableItem)ItemFactory.CreateItemUsable(TableSheets.EquipmentItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Armor), Guid.NewGuid(), 1L);
ItemFactory.CreateItemUsable(TableSheets.EquipmentItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Armor), Guid.NewGuid(), 1L);

private readonly Address _sellerAgentAddress2;
private readonly Address _sellerAvatarAddress2;
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/BuyProductTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BuyProductTest
private static readonly Currency Gold = Currency.Legacy("NCG", 2, null);
private static readonly TableSheets TableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
private static readonly ITradableItem TradableItem =
(ITradableItem)ItemFactory.CreateItemUsable(TableSheets.EquipmentItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Armor), Guid.NewGuid(), 1L);
ItemFactory.CreateItemUsable(TableSheets.EquipmentItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Armor), Guid.NewGuid(), 1L);

private readonly Address _sellerAgentAddress2;
private readonly Address _sellerAvatarAddress2;
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/BuyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void Execute(params OrderData[] orderDataList)
_tableSheets.EquipmentItemSheet.First,
itemId,
0);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
}
else if (orderData.ItemType == ItemType.Costume)
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/ItemEnhancement10Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public void Execute(int level, int expectedGold, bool backward)
break;
}

Assert.Equal(preItemUsable.ItemId, slotResult.preItemUsable.ItemId);
Assert.Equal(preItemUsable.ItemId, resultEquipment.ItemId);
Assert.Equal(preItemUsable.TradableId, slotResult.preItemUsable.TradableId);
Assert.Equal(preItemUsable.TradableId, resultEquipment.TradableId);
Assert.Equal(costRow.Cost, slotResult.gold);
}

Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/ItemEnhancement9Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public void Execute(int level, int expectedGold, bool backward)
break;
}

Assert.Equal(preItemUsable.ItemId, slotResult.preItemUsable.ItemId);
Assert.Equal(preItemUsable.ItemId, resultEquipment.ItemId);
Assert.Equal(preItemUsable.TradableId, slotResult.preItemUsable.TradableId);
Assert.Equal(preItemUsable.TradableId, resultEquipment.TradableId);
Assert.Equal(costRow.Cost, slotResult.gold);
}

Expand Down
5 changes: 2 additions & 3 deletions .Lib9c.Tests/Action/ItemEnhancementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,8 @@ public void Execute(
expectedBlockIndex + 1, // +1 for execution
resultEquipment.RequiredBlockIndex
);
Assert.Equal(preItemUsable.ItemId, slotResult.preItemUsable.ItemId);
Assert.Equal(preItemUsable.ItemId, resultEquipment.ItemId);
Assert.Equal(targetRow.Cost - startRow.Cost, slotResult.gold);
Assert.Equal(preItemUsable.TradableId, slotResult.preItemUsable.TradableId);
Assert.Equal(preItemUsable.TradableId, resultEquipment.TradableId);
}
}
}
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/ReRegisterProduct0Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool fromPreviousAction
_tableSheets.EquipmentItemSheet.First,
itemId,
requiredBlockIndex);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/ReRegisterProductTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool fromPreviousAction
_tableSheets.EquipmentItemSheet.First,
itemId,
requiredBlockIndex);
tradableItem = (ITradableItem)itemUsable;
tradableItem = itemUsable;
itemSubType = itemUsable.ItemSubType;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/RegisterProduct0Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void Execute()
AvatarAddress = AvatarAddress,
ItemCount = 1,
Price = 1 * Gold,
TradableId = equipment.ItemId,
TradableId = equipment.TradableId,
Type = ProductType.NonFungible,
},
new AssetInfo
Expand Down Expand Up @@ -329,7 +329,7 @@ public void Execute_Throw_ItemDoesNotExistException(ProductType type, int itemCo
{
var equipmentRow = _tableSheets.EquipmentItemSheet.Values.First();
var id = Guid.NewGuid();
tradableItem = (ITradableItem)ItemFactory.CreateItemUsable(equipmentRow, id, requiredBlockIndex);
tradableItem = ItemFactory.CreateItemUsable(equipmentRow, id, requiredBlockIndex);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/RegisterProductTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void Execute()
AvatarAddress = AvatarAddress,
ItemCount = 1,
Price = 1 * Gold,
TradableId = equipment.ItemId,
TradableId = equipment.TradableId,
Type = ProductType.NonFungible,
},
new AssetInfo
Expand Down Expand Up @@ -330,7 +330,7 @@ public void Execute_Throw_ItemDoesNotExistException(ProductType type, int itemCo
{
var equipmentRow = _tableSheets.EquipmentItemSheet.Values.First();
var id = Guid.NewGuid();
tradableItem = (ITradableItem)ItemFactory.CreateItemUsable(equipmentRow, id, requiredBlockIndex);
tradableItem = ItemFactory.CreateItemUsable(equipmentRow, id, requiredBlockIndex);
break;
}

Expand Down
47 changes: 1 addition & 46 deletions .Lib9c.Tests/Action/Scenario/AuraScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Lib9c.Tests.Action.Scenario
using Nekoyume.Model.BattleStatus.Arena;
using Nekoyume.Model.EnumType;
using Nekoyume.Model.Item;
using Nekoyume.Model.Market;
using Nekoyume.Model.Skill;
using Nekoyume.Model.Stat;
using Nekoyume.Model.State;
Expand All @@ -30,7 +29,6 @@ public class AuraScenarioTest
private readonly IAccountStateDelta _initialState;
private readonly Aura _aura;
private readonly TableSheets _tableSheets;
private readonly Currency _currency;

public AuraScenarioTest()
{
Expand Down Expand Up @@ -76,12 +74,11 @@ public AuraScenarioTest()
avatarState.questList.Serialize());
}

_currency = Currency.Legacy("NCG", 2, minters: null);
_initialState = _initialState
.SetState(_agentAddress, agentState.Serialize())
.SetState(
Addresses.GoldCurrency,
new GoldCurrencyState(_currency).Serialize())
new GoldCurrencyState(Currency.Legacy("NCG", 2, minters: null)).Serialize())
.SetState(gameConfigState.address, gameConfigState.Serialize())
.MintAsset(new ActionContext(), _agentAddress, Currencies.Crystal * 2);
foreach (var (key, value) in sheets)
Expand Down Expand Up @@ -269,48 +266,6 @@ public void Arena()
}
}

[Fact]
public void Market()
{
var avatarState = _initialState.GetAvatarStateV2(_avatarAddress);
avatarState.inventory.TryGetNonFungibleItem(_aura.ItemId, out Aura aura);
Assert.NotNull(aura);
Assert.IsAssignableFrom<Equipment>(aura);
Assert.Null(aura as ITradableItem);
for (int i = 0; i < GameConfig.RequireClearedStageLevel.ActionsInShop; i++)
{
avatarState.worldInformation.ClearStage(1, i + 1, 0, _tableSheets.WorldSheet, _tableSheets.WorldUnlockSheet);
}

var previousState = _initialState.SetState(
_avatarAddress.Derive(LegacyWorldInformationKey),
avatarState.worldInformation.Serialize());

var register = new RegisterProduct
{
AvatarAddress = _avatarAddress,
RegisterInfos = new List<IRegisterInfo>
{
new RegisterInfo
{
AvatarAddress = _avatarAddress,
Price = 1 * _currency,
TradableId = _aura.ItemId,
ItemCount = 1,
Type = ProductType.NonFungible,
},
},
ChargeAp = false,
};
// Because Aura is not ITradableItem.
Assert.Throws<ItemDoesNotExistException>(() => register.Execute(new ActionContext
{
Signer = _agentAddress,
PreviousState = previousState,
BlockIndex = 0L,
}));
}

private void Assert_Player(AvatarState avatarState, IAccountStateDelta state, Address avatarAddress, Address itemSlotStateAddress)
{
var nextAvatarState = state.GetAvatarStateV2(avatarAddress);
Expand Down
Loading

0 comments on commit 0e4f6bc

Please sign in to comment.