diff --git a/.Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs b/.Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs index 702f89f8e8..948b3e6400 100644 --- a/.Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs +++ b/.Lib9c.DevExtensions.Tests/Action/CreateOrReplaceAvatarTest.cs @@ -9,6 +9,7 @@ using Lib9c.Tests.Action; using Libplanet.Action.State; using Libplanet.Crypto; +using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -30,7 +31,7 @@ public class CreateOrReplaceAvatarTest public CreateOrReplaceAvatarTest() { - _initialStates = new World(new MockWorldState()); + _initialStates = new World(MockUtil.MockModernWorldState); #pragma warning disable CS0618 var ncgCurrency = Currency.Legacy("NCG", 2, null); diff --git a/.Lib9c.DevExtensions.Tests/Action/FaucetCurrencyTest.cs b/.Lib9c.DevExtensions.Tests/Action/FaucetCurrencyTest.cs index 2205f5c2e9..7b4fd7f1f4 100644 --- a/.Lib9c.DevExtensions.Tests/Action/FaucetCurrencyTest.cs +++ b/.Lib9c.DevExtensions.Tests/Action/FaucetCurrencyTest.cs @@ -2,6 +2,7 @@ using Lib9c.Tests.Action; using Libplanet.Action.State; using Libplanet.Crypto; +using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume.Model.State; using Nekoyume.Module; @@ -30,9 +31,8 @@ public FaucetCurrencyTest(ITestOutputHelper outputHelper) _crystal = Currency.Legacy("CRYSTAL", 18, null); #pragma warning restore CS0618 - _initialState = new World( - new MockWorldState() - .AddBalance(GoldCurrencyState.Address, _ncg * int.MaxValue)); + _initialState = new World(MockWorldState.CreateModern() + .SetBalance(GoldCurrencyState.Address, _ncg * int.MaxValue)); var goldCurrencyState = new GoldCurrencyState(_ncg); _agentAddress = new PrivateKey().Address; diff --git a/.Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs b/.Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs index ae007716b1..293c5e5bb7 100644 --- a/.Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs +++ b/.Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs @@ -17,6 +17,7 @@ using Xunit; using Xunit.Abstractions; using static Lib9c.SerializeKeys; +using Libplanet.Mocks; namespace Lib9c.DevExtensions.Tests.Action { @@ -33,7 +34,7 @@ public FaucetRuneTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/AccountExtensions.cs b/.Lib9c.Tests/AccountExtensions.cs deleted file mode 100644 index b1d821da39..0000000000 --- a/.Lib9c.Tests/AccountExtensions.cs +++ /dev/null @@ -1,67 +0,0 @@ -namespace Lib9c.Tests -{ - using Lib9c.Tests.Action; - using Libplanet.Action.State; - using Libplanet.Crypto; - using Libplanet.Store.Trie; - - public static class AccountExtensions - { - private static readonly byte[] _conversionTable = - { - 48, // '0' - 49, // '1' - 50, // '2' - 51, // '3' - 52, // '4' - 53, // '5' - 54, // '6' - 55, // '7' - 56, // '8' - 57, // '9' - 97, // 'a' - 98, // 'b' - 99, // 'c' - 100, // 'd' - 101, // 'e' - 102, // 'f' - }; - - /// - /// A rather shrewed method of removing value from an account. - /// This can be very slow depending on the size of the state. - /// For test backward compatibility only. Should not be used in production. - /// - /// The account to remove the value from. - /// The address of the value to remove. - /// - /// A new instance with the value removed. - /// - public static IAccount SetNull(this IAccount account, Address address) - { - var trie = new MockAccountState().Trie; - var path = ToStateKey(address); - foreach (var kv in account.Trie.IterateValues()) - { - trie = kv.Path.Equals(path) - ? trie - : trie.Set(kv.Path, kv.Value); - } - - return new Account(new AccountState(trie)); - } - - private static KeyBytes ToStateKey(Address address) - { - var addressBytes = address.ByteArray; - byte[] buffer = new byte[addressBytes.Length * 2]; - for (int i = 0; i < addressBytes.Length; i++) - { - buffer[i * 2] = _conversionTable[addressBytes[i] >> 4]; - buffer[i * 2 + 1] = _conversionTable[addressBytes[i] & 0xf]; - } - - return new KeyBytes(buffer); - } - } -} diff --git a/.Lib9c.Tests/Action/AccountStateDeltaExtensionsTest.cs b/.Lib9c.Tests/Action/AccountStateDeltaExtensionsTest.cs index 569fc4f694..526186afe0 100644 --- a/.Lib9c.Tests/Action/AccountStateDeltaExtensionsTest.cs +++ b/.Lib9c.Tests/Action/AccountStateDeltaExtensionsTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Helper; using Nekoyume.Model.Coupons; @@ -46,7 +47,7 @@ public AccountStateDeltaExtensionsTest() public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrystal, Type exc) { var context = new ActionContext(); - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); var rewardInfoAddress = new PrivateKey().Address; var rewardRecord = new WorldBossKillRewardRecord(); for (int i = 0; i < level; i++) @@ -106,7 +107,7 @@ public void SetWorldBossKillReward(int level, int expectedRune, int expectedCrys [Fact] public void SetCouponWallet() { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); var guid1 = new Guid("6856AE42-A820-4041-92B0-5D7BAA52F2AA"); var guid2 = new Guid("701BA698-CCB9-4FC7-B88F-7CB8C707D135"); var guid3 = new Guid("910296E7-34E4-45D7-9B4E-778ED61F278B"); @@ -162,7 +163,7 @@ public void Mead(int agentBalance) var mead = Currencies.Mead; var price = RequestPledge.DefaultRefillMead * mead; ActionContext context = new ActionContext(); - IWorld states = new World(new MockWorldState()) + IWorld states = new World(MockUtil.MockModernWorldState) .SetLegacyState( agentContractAddress, List.Empty.Add(patron.Serialize()).Add(true.Serialize())) diff --git a/.Lib9c.Tests/Action/AccountStateViewExtensionsTest.cs b/.Lib9c.Tests/Action/AccountStateViewExtensionsTest.cs index 993eef78ad..748db0cfd5 100644 --- a/.Lib9c.Tests/Action/AccountStateViewExtensionsTest.cs +++ b/.Lib9c.Tests/Action/AccountStateViewExtensionsTest.cs @@ -9,6 +9,7 @@ namespace Lib9c.Tests.Action using Lib9c.Tests.Extensions; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -49,7 +50,7 @@ public AccountStateViewExtensionsTest() [Fact] public void TryGetAvatarStateEmptyAddress() { - var states = new World(new MockWorldState()); + var states = new World(MockUtil.MockModernWorldState); Assert.False(states.TryGetAvatarState(default, default, out _)); } @@ -57,7 +58,7 @@ public void TryGetAvatarStateEmptyAddress() [Fact] public void TryGetAvatarStateAddressKeyNotFoundException() { - var states = new World(new MockWorldState()).SetLegacyState(default, Dictionary.Empty); + var states = new World(MockUtil.MockModernWorldState).SetLegacyState(default, Dictionary.Empty); Assert.False(states.TryGetAvatarState(default, default, out _)); } @@ -65,7 +66,7 @@ public void TryGetAvatarStateAddressKeyNotFoundException() [Fact] public void TryGetAvatarStateKeyNotFoundException() { - var states = new World(new MockWorldState()) + var states = new World(MockUtil.MockModernWorldState) .SetLegacyState( default, Dictionary.Empty @@ -78,7 +79,7 @@ public void TryGetAvatarStateKeyNotFoundException() [Fact] public void TryGetAvatarStateInvalidCastException() { - var states = new World(new MockWorldState()).SetLegacyState(default, default(Text)); + var states = new World(MockUtil.MockModernWorldState).SetLegacyState(default, default(Text)); Assert.False(states.TryGetAvatarState(default, default, out _)); } @@ -86,7 +87,7 @@ public void TryGetAvatarStateInvalidCastException() [Fact] public void TryGetAvatarStateInvalidAddress() { - var states = new World(new MockWorldState()).SetAvatarState(default, _avatarState); + var states = new World(MockUtil.MockModernWorldState).SetAvatarState(default, _avatarState); Assert.False(states.TryGetAvatarState(Addresses.GameConfig, _avatarAddress, out _)); } @@ -94,7 +95,7 @@ public void TryGetAvatarStateInvalidAddress() [Fact] public void GetAvatarStateV2() { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); states = states .SetAvatarState(_avatarAddress, _avatarState); @@ -118,12 +119,12 @@ public void GetAvatarStateV2_Throw_FailedLoadStateException(string account) _ => throw new ArgumentException(), }; - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); states = states .SetAvatarState(_avatarAddress, _avatarState); states = states.SetAccount( accountAddress, - states.GetAccount(accountAddress).SetNull(_avatarAddress)); + states.GetAccount(accountAddress).RemoveState(_avatarAddress)); var exc = Assert.Throws(() => states.GetAvatarState(_avatarAddress)); Assert.Contains(account, exc.Message); } @@ -133,7 +134,7 @@ public void GetAvatarStateV2_Throw_FailedLoadStateException(string account) [InlineData(false)] public void TryGetAvatarState(bool backward) { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); if (backward) { states = states @@ -151,7 +152,7 @@ public void TryGetAvatarState(bool backward) [Fact] public void GetStatesAsDict() { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); var dict = new Dictionary { { new PrivateKey().Address, Null.Value }, @@ -178,7 +179,7 @@ public void GetStatesAsDict() [Fact] public void GetSheets() { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); SheetsExtensionsTest.InitSheets( states, out _, @@ -205,7 +206,7 @@ public void GetSheets() [InlineData(true)] public void GetCrystalCostState(bool exist) { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); int expectedCount = exist ? 1 : 0; FungibleAssetValue expectedCrystal = exist ? 100 * CrystalCalculator.CRYSTAL @@ -238,7 +239,7 @@ public void GetCrystalCostStates(long blockIndex, bool previousWeeklyExist) Address previousCostAddress = Addresses.GetWeeklyCrystalCostAddress(weeklyIndex - 1); Address beforePreviousCostAddress = Addresses.GetWeeklyCrystalCostAddress(weeklyIndex - 2); var crystalCostState = new CrystalCostState(default, 100 * CrystalCalculator.CRYSTAL); - IWorld state = new World(new MockWorldState()) + IWorld state = new World(MockUtil.MockModernWorldState) .SetLegacyState(dailyCostAddress, crystalCostState.Serialize()) .SetLegacyState(weeklyCostAddress, crystalCostState.Serialize()) .SetLegacyState(previousCostAddress, crystalCostState.Serialize()) @@ -268,7 +269,7 @@ public void GetCrystalCostStates(long blockIndex, bool previousWeeklyExist) [Fact] public void GetCouponWallet() { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); var guid1 = new Guid("6856AE42-A820-4041-92B0-5D7BAA52F2AA"); var guid2 = new Guid("701BA698-CCB9-4FC7-B88F-7CB8C707D135"); var guid3 = new Guid("910296E7-34E4-45D7-9B4E-778ED61F278B"); diff --git a/.Lib9c.Tests/Action/ActionContextExtensionsTest.cs b/.Lib9c.Tests/Action/ActionContextExtensionsTest.cs index 50dd23f3b0..6af16f6417 100644 --- a/.Lib9c.Tests/Action/ActionContextExtensionsTest.cs +++ b/.Lib9c.Tests/Action/ActionContextExtensionsTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -143,7 +144,7 @@ public static IEnumerable IsPreviewNetTestcases() [MemberData(nameof(IsMainNetTestcases))] public void IsMainNet(GoldCurrencyState goldCurrencyState, bool expected) { - var state = new World(new MockWorldState()).SetLegacyState(Addresses.GoldCurrency, goldCurrencyState.Serialize()); + var state = new World(MockUtil.MockModernWorldState).SetLegacyState(Addresses.GoldCurrency, goldCurrencyState.Serialize()); IActionContext context = new ActionContext { PreviousState = state, diff --git a/.Lib9c.Tests/Action/ActionEvaluationTest.cs b/.Lib9c.Tests/Action/ActionEvaluationTest.cs index 3a58483705..2f20cfef93 100644 --- a/.Lib9c.Tests/Action/ActionEvaluationTest.cs +++ b/.Lib9c.Tests/Action/ActionEvaluationTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using Lib9c.Formatters; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using MessagePack; using MessagePack.Resolvers; @@ -34,7 +35,7 @@ public ActionEvaluationTest() #pragma warning restore CS0618 _signer = new PrivateKey().Address; _sender = new PrivateKey().Address; - _states = new World(new MockWorldState()) + _states = new World(MockUtil.MockModernWorldState) .SetLegacyState(_signer, (Text)"ANYTHING") .SetLegacyState(default, Dictionary.Empty.Add("key", "value")) .MintAsset(context, _signer, _currency * 10000); diff --git a/.Lib9c.Tests/Action/ActivateAccount0Test.cs b/.Lib9c.Tests/Action/ActivateAccount0Test.cs index 2066fd1040..2343a3e7c9 100644 --- a/.Lib9c.Tests/Action/ActivateAccount0Test.cs +++ b/.Lib9c.Tests/Action/ActivateAccount0Test.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Model; using Nekoyume.Model.State; @@ -19,16 +20,13 @@ public void Execute() var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); - var state = new World( - new MockWorldState() - .SetState( - ReservedAddresses.LegacyAccount, - ActivatedAccountsState.Address, - new ActivatedAccountsState().Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, - pendingActivation.address, - pendingActivation.Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState( + ActivatedAccountsState.Address, + new ActivatedAccountsState().Serialize()) + .SetLegacyState( + pendingActivation.address, + pendingActivation.Serialize()); ActivateAccount0 action = activationKey.CreateActivateAccount0(nonce); IWorld nextState = action.Execute(new ActionContext() @@ -53,16 +51,13 @@ public void ExecuteWithInvalidSignature() var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); - var state = new World( - new MockWorldState() - .SetState( - ReservedAddresses.LegacyAccount, - ActivatedAccountsState.Address, - new ActivatedAccountsState().Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, - pendingActivation.address, - pendingActivation.Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState( + ActivatedAccountsState.Address, + new ActivatedAccountsState().Serialize()) + .SetLegacyState( + pendingActivation.address, + pendingActivation.Serialize()); // 잘못된 논스를 넣습니다. ActivateAccount0 action = activationKey.CreateActivateAccount0(new byte[] { 0x00, }); @@ -86,12 +81,10 @@ public void ExecuteWithNonExistsPending() ActivationKey.Create(privateKey, nonce); // state에는 pendingActivation에 해당하는 대기가 없는 상태를 가정합니다. - var state = new World( - new MockWorldState() - .SetState( - ReservedAddresses.LegacyAccount, - ActivatedAccountsState.Address, - new ActivatedAccountsState().Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState( + ActivatedAccountsState.Address, + new ActivatedAccountsState().Serialize()); ActivateAccount0 action = activationKey.CreateActivateAccount0(nonce); Assert.Throws(() => @@ -114,7 +107,7 @@ public void ExecuteWithNonExistsAccounts() ActivationKey.Create(privateKey, nonce); // state가 올바르게 초기화되지 않은 상태를 가정합니다. - var state = new World(new MockWorldState()); + var state = new World(MockUtil.MockModernWorldState); ActivateAccount0 action = activationKey.CreateActivateAccount0(nonce); Assert.Throws(() => @@ -135,16 +128,13 @@ public void ForbidReusingActivationKey() var privateKey = new PrivateKey(); (ActivationKey activationKey, PendingActivationState pendingActivation) = ActivationKey.Create(privateKey, nonce); - var state = new World( - new MockWorldState() - .SetState( - ReservedAddresses.LegacyAccount, - ActivatedAccountsState.Address, - new ActivatedAccountsState().Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, - pendingActivation.address, - pendingActivation.Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState( + ActivatedAccountsState.Address, + new ActivatedAccountsState().Serialize()) + .SetLegacyState( + pendingActivation.address, + pendingActivation.Serialize()); ActivateAccount0 action = activationKey.CreateActivateAccount0(nonce); IWorld nextState = action.Execute(new ActionContext() diff --git a/.Lib9c.Tests/Action/ActivateAccountTest.cs b/.Lib9c.Tests/Action/ActivateAccountTest.cs index 752ea3dbac..0aa531f1bf 100644 --- a/.Lib9c.Tests/Action/ActivateAccountTest.cs +++ b/.Lib9c.Tests/Action/ActivateAccountTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Model; using Nekoyume.Model.State; @@ -25,7 +26,7 @@ public void Execute(bool invalid, bool pendingExist, bool alreadyActivated, Type ActivationKey.Create(privateKey, nonce); Address activatedAddress = default(Address).Derive(ActivationKey.DeriveKey); - IWorld state = new World(new MockWorldState()); + IWorld state = new World(MockUtil.MockModernWorldState); if (pendingExist) { diff --git a/.Lib9c.Tests/Action/ActivateCollectionTest.cs b/.Lib9c.Tests/Action/ActivateCollectionTest.cs index e51d4fbb7f..2d36313d67 100644 --- a/.Lib9c.Tests/Action/ActivateCollectionTest.cs +++ b/.Lib9c.Tests/Action/ActivateCollectionTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model.Collection; @@ -50,7 +51,7 @@ public ActivateCollectionTest() }; agentState.avatarAddresses.Add(0, _avatarAddress); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetAgentState(_agentAddress, agentState) .SetAvatarState(_avatarAddress, avatarState, true, true, true, true) .SetLegacyState(gameConfigState.address, gameConfigState.Serialize()); diff --git a/.Lib9c.Tests/Action/AddActivatedAccountTest.cs b/.Lib9c.Tests/Action/AddActivatedAccountTest.cs index 41c7e4e9fd..9a4240fc54 100644 --- a/.Lib9c.Tests/Action/AddActivatedAccountTest.cs +++ b/.Lib9c.Tests/Action/AddActivatedAccountTest.cs @@ -3,6 +3,7 @@ namespace Lib9c.Tests.Action using System; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Model; using Nekoyume.Model.State; @@ -19,9 +20,8 @@ public class AddActivatedAccountTest public void Execute(bool isAdmin, long blockIndex, bool alreadyActivated, Type exc) { var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7"); - IWorld state = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, new AdminState(admin, 100).Serialize())); + IWorld state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, new AdminState(admin, 100).Serialize()); var newComer = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var activatedAddress = newComer.Derive(ActivationKey.DeriveKey); if (alreadyActivated) diff --git a/.Lib9c.Tests/Action/AddRedeemCodeTest.cs b/.Lib9c.Tests/Action/AddRedeemCodeTest.cs index c9cdb81c6c..7e04a39cdf 100644 --- a/.Lib9c.Tests/Action/AddRedeemCodeTest.cs +++ b/.Lib9c.Tests/Action/AddRedeemCodeTest.cs @@ -2,6 +2,7 @@ namespace Lib9c.Tests.Action { using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model.State; @@ -16,9 +17,8 @@ public void CheckPermission() { var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); - var initStates = new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize()); - var state = new World(initStates); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()); var action = new AddRedeemCode { redeemCsv = "New Value", @@ -68,7 +68,7 @@ public void Execute() { Signer = adminAddress, BlockIndex = 0, - PreviousState = new World(new MockWorldState()) + PreviousState = new World(MockUtil.MockModernWorldState) .SetLegacyState(Addresses.Admin, adminState.Serialize()) .SetLegacyState(Addresses.RedeemCode, new RedeemCodeState(new RedeemCodeListSheet()).Serialize()), }); @@ -90,7 +90,7 @@ public void ExecuteThrowSheetRowValidateException() var sheet = new RedeemCodeListSheet(); sheet.Set(csv); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(Addresses.RedeemCode, new RedeemCodeState(sheet).Serialize()); var action = new AddRedeemCode diff --git a/.Lib9c.Tests/Action/ApprovePledgeTest.cs b/.Lib9c.Tests/Action/ApprovePledgeTest.cs index fef336d40d..f0aaddfcef 100644 --- a/.Lib9c.Tests/Action/ApprovePledgeTest.cs +++ b/.Lib9c.Tests/Action/ApprovePledgeTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model.State; @@ -20,7 +21,7 @@ public void Execute(int mead) var address = new PrivateKey().Address; var patron = new PrivateKey().Address; var contractAddress = address.Derive(nameof(RequestPledge)); - IWorld states = new World(new MockWorldState()) + IWorld states = new World(MockUtil.MockModernWorldState) .SetLegacyState( contractAddress, List.Empty.Add(patron.Serialize()).Add(false.Serialize()).Add(mead.Serialize()) @@ -62,7 +63,7 @@ public void Execute_Throw_Exception(bool invalidPatron, bool alreadyContract, Ty contract = List.Empty.Add(patron.Serialize()).Add(true.Serialize()); } - IWorld states = new World(new MockWorldState()).SetLegacyState(contractAddress, contract); + IWorld states = new World(MockUtil.MockModernWorldState).SetLegacyState(contractAddress, contract); var action = new ApprovePledge { diff --git a/.Lib9c.Tests/Action/ArenahelperTest.cs b/.Lib9c.Tests/Action/ArenahelperTest.cs index cda73b8043..7f94084a3e 100644 --- a/.Lib9c.Tests/Action/ArenahelperTest.cs +++ b/.Lib9c.Tests/Action/ArenahelperTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -35,7 +36,7 @@ public ArenaHelperTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _state = new World(new MockWorldState()); + _state = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); var tableSheets = new TableSheets(sheets); diff --git a/.Lib9c.Tests/Action/BattleArenaTest.cs b/.Lib9c.Tests/Action/BattleArenaTest.cs index 23397678b2..76b680273e 100644 --- a/.Lib9c.Tests/Action/BattleArenaTest.cs +++ b/.Lib9c.Tests/Action/BattleArenaTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -47,7 +48,7 @@ public BattleArenaTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialStates = new World(new MockWorldState()); + _initialStates = new World(MockUtil.MockModernWorldState); _sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in _sheets) diff --git a/.Lib9c.Tests/Action/BurnAssetTest.cs b/.Lib9c.Tests/Action/BurnAssetTest.cs index 5a05f505c6..5d90e088b0 100644 --- a/.Lib9c.Tests/Action/BurnAssetTest.cs +++ b/.Lib9c.Tests/Action/BurnAssetTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Exceptions; using Nekoyume.Module; @@ -20,17 +21,14 @@ public BurnAssetTest() { _signer = new PrivateKey().Address; _prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_signer, Currencies.Crystal * 100) .SetBalance( _signer.Derive(string.Format( CultureInfo.InvariantCulture, CreateAvatar.DeriveFormat, - 1 - )), - Currencies.DailyRewardRune * 20 - ) - ); + 1)), + Currencies.DailyRewardRune * 20)); } [Fact] diff --git a/.Lib9c.Tests/Action/Buy7Test.cs b/.Lib9c.Tests/Action/Buy7Test.cs index 08543d57c3..508cb5e3b6 100644 --- a/.Lib9c.Tests/Action/Buy7Test.cs +++ b/.Lib9c.Tests/Action/Buy7Test.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -40,7 +41,7 @@ public Buy7Test(ITestOutputHelper outputHelper) .CreateLogger(); var context = new ActionContext(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { @@ -444,7 +445,7 @@ public void Execute_Throw_FailedLoadStateException() Assert.Throws(() => action.Execute(new ActionContext() { BlockIndex = 0, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), RandomSeed = 0, Signer = _buyerAgentAddress, }) diff --git a/.Lib9c.Tests/Action/BuyMultipleTest.cs b/.Lib9c.Tests/Action/BuyMultipleTest.cs index 5aae102522..3f212dd6bb 100644 --- a/.Lib9c.Tests/Action/BuyMultipleTest.cs +++ b/.Lib9c.Tests/Action/BuyMultipleTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using System.Numerics; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -35,7 +36,7 @@ public BuyMultipleTest(ITestOutputHelper outputHelper) .CreateLogger(); var context = new ActionContext(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { @@ -407,7 +408,7 @@ public void ExecuteThrowInvalidAddressException() Assert.Throws(() => action.Execute(new ActionContext() { BlockIndex = 0, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), RandomSeed = 0, Signer = _buyerAgentAddress, }) @@ -426,7 +427,7 @@ public void ExecuteThrowFailedLoadStateException() Assert.Throws(() => action.Execute(new ActionContext() { BlockIndex = 0, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), RandomSeed = 0, Signer = _buyerAgentAddress, }) diff --git a/.Lib9c.Tests/Action/BuyProductTest.cs b/.Lib9c.Tests/Action/BuyProductTest.cs index 509175c5ee..20327a1570 100644 --- a/.Lib9c.Tests/Action/BuyProductTest.cs +++ b/.Lib9c.Tests/Action/BuyProductTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -46,7 +47,7 @@ public BuyProductTest(ITestOutputHelper outputHelper) .CreateLogger(); var context = new ActionContext(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/Action/BuyTest.cs b/.Lib9c.Tests/Action/BuyTest.cs index 9ad40c8916..ceb1408701 100644 --- a/.Lib9c.Tests/Action/BuyTest.cs +++ b/.Lib9c.Tests/Action/BuyTest.cs @@ -11,6 +11,7 @@ namespace Lib9c.Tests.Action using Lib9c.Tests.TestHelper; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -45,7 +46,7 @@ public BuyTest(ITestOutputHelper outputHelper) .CreateLogger(); var context = new ActionContext(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/Action/CancelProductRegistration0Test.cs b/.Lib9c.Tests/Action/CancelProductRegistration0Test.cs index 97b097daaa..a8323be1af 100644 --- a/.Lib9c.Tests/Action/CancelProductRegistration0Test.cs +++ b/.Lib9c.Tests/Action/CancelProductRegistration0Test.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -33,7 +34,7 @@ public CancelProductRegistration0Test(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/Action/ChargeActionPointTest.cs b/.Lib9c.Tests/Action/ChargeActionPointTest.cs index 258b691cdd..2b57f745f7 100644 --- a/.Lib9c.Tests/Action/ChargeActionPointTest.cs +++ b/.Lib9c.Tests/Action/ChargeActionPointTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model.Item; @@ -46,7 +47,7 @@ public ChargeActionPointTest() }; agent.avatarAddresses.Add(0, _avatarAddress); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(Addresses.GameConfig, gameConfigState.Serialize()) .SetAgentState(_agentAddress, agent) .SetAvatarState(_avatarAddress, avatarState); diff --git a/.Lib9c.Tests/Action/ClaimItemsTest.cs b/.Lib9c.Tests/Action/ClaimItemsTest.cs index c74ddb646d..d358703d7a 100644 --- a/.Lib9c.Tests/Action/ClaimItemsTest.cs +++ b/.Lib9c.Tests/Action/ClaimItemsTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -36,7 +37,7 @@ public ClaimItemsTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) diff --git a/.Lib9c.Tests/Action/ClaimRaidRewardTest.cs b/.Lib9c.Tests/Action/ClaimRaidRewardTest.cs index d2a07dfead..541bb31d29 100644 --- a/.Lib9c.Tests/Action/ClaimRaidRewardTest.cs +++ b/.Lib9c.Tests/Action/ClaimRaidRewardTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Helper; @@ -20,7 +21,7 @@ public ClaimRaidRewardTest() { var tableCsv = TableSheetsImporter.ImportSheets(); _tableSheets = new TableSheets(tableCsv); - _state = new World(new MockWorldState()); + _state = new World(MockUtil.MockModernWorldState); foreach (var kv in tableCsv) { _state = _state.SetLegacyState(Addresses.GetSheetAddress(kv.Key), kv.Value.Serialize()); diff --git a/.Lib9c.Tests/Action/ClaimWorldBossKillRewardTest.cs b/.Lib9c.Tests/Action/ClaimWorldBossKillRewardTest.cs index ce8f01a076..cafdbc156e 100644 --- a/.Lib9c.Tests/Action/ClaimWorldBossKillRewardTest.cs +++ b/.Lib9c.Tests/Action/ClaimWorldBossKillRewardTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -27,7 +28,7 @@ public void Execute(long blockIndex, Type exc) var tableSheets = new TableSheets(sheets); Address agentAddress = new PrivateKey().Address; Address avatarAddress = new PrivateKey().Address; - IWorld state = new World(new MockWorldState()); + IWorld state = new World(MockUtil.MockModernWorldState); var runeWeightSheet = new RuneWeightSheet(); runeWeightSheet.Set(@"id,boss_id,rank,rune_id,weight diff --git a/.Lib9c.Tests/Action/CombinationConsumableTest.cs b/.Lib9c.Tests/Action/CombinationConsumableTest.cs index 44844b56f3..00116f45b5 100644 --- a/.Lib9c.Tests/Action/CombinationConsumableTest.cs +++ b/.Lib9c.Tests/Action/CombinationConsumableTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -57,7 +58,7 @@ public CombinationConsumableTest() var gold = new GoldCurrencyState(Currency.Legacy("NCG", 2, null)); #pragma warning restore CS0618 - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetAgentState(_agentAddress, agentState) .SetAvatarState(_avatarAddress, avatarState) .SetLegacyState( diff --git a/.Lib9c.Tests/Action/CombinationEquipmentTest.cs b/.Lib9c.Tests/Action/CombinationEquipmentTest.cs index e790df9d75..fe9b374b27 100644 --- a/.Lib9c.Tests/Action/CombinationEquipmentTest.cs +++ b/.Lib9c.Tests/Action/CombinationEquipmentTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -76,7 +77,7 @@ public CombinationEquipmentTest(ITestOutputHelper outputHelper) _slotAddress, 0); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(_slotAddress, combinationSlotState.Serialize()) .SetLegacyState(GoldCurrencyState.Address, gold.Serialize()); diff --git a/.Lib9c.Tests/Action/Common/MockAccountState.cs b/.Lib9c.Tests/Action/Common/MockAccountState.cs deleted file mode 100644 index ed31addbf5..0000000000 --- a/.Lib9c.Tests/Action/Common/MockAccountState.cs +++ /dev/null @@ -1,219 +0,0 @@ -#nullable enable -namespace Lib9c.Tests.Action -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Numerics; - using System.Security.Cryptography; - using Bencodex.Types; - using Libplanet.Action.State; - using Libplanet.Common; - using Libplanet.Crypto; - using Libplanet.Store; - using Libplanet.Store.Trie; - using Libplanet.Types.Assets; - using Libplanet.Types.Consensus; - - /// - /// A mock implementation of with various overloaded methods for - /// improving QoL. - /// - /// - /// All methods are pretty self-explanatory with no side-effects. There are some caveats: - /// - /// - /// Every balance related operation can accept a negative amount. Each behave as expected. - /// That is, adding negative amount would decrease the balance. - /// - /// - /// Negative balance is allowed for all cases. This includes total supply. - /// - /// - /// Total supply is not automatically tracked. That is, changing the balance associated - /// with an does not change the total supply in any way. - /// Total supply must be explicitly set if needed. - /// - /// - /// There are only few restrictions that apply for manipulating this object, mostly - /// pertaining to total supplies: - /// - /// - /// It is not possible to set a total supply amount for a currency that is - /// not trackable. - /// - /// - /// It is not possible to set a total supply amount that is over the currency's - /// capped maximum total supply. - /// - /// - /// - /// - /// - public class MockAccountState : IAccountState - { - private readonly IStateStore _stateStore; - - public MockAccountState() - : this(new TrieStateStore(new MemoryKeyValueStore()), null) - { - } - - public MockAccountState( - IStateStore stateStore, - HashDigest? stateRootHash = null) - { - _stateStore = stateStore; - Trie = stateStore.GetStateRoot(stateRootHash); - } - - public ITrie Trie { get; } - - public IValue? GetState(Address address) => - Trie.Get(MockKeyConverters.ToStateKey(address)); - - public IReadOnlyList GetStates(IReadOnlyList
addresses) => - addresses.Select(GetState).ToList(); - - public FungibleAssetValue GetBalance(Address address, Currency currency) => - Trie.Get(MockKeyConverters.ToFungibleAssetKey(address, currency)) is Integer rawValue - ? FungibleAssetValue.FromRawValue(currency, rawValue) - : currency * 0; - - public FungibleAssetValue GetTotalSupply(Currency currency) - { - if (!currency.TotalSupplyTrackable) - { - var msg = - $"The total supply value of the currency {currency} is not trackable " + - "because it is a legacy untracked currency which might have been" + - "established before the introduction of total supply tracking support."; - throw new TotalSupplyNotTrackableException(msg, currency); - } - - return Trie.Get(MockKeyConverters.ToTotalSupplyKey(currency)) is Integer rawValue - ? FungibleAssetValue.FromRawValue(currency, rawValue) - : currency * 0; - } - - public ValidatorSet GetValidatorSet() => - Trie.Get(MockKeyConverters.ValidatorSetKey) is List list - ? new ValidatorSet(list) - : new ValidatorSet(); - - public MockAccountState SetState(Address address, IValue state) => - new MockAccountState( - _stateStore, - _stateStore.Commit(Trie.Set(MockKeyConverters.ToStateKey(address), state)).Hash); - - public MockAccountState SetBalance( - Address address, FungibleAssetValue amount) => - SetBalance((address, amount.Currency), amount.RawValue); - - public MockAccountState SetBalance( - Address address, Currency currency, BigInteger rawAmount) => - SetBalance((address, currency), rawAmount); - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockAccountState SetBalance( - (Address Address, Currency Currency) pair, BigInteger rawAmount) => - new MockAccountState( - _stateStore, - _stateStore.Commit( - Trie.Set( - MockKeyConverters.ToFungibleAssetKey(pair.Address, pair.Currency), - new Integer(rawAmount))).Hash); -#pragma warning restore SA1118 // Parameter should not span multiple lines - - public MockAccountState AddBalance(Address address, FungibleAssetValue amount) => - AddBalance((address, amount.Currency), amount.RawValue); - - public MockAccountState AddBalance( - Address address, Currency currency, BigInteger rawAmount) => - AddBalance((address, currency), rawAmount); - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockAccountState AddBalance( - (Address Address, Currency Currency) pair, BigInteger rawAmount) => - SetBalance( - pair, - (Trie.Get(MockKeyConverters.ToFungibleAssetKey(pair.Address, pair.Currency)) is - Integer amount ? amount : 0) + rawAmount); -#pragma warning restore SA1118 // Parameter should not span multiple lines - - public MockAccountState SubtractBalance( - Address address, FungibleAssetValue amount) => - SubtractBalance((address, amount.Currency), amount.RawValue); - - public MockAccountState SubtractBalance( - Address address, Currency currency, BigInteger rawAmount) => - SubtractBalance((address, currency), rawAmount); - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockAccountState SubtractBalance( - (Address Address, Currency Currency) pair, BigInteger rawAmount) => - SetBalance( - pair, - (Trie.Get(MockKeyConverters.ToFungibleAssetKey(pair.Address, pair.Currency)) is - Integer amount ? amount : 0) - rawAmount); -#pragma warning restore SA1118 // Parameter should not span multiple lines - - public MockAccountState TransferBalance( - Address sender, Address recipient, FungibleAssetValue amount) => - TransferBalance(sender, recipient, amount.Currency, amount.RawValue); - - public MockAccountState TransferBalance( - Address sender, Address recipient, Currency currency, BigInteger rawAmount) => - SubtractBalance(sender, currency, rawAmount).AddBalance(recipient, currency, rawAmount); - - public MockAccountState SetTotalSupply(FungibleAssetValue amount) => - SetTotalSupply(amount.Currency, amount.RawValue); - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockAccountState SetTotalSupply(Currency currency, BigInteger rawAmount) => - currency.TotalSupplyTrackable - ? !(currency.MaximumSupply is FungibleAssetValue maximumSupply) || - rawAmount <= maximumSupply.RawValue - ? new MockAccountState( - _stateStore, - _stateStore.Commit( - Trie.Set(MockKeyConverters.ToTotalSupplyKey(currency), new Integer(rawAmount))).Hash) - : throw new ArgumentException( - $"Given {currency}'s total supply is capped at {maximumSupply.RawValue} " + - $"and cannot be set to {rawAmount}.") - : throw new ArgumentException( - $"Given {currency} is not trackable."); -#pragma warning restore SA1118 // Parameter should not span multiple lines - - public MockAccountState AddTotalSupply(FungibleAssetValue amount) => - AddTotalSupply(amount.Currency, amount.RawValue); - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockAccountState AddTotalSupply(Currency currency, BigInteger rawAmount) => - SetTotalSupply( - currency, - (Trie.Get(MockKeyConverters.ToTotalSupplyKey(currency)) is - Integer amount ? amount : 0) + rawAmount); -#pragma warning restore SA1118 // Parameter should not span multiple lines - - public MockAccountState SubtractTotalSupply(FungibleAssetValue amount) => - SubtractTotalSupply(amount.Currency, amount.RawValue); - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockAccountState SubtractTotalSupply(Currency currency, BigInteger rawAmount) => - SetTotalSupply( - currency, - (Trie.Get(MockKeyConverters.ToTotalSupplyKey(currency)) is - Integer amount ? amount : 0) - rawAmount); -#pragma warning restore SA1118 // Parameter should not span multiple lines - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockAccountState SetValidator(Validator validator) => - new MockAccountState( - _stateStore, - _stateStore.Commit( - Trie.Set(MockKeyConverters.ValidatorSetKey, GetValidatorSet().Update(validator).Bencoded)).Hash); -#pragma warning restore SA1118 // Parameter should not span multiple lines - - } -} diff --git a/.Lib9c.Tests/Action/Common/MockKeyConverters.cs b/.Lib9c.Tests/Action/Common/MockKeyConverters.cs deleted file mode 100644 index 44d0239eac..0000000000 --- a/.Lib9c.Tests/Action/Common/MockKeyConverters.cs +++ /dev/null @@ -1,96 +0,0 @@ -namespace Lib9c.Tests.Action -{ - using Libplanet.Crypto; - using Libplanet.Store.Trie; - using Libplanet.Types.Assets; - - internal static class MockKeyConverters - { - // "___" - internal static readonly KeyBytes ValidatorSetKey = - new KeyBytes(new byte[] { _underScore, _underScore, _underScore }); - - private const byte _underScore = 95; // '_' - - private static readonly byte[] _conversionTable = - { - 48, // '0' - 49, // '1' - 50, // '2' - 51, // '3' - 52, // '4' - 53, // '5' - 54, // '6' - 55, // '7' - 56, // '8' - 57, // '9' - 97, // 'a' - 98, // 'b' - 99, // 'c' - 100, // 'd' - 101, // 'e' - 102, // 'f' - }; - - // $"{ByteUtil.Hex(address.ByteArray)}" - internal static KeyBytes ToStateKey(Address address) - { - var addressBytes = address.ByteArray; - byte[] buffer = new byte[addressBytes.Length * 2]; - for (int i = 0; i < addressBytes.Length; i++) - { - buffer[i * 2] = _conversionTable[addressBytes[i] >> 4]; - buffer[i * 2 + 1] = _conversionTable[addressBytes[i] & 0xf]; - } - - return new KeyBytes(buffer); - } - - // $"_{ByteUtil.Hex(address.ByteArray)}_{ByteUtil.Hex(currency.Hash.ByteArray)}" - internal static KeyBytes ToFungibleAssetKey(Address address, Currency currency) - { - var addressBytes = address.ByteArray; - var currencyBytes = currency.Hash.ByteArray; - byte[] buffer = new byte[addressBytes.Length * 2 + currencyBytes.Length * 2 + 2]; - - buffer[0] = _underScore; - for (int i = 0; i < addressBytes.Length; i++) - { - buffer[1 + i * 2] = _conversionTable[addressBytes[i] >> 4]; - buffer[1 + i * 2 + 1] = _conversionTable[addressBytes[i] & 0xf]; - } - - var offset = addressBytes.Length * 2; - buffer[offset + 1] = _underScore; - for (int i = 0; i < currencyBytes.Length; i++) - { - buffer[offset + 2 + i * 2] = _conversionTable[currencyBytes[i] >> 4]; - buffer[offset + 2 + i * 2 + 1] = _conversionTable[currencyBytes[i] & 0xf]; - } - - return new KeyBytes(buffer); - } - - internal static KeyBytes ToFungibleAssetKey( - (Address Address, Currency Currency) pair) => - ToFungibleAssetKey(pair.Address, pair.Currency); - - // $"__{ByteUtil.Hex(currency.Hash.ByteArray)}" - internal static KeyBytes ToTotalSupplyKey(Currency currency) - { - var currencyBytes = currency.Hash.ByteArray; - byte[] buffer = new byte[currencyBytes.Length * 2 + 2]; - - buffer[0] = _underScore; - buffer[1] = _underScore; - - for (int i = 0; i < currencyBytes.Length; i++) - { - buffer[2 + i * 2] = _conversionTable[currencyBytes[i] >> 4]; - buffer[2 + i * 2 + 1] = _conversionTable[currencyBytes[i] & 0xf]; - } - - return new KeyBytes(buffer); - } - } -} diff --git a/.Lib9c.Tests/Action/Common/MockWorldState.cs b/.Lib9c.Tests/Action/Common/MockWorldState.cs deleted file mode 100644 index 6771fb20ee..0000000000 --- a/.Lib9c.Tests/Action/Common/MockWorldState.cs +++ /dev/null @@ -1,179 +0,0 @@ -namespace Lib9c.Tests.Action -{ - using System.Numerics; - using System.Security.Cryptography; - using Bencodex.Types; - using Libplanet.Action.State; - using Libplanet.Common; - using Libplanet.Crypto; - using Libplanet.Store; - using Libplanet.Store.Trie; - using Libplanet.Types.Assets; - using Libplanet.Types.Consensus; - - public class MockWorldState : IWorldState - { - private readonly IStateStore _stateStore; - - public MockWorldState() - : this(new TrieStateStore(new MemoryKeyValueStore()), null) - { - } - - public MockWorldState( - IStateStore stateStore, - HashDigest? stateRootHash = null) - { - _stateStore = stateStore; - Trie = stateStore.GetStateRoot(stateRootHash); - Legacy = false; - } - - public ITrie Trie { get; } - - public bool Legacy { get; private set; } - - public IAccountState GetAccountState(Address address) => GetMockAccountState(address); - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockAccountState GetMockAccountState(Address address) - => Legacy - ? new MockAccountState(_stateStore, Trie.Hash) - : new MockAccountState( - _stateStore, - Trie.Get(MockKeyConverters.ToStateKey(address)) is { } stateRootNotNull - ? new HashDigest(stateRootNotNull) - : null); -#pragma warning restore SA1118 // Parameter should not span multiple lines - -#pragma warning disable SA1118 // Parameter should not span multiple lines - public MockWorldState SetAccountState(Address address, IAccountState accountState) - => Legacy - ? new MockWorldState(_stateStore, accountState.Trie.Hash) - : new MockWorldState( - _stateStore, - _stateStore.Commit( - Trie.Set( - MockKeyConverters.ToStateKey(address), - new Binary(accountState.Trie.Hash.ByteArray))).Hash); -#pragma warning restore SA1118 // Parameter should not span multiple lines - - public MockWorldState SetState(Address accountAddress, Address address, IValue state) - => SetAccountState(accountAddress, GetMockAccountState(accountAddress).SetState(address, state)); - - public FungibleAssetValue GetBalance(Address address, Currency currency) - => GetAccountState(ReservedAddresses.LegacyAccount).Trie.Get(MockKeyConverters.ToFungibleAssetKey(address, currency)) is Integer value - ? FungibleAssetValue.FromRawValue(currency, value) - : currency * 0; - - public MockWorldState SetBalance( - Address address, - FungibleAssetValue amount) - => SetBalance((address, amount.Currency), amount.RawValue); - - public MockWorldState SetBalance( - Address address, Currency currency, BigInteger rawAmount) - => SetBalance((address, currency), rawAmount); - - public MockWorldState SetBalance( - (Address Address, Currency Currency) pair, - BigInteger rawAmount) - => SetAccountState( - ReservedAddresses.LegacyAccount, - GetMockAccountState(ReservedAddresses.LegacyAccount) - .SetBalance((pair.Address, pair.Currency), rawAmount)); - - public MockWorldState AddBalance( - Address address, FungibleAssetValue amount) - => AddBalance((address, amount.Currency), amount.RawValue); - - public MockWorldState AddBalance( - Address address, Currency currency, BigInteger rawAmount) - => AddBalance((address, currency), rawAmount); - - public MockWorldState AddBalance( - (Address Address, Currency Currency) pair, - BigInteger rawAmount) - => SetAccountState( - ReservedAddresses.LegacyAccount, - GetMockAccountState(ReservedAddresses.LegacyAccount) - .AddBalance(pair, rawAmount)); - - public MockWorldState SubtractBalance( - Address address, FungibleAssetValue amount) - => SubtractBalance((address, amount.Currency), amount.RawValue); - - public MockWorldState SubtractBalance( - Address address, Currency currency, BigInteger rawAmount) - => SubtractBalance((address, currency), rawAmount); - - public MockWorldState SubtractBalance( - (Address Address, Currency Currency) pair, - BigInteger rawAmount) - => SetAccountState( - ReservedAddresses.LegacyAccount, - GetMockAccountState(ReservedAddresses.LegacyAccount) - .SubtractBalance(pair, rawAmount)); - - public MockWorldState TransferBalance( - Address sender, - Address recipient, - FungibleAssetValue amount) => - TransferBalance( - sender, - recipient, - amount.Currency, - amount.RawValue); - - public MockWorldState TransferBalance( - Address sender, - Address recipient, - Currency currency, - BigInteger rawAmount) - => SubtractBalance(sender, currency, rawAmount) - .AddBalance(recipient, currency, rawAmount); - - public FungibleAssetValue GetTotalSupply(Currency currency) - => GetAccountState(ReservedAddresses.LegacyAccount).Trie.Get(MockKeyConverters.ToTotalSupplyKey(currency)) is Integer value - ? FungibleAssetValue.FromRawValue(currency, value) - : currency * 0; - - public MockWorldState SetTotalSupply(FungibleAssetValue amount) - => SetTotalSupply(amount.Currency, amount.RawValue); - - public MockWorldState SetTotalSupply(Currency currency, BigInteger rawAmount) - => SetAccountState( - ReservedAddresses.LegacyAccount, - GetMockAccountState(ReservedAddresses.LegacyAccount) - .SetTotalSupply(currency, rawAmount)); - - public MockWorldState AddTotalSupply(FungibleAssetValue amount) - => AddTotalSupply(amount.Currency, amount.RawValue); - - public MockWorldState AddTotalSupply(Currency currency, BigInteger rawAmount) - => SetAccountState( - ReservedAddresses.LegacyAccount, - GetMockAccountState(ReservedAddresses.LegacyAccount) - .AddTotalSupply(currency, rawAmount)); - - public MockWorldState SubtractTotalSupply(FungibleAssetValue amount) - => SubtractTotalSupply(amount.Currency, amount.RawValue); - - public MockWorldState SubtractTotalSupply(Currency currency, BigInteger rawAmount) - => SetAccountState( - ReservedAddresses.LegacyAccount, - GetMockAccountState(ReservedAddresses.LegacyAccount) - .SubtractTotalSupply(currency, rawAmount)); - - public ValidatorSet GetValidatorSet() - => GetMockAccountState(ReservedAddresses.LegacyAccount).Trie.Get(MockKeyConverters.ValidatorSetKey) is { } value - ? new ValidatorSet(value) - : new ValidatorSet(); - - public MockWorldState SetValidator(Validator validator) - => SetAccountState( - ReservedAddresses.LegacyAccount, - GetMockAccountState(ReservedAddresses.LegacyAccount) - .SetValidator(validator)); - } -} diff --git a/.Lib9c.Tests/Action/Coupons/IssueCouponsTest.cs b/.Lib9c.Tests/Action/Coupons/IssueCouponsTest.cs index 340c00d8c1..77999b3573 100644 --- a/.Lib9c.Tests/Action/Coupons/IssueCouponsTest.cs +++ b/.Lib9c.Tests/Action/Coupons/IssueCouponsTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action.Coupons using Bencodex.Types; using Libplanet.Action; using Libplanet.Action.State; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Action.Coupons; using Nekoyume.Model.Coupons; @@ -19,7 +20,7 @@ public class IssueCouponsTest [Fact] public void Execute() { - IWorld state = new World(new MockWorldState()) + IWorld state = new World(MockUtil.MockModernWorldState) .SetLegacyState( AdminState.Address, new AdminState(CouponsFixture.AgentAddress1, 1) diff --git a/.Lib9c.Tests/Action/Coupons/RedeemCouponTest.cs b/.Lib9c.Tests/Action/Coupons/RedeemCouponTest.cs index c06a3390f5..fcffb2998d 100644 --- a/.Lib9c.Tests/Action/Coupons/RedeemCouponTest.cs +++ b/.Lib9c.Tests/Action/Coupons/RedeemCouponTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action.Coupons using System.Linq; using Libplanet.Action; using Libplanet.Action.State; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Action.Coupons; @@ -21,7 +22,7 @@ public void Execute() { IRandom random = new TestRandom(); var sheets = TableSheetsImporter.ImportSheets(); - IWorld state = new World(new MockWorldState()) + IWorld state = new World(MockUtil.MockModernWorldState) .SetLegacyState( Addresses.GameConfig, new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize() diff --git a/.Lib9c.Tests/Action/Coupons/TransferCouponsTest.cs b/.Lib9c.Tests/Action/Coupons/TransferCouponsTest.cs index 4b8fae9ae8..7986ce2f52 100644 --- a/.Lib9c.Tests/Action/Coupons/TransferCouponsTest.cs +++ b/.Lib9c.Tests/Action/Coupons/TransferCouponsTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action.Coupons using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Action.Coupons; using Nekoyume.Model.Coupons; @@ -18,7 +19,7 @@ public class TransferCouponsTest [Fact] public void Execute() { - IWorld state = new World(new MockWorldState()); + IWorld state = new World(MockUtil.MockModernWorldState); IRandom random = new TestRandom(); var coupon1 = new Coupon(CouponsFixture.Guid1, CouponsFixture.RewardSet1); diff --git a/.Lib9c.Tests/Action/CreateAvatarTest.cs b/.Lib9c.Tests/Action/CreateAvatarTest.cs index 127a3d172e..b6e4b39ae4 100644 --- a/.Lib9c.Tests/Action/CreateAvatarTest.cs +++ b/.Lib9c.Tests/Action/CreateAvatarTest.cs @@ -8,6 +8,7 @@ namespace Lib9c.Tests.Action using System.Runtime.Serialization.Formatters.Binary; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -46,7 +47,7 @@ public void Execute(long blockIndex) }; var sheets = TableSheetsImporter.ImportSheets(); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState( Addresses.GameConfig, new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize() @@ -117,7 +118,7 @@ public void ExecuteThrowInvalidNamePatterException(string nickName) name = nickName, }; - var state = new World(new MockWorldState()); + var state = new World(MockUtil.MockModernWorldState); Assert.Throws(() => action.Execute(new ActionContext() { @@ -158,7 +159,7 @@ public void ExecuteThrowInvalidAddressException() name = "test", }; - var state = new World(new MockWorldState()).SetAvatarState(avatarAddress, avatarState); + var state = new World(MockUtil.MockModernWorldState).SetAvatarState(avatarAddress, avatarState); Assert.Throws(() => action.Execute(new ActionContext() { @@ -175,7 +176,7 @@ public void ExecuteThrowInvalidAddressException() public void ExecuteThrowAvatarIndexOutOfRangeException(int index) { var agentState = new AgentState(_agentAddress); - var state = new World(new MockWorldState()).SetAgentState(_agentAddress, agentState); + var state = new World(MockUtil.MockModernWorldState).SetAgentState(_agentAddress, agentState); var action = new CreateAvatar() { index = index, @@ -210,7 +211,7 @@ public void ExecuteThrowAvatarIndexAlreadyUsedException(int index) ) ); agentState.avatarAddresses[index] = avatarAddress; - var state = new World(new MockWorldState()).SetAgentState(_agentAddress, agentState); + var state = new World(MockUtil.MockModernWorldState).SetAgentState(_agentAddress, agentState); var action = new CreateAvatar() { @@ -267,7 +268,7 @@ public void MintAsset() var avatarAddress = new PrivateKey().Address; var agentAddress = new PrivateKey().Address; var avatarState = new AvatarState(avatarAddress, agentAddress, 0L, _tableSheets.GetAvatarSheets(), new GameConfigState(), default, "test"); - var nextState = CreateAvatar.MintAsset(createAvatarFavSheet, avatarState, new World(new MockWorldState()), new ActionContext()); + var nextState = CreateAvatar.MintAsset(createAvatarFavSheet, avatarState, new World(MockUtil.MockModernWorldState), new ActionContext()); foreach (var row in createAvatarFavSheet.Values) { var targetAddress = row.Target == CreateAvatarFavSheet.Target.Agent diff --git a/.Lib9c.Tests/Action/CreatePendingActivationTest.cs b/.Lib9c.Tests/Action/CreatePendingActivationTest.cs index c2bc9dff45..9478aa2f28 100644 --- a/.Lib9c.Tests/Action/CreatePendingActivationTest.cs +++ b/.Lib9c.Tests/Action/CreatePendingActivationTest.cs @@ -3,6 +3,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action.State; using Libplanet.Common; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Model.State; using Nekoyume.Module; @@ -21,9 +22,8 @@ public void Execute() var action = new CreatePendingActivation(pendingActivation); var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); - var state = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()); var actionContext = new ActionContext() { BlockIndex = 1, @@ -49,9 +49,8 @@ public void CheckPermission() var action = new CreatePendingActivation(pendingActivation); var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); - var state = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()); Assert.Throws( () => action.Execute(new ActionContext() diff --git a/.Lib9c.Tests/Action/CreatePendingActivationsTest.cs b/.Lib9c.Tests/Action/CreatePendingActivationsTest.cs index 5367bfa212..efd37f9663 100644 --- a/.Lib9c.Tests/Action/CreatePendingActivationsTest.cs +++ b/.Lib9c.Tests/Action/CreatePendingActivationsTest.cs @@ -4,8 +4,9 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; - using Nekoyume.Model.State; + using Nekoyume.Model.State; using Nekoyume.Module; using Xunit; @@ -28,9 +29,8 @@ PendingActivationState CreatePendingActivation() var action = new CreatePendingActivations(activations); var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); - var state = new World( - new MockWorldState().SetState( - ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()); var actionContext = new ActionContext() { BlockIndex = 1, @@ -79,9 +79,8 @@ public void CheckPermission() var action = new CreatePendingActivations(); var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); - var state = new World( - new MockWorldState().SetState( - ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()); Assert.Throws( () => action.Execute(new ActionContext() diff --git a/.Lib9c.Tests/Action/CreatePledgeTest.cs b/.Lib9c.Tests/Action/CreatePledgeTest.cs index 8a5fb64501..9799227cf9 100644 --- a/.Lib9c.Tests/Action/CreatePledgeTest.cs +++ b/.Lib9c.Tests/Action/CreatePledgeTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using System.Collections.Generic; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model.State; @@ -35,7 +36,7 @@ public void Execute(bool admin, Type exc) var agentAddress = new PrivateKey().Address; var pledgeAddress = agentAddress.GetPledgeAddress(); var context = new ActionContext(); - IWorld states = new World(new MockWorldState()) + IWorld states = new World(MockUtil.MockModernWorldState) .SetLegacyState(Addresses.Admin, adminState.Serialize()) .MintAsset(context, patronAddress, 4 * 500 * mead); diff --git a/.Lib9c.Tests/Action/DailyRewardTest.cs b/.Lib9c.Tests/Action/DailyRewardTest.cs index dd24648622..c8fc505a1b 100644 --- a/.Lib9c.Tests/Action/DailyRewardTest.cs +++ b/.Lib9c.Tests/Action/DailyRewardTest.cs @@ -2,6 +2,7 @@ namespace Lib9c.Tests.Action { using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Helper; @@ -26,7 +27,7 @@ public DailyRewardTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { @@ -92,7 +93,7 @@ public void Execute(bool legacy) [Fact] public void Execute_Throw_FailedLoadStateException() => - Assert.Throws(() => ExecuteInternal(new World(new MockWorldState()))); + Assert.Throws(() => ExecuteInternal(new World(MockUtil.MockModernWorldState))); [Theory] [InlineData(0, 0, true)] diff --git a/.Lib9c.Tests/Action/EndPledgeTest.cs b/.Lib9c.Tests/Action/EndPledgeTest.cs index 82b7c2e589..6f72fa720d 100644 --- a/.Lib9c.Tests/Action/EndPledgeTest.cs +++ b/.Lib9c.Tests/Action/EndPledgeTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Model.State; using Nekoyume.Module; @@ -19,7 +20,7 @@ public void Execute(int balance) var patron = new PrivateKey().Address; var agent = new PrivateKey().Address; var context = new ActionContext(); - IWorld states = new World(new MockWorldState()) + IWorld states = new World(MockUtil.MockModernWorldState) .SetLegacyState(agent.GetPledgeAddress(), List.Empty.Add(patron.Serialize()).Add(true.Serialize())); var mead = Currencies.Mead; if (balance > 0) @@ -52,7 +53,7 @@ public void Execute_Throw_Exception(bool invalidSigner, bool invalidAgent, Type Address patron = new PrivateKey().Address; Address agent = new PrivateKey().Address; List contract = List.Empty.Add(patron.Serialize()).Add(true.Serialize()); - IWorld states = new World(new MockWorldState()).SetLegacyState(agent.GetPledgeAddress(), contract); + IWorld states = new World(MockUtil.MockModernWorldState).SetLegacyState(agent.GetPledgeAddress(), contract); var action = new EndPledge { diff --git a/.Lib9c.Tests/Action/EventConsumableItemCraftsTest.cs b/.Lib9c.Tests/Action/EventConsumableItemCraftsTest.cs index dcf9a59df5..72fddc9d3d 100644 --- a/.Lib9c.Tests/Action/EventConsumableItemCraftsTest.cs +++ b/.Lib9c.Tests/Action/EventConsumableItemCraftsTest.cs @@ -3,6 +3,7 @@ namespace Lib9c.Tests.Action using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model; @@ -24,7 +25,7 @@ public class EventConsumableItemCraftsTest public EventConsumableItemCraftsTest() { - _initialStates = new World(new MockWorldState()); + _initialStates = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/Action/EventDungeonBattleTest.cs b/.Lib9c.Tests/Action/EventDungeonBattleTest.cs index 92d23c0ced..65113fb626 100644 --- a/.Lib9c.Tests/Action/EventDungeonBattleTest.cs +++ b/.Lib9c.Tests/Action/EventDungeonBattleTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using System.Text; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -30,7 +31,7 @@ public class EventDungeonBattleTest public EventDungeonBattleTest() { - _initialStates = new World(new MockWorldState()); + _initialStates = new World(MockUtil.MockModernWorldState); #pragma warning disable CS0618 // Use of obsolete method Currency.Legacy(): https://github.com/planetarium/lib9c/discussions/1319 diff --git a/.Lib9c.Tests/Action/EventMaterialItemCraftsTest.cs b/.Lib9c.Tests/Action/EventMaterialItemCraftsTest.cs index e29c0b5779..82a9cc4169 100644 --- a/.Lib9c.Tests/Action/EventMaterialItemCraftsTest.cs +++ b/.Lib9c.Tests/Action/EventMaterialItemCraftsTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Exceptions; @@ -27,7 +28,7 @@ public class EventMaterialItemCraftsTest public EventMaterialItemCraftsTest() { - _initialStates = new World(new MockWorldState()); + _initialStates = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/Action/Grinding0Test.cs b/.Lib9c.Tests/Action/Grinding0Test.cs index 47b983cc6a..be674f5a7a 100644 --- a/.Lib9c.Tests/Action/Grinding0Test.cs +++ b/.Lib9c.Tests/Action/Grinding0Test.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -61,7 +62,7 @@ public Grinding0Test() #pragma warning restore CS0618 var goldCurrencyState = new GoldCurrencyState(_ncgCurrency); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState( Addresses.GetSheetAddress(), _tableSheets.CrystalMonsterCollectionMultiplierSheet.Serialize()) diff --git a/.Lib9c.Tests/Action/GrindingTest.cs b/.Lib9c.Tests/Action/GrindingTest.cs index 9a8004fa4f..892e1c71c3 100644 --- a/.Lib9c.Tests/Action/GrindingTest.cs +++ b/.Lib9c.Tests/Action/GrindingTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -61,7 +62,7 @@ public GrindingTest() #pragma warning restore CS0618 var goldCurrencyState = new GoldCurrencyState(_ncgCurrency); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState( Addresses.GetSheetAddress(), _tableSheets.CrystalMonsterCollectionMultiplierSheet.Serialize()) diff --git a/.Lib9c.Tests/Action/HackAndSlashRandomBuffTest.cs b/.Lib9c.Tests/Action/HackAndSlashRandomBuffTest.cs index d1d8d3b39d..69894b45dd 100644 --- a/.Lib9c.Tests/Action/HackAndSlashRandomBuffTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashRandomBuffTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -64,7 +65,7 @@ public HackAndSlashRandomBuffTest() _weeklyArenaState = new WeeklyArenaState(0); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(_weeklyArenaState.address, _weeklyArenaState.Serialize()) .SetAgentState(_agentAddress, agentState) .SetAvatarState(_avatarAddress, _avatarState) diff --git a/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs b/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs index f14fe1e177..154542a581 100644 --- a/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -68,7 +69,7 @@ public HackAndSlashSweepTest() #pragma warning restore CS0618 var goldCurrencyState = new GoldCurrencyState(currency); _weeklyArenaState = new WeeklyArenaState(0); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(_weeklyArenaState.address, _weeklyArenaState.Serialize()) .SetAgentState(_agentAddress, agentState) .SetAvatarState(_avatarAddress, _avatarState) @@ -125,7 +126,7 @@ public void Execute_FailedLoadStateException() stageId = 1, }; - IWorld state = new World(new MockWorldState()); + IWorld state = new World(MockUtil.MockModernWorldState); Assert.Throws(() => action.Execute(new ActionContext() { diff --git a/.Lib9c.Tests/Action/HackAndSlashTest.cs b/.Lib9c.Tests/Action/HackAndSlashTest.cs index b99f062702..291a3f853c 100644 --- a/.Lib9c.Tests/Action/HackAndSlashTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashTest.cs @@ -9,6 +9,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -79,7 +80,7 @@ public HackAndSlashTest() var currency = Currency.Legacy("NCG", 2, null); #pragma warning restore CS0618 var goldCurrencyState = new GoldCurrencyState(currency); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); _initialState = _initialState .SetLegacyState(Addresses.GoldCurrency, goldCurrencyState.Serialize()) .SetLegacyState(_weeklyArenaState.address, _weeklyArenaState.Serialize()) @@ -411,10 +412,10 @@ public void Execute_Throw_FailedLoadStateException(bool empty) }; IWorld state = empty - ? new World(new MockWorldState()) + ? new World(MockUtil.MockModernWorldState) : _initialState .SetAvatarState(_avatarAddress, _avatarState) - .SetAccount(Addresses.Inventory, new Account(new MockAccountState())); + .SetAccount(Addresses.Inventory, new Account(MockUtil.MockAccountState)); var exec = Assert.Throws(() => action.Execute(new ActionContext { diff --git a/.Lib9c.Tests/Action/InitializeStatesTest.cs b/.Lib9c.Tests/Action/InitializeStatesTest.cs index 07d776ef0f..7af13e7d5f 100644 --- a/.Lib9c.Tests/Action/InitializeStatesTest.cs +++ b/.Lib9c.Tests/Action/InitializeStatesTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -64,7 +65,7 @@ public void Execute() BlockIndex = 0, Signer = minterKey.Address, Miner = default, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), }); var addresses = new List
() @@ -131,7 +132,7 @@ public void ExecuteWithAuthorizedMinersState() BlockIndex = 0, Miner = default, Signer = minterKey.Address, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), }); var fetchedState = new AuthorizedMinersState( @@ -180,7 +181,7 @@ public void ExecuteWithActivateAdminKey() BlockIndex = 0, Miner = default, Signer = minterKey.Address, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), }); var fetchedState = new ActivatedAccountsState( @@ -232,7 +233,7 @@ public void ExecuteWithCredits() BlockIndex = 0, Miner = default, Signer = minterKey.Address, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), }); var fetchedState = new CreditsState( @@ -278,7 +279,7 @@ public void ExecuteWithoutAdminState() BlockIndex = 0, Miner = default, Signer = minterKey.Address, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), }); var fetchedState = new ActivatedAccountsState( @@ -321,7 +322,7 @@ public void ExecuteWithoutInitialSupply() BlockIndex = 0, Miner = default, Signer = minterKey.Address, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), }); Assert.Equal(0 * ncg, genesisState.GetBalance(GoldCurrencyState.Address, ncg)); @@ -362,7 +363,7 @@ public void ExecuteWithAssetMinters() BlockIndex = 0, Miner = default, Signer = minterKey.Address, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), }); var assetMinters = Assert.IsType(genesisState.GetLegacyState(Addresses.AssetMinters)); diff --git a/.Lib9c.Tests/Action/IssueTokensFromGarageTest.cs b/.Lib9c.Tests/Action/IssueTokensFromGarageTest.cs index 7ec5e15d7d..ef79bed692 100644 --- a/.Lib9c.Tests/Action/IssueTokensFromGarageTest.cs +++ b/.Lib9c.Tests/Action/IssueTokensFromGarageTest.cs @@ -8,6 +8,7 @@ namespace Lib9c.Tests using Libplanet.Action.State; using Libplanet.Common; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -36,9 +37,8 @@ public IssueTokensFromGarageTest() var garageBalanceAddr = Addresses.GetGarageBalanceAddress(_signer); _prevState = new World( - new MockWorldState() - .SetBalance(garageBalanceAddr, Currencies.Crystal * 1000) - ); + MockWorldState.CreateModern() + .SetBalance(garageBalanceAddr, Currencies.Crystal * 1000)); IEnumerable materials = _tableSheets.MaterialItemSheet.OrderedList! .Take(3) diff --git a/.Lib9c.Tests/Action/ItemEnhancementTest.cs b/.Lib9c.Tests/Action/ItemEnhancementTest.cs index 901db08f20..82a2f2468b 100644 --- a/.Lib9c.Tests/Action/ItemEnhancementTest.cs +++ b/.Lib9c.Tests/Action/ItemEnhancementTest.cs @@ -9,6 +9,7 @@ namespace Lib9c.Tests.Action using Lib9c.Tests.Util; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -30,7 +31,7 @@ public class ItemEnhancementTest public ItemEnhancementTest() { - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); Dictionary sheets; (_initialState, sheets) = InitializeUtil.InitializeTableSheets( _initialState, diff --git a/.Lib9c.Tests/Action/JoinArena1Test.cs b/.Lib9c.Tests/Action/JoinArena1Test.cs index 199df55e88..3ef350f8fc 100644 --- a/.Lib9c.Tests/Action/JoinArena1Test.cs +++ b/.Lib9c.Tests/Action/JoinArena1Test.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -46,7 +47,7 @@ public JoinArena1Test(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _state = new World(new MockWorldState()); + _state = new World(MockUtil.MockModernWorldState); _signer = new PrivateKey().Address; _avatarAddress = _signer.Derive("avatar"); diff --git a/.Lib9c.Tests/Action/JoinArena3Test.cs b/.Lib9c.Tests/Action/JoinArena3Test.cs index 9a4ee71222..e5231ea72e 100644 --- a/.Lib9c.Tests/Action/JoinArena3Test.cs +++ b/.Lib9c.Tests/Action/JoinArena3Test.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -47,7 +48,7 @@ public JoinArena3Test(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _state = new World(new MockWorldState()); + _state = new World(MockUtil.MockModernWorldState); _signer = new PrivateKey().Address; _avatarAddress = _signer.Derive("avatar"); diff --git a/.Lib9c.Tests/Action/MarketValidationTest.cs b/.Lib9c.Tests/Action/MarketValidationTest.cs index 4889ee45cf..f74c764070 100644 --- a/.Lib9c.Tests/Action/MarketValidationTest.cs +++ b/.Lib9c.Tests/Action/MarketValidationTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using System.Collections.Generic; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume.Action; using Nekoyume.Battle; @@ -23,7 +24,7 @@ public class MarketValidationTest public MarketValidationTest() { - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(Gold).Serialize()); } diff --git a/.Lib9c.Tests/Action/MigrateAgentAvatarTest.cs b/.Lib9c.Tests/Action/MigrateAgentAvatarTest.cs index befb0fe72d..956b5b3574 100644 --- a/.Lib9c.Tests/Action/MigrateAgentAvatarTest.cs +++ b/.Lib9c.Tests/Action/MigrateAgentAvatarTest.cs @@ -8,6 +8,7 @@ using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -62,21 +63,17 @@ public void MigrateAgentAvatar(int legacyAvatarVersion, bool alreadyMigrated) gameConfigState, default); - MockWorldState mock = new MockWorldState() - .SetState( - ReservedAddresses.LegacyAccount, + IWorld mock = new World(MockUtil.MockModernWorldState) + .SetLegacyState( GoldCurrencyState.Address, new GoldCurrencyState(currency, 0).Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( weekly.address, weekly.Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( Addresses.GoldDistribution, new List()) - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( gameConfigState.address, gameConfigState.Serialize()); @@ -84,35 +81,28 @@ public void MigrateAgentAvatar(int legacyAvatarVersion, bool alreadyMigrated) { case 1: mock = mock - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( agentAddress, SerializeLegacyAgent(agentState)) - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( avatarAddress, MigrationAvatarState.LegacySerializeV1(avatarState)); break; case 2: mock = mock - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( agentAddress, SerializeLegacyAgent(agentState)) - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( avatarAddress, MigrationAvatarState.LegacySerializeV2(avatarState)) - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( inventoryAddress, avatarState.inventory.Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( worldInformationAddress, avatarState.questList.Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, + .SetLegacyState( questListAddress, avatarState.questList.Serialize()); break; @@ -122,27 +112,26 @@ public void MigrateAgentAvatar(int legacyAvatarVersion, bool alreadyMigrated) if (alreadyMigrated) { - mock = mock - .SetState( - Addresses.Agent, - agentAddress, - agentState.SerializeList()) - .SetState( - Addresses.Avatar, - avatarAddress, - avatarState.SerializeList()) - .SetState( - Addresses.Inventory, - avatarAddress, - avatarState.inventory.Serialize()) - .SetState( - Addresses.WorldInformation, - avatarAddress, - avatarState.worldInformation.Serialize()) - .SetState( - Addresses.QuestList, - avatarAddress, - avatarState.questList.Serialize()); + mock = mock.SetAccount( + Addresses.Agent, + mock.GetAccount(Addresses.Agent) + .SetState(agentAddress, agentState.SerializeList())); + mock = mock.SetAccount( + Addresses.Avatar, + mock.GetAccount(Addresses.Avatar) + .SetState(avatarAddress, avatarState.SerializeList())); + mock = mock.SetAccount( + Addresses.Inventory, + mock.GetAccount(Addresses.Inventory) + .SetState(avatarAddress, avatarState.inventory.Serialize())); + mock = mock.SetAccount( + Addresses.WorldInformation, + mock.GetAccount(Addresses.WorldInformation) + .SetState(avatarAddress, avatarState.worldInformation.Serialize())); + mock = mock.SetAccount( + Addresses.QuestList, + mock.GetAccount(Addresses.QuestList) + .SetState(avatarAddress, avatarState.questList.Serialize())); } IAction action = new MigrateAgentAvatar @@ -154,11 +143,10 @@ public void MigrateAgentAvatar(int legacyAvatarVersion, bool alreadyMigrated) var actionLoader = new NCActionLoader(); action = actionLoader.LoadAction(123, plainValue); - var states = new World(mock); IWorld nextState = action.Execute( new ActionContext() { - PreviousState = states, + PreviousState = mock, Miner = default, Signer = new Address("e2D18a50472e93d3165c478DefA69fa149214E72"), } diff --git a/.Lib9c.Tests/Action/MigrateMonsterCollectionTest.cs b/.Lib9c.Tests/Action/MigrateMonsterCollectionTest.cs index 4a0fc6c454..257d9c5fa3 100644 --- a/.Lib9c.Tests/Action/MigrateMonsterCollectionTest.cs +++ b/.Lib9c.Tests/Action/MigrateMonsterCollectionTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -31,7 +32,7 @@ public MigrateMonsterCollectionTest(ITestOutputHelper outputHelper) _signer = default; _avatarAddress = _signer.Derive("avatar"); - _state = new World(new MockWorldState()); + _state = new World(MockUtil.MockModernWorldState); Dictionary sheets = TableSheetsImporter.ImportSheets(); var tableSheets = new TableSheets(sheets); var rankingMapAddress = new PrivateKey().Address; diff --git a/.Lib9c.Tests/Action/MigrationActivatedAccountsStateTest.cs b/.Lib9c.Tests/Action/MigrationActivatedAccountsStateTest.cs index 63fc3b4328..f131917863 100644 --- a/.Lib9c.Tests/Action/MigrationActivatedAccountsStateTest.cs +++ b/.Lib9c.Tests/Action/MigrationActivatedAccountsStateTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Model; using Nekoyume.Model.State; @@ -17,10 +18,9 @@ public void Execute() { var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7"); - var state = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, new AdminState(admin, 100).Serialize()) - .SetState(ReservedAddresses.LegacyAccount, ActivatedAccountsState.Address, new ActivatedAccountsState().AddAccount(default).Serialize())); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, new AdminState(admin, 100).Serialize()) + .SetLegacyState(ActivatedAccountsState.Address, new ActivatedAccountsState().AddAccount(default).Serialize()); var action = new MigrationActivatedAccountsState(); diff --git a/.Lib9c.Tests/Action/MigrationAvatarStateTest.cs b/.Lib9c.Tests/Action/MigrationAvatarStateTest.cs index 3b2e115951..fa11a13926 100644 --- a/.Lib9c.Tests/Action/MigrationAvatarStateTest.cs +++ b/.Lib9c.Tests/Action/MigrationAvatarStateTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Model.State; using Nekoyume.Module; @@ -33,10 +34,9 @@ public void Execute() ); var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7"); - var state = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, new AdminState(admin, 100).Serialize()) - .SetState(ReservedAddresses.LegacyAccount, avatarAddress, MigrationAvatarState.LegacySerializeV2(avatarState))); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, new AdminState(admin, 100).Serialize()) + .SetLegacyState(avatarAddress, MigrationAvatarState.LegacySerializeV2(avatarState)); var action = new MigrationAvatarState { diff --git a/.Lib9c.Tests/Action/MintAssetsTest.cs b/.Lib9c.Tests/Action/MintAssetsTest.cs index 981ebb1913..23523f397e 100644 --- a/.Lib9c.Tests/Action/MintAssetsTest.cs +++ b/.Lib9c.Tests/Action/MintAssetsTest.cs @@ -8,6 +8,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action.State; using Libplanet.Common; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Libplanet.Types.Tx; using Nekoyume; @@ -38,11 +39,9 @@ public MintAssetsTest() new PrivateKey().Address, new PrivateKey().Address, }; - _prevState = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, new AdminState(_adminAddress, 100).Serialize()) - .SetState(ReservedAddresses.LegacyAccount, Addresses.AssetMinters, new List(_minters.Select(m => m.Serialize()))) - ); + _prevState = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, new AdminState(_adminAddress, 100).Serialize()) + .SetLegacyState(Addresses.AssetMinters, new List(_minters.Select(m => m.Serialize()))); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) diff --git a/.Lib9c.Tests/Action/PatchTableSheetTest.cs b/.Lib9c.Tests/Action/PatchTableSheetTest.cs index ef629fc041..28f8a63912 100644 --- a/.Lib9c.Tests/Action/PatchTableSheetTest.cs +++ b/.Lib9c.Tests/Action/PatchTableSheetTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model.State; @@ -24,7 +25,7 @@ public PatchTableSheetTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { @@ -114,13 +115,11 @@ public void CheckPermission() var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); const string tableName = "TestTable"; - var initStates = new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()) + .SetLegacyState( Addresses.TableSheet.Derive(tableName), Dictionary.Empty.Add(tableName, "Initial")); - var state = new World(initStates); var action = new PatchTableSheet() { TableName = tableName, @@ -160,13 +159,11 @@ public void ExecuteNewTable() var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); const string tableName = "TestTable"; - var initStates = new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize()) - .SetState( - ReservedAddresses.LegacyAccount, + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()) + .SetLegacyState( Addresses.TableSheet.Derive(tableName), Dictionary.Empty.Add(tableName, "Initial")); - var state = new World(initStates); var action = new PatchTableSheet() { TableName = nameof(CostumeStatSheet), diff --git a/.Lib9c.Tests/Action/PrepareRewardAssetsTest.cs b/.Lib9c.Tests/Action/PrepareRewardAssetsTest.cs index bf7189ee75..ce2b205f36 100644 --- a/.Lib9c.Tests/Action/PrepareRewardAssetsTest.cs +++ b/.Lib9c.Tests/Action/PrepareRewardAssetsTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using System.Collections.Immutable; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -37,7 +38,7 @@ public void Execute(bool admin, bool includeNcg, Type exc) #pragma warning restore CS0618 } - IWorld state = new World(new MockWorldState()) + IWorld state = new World(MockUtil.MockModernWorldState) .SetLegacyState(Addresses.Admin, adminState.Serialize()); var action = new PrepareRewardAssets(poolAddress, assets); diff --git a/.Lib9c.Tests/Action/RaidTest.cs b/.Lib9c.Tests/Action/RaidTest.cs index 3a383361a0..c46af29cdd 100644 --- a/.Lib9c.Tests/Action/RaidTest.cs +++ b/.Lib9c.Tests/Action/RaidTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -136,7 +137,7 @@ int runeId2 var fee = _tableSheets.WorldBossListSheet[raidId].EntranceFee; var context = new ActionContext(); - IWorld state = new World(new MockWorldState()) + IWorld state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(_agentAddress, new AgentState(_agentAddress)); @@ -432,7 +433,7 @@ public void Execute_With_Reward() Address bossAddress = Addresses.GetWorldBossAddress(raidId); Address worldBossKillRewardRecordAddress = Addresses.GetWorldBossKillRewardRecordAddress(_avatarAddress, raidId); - IWorld state = new World(new MockWorldState()) + IWorld state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(_agentAddress, new AgentState(_agentAddress)); @@ -583,7 +584,7 @@ public void Execute_With_Free_Crystal_Fee() "1,900002,0,100,0,1,1,40"; var goldCurrencyState = new GoldCurrencyState(_goldCurrency); - IWorld state = new World(new MockWorldState()) + IWorld state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(_agentAddress, new AgentState(_agentAddress)); diff --git a/.Lib9c.Tests/Action/RankingBattleTest.cs b/.Lib9c.Tests/Action/RankingBattleTest.cs index 2bff5d2cfc..e16518da31 100644 --- a/.Lib9c.Tests/Action/RankingBattleTest.cs +++ b/.Lib9c.Tests/Action/RankingBattleTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model; @@ -29,7 +30,7 @@ public class RankingBattleTest public RankingBattleTest(ITestOutputHelper outputHelper) { - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var keys = new List { diff --git a/.Lib9c.Tests/Action/RapidCombinationTest.cs b/.Lib9c.Tests/Action/RapidCombinationTest.cs index fa6976dbcf..a81c03df5b 100644 --- a/.Lib9c.Tests/Action/RapidCombinationTest.cs +++ b/.Lib9c.Tests/Action/RapidCombinationTest.cs @@ -12,6 +12,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Helper; @@ -35,7 +36,7 @@ public class RapidCombinationTest public RapidCombinationTest() { - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); Dictionary sheets; (_initialState, sheets) = InitializeUtil.InitializeTableSheets( _initialState, diff --git a/.Lib9c.Tests/Action/ReRegisterProduct0Test.cs b/.Lib9c.Tests/Action/ReRegisterProduct0Test.cs index 6b1d315fea..c200602f7e 100644 --- a/.Lib9c.Tests/Action/ReRegisterProduct0Test.cs +++ b/.Lib9c.Tests/Action/ReRegisterProduct0Test.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Lib9c.Model.Order; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -40,7 +41,7 @@ public ReRegisterProduct0Test(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/Action/ReRegisterProductTest.cs b/.Lib9c.Tests/Action/ReRegisterProductTest.cs index b0c1ecabc4..9b74188d4e 100644 --- a/.Lib9c.Tests/Action/ReRegisterProductTest.cs +++ b/.Lib9c.Tests/Action/ReRegisterProductTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Lib9c.Model.Order; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -40,7 +41,7 @@ public ReRegisterProductTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/Action/RedeemCodeTest.cs b/.Lib9c.Tests/Action/RedeemCodeTest.cs index e491e300f3..dcc2266601 100644 --- a/.Lib9c.Tests/Action/RedeemCodeTest.cs +++ b/.Lib9c.Tests/Action/RedeemCodeTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action.State; using Libplanet.Common; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -71,7 +72,7 @@ public void Execute(bool backward) #pragma warning restore CS0618 var context = new ActionContext(); - var initialState = new World(new MockWorldState()) + var initialState = new World(MockUtil.MockModernWorldState) .SetAgentState(_agentAddress, agentState) .SetLegacyState(RedeemCodeState.Address, prevRedeemCodesState.Serialize()) .SetLegacyState(GoldCurrencyState.Address, goldState.Serialize()) diff --git a/.Lib9c.Tests/Action/RegisterProduct0Test.cs b/.Lib9c.Tests/Action/RegisterProduct0Test.cs index 3acb53a28f..72b261530f 100644 --- a/.Lib9c.Tests/Action/RegisterProduct0Test.cs +++ b/.Lib9c.Tests/Action/RegisterProduct0Test.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -55,7 +56,7 @@ public RegisterProduct0Test() }; agentState.avatarAddresses[0] = AvatarAddress; - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(Gold).Serialize()) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.MaterialItemSheet.Serialize()) .SetLegacyState(Addresses.GameConfig, _gameConfigState.Serialize()) diff --git a/.Lib9c.Tests/Action/RegisterProductTest.cs b/.Lib9c.Tests/Action/RegisterProductTest.cs index d9c92299dd..9ee04961cf 100644 --- a/.Lib9c.Tests/Action/RegisterProductTest.cs +++ b/.Lib9c.Tests/Action/RegisterProductTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -55,7 +56,7 @@ public RegisterProductTest() }; agentState.avatarAddresses[0] = AvatarAddress; - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(Gold).Serialize()) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.MaterialItemSheet.Serialize()) .SetLegacyState(Addresses.GameConfig, _gameConfigState.Serialize()) diff --git a/.Lib9c.Tests/Action/RenewAdminStateTest.cs b/.Lib9c.Tests/Action/RenewAdminStateTest.cs index a43b873bcc..b41e36146f 100644 --- a/.Lib9c.Tests/Action/RenewAdminStateTest.cs +++ b/.Lib9c.Tests/Action/RenewAdminStateTest.cs @@ -3,6 +3,7 @@ namespace Lib9c.Tests.Action using System; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Model.State; @@ -21,9 +22,8 @@ public RenewAdminStateTest() _adminPrivateKey = new PrivateKey(); _validUntil = 1_500_000L; _adminState = new AdminState(_adminPrivateKey.Address, _validUntil); - _stateDelta = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, Addresses.Admin, _adminState.Serialize())); + _stateDelta = new World(MockUtil.MockModernWorldState) + .SetLegacyState(Addresses.Admin, _adminState.Serialize()); } [Fact] diff --git a/.Lib9c.Tests/Action/RequestPledgeTest.cs b/.Lib9c.Tests/Action/RequestPledgeTest.cs index 71486ac433..77b25fcdb6 100644 --- a/.Lib9c.Tests/Action/RequestPledgeTest.cs +++ b/.Lib9c.Tests/Action/RequestPledgeTest.cs @@ -3,6 +3,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume.Action; using Nekoyume.Model.State; @@ -19,7 +20,7 @@ public void Execute(int contractedMead) Currency mead = Currencies.Mead; Address patron = new PrivateKey().Address; var context = new ActionContext(); - IWorld states = new World(new MockWorldState()).MintAsset(context, patron, 2 * mead); + IWorld states = new World(MockUtil.MockModernWorldState).MintAsset(context, patron, 2 * mead); var address = new PrivateKey().Address; var action = new RequestPledge { @@ -50,7 +51,7 @@ public void Execute_Throw_AlreadyContractedException() Address patron = new PrivateKey().Address; var address = new PrivateKey().Address; Address contractAddress = address.GetPledgeAddress(); - IWorld states = new World(new MockWorldState()).SetLegacyState(contractAddress, List.Empty); + IWorld states = new World(MockUtil.MockModernWorldState).SetLegacyState(contractAddress, List.Empty); var action = new RequestPledge { AgentAddress = address, diff --git a/.Lib9c.Tests/Action/RewardGoldTest.cs b/.Lib9c.Tests/Action/RewardGoldTest.cs index 08096bcc43..d97f34d4bf 100644 --- a/.Lib9c.Tests/Action/RewardGoldTest.cs +++ b/.Lib9c.Tests/Action/RewardGoldTest.cs @@ -15,6 +15,7 @@ namespace Lib9c.Tests.Action using Libplanet.Blockchain.Policies; using Libplanet.Blockchain.Renderers; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Store; using Libplanet.Store.Trie; using Libplanet.Types.Assets; @@ -77,7 +78,7 @@ public RewardGoldTest() var gold = new GoldCurrencyState(Currency.Legacy("NCG", 2, null)); #pragma warning restore CS0618 IActionContext context = new ActionContext(); - _baseState = new World(new MockWorldState()) + _baseState = new World(MockUtil.MockModernWorldState) .SetLegacyState(GoldCurrencyState.Address, gold.Serialize()) .SetLegacyState(Addresses.GoldDistribution, GoldDistributionTest.Fixture.Select(v => v.Serialize()).Serialize()) .MintAsset(context, GoldCurrencyState.Address, gold.Currency * 100000000000); @@ -585,7 +586,7 @@ public void TransferMead(int patronMead, int balance) var patronAddress = new PrivateKey().Address; var contractAddress = agentAddress.GetPledgeAddress(); IActionContext context = new ActionContext(); - IWorld states = new World(new MockWorldState()) + IWorld states = new World(MockUtil.MockModernWorldState) .MintAsset(context, patronAddress, patronMead * Currencies.Mead) .TransferAsset(context, patronAddress, agentAddress, 1 * Currencies.Mead) .SetLegacyState(contractAddress, List.Empty.Add(patronAddress.Serialize()).Add(true.Serialize()).Add(balance.Serialize())) @@ -607,7 +608,7 @@ public void NoRewardWhenEmptySupply() gameConfigState.Set(_tableSheets.GameConfigSheet); var currency = Currency.Legacy("NCG", 2, null); - IWorld states = new World(new MockWorldState()) + IWorld states = new World(MockUtil.MockModernWorldState) .SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(currency, 0).Serialize()) .SetLegacyState(weekly.address, weekly.Serialize()) .SetLegacyState(Addresses.GoldDistribution, new List()) diff --git a/.Lib9c.Tests/Action/RuneEnhancement0Test.cs b/.Lib9c.Tests/Action/RuneEnhancement0Test.cs index c80199ccb6..d2a7b1f968 100644 --- a/.Lib9c.Tests/Action/RuneEnhancement0Test.cs +++ b/.Lib9c.Tests/Action/RuneEnhancement0Test.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -40,7 +41,7 @@ public void Execute(int seed) var goldCurrencyState = new GoldCurrencyState(_goldCurrency); var context = new ActionContext(); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, new AgentState(agentAddress)); @@ -191,7 +192,7 @@ public void Execute_RuneCostNotFoundException() .StartedBlockIndex; var goldCurrencyState = new GoldCurrencyState(_goldCurrency); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, new AgentState(agentAddress)); @@ -244,7 +245,7 @@ public void Execute_RuneCostDataNotFoundException() .StartedBlockIndex; var goldCurrencyState = new GoldCurrencyState(_goldCurrency); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, new AgentState(agentAddress)); @@ -313,7 +314,7 @@ public void Execute_NotEnoughFungibleAssetValueException(bool ncg, bool crystal, var goldCurrencyState = new GoldCurrencyState(_goldCurrency); var context = new ActionContext(); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, new AgentState(agentAddress)); @@ -425,7 +426,7 @@ public void Execute_TryCountIsZeroException() .StartedBlockIndex; var goldCurrencyState = new GoldCurrencyState(_goldCurrency); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, new AgentState(agentAddress)); diff --git a/.Lib9c.Tests/Action/RuneEnhancementTest.cs b/.Lib9c.Tests/Action/RuneEnhancementTest.cs index 16b398d0a4..ec108d4b75 100644 --- a/.Lib9c.Tests/Action/RuneEnhancementTest.cs +++ b/.Lib9c.Tests/Action/RuneEnhancementTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -51,7 +52,7 @@ public void Execute(int seed) ); agentState.avatarAddresses.Add(0, avatarAddress); var context = new ActionContext(); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, agentState) .SetAvatarState(avatarAddress, avatarState); @@ -205,7 +206,7 @@ public void Execute_RuneCostNotFoundException() rankingMapAddress ); agentState.avatarAddresses.Add(0, avatarAddress); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, agentState) .SetAvatarState(avatarAddress, avatarState); @@ -261,7 +262,7 @@ public void Execute_RuneCostDataNotFoundException() rankingMapAddress ); agentState.avatarAddresses.Add(0, avatarAddress); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, agentState) .SetAvatarState(avatarAddress, avatarState); @@ -333,7 +334,7 @@ public void Execute_NotEnoughFungibleAssetValueException(bool ncg, bool crystal, ); agentState.avatarAddresses.Add(0, avatarAddress); var context = new ActionContext(); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, agentState) .SetAvatarState(avatarAddress, avatarState); @@ -448,7 +449,7 @@ public void Execute_TryCountIsZeroException() rankingMapAddress ); agentState.avatarAddresses.Add(0, avatarAddress); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, agentState) .SetAvatarState(avatarAddress, avatarState); @@ -494,7 +495,7 @@ public void Execute_FailedLoadStateException() .StartedBlockIndex; var goldCurrencyState = new GoldCurrencyState(_goldCurrency); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, new AgentState(agentAddress)); diff --git a/.Lib9c.Tests/Action/Scenario/ArenaScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/ArenaScenarioTest.cs index 5b6262816e..4818449363 100644 --- a/.Lib9c.Tests/Action/Scenario/ArenaScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/ArenaScenarioTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action.Scenario using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -36,7 +37,7 @@ public ArenaScenarioTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _state = new World(new MockWorldState()); + _state = new World(MockUtil.MockModernWorldState); _sheets = TableSheetsImporter.ImportSheets(); var tableSheets = new TableSheets(_sheets); diff --git a/.Lib9c.Tests/Action/Scenario/AuraScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/AuraScenarioTest.cs index 35358695e4..2aa1414c0e 100644 --- a/.Lib9c.Tests/Action/Scenario/AuraScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/AuraScenarioTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action.Scenario using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -50,7 +51,7 @@ public AuraScenarioTest() var skill = SkillFactory.Get(skillRow, 0, 100, 0, StatType.NONE); _aura.Skills.Add(skill); var addresses = new[] { _avatarAddress, _enemyAvatarAddress }; - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); for (int i = 0; i < addresses.Length; i++) { var avatarAddress = addresses[i]; diff --git a/.Lib9c.Tests/Action/Scenario/CollectionScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/CollectionScenarioTest.cs index 720f58cc4a..745a8415c4 100644 --- a/.Lib9c.Tests/Action/Scenario/CollectionScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/CollectionScenarioTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action.Scenario using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -35,7 +36,7 @@ public CollectionScenarioTest() _tableSheets = new TableSheets(_sheets); var gameConfigState = new GameConfigState(_sheets[nameof(GameConfigSheet)]); var addresses = new[] { _avatarAddress, _enemyAvatarAddress }; - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); for (int i = 0; i < addresses.Length; i++) { var avatarAddress = addresses[i]; diff --git a/.Lib9c.Tests/Action/Scenario/MarketScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/MarketScenarioTest.cs index c89b190833..1f81d45d36 100644 --- a/.Lib9c.Tests/Action/Scenario/MarketScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/MarketScenarioTest.cs @@ -8,6 +8,7 @@ namespace Lib9c.Tests.Action.Scenario using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -103,7 +104,7 @@ public MarketScenarioTest(ITestOutputHelper outputHelper) agentState3.avatarAddresses[0] = _buyerAvatarAddress; _currency = Currency.Legacy("NCG", 2, minters: null); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(_currency).Serialize()) .SetLegacyState(Addresses.GameConfig, _gameConfigState.Serialize()) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.MaterialItemSheet.Serialize()) diff --git a/.Lib9c.Tests/Action/Scenario/MeadScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/MeadScenarioTest.cs index de83be4c2c..ac56297807 100644 --- a/.Lib9c.Tests/Action/Scenario/MeadScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/MeadScenarioTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action.Scenario using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -20,7 +21,7 @@ public void Contract() Currency mead = Currencies.Mead; var patron = new PrivateKey().Address; IActionContext context = new ActionContext(); - IWorld states = new World(new MockWorldState()).MintAsset(context, patron, 10 * mead); + IWorld states = new World(MockUtil.MockModernWorldState).MintAsset(context, patron, 10 * mead); var agentAddress = new PrivateKey().Address; var requestPledge = new RequestPledge @@ -85,7 +86,7 @@ bool IsTarget(Type type) var action = (IAction)Activator.CreateInstance(typeId)!; var actionContext = new ActionContext { - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), }; try { diff --git a/.Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs index d6f786bbbe..48cb43d1bb 100644 --- a/.Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action.Scenario using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -40,7 +41,7 @@ public void Craft_And_Unlock_And_Equip() ); var context = new ActionContext(); - IWorld initialState = new World(new MockWorldState()) + IWorld initialState = new World(MockUtil.MockModernWorldState) .SetAgentState(agentAddress, agentState) .SetAvatarState(avatarAddress, avatarState) .SetLegacyState( diff --git a/.Lib9c.Tests/Action/Scenario/SellAndCancellationAndSellTest.cs b/.Lib9c.Tests/Action/Scenario/SellAndCancellationAndSellTest.cs index 5aa2457b93..63186f8a01 100644 --- a/.Lib9c.Tests/Action/Scenario/SellAndCancellationAndSellTest.cs +++ b/.Lib9c.Tests/Action/Scenario/SellAndCancellationAndSellTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action.Scenario using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -60,7 +61,7 @@ public SellAndCancellationAndSellTest(ITestOutputHelper outputHelper) GameConfig.RequireClearedStageLevel.ActionsInShop), }; - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(GoldCurrencyState.Address, gold.Serialize()) .SetLegacyState(gameConfigState.address, gameConfigState.Serialize()) .SetAgentState(_agentAddress, agentState) diff --git a/.Lib9c.Tests/Action/Scenario/WorldUnlockScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/WorldUnlockScenarioTest.cs index c158ccce4c..fbe0dc1065 100644 --- a/.Lib9c.Tests/Action/Scenario/WorldUnlockScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/WorldUnlockScenarioTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action.Scenario using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -56,7 +57,7 @@ public WorldUnlockScenarioTest() var currency = Currency.Legacy("NCG", 2, null); #pragma warning restore CS0618 var goldCurrencyState = new GoldCurrencyState(currency); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(Addresses.GoldCurrency, goldCurrencyState.Serialize()) .SetLegacyState(_weeklyArenaState.address, _weeklyArenaState.Serialize()) .SetAgentState(_agentAddress, agentState) diff --git a/.Lib9c.Tests/Action/SecureMiningRewardTest.cs b/.Lib9c.Tests/Action/SecureMiningRewardTest.cs index 1d84b24da6..4ba4db9052 100644 --- a/.Lib9c.Tests/Action/SecureMiningRewardTest.cs +++ b/.Lib9c.Tests/Action/SecureMiningRewardTest.cs @@ -3,6 +3,7 @@ namespace Lib9c.Tests.Action using System.Collections.Immutable; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume.Action; using Nekoyume.Model.State; @@ -35,13 +36,13 @@ public class SecureMiningRewardTest }.ToImmutableList(); private static readonly IWorld _previousState = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, new AdminState(_admin, 100).Serialize()) - .SetState(ReservedAddresses.LegacyAccount, GoldCurrencyState.Address, new GoldCurrencyState(NCG).Serialize()) + MockWorldState.CreateModern() .SetBalance(_authMiners[0], NCG * 1000) .SetBalance(_authMiners[1], NCG * 2000) .SetBalance(_authMiners[2], NCG * 3000) - .SetBalance(_authMiners[3], NCG * 4000)); + .SetBalance(_authMiners[3], NCG * 4000)) + .SetLegacyState(AdminState.Address, new AdminState(_admin, 100).Serialize()) + .SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(NCG).Serialize()); [Fact] public void Execute() diff --git a/.Lib9c.Tests/Action/SellCancellationTest.cs b/.Lib9c.Tests/Action/SellCancellationTest.cs index 5feb2f10a2..cdf83dd75a 100644 --- a/.Lib9c.Tests/Action/SellCancellationTest.cs +++ b/.Lib9c.Tests/Action/SellCancellationTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Lib9c.Model.Order; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -38,7 +39,7 @@ public SellCancellationTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { diff --git a/.Lib9c.Tests/Action/SellTest.cs b/.Lib9c.Tests/Action/SellTest.cs index d791456cc4..474cbc890c 100644 --- a/.Lib9c.Tests/Action/SellTest.cs +++ b/.Lib9c.Tests/Action/SellTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests.Action using Lib9c.Model.Order; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -35,7 +36,7 @@ public SellTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { @@ -297,7 +298,7 @@ public void Execute_Throw_InvalidOperationException_DueTo_EmptyState() Assert.Throws(() => action.Execute(new ActionContext { BlockIndex = 0, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), Signer = _agentAddress, })); } diff --git a/.Lib9c.Tests/Action/Stake0Test.cs b/.Lib9c.Tests/Action/Stake0Test.cs index dddc15b24a..d47d89be41 100644 --- a/.Lib9c.Tests/Action/Stake0Test.cs +++ b/.Lib9c.Tests/Action/Stake0Test.cs @@ -3,6 +3,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -28,7 +29,7 @@ public Stake0Test(ITestOutputHelper outputHelper) .CreateLogger(); var context = new ActionContext(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) diff --git a/.Lib9c.Tests/Action/Stake2Test.cs b/.Lib9c.Tests/Action/Stake2Test.cs index 7fc03212dc..22816c8886 100644 --- a/.Lib9c.Tests/Action/Stake2Test.cs +++ b/.Lib9c.Tests/Action/Stake2Test.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -29,7 +30,7 @@ public Stake2Test(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) diff --git a/.Lib9c.Tests/Action/Summon/AuraSummonTest.cs b/.Lib9c.Tests/Action/Summon/AuraSummonTest.cs index d8a70fd4ec..3b331002dd 100644 --- a/.Lib9c.Tests/Action/Summon/AuraSummonTest.cs +++ b/.Lib9c.Tests/Action/Summon/AuraSummonTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action.Summon using Lib9c.Tests.Fixtures.TableCSV.Summon; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -55,7 +56,7 @@ public AuraSummonTest() var gold = new GoldCurrencyState(_currency); var context = new ActionContext(); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetAgentState(_agentAddress, agentState) .SetAvatarState(_avatarAddress, _avatarState) .SetLegacyState(GoldCurrencyState.Address, gold.Serialize()) diff --git a/.Lib9c.Tests/Action/Summon/RuneSummonTest.cs b/.Lib9c.Tests/Action/Summon/RuneSummonTest.cs index 8dc111a3cd..7cf03d4e9d 100644 --- a/.Lib9c.Tests/Action/Summon/RuneSummonTest.cs +++ b/.Lib9c.Tests/Action/Summon/RuneSummonTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action.Summon using System.Linq; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -55,7 +56,7 @@ public RuneSummonTest() var gold = new GoldCurrencyState(_currency); var context = new ActionContext(); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetAgentState(_agentAddress, agentState) .SetAvatarState(_avatarAddress, _avatarState) .SetLegacyState(GoldCurrencyState.Address, gold.Serialize()) diff --git a/.Lib9c.Tests/Action/TransferAssetTest.cs b/.Lib9c.Tests/Action/TransferAssetTest.cs index 7c5e8fae63..4ec020e08e 100644 --- a/.Lib9c.Tests/Action/TransferAssetTest.cs +++ b/.Lib9c.Tests/Action/TransferAssetTest.cs @@ -8,6 +8,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -54,7 +55,7 @@ public void Execute() var contractAddress = _sender.Derive(nameof(RequestPledge)); var patronAddress = new PrivateKey().Address; var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000) .SetBalance(_recipient, _currency * 10)); var action = new TransferAsset( @@ -77,7 +78,7 @@ public void Execute() public void Execute_Throw_InvalidTransferSignerException() { var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000) .SetBalance(_recipient, _currency * 10) .SetBalance(_sender, Currencies.Mead * 1)); @@ -107,7 +108,7 @@ public void Execute_Throw_InvalidTransferSignerException() public void Execute_Throw_InvalidTransferRecipientException() { var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000) .SetBalance(_sender, Currencies.Mead * 1)); // Should not allow TransferAsset with same sender and recipient. @@ -135,7 +136,7 @@ public void Execute_Throw_InvalidTransferRecipientException() public void Execute_Throw_InsufficientBalanceException() { IWorld prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000) .SetBalance(_recipient, _currency * 10)); prevState = prevState.SetAgentState(_recipient, new AgentState(_recipient)); @@ -170,7 +171,7 @@ public void Execute_Throw_InvalidTransferMinterException(bool minterAsSender) var currencyBySender = Currency.Legacy("NCG", 2, minter); #pragma warning restore CS0618 var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, currencyBySender * 1000) .SetBalance(_recipient, currencyBySender * 10) .SetBalance(_sender, Currencies.Mead * 1)) @@ -247,10 +248,10 @@ public void Execute_Throw_InvalidTransferCurrencyException() { var crystal = CrystalCalculator.CRYSTAL; var prevState = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, _recipient.Derive(ActivationKey.DeriveKey), true.Serialize()) + MockWorldState.CreateModern() .SetBalance(_sender, crystal * 1000) - .SetBalance(_sender, Currencies.Mead * 1)); + .SetBalance(_sender, Currencies.Mead * 1)) + .SetLegacyState(_recipient.Derive(ActivationKey.DeriveKey), true.Serialize()); var action = new TransferAsset( sender: _sender, recipient: _recipient, @@ -285,7 +286,7 @@ public void LoadPlainValue_ThrowsMemoLengthOverflowException() public void Execute_Throw_ArgumentException() { var baseState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000)); var action = new TransferAsset( sender: _sender, diff --git a/.Lib9c.Tests/Action/TransferAssetsTest.cs b/.Lib9c.Tests/Action/TransferAssetsTest.cs index 45c828e486..70a3169f44 100644 --- a/.Lib9c.Tests/Action/TransferAssetsTest.cs +++ b/.Lib9c.Tests/Action/TransferAssetsTest.cs @@ -8,6 +8,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -69,7 +70,7 @@ public void Execute() var contractAddress = _sender.Derive(nameof(RequestPledge)); var patronAddress = new PrivateKey().Address; var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000) .SetBalance(_recipient, _currency * 10)); var action = new TransferAssets( @@ -98,7 +99,7 @@ public void Execute() public void Execute_Throw_InvalidTransferSignerException() { var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000) .SetBalance(_recipient, _currency * 10)); var action = new TransferAssets( @@ -129,7 +130,7 @@ public void Execute_Throw_InvalidTransferSignerException() public void Execute_Throw_InvalidTransferRecipientException() { var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000)); // Should not allow TransferAsset with same sender and recipient. var action = new TransferAssets( @@ -158,7 +159,7 @@ public void Execute_Throw_InvalidTransferRecipientException() public void Execute_Throw_InsufficientBalanceException() { var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, _currency * 1000) .SetBalance(_recipient, _currency * 10)) .SetAgentState(_recipient, new AgentState(_recipient)); @@ -192,7 +193,7 @@ public void Execute_Throw_InvalidTransferMinterException() var currencyBySender = Currency.Legacy("NCG", 2, _sender); #pragma warning restore CS0618 var prevState = new World( - new MockWorldState() + MockWorldState.CreateModern() .SetBalance(_sender, currencyBySender * 1000) .SetBalance(_recipient, currencyBySender * 10)) .SetAgentState(_recipient, new AgentState(_recipient)); @@ -332,7 +333,7 @@ public void Execute_Throw_ArgumentOutOfRangeException() { action.Execute(new ActionContext() { - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), Signer = _sender, BlockIndex = 1, }); @@ -344,9 +345,9 @@ public void Execute_Throw_InvalidTransferCurrencyException() { var crystal = CrystalCalculator.CRYSTAL; var prevState = new World( - new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, _recipient.Derive(ActivationKey.DeriveKey), true.Serialize()) - .SetBalance(_sender, crystal * 1000)); + MockWorldState.CreateModern() + .SetBalance(_sender, crystal * 1000)) + .SetLegacyState(_recipient.Derive(ActivationKey.DeriveKey), true.Serialize()); var action = new TransferAssets( sender: _sender, recipients: new List<(Address, FungibleAssetValue)> @@ -366,9 +367,7 @@ public void Execute_Throw_InvalidTransferCurrencyException() [Fact] public void Execute_Throw_ArgumentException() { - var baseState = new World( - new MockWorldState() - .SetBalance(_sender, _currency * 1000)); + var baseState = new World(MockWorldState.CreateModern().SetBalance(_sender, _currency * 1000)); var action = new TransferAssets( sender: _sender, new List<(Address, FungibleAssetValue)> diff --git a/.Lib9c.Tests/Action/UnlockEquipmentRecipe1Test.cs b/.Lib9c.Tests/Action/UnlockEquipmentRecipe1Test.cs index ab9c910537..aa71d5b286 100644 --- a/.Lib9c.Tests/Action/UnlockEquipmentRecipe1Test.cs +++ b/.Lib9c.Tests/Action/UnlockEquipmentRecipe1Test.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -52,7 +53,7 @@ public UnlockEquipmentRecipe1Test() agentState.avatarAddresses.Add(0, _avatarAddress); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetAgentState(_agentAddress, agentState) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.EquipmentItemSheet.Serialize()) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.EquipmentItemRecipeSheet.Serialize()) diff --git a/.Lib9c.Tests/Action/UnlockEquipmentRecipeTest.cs b/.Lib9c.Tests/Action/UnlockEquipmentRecipeTest.cs index d45563ae92..69ab353f07 100644 --- a/.Lib9c.Tests/Action/UnlockEquipmentRecipeTest.cs +++ b/.Lib9c.Tests/Action/UnlockEquipmentRecipeTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -52,7 +53,7 @@ public UnlockEquipmentRecipeTest() agentState.avatarAddresses.Add(0, _avatarAddress); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetAgentState(_agentAddress, agentState) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.EquipmentItemSheet.Serialize()) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.EquipmentItemRecipeSheet.Serialize()) diff --git a/.Lib9c.Tests/Action/UnlockRuneSlotTest.cs b/.Lib9c.Tests/Action/UnlockRuneSlotTest.cs index 6491c72a19..215f08f96b 100644 --- a/.Lib9c.Tests/Action/UnlockRuneSlotTest.cs +++ b/.Lib9c.Tests/Action/UnlockRuneSlotTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -35,7 +36,7 @@ public IWorld Init(out Address agentAddress, out Address avatarAddress, out long .StartedBlockIndex; var goldCurrencyState = new GoldCurrencyState(_goldCurrency); - var state = new World(new MockWorldState()) + var state = new World(MockUtil.MockModernWorldState) .SetLegacyState(goldCurrencyState.address, goldCurrencyState.Serialize()) .SetAgentState(agentAddress, new AgentState(agentAddress)); diff --git a/.Lib9c.Tests/Action/UnlockWorld1Test.cs b/.Lib9c.Tests/Action/UnlockWorld1Test.cs index 628bcc6bf0..66753727e3 100644 --- a/.Lib9c.Tests/Action/UnlockWorld1Test.cs +++ b/.Lib9c.Tests/Action/UnlockWorld1Test.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -50,7 +51,7 @@ public UnlockWorld1Test() agentState.avatarAddresses.Add(0, _avatarAddress); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.WorldUnlockSheet.Serialize()) .SetLegacyState(Addresses.GameConfig, gameConfigState.Serialize()); } diff --git a/.Lib9c.Tests/Action/UnlockWorldTest.cs b/.Lib9c.Tests/Action/UnlockWorldTest.cs index 28d57e370a..04bbd92d77 100644 --- a/.Lib9c.Tests/Action/UnlockWorldTest.cs +++ b/.Lib9c.Tests/Action/UnlockWorldTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Libplanet.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -50,7 +51,7 @@ public UnlockWorldTest() agentState.avatarAddresses.Add(0, _avatarAddress); - _initialState = new World(new MockWorldState()) + _initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(Addresses.GetSheetAddress(), _tableSheets.WorldUnlockSheet.Serialize()) .SetLegacyState(Addresses.GameConfig, gameConfigState.Serialize()); } diff --git a/.Lib9c.Tests/Action/UpdateSellTest.cs b/.Lib9c.Tests/Action/UpdateSellTest.cs index 3791cc5f1e..944b72a8da 100644 --- a/.Lib9c.Tests/Action/UpdateSellTest.cs +++ b/.Lib9c.Tests/Action/UpdateSellTest.cs @@ -7,6 +7,7 @@ namespace Lib9c.Tests.Action using Lib9c.Model.Order; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -38,7 +39,7 @@ public UpdateSellTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); var sheets = TableSheetsImporter.ImportSheets(); foreach (var (key, value) in sheets) { @@ -254,7 +255,7 @@ public void Execute_Throw_ListEmptyException() Assert.Throws(() => action.Execute(new ActionContext { BlockIndex = 0, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), Signer = _agentAddress, })); } @@ -279,7 +280,7 @@ public void Execute_Throw_FailedLoadStateException() Assert.Throws(() => action.Execute(new ActionContext { BlockIndex = 0, - PreviousState = new World(new MockWorldState()), + PreviousState = new World(MockUtil.MockModernWorldState), Signer = _agentAddress, })); } diff --git a/.Lib9c.Tests/Action/ValidatorSetOperateTest.cs b/.Lib9c.Tests/Action/ValidatorSetOperateTest.cs index 743242fcd3..73f0cf0a6a 100644 --- a/.Lib9c.Tests/Action/ValidatorSetOperateTest.cs +++ b/.Lib9c.Tests/Action/ValidatorSetOperateTest.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Action using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Consensus; using Nekoyume; using Nekoyume.Action; @@ -27,7 +28,7 @@ public ValidatorSetOperateTest(ITestOutputHelper outputHelper) .WriteTo.TestOutput(outputHelper) .CreateLogger(); - _initialState = new World(new MockWorldState()); + _initialState = new World(MockUtil.MockModernWorldState); _validator = new Validator(new PrivateKey().PublicKey, BigInteger.One); var sheets = TableSheetsImporter.ImportSheets(); @@ -44,9 +45,8 @@ public void CheckPermission() { var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); - var initStates = new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize()); - var state = new World(initStates); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()); var action = ValidatorSetOperate.Append(_validator); var nextState = action.Execute( new ActionContext() @@ -65,9 +65,8 @@ public void CheckPermission_Throws_PermissionDenied() { var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730"); var adminState = new AdminState(adminAddress, 100); - var initStates = new MockWorldState() - .SetState(ReservedAddresses.LegacyAccount, AdminState.Address, adminState.Serialize()); - var state = new World(initStates); + var state = new World(MockUtil.MockModernWorldState) + .SetLegacyState(AdminState.Address, adminState.Serialize()); var action = ValidatorSetOperate.Append(_validator); PermissionDeniedException exc1 = Assert.Throws(() => @@ -101,7 +100,7 @@ public void Append_Throws_WhenAlreadyExistValidator() [Fact] public void Update_Throws_WhenDoNotExistValidator() { - var state = new World(new MockWorldState()); + var state = new World(MockUtil.MockModernWorldState); var action = ValidatorSetOperate.Update(_validator); InvalidOperationException exc = Assert.Throws(() => action.Execute(new ActionContext @@ -116,7 +115,7 @@ public void Update_Throws_WhenDoNotExistValidator() [Fact] public void Remove_Throws_WhenDoNotExistValidator() { - var state = new World(new MockWorldState()); + var state = new World(MockUtil.MockModernWorldState); var action = ValidatorSetOperate.Remove(_validator); InvalidOperationException exc = Assert.Throws(() => action.Execute(new ActionContext diff --git a/.Lib9c.Tests/Extensions/SheetsExtensionsTest.cs b/.Lib9c.Tests/Extensions/SheetsExtensionsTest.cs index 99e281627f..b556f78a6e 100644 --- a/.Lib9c.Tests/Extensions/SheetsExtensionsTest.cs +++ b/.Lib9c.Tests/Extensions/SheetsExtensionsTest.cs @@ -8,6 +8,7 @@ namespace Lib9c.Tests.Extensions using Lib9c.Tests.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Action; using Nekoyume.Extensions; @@ -26,7 +27,7 @@ public class SheetsExtensionsTest public SheetsExtensionsTest() { - _states = new World(new MockWorldState()); + _states = new World(MockUtil.MockModernWorldState); InitSheets( _states, out _sheetNameAndFiles, diff --git a/.Lib9c.Tests/Lib9c.Tests.csproj b/.Lib9c.Tests/Lib9c.Tests.csproj index fb877391a1..d6545f071e 100644 --- a/.Lib9c.Tests/Lib9c.Tests.csproj +++ b/.Lib9c.Tests/Lib9c.Tests.csproj @@ -50,6 +50,7 @@ + diff --git a/.Lib9c.Tests/Model/Stake/StakeStateUtilsTest.cs b/.Lib9c.Tests/Model/Stake/StakeStateUtilsTest.cs index 8c3b103ca5..37626bee61 100644 --- a/.Lib9c.Tests/Model/Stake/StakeStateUtilsTest.cs +++ b/.Lib9c.Tests/Model/Stake/StakeStateUtilsTest.cs @@ -2,11 +2,11 @@ namespace Lib9c.Tests.Model.Stake { using System; using Bencodex.Types; - using Lib9c.Tests.Action; using Lib9c.Tests.Fixtures.TableCSV; using Lib9c.Tests.Fixtures.TableCSV.Stake; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume; using Nekoyume.Model.Stake; using Nekoyume.Model.State; @@ -32,7 +32,7 @@ public void TryMigrate_Return_False_When_IValue_Null() [Fact] public void TryMigrate_Return_False_When_Staking_State_Null() { - var state = new World(new MockWorldState()); + var state = new World(MockUtil.MockModernWorldState); Assert.False(StakeStateUtils.TryMigrate(state, new PrivateKey().Address, out _)); } @@ -108,7 +108,7 @@ public void TryMigrate_Return_True_With_StakeState( string stakeRegularFixedRewardSheetTableName, string stakeRegularRewardSheetTableName) { - IWorld state = new World(new MockWorldState()); + IWorld state = new World(MockUtil.MockModernWorldState); state = state.SetLegacyState( Addresses.GameConfig, new GameConfigState(GameConfigSheetFixtures.Default).Serialize()); @@ -140,7 +140,7 @@ public void TryMigrate_Return_True_With_StakeStateV2( long startedBlockIndex, long? receivedBlockIndex) { - IWorld state = new World(new MockWorldState()); + IWorld state = new World(MockUtil.MockModernWorldState); state = state.SetLegacyState( Addresses.GameConfig, new GameConfigState(GameConfigSheetFixtures.Default).Serialize()); diff --git a/.Lib9c.Tests/Module/CollectionModuleTest.cs b/.Lib9c.Tests/Module/CollectionModuleTest.cs index b3ea162800..a996886239 100644 --- a/.Lib9c.Tests/Module/CollectionModuleTest.cs +++ b/.Lib9c.Tests/Module/CollectionModuleTest.cs @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Module using Lib9c.Tests.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Nekoyume.Action; using Nekoyume.Model.State; using Nekoyume.Module; @@ -14,7 +15,7 @@ public class CollectionModuleTest [Fact] public void CollectionState() { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); var address = new PrivateKey().Address; Assert.Throws(() => states.GetCollectionState(address)); Assert.False(states.TryGetCollectionState(address, out _)); @@ -37,7 +38,7 @@ public void CollectionState() [Fact] public void CollectionStates() { - IWorld states = new World(new MockWorldState()); + IWorld states = new World(MockUtil.MockModernWorldState); var address = new PrivateKey().Address; var address2 = new PrivateKey().Address; var addresses = new[] { address, address2 }; diff --git a/.Lib9c.Tests/TestHelper/BlockChainHelper.cs b/.Lib9c.Tests/TestHelper/BlockChainHelper.cs index 42a9b17e2f..6383494f65 100644 --- a/.Lib9c.Tests/TestHelper/BlockChainHelper.cs +++ b/.Lib9c.Tests/TestHelper/BlockChainHelper.cs @@ -12,6 +12,7 @@ namespace Lib9c.Tests.TestHelper using Libplanet.Blockchain; using Libplanet.Blockchain.Policies; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Store; using Libplanet.Store.Trie; using Libplanet.Types.Assets; @@ -99,16 +100,14 @@ public static MakeInitialStateResult MakeInitialState() var sheets = TableSheetsImporter.ImportSheets(); var weeklyArenaAddress = WeeklyArenaState.DeriveAddress(0); var context = new ActionContext(); - var initialState = new World(new MockWorldState()) + var initialState = new World(MockUtil.MockModernWorldState) .SetLegacyState(GoldCurrencyState.Address, goldCurrencyState.Serialize()) .SetLegacyState( Addresses.GoldDistribution, - GoldDistributionTest.Fixture.Select(v => v.Serialize()).Serialize() - ) + GoldDistributionTest.Fixture.Select(v => v.Serialize()).Serialize()) .SetLegacyState( Addresses.GameConfig, - new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize() - ) + new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize()) .SetLegacyState(Addresses.Ranking, ranking.Serialize()) .SetLegacyState(weeklyArenaAddress, new WeeklyArenaState(0).Serialize()); diff --git a/.Lib9c.Tests/Util/InitializeUtil.cs b/.Lib9c.Tests/Util/InitializeUtil.cs index 8d3490af88..4bc3089055 100644 --- a/.Lib9c.Tests/Util/InitializeUtil.cs +++ b/.Lib9c.Tests/Util/InitializeUtil.cs @@ -5,6 +5,7 @@ namespace Lib9c.Tests.Util using Lib9c.Tests.Action; using Libplanet.Action.State; using Libplanet.Crypto; + using Libplanet.Mocks; using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; @@ -29,9 +30,10 @@ IWorld initialStatesWithAvatarStateV2 { adminAddr ??= new PrivateKey().Address; var context = new ActionContext(); - var states = new World(new MockWorldState()).SetLegacyState( - Addresses.Admin, - new AdminState(adminAddr.Value, long.MaxValue).Serialize()); + var states = new World(MockUtil.MockModernWorldState) + .SetLegacyState( + Addresses.Admin, + new AdminState(adminAddr.Value, long.MaxValue).Serialize()); var goldCurrency = Currency.Legacy( "NCG",