Skip to content

Commit

Permalink
Merge pull request #2436 from planetarium/world-8-pull-dev
Browse files Browse the repository at this point in the history
World 8 pull development
  • Loading branch information
ipdae authored Mar 4, 2024
2 parents c57f3a7 + f80c987 commit 41145fb
Show file tree
Hide file tree
Showing 209 changed files with 4,051 additions and 4,612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Nekoyume.Model;
using Nekoyume.Module;
using Xunit;
using static Lib9c.SerializeKeys;

namespace Lib9c.DevExtensions.Tests.Action.Craft
{
Expand All @@ -21,13 +20,11 @@ public class UnlockCraftActionTest
private readonly Address _agentAddress;
private readonly Address _avatarAddress;
private readonly IWorld _initialStateV2;
private readonly Address _worldInformationAddress;

public UnlockCraftActionTest()
{
(_tableSheets, _agentAddress, _avatarAddress, _, _initialStateV2) =
InitializeUtil.InitializeStates(isDevEx: true);
_worldInformationAddress = _avatarAddress.Derive(LegacyWorldInformationKey);
}

[Theory]
Expand Down Expand Up @@ -58,8 +55,8 @@ public void StageUnlockTest(string typeIdentifier, int expectedStage)
BlockIndex = 0L
});

var worldInformation =
new WorldInformation((Dictionary)state.GetLegacyState(_worldInformationAddress));
var avatarState = state.GetAvatarState(_avatarAddress);
var worldInformation = avatarState.worldInformation;
Assert.True(worldInformation.IsStageCleared(expectedStage));
}
}
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public FaucetRuneTest(ITestOutputHelper outputHelper)

_initialState = _initialState
.SetAgentState(agentAddress, agentState)
.SetAvatarState(_avatarAddress, avatarState, true, true, true, true);
.SetAvatarState(_avatarAddress, avatarState);
}

