Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into feature/synthe…
Browse files Browse the repository at this point in the history
…size-interface
  • Loading branch information
eugene-doobu committed Oct 15, 2024
2 parents 494d1a6 + 7397fd3 commit e70e7fc
Show file tree
Hide file tree
Showing 80 changed files with 4,799 additions and 1,467 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private static void Execute(
Addresses.GetSkillStateAddressFromAvatarAddress(avatarAddr.Value);
if (action.CrystalRandomBuff is null)
{
Assert.Equal(Null.Value, nextStates.GetLegacyState(crystalRandomSkillAddr));
Assert.Null(nextStates.GetLegacyState(crystalRandomSkillAddr));
}
else
{
Expand Down
54 changes: 53 additions & 1 deletion .Lib9c.Tests/Action/BattleArenaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Lib9c.Tests.Action
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Arena;
using Nekoyume.Exceptions;
using Nekoyume.Model;
using Nekoyume.Model.Arena;
using Nekoyume.Model.EnumType;
Expand Down Expand Up @@ -199,6 +200,57 @@ public void Execute_InvalidAddressException()
}));
}

[Fact]
public void Execute_MedalIdNotFoundException()
{
var prevState = _initialStates;
var context = new ActionContext
{
PreviousState = prevState,
Signer = _agent1Address,
RandomSeed = 0,
};
prevState = prevState.SetLegacyState(Addresses.TableSheet.Derive("ArenaSheet"), @"id,round,arena_type,start_block_index,end_block_index,required_medal_count,entrance_fee,ticket_price,additional_ticket_price,max_purchase_count,max_purchase_count_during_interval,medal_id
1,1,Season,1,100,0,0,5,2,80,79".Serialize());
prevState = JoinArena(
context,
prevState,
_agent1Address,
_avatar1Address,
1,
1,
1,
new TestRandom());
prevState = JoinArena(
context,
prevState,
_agent2Address,
_avatar2Address,
1,
1,
1,
new TestRandom());

var action = new BattleArena
{
myAvatarAddress = _avatar1Address,
enemyAvatarAddress = _avatar2Address,
championshipId = 1,
round = 1,
ticket = 1,
costumes = new List<Guid>(),
equipments = new List<Guid>(),
runeInfos = new List<RuneSlotInfo>(),
};
Assert.Throws<MedalIdNotFoundException>(() => action.Execute(new ActionContext
{
PreviousState = prevState,
Signer = _agent1Address,
RandomSeed = 0,
BlockIndex = 10,
}));
}

[Fact]
public void Execute_FailedLoadStateException()
{
Expand Down Expand Up @@ -1249,7 +1301,7 @@ private void Execute(
var medalCount = 0;
if (roundData.ArenaType != ArenaType.OffSeason)
{
var medalId = ArenaHelper.GetMedalItemId(championshipId, round);
var medalId = roundData.MedalId;
myAvatarStateNext.inventory.TryGetItem(medalId, out var medal);
if (myAfterInfoNext.Win > 0)
{
Expand Down
62 changes: 62 additions & 0 deletions .Lib9c.Tests/Action/CancelProductRegistrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ namespace Lib9c.Tests.Action
using Nekoyume.Action;
using Nekoyume.Helper;
using Nekoyume.Model;
using Nekoyume.Model.Item;
using Nekoyume.Model.Mail;
using Nekoyume.Model.Market;
using Nekoyume.Model.State;
using Nekoyume.Module;
using Newtonsoft.Json.Serialization;
using Serilog;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -210,5 +213,64 @@ public void Execute_Throw_ArgumentOutOfRangeException()

Assert.Throws<ArgumentOutOfRangeException>(() => action.Execute(new ActionContext()));
}

[Theory]
[InlineData(ProductType.FungibleAssetValue)]
[InlineData(ProductType.NonFungible)]
[InlineData(ProductType.Fungible)]
public void Mail_Serialize_BackwardCompatibility(ProductType productType)
{
Product product;
var gold = _goldCurrencyState.Currency;
switch (productType)
{
case ProductType.FungibleAssetValue:
product = new FavProduct
{
SellerAgentAddress = new PrivateKey().Address,
SellerAvatarAddress = new PrivateKey().Address,
Asset = 1 * RuneHelper.StakeRune,
RegisteredBlockIndex = 1L,
ProductId = Guid.NewGuid(),
Price = 1 * gold,
Type = ProductType.FungibleAssetValue,
};
break;
case ProductType.Fungible:
case ProductType.NonFungible:
{
ITradableItem tradableItem = productType == ProductType.Fungible
? ItemFactory.CreateTradableMaterial(_tableSheets.MaterialItemSheet.First)
: (ITradableItem)ItemFactory.CreateItemUsable(_tableSheets.EquipmentItemSheet.First, Guid.NewGuid(), 0L);
product = new ItemProduct
{
SellerAgentAddress = new PrivateKey().Address,
SellerAvatarAddress = new PrivateKey().Address,
RegisteredBlockIndex = 1L,
ProductId = Guid.NewGuid(),
Price = 1 * gold,
Type = ProductType.NonFungible,
ItemCount = 1,
TradableItem = tradableItem,
};
break;
}

default:
throw new ArgumentOutOfRangeException(nameof(productType), productType, null);
}

var mail = new ProductCancelMail(2L, Guid.NewGuid(), 2L, product!.ProductId, product!);
var serialized = (Dictionary)mail.Serialize();
var deserialized = new ProductCancelMail(serialized);
Assert.Equal(serialized, deserialized.Serialize());
// serialized mail on v200220;
serialized = (Dictionary)serialized.Remove((Text)ProductCancelMail.ProductKey);
deserialized = new ProductCancelMail(serialized);
Assert.Equal(deserialized.ProductId, product.ProductId);
Assert.Null(deserialized.Product);
// check serialize not throw exception
deserialized.Serialize();
}
}
}
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/ClaimStakeRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void Execute_Throw_FailedLoadStateException_When_Staking_State_Null()
0));

