Skip to content

Commit

Permalink
Merge branch 'development' into feature/grinding-test
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrosine1153 authored Oct 11, 2024
2 parents 02f2001 + 1f53d2e commit 6ae3df2
Show file tree
Hide file tree
Showing 86 changed files with 4,650 additions and 1,460 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
Loading

0 comments on commit 6ae3df2

Please sign in to comment.