[Theory]
Expand Down
2 changes: 2 additions & 0 deletions .Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ public void SetInventoryState(Inventory targetInventory)
[MemberData(nameof(FetchWorldInfo))]
public void SetWorldInformation(int lastClearedStage, WorldInformation targetInfo)
{
// FIXME: The test now writes worldInformation in LegacyAccount,
// which should be moved to Addresses.WorldInformation
var state = Manipulate(
_initialStateV2,
new List<(Address, Address, IValue)>
Expand Down
2 changes: 0 additions & 2 deletions .Lib9c.DevExtensions.Tests/Action/Stage/ClearStageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ public class ClearStageTest
private readonly Address _agentAddress;
private readonly Address _avatarAddress;
private readonly IWorld _initialStateV2;
private readonly Address _worldInfoAddress;

public ClearStageTest()
{
(_tableSheets, _agentAddress, _avatarAddress, _, _initialStateV2) =
InitializeUtil.InitializeStates(isDevEx: true);
_worldInfoAddress = _avatarAddress.Derive(SerializeKeys.LegacyWorldInformationKey);
}

[Fact]
Expand Down
9 changes: 4 additions & 5 deletions .Lib9c.Tests/Action/AccountStateViewExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public void TryGetAvatarStateInvalidCastException()
[Fact]
public void TryGetAvatarStateInvalidAddress()
{
var states = new World(new MockWorldState()).SetAvatarState(
default, _avatarState, true, true, true, true);
var states = new World(new MockWorldState()).SetAvatarState(default, _avatarState);

Assert.False(states.TryGetAvatarState(Addresses.GameConfig, _avatarAddress, out _));
}
Expand All @@ -97,7 +96,7 @@ public void GetAvatarStateV2()
{
IWorld states = new World(new MockWorldState());
states = states
.SetAvatarState(_avatarAddress, _avatarState, true, true, true, true);
.SetAvatarState(_avatarAddress, _avatarState);

var v2 = states.GetAvatarState(_avatarAddress);
Assert.NotNull(v2.inventory);
Expand All @@ -121,7 +120,7 @@ public void GetAvatarStateV2_Throw_FailedLoadStateException(string account)

IWorld states = new World(new MockWorldState());
states = states
.SetAvatarState(_avatarAddress, _avatarState, true, true, true, true);
.SetAvatarState(_avatarAddress, _avatarState);
states = states.SetAccount(
accountAddress,
states.GetAccount(accountAddress).SetNull(_avatarAddress));
Expand All @@ -143,7 +142,7 @@ public void TryGetAvatarState(bool backward)
else
{
states = states
.SetAvatarState(_avatarAddress, _avatarState, true, true, true, true);
.SetAvatarState(_avatarAddress, _avatarState);
}

Assert.True(states.TryGetAvatarState(_agentAddress, _avatarAddress, out _));
Expand Down
28 changes: 28 additions & 0 deletions .Lib9c.Tests/Action/ActionEvaluationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Lib9c.Tests.Action
using MessagePack.Resolvers;
using Nekoyume.Action;
using Nekoyume.Helper;
using Nekoyume.Model.Collection;
using Nekoyume.Model.Item;
using Nekoyume.Model.Market;
using Nekoyume.Model.State;
Expand Down Expand Up @@ -90,6 +91,7 @@ public ActionEvaluationTest()
[InlineData(typeof(CreatePledge))]
[InlineData(typeof(TransferAssets))]
[InlineData(typeof(RuneSummon))]
[InlineData(typeof(ActivateCollection))]
public void Serialize_With_MessagePack(Type actionType)
{
var action = GetAction(actionType);
Expand Down Expand Up @@ -453,6 +455,32 @@ private ActionBase GetAction(Type type)
GroupId = 20001,
SummonCount = 10,
},
ActivateCollection _ => new ActivateCollection
{
AvatarAddress = _sender,
CollectionData =
{
(
1,
new List<ICollectionMaterial>
{
new FungibleCollectionMaterial
{
ItemId = 1,
ItemCount = 2,
},
new NonFungibleCollectionMaterial
{
ItemId = 2,
ItemCount = 3,
NonFungibleId = Guid.NewGuid(),
Level = 1,
SkillContains = true,
},
}
),
},
},
_ => throw new InvalidCastException(),
};
}
Expand Down
141 changes: 141 additions & 0 deletions .Lib9c.Tests/Action/ActivateCollectionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
namespace Lib9c.Tests.Action
{
using System.Collections.Generic;
using System.Linq;
using Libplanet.Action;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Model.Collection;
using Nekoyume.Model.Item;
using Nekoyume.Model.State;
using Nekoyume.Module;
using Nekoyume.TableData;
using Xunit;

public class ActivateCollectionTest
{
private readonly IWorld _initialState;
private readonly Address _agentAddress;
private readonly Address _avatarAddress;
private readonly TableSheets _tableSheets;

public ActivateCollectionTest()
{
var sheets = TableSheetsImporter.ImportSheets();
// Fix csv data for test
sheets[nameof(CollectionSheet)] = @"id,item_id,count,level,skill,item_id,count,level,skill,item_id,count,level,skill,item_id,count,level,skill,item_id,count,level,skill,item_id,count,level,skill,stat_type,modify_type,modify_value,stat_type,modify_type,modify_value,stat_type,modify_type,modify_value
1,10110000,1,0,,302000,2,,,200000,2,,,40100000,1,,,,,,,,,,,ATK,Add,1,,,,,,
2,10110000,1,0,,,,,,,,,,,,,,,,,,,,,,ATK,Percentage,1,,,,,,";

_tableSheets = new TableSheets(sheets);

var privateKey = new PrivateKey();
_agentAddress = privateKey.PublicKey.Address;
var agentState = new AgentState(_agentAddress);

_avatarAddress = _agentAddress.Derive("avatar");
var gameConfigState = new GameConfigState(sheets[nameof(GameConfigSheet)]);
var avatarState = new AvatarState(
_avatarAddress,
_agentAddress,
0,
_tableSheets.GetAvatarSheets(),
gameConfigState,
default
)
{
level = 100,
};
agentState.avatarAddresses.Add(0, _avatarAddress);

_initialState = new World(new MockWorldState())
.SetAgentState(_agentAddress, agentState)
.SetAvatarState(_avatarAddress, avatarState, true, true, true, true)
.SetLegacyState(gameConfigState.address, gameConfigState.Serialize());

foreach (var (key, value) in sheets)
{
_initialState = _initialState
.SetLegacyState(Addresses.TableSheet.Derive(key), value.Serialize());
}
}

[Fact]
public void Execute()
{
var row = _tableSheets.CollectionSheet.Values.First();
var avatarState = _initialState.GetAvatarState(_avatarAddress);
var materials = new List<ICollectionMaterial>();
var random = new TestRandom();
foreach (var material in row.Materials)
{
var itemRow = _tableSheets.ItemSheet[material.ItemId];
var itemType = itemRow.ItemType;
if (itemType == ItemType.Material)
{
var item = ItemFactory.CreateItem(itemRow, random);
avatarState.inventory.AddItem(item, material.Count);
materials.Add(new FungibleCollectionMaterial
{
ItemId = item.Id,
ItemCount = material.Count,
});
}
else
{
for (int i = 0; i < material.Count; i++)
{
var item = ItemFactory.CreateItem(itemRow, random);
var nonFungibleId = ((INonFungibleItem)item).NonFungibleId;
avatarState.inventory.AddItem(item);
if (item.ItemType != ItemType.Consumable)
{
materials.Add(new NonFungibleCollectionMaterial
{
ItemId = item.Id,
NonFungibleId = nonFungibleId,
SkillContains = material.SkillContains,
});
}
else
{
// Add consumable material only one.
if (i == 0)
{
materials.Add(new FungibleCollectionMaterial
{
ItemId = item.Id,
ItemCount = material.Count,
});
}
}
}
}
}

var state = _initialState.SetAvatarState(_avatarAddress, avatarState, false, true, false, false);
IActionContext context = new ActionContext()
{
PreviousState = state,
Signer = _agentAddress,
};
ActivateCollection activateCollection = new ActivateCollection()
{
AvatarAddress = _avatarAddress,
CollectionData =
{
(row.Id, materials),
},
};

var nextState = activateCollection.Execute(context);
var collectionState = nextState.GetCollectionState(_avatarAddress);
Assert.Equal(row.Id, collectionState.Ids.Single());

var nextAvatarState = nextState.GetAvatarState(_avatarAddress);
Assert.Empty(nextAvatarState.inventory.Items);
}
}
}
97 changes: 0 additions & 97 deletions .Lib9c.Tests/Action/AddActivatedAccount0Test.cs

This file was deleted.

2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/ArenahelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ArenaHelperTest(ITestOutputHelper outputHelper)
_state = _state
.SetLegacyState(Addresses.GoldCurrency, goldCurrencyState.Serialize())
.SetAgentState(_agent1Address, agent1State)
.SetAvatarState(_avatar1Address, _avatar1, true, true, true, true)
.SetAvatarState(_avatar1Address, _avatar1)
.SetLegacyState(Addresses.GameConfig, new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize());

Log.Logger = new LoggerConfiguration()
Expand Down
Loading

0 comments on commit 41145fb

Please sign in to comment.