var stakeAddr = StakeStateV2.DeriveAddress(AgentAddr);
var previousState = _initialState.SetLegacyState(stakeAddr, Null.Value);
var previousState = _initialState.RemoveLegacyState(stakeAddr);
Assert.Throws<FailedLoadStateException>(() =>
Execute(
previousState,
Expand Down Expand Up @@ -447,7 +447,7 @@ public void Execute_Throw_FailedLoadStateException_When_Sheet_Null()
// NOTE: Set StakeRegularFixedRewardSheetTable to Null
var sheetAddr = Addresses.GetSheetAddress(
stakeStateV2.Contract.StakeRegularFixedRewardSheetTableName);
prevState = prevState.SetLegacyState(sheetAddr, Null.Value);
prevState = prevState.RemoveLegacyState(sheetAddr);
Assert.Throws<FailedLoadStateException>(() =>
Execute(
prevState,
Expand All @@ -462,7 +462,7 @@ public void Execute_Throw_FailedLoadStateException_When_Sheet_Null()
// NOTE: Set StakeRegularRewardSheetTableName to Null
sheetAddr = Addresses.GetSheetAddress(
stakeStateV2.Contract.StakeRegularRewardSheetTableName);
prevState = prevState.SetLegacyState(sheetAddr, Null.Value);
prevState = prevState.RemoveLegacyState(sheetAddr);
Assert.Throws<FailedLoadStateException>(() =>
Execute(
prevState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ public CustomEquipmentCraftTest()
{
new ()
{
MinCp = 900,
MaxCp = 1000,
MinCp = 78811,
MaxCp = 118133,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
},
10, null,
21600, null,
};

// Random Icon
Expand All @@ -129,13 +129,13 @@ public CustomEquipmentCraftTest()
{
new ()
{
MinCp = 900,
MaxCp = 1000,
MinCp = 196780,
MaxCp = 236104,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
ElementalType = ElementalType.Water,
},
},
10, null, 8,
21600, null, 17,
};

// Move to next group with additional cost
Expand All @@ -150,13 +150,13 @@ public CustomEquipmentCraftTest()
{
new ()
{
MinCp = 900,
MaxCp = 1000,
MinCp = 78811,
MaxCp = 118133,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
},
10, null,
21600, null,
};
yield return new object?[]
{
Expand All @@ -169,13 +169,13 @@ public CustomEquipmentCraftTest()
{
new ()
{
MinCp = 9000,
MaxCp = 10000,
MinCp = 127372,
MaxCp = 166695,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
},
12, null,
21600 * 2, null,
};
yield return new object?[]
{
Expand All @@ -188,13 +188,13 @@ public CustomEquipmentCraftTest()
{
new ()
{
MinCp = 90000,
MaxCp = 100000,
MinCp = 231654,
MaxCp = 270976,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
},
15, null,
21600 * 8, null,
};

// Multiple slots
Expand All @@ -210,20 +210,20 @@ public CustomEquipmentCraftTest()
{
new ()
{
MinCp = 900,
MaxCp = 1000,
MinCp = 78811,
MaxCp = 118133,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
new ()
{
MinCp = 800,
MaxCp = 900,
MinCp = 196780,
MaxCp = 236104,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
},
10, null,
21600, null,
};
yield return new object?[]
{
Expand All @@ -236,20 +236,20 @@ public CustomEquipmentCraftTest()
{
new ()
{
MinCp = 900,
MaxCp = 1000,
MinCp = 78811,
MaxCp = 118133,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
new ()
{
MinCp = 800,
MaxCp = 900,
MinCp = 196780,
MaxCp = 236104,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
},
10, null,
21600, null,
};
yield return new object?[]
{
Expand All @@ -264,34 +264,34 @@ public CustomEquipmentCraftTest()
{
new ()
{
MinCp = 500,
MaxCp = 600,
MinCp = 39487,
MaxCp = 78810,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Water,
ElementalType = ElementalType.Normal,
},
new ()
{
MinCp = 300,
MaxCp = 400,
MinCp = 78811,
MaxCp = 118133,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Wind,
},
new ()
{
MinCp = 100,
MaxCp = 200,
MinCp = 39487,
MaxCp = 78810,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Water,
ElementalType = ElementalType.Wind,
},
new ()
{
MinCp = 900,
MaxCp = 1000,
MinCp = 39487,
MaxCp = 78810,
ItemSubType = ItemSubType.Weapon,
ElementalType = ElementalType.Normal,
ElementalType = ElementalType.Fire,
},
},
10, null, 4,
21600, null, 22,
};
}

Expand Down Expand Up @@ -321,7 +321,7 @@ public CustomEquipmentCraftTest()
{
new List<CustomCraftData>
{
new () { RecipeId = 1, SlotIndex = 0, IconId = 10131001, },
new () { RecipeId = 1, SlotIndex = 0, IconId = 10140000, },
},
true, 0, false, new List<TestResult>(), 0, typeof(NotEnoughRelationshipException),
};
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/EndPledgeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Execute(int balance)
Signer = patron,
PreviousState = states,
});
Assert.Equal(Null.Value, nextState.GetLegacyState(agent.GetPledgeAddress()));
Assert.Null(nextState.GetLegacyState(agent.GetPledgeAddress()));
Assert.Equal(mead * 0, nextState.GetBalance(agent, mead));
if (balance > 0)
{
Expand Down
Loading

0 comments on commit e70e7fc

Please sign in to comment.