Skip to content

Commit

Permalink
Merge pull request #3112 from planetarium/improve/issue-3107
Browse files Browse the repository at this point in the history
액션내 사용 NCG 주소 변경
  • Loading branch information
ipdae authored Jan 6, 2025
2 parents 8613e22 + 310690b commit 7c0496c
Show file tree
Hide file tree
Showing 28 changed files with 124 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ FungibleAssetValue expectedRemainingNcg
expectedRemainingNcg,
resultState.GetBalance(seasonBountyBoardAddress, NCG)
);
Assert.True(resultState.GetBalance(Addresses.RewardPool, NCG) > 0 * NCG);
Assert.True(resultState.GetExplorer(1, TesterAvatarAddress).Claimed);

if (anotherExplorerCount > 0)
Expand Down
8 changes: 7 additions & 1 deletion .Lib9c.Tests/Action/AdventureBoss/UnlockFloorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Lib9c.Tests.Action.AdventureBoss
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Action.AdventureBoss;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Model.Item;
using Nekoyume.Model.State;
using Nekoyume.Module;
Expand Down Expand Up @@ -84,7 +85,8 @@ public class UnlockFloorTest
.SetAgentState(WantedAddress, WantedState)
.SetAvatarState(TesterAvatarAddress, TesterAvatarState)
.SetAgentState(TesterAddress, TesterState)
.MintAsset(new ActionContext(), WantedAddress, 1_000_000 * NCG);
.MintAsset(new ActionContext(), WantedAddress, 1_000_000 * NCG)
.SetDelegationMigrationHeight(0);

[Theory]
// Success
Expand Down Expand Up @@ -217,6 +219,10 @@ Type exc
var inventory = resultState.GetInventoryV2(TesterAvatarAddress);
Assert.Null(inventory.Items.FirstOrDefault(i => i.item.Id == 600202));
}
else
{
Assert.True(resultState.GetBalance(Addresses.RewardPool, NCG) > 0 * NCG);
}

Assert.Equal(
expectedFloor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#nullable enable

namespace Lib9c.Tests.Action.CustomEquipmentCraft
{
#nullable enable

using System;
using System.Collections.Generic;
using System.Globalization;
Expand All @@ -16,6 +16,7 @@ namespace Lib9c.Tests.Action.CustomEquipmentCraft
using Nekoyume.Action.CustomEquipmentCraft;
using Nekoyume.Action.Exceptions;
using Nekoyume.Action.Exceptions.CustomEquipmentCraft;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Battle;
using Nekoyume.Exceptions;
using Nekoyume.Model.Elemental;
Expand Down Expand Up @@ -75,6 +76,7 @@ public CustomEquipmentCraftTest()
GameConfigState.Address,
new GameConfigState(sheets["GameConfigSheet"]).Serialize()
)
.SetDelegationMigrationHeight(0)
;

for (var i = 0; i < 4; i++)
Expand Down Expand Up @@ -371,6 +373,7 @@ public void Execute(

var gameConfig = state.GetGameConfigState();
var materialList = new List<int> { ScrollItemId, CircleItemId, };
bool costExist = false;
if (enoughMaterials)
{
var relationshipSheet = _tableSheets.CustomEquipmentCraftRelationshipSheet;
Expand Down Expand Up @@ -411,6 +414,7 @@ public void Execute(
{
if (nextRow.GoldAmount > 0)
{
costExist = true;
state = state.MintAsset(
context,
_agentAddress,
Expand Down Expand Up @@ -488,6 +492,10 @@ public void Execute(
// Test
var gold = resultState.GetGoldCurrency();
Assert.Equal(0 * gold, resultState.GetBalance(_agentAddress, gold));
if (costExist)
{
Assert.True(resultState.GetBalance(Addresses.RewardPool, gold) > 0 * gold);
}

var inventory = resultState.GetInventoryV2(_avatarAddress);
foreach (var material in materialList)
Expand Down
10 changes: 9 additions & 1 deletion .Lib9c.Tests/Action/Summon/CostumeSummonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Action.Exceptions;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Model.Item;
using Nekoyume.Model.State;
using Nekoyume.Module;
Expand Down Expand Up @@ -66,7 +67,8 @@ public CostumeSummonTest()
Addresses.GoldCurrency,
_agentAddress,
gold.Currency * 1000
);
)
.SetDelegationMigrationHeight(0);

Assert.Equal(
gold.Currency * 99999999000,
Expand Down Expand Up @@ -146,6 +148,12 @@ Type expectedExc

inventory.TryGetItem((int)materialId!, out var resultMaterial);
Assert.Equal(0, resultMaterial?.count ?? 0);

var row = _tableSheets.CostumeSummonSheet[groupId];
if (row.CostNcg > 0)
{
Assert.True(nextState.GetBalance(Addresses.RewardPool, _currency) > 0 * _currency);
}
}
else
{
Expand Down
15 changes: 15 additions & 0 deletions .Lib9c.Tests/Action/UnlockCombinationSlotTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Libplanet.Types.Assets;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Extensions;
using Nekoyume.Model.Item;
using Nekoyume.Model.State;
Expand Down Expand Up @@ -147,6 +149,7 @@ public void Execute(int slotIndex)
var context = new ActionContext();
var state = Init(out var agentAddress, out var avatarAddress, out var blockIndex);
state = MintAssetForCost(state, slotIndex, context, agentAddress, avatarAddress);
state = state.SetDelegationMigrationHeight(0);
var action = new UnlockCombinationSlot()
{
AvatarAddress = avatarAddress,
Expand All @@ -164,12 +167,24 @@ public void Execute(int slotIndex)
state = action.Execute(ctx);

// Check Items
var costSheet = state.GetSheet<UnlockCombinationSlotCostSheet>();
var costRow = costSheet[slotIndex];
var ncgCurrency = state.GetGoldCurrency();
var ncgBalance = state.GetBalance(agentAddress, ncgCurrency);
var crystalBalance = state.GetBalance(agentAddress, Currencies.Crystal);
var inventory = state.GetInventoryV2(avatarAddress);
Assert.Equal("0", ncgBalance.GetQuantityString());
Assert.Equal("0", crystalBalance.GetQuantityString());
if (costRow.CrystalPrice > 0)
{
Assert.True(state.GetBalance(Addresses.RewardPool, Currencies.Crystal) > 0 * Currencies.Crystal);
}

if (costRow.NcgPrice > 0)
{
Assert.True(state.GetBalance(ArenaHelper.DeriveArenaAddress(0, 0), ncgCurrency) > 0 * ncgCurrency);
}

Assert.False(inventory.HasItem(GoldenDustId));
Assert.False(inventory.HasItem(RubyDustId));

Expand Down
13 changes: 11 additions & 2 deletions Lib9c/Action/AdventureBoss/ClaimAdventureBossReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Action.Exceptions;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Data;
using Nekoyume.Exceptions;
using Nekoyume.Helper;
Expand Down Expand Up @@ -133,9 +135,16 @@ public override IWorld Execute(IActionContext context)
states.GetBalance(seasonBountyBoardAddress, bountyBoard.totalBounty().Currency)
)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
feeAddress = AdventureBossGameData.AdventureBossOperationalAddress;
}

states = states.TransferAsset(context, seasonBountyBoardAddress,
// FIXME: Set operational account address
AdventureBossGameData.AdventureBossOperationalAddress,
feeAddress,
(bountyBoard.totalBounty() * 80).DivRem(100, out _)
);
}
Expand Down
12 changes: 10 additions & 2 deletions Lib9c/Action/AdventureBoss/UnlockFloor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Libplanet.Action.State;
using Libplanet.Crypto;
using Nekoyume.Action.Exceptions.AdventureBoss;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Data;
using Nekoyume.Exceptions;
using Nekoyume.Extensions;
Expand Down Expand Up @@ -129,7 +130,7 @@ public override IWorld Execute(IActionContext context)
var addressesHex = GetSignerAndOtherAddressesHex(context, AvatarAddress);
throw new FailedLoadStateException($"{addressesHex}Aborted as the avatar state of the signer was failed to load.");
}

var agentAddress = avatarState.agentAddress;
var balance = states.GetBalance(agentAddress, currency);
var exploreBoard = states.GetExploreBoard(Season);
Expand All @@ -145,8 +146,15 @@ public override IWorld Execute(IActionContext context)

explorer.UsedNcg += price.NcgPrice;
exploreBoard.UsedNcg += price.NcgPrice;
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
feeAddress = AdventureBossGameData.AdventureBossOperationalAddress;
}
states = states.TransferAsset(context, agentAddress,
AdventureBossGameData.AdventureBossOperationalAddress,
feeAddress,
price.NcgPrice * currency);
}
else // Use GoldenDust
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/AuraSummon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,7 @@ public override IWorld Execute(IActionContext context)
// Transfer Cost NCG first for fast-fail
if (summonRow.CostNcg > 0L)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(
context,
Expand Down
8 changes: 1 addition & 7 deletions Lib9c/Action/BattleArena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,7 @@ public override IWorld Execute(IActionContext context)

purchasedCountDuringInterval++;

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states
.TransferAsset(context, context.Signer, feeAddress, ticketBalance)
Expand Down
11 changes: 2 additions & 9 deletions Lib9c/Action/Buy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Libplanet.Types.Assets;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Extensions;
using Nekoyume.Model.EnumType;
using Nekoyume.Model.Mail;
using Nekoyume.Model.State;
Expand Down Expand Up @@ -251,15 +252,7 @@ public override IWorld Execute(IActionContext context)
var taxedPrice = order.Price - tax;

// Transfer tax.
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states
.TransferAsset(context, context.Signer, feeAddress, tax);
Expand Down
21 changes: 3 additions & 18 deletions Lib9c/Action/BuyProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Battle;
using Nekoyume.Extensions;
using Nekoyume.Model.EnumType;
using Nekoyume.Model.Item;
using Nekoyume.Model.Mail;
Expand Down Expand Up @@ -176,15 +177,7 @@ private IWorld Buy(IActionContext context, IProductInfo productInfo, Address sel
var receipt = new ProductReceipt(productId, sellerAvatarAddress, buyerAvatarState.address, product.Price,
context.BlockIndex);

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states
.RemoveLegacyState(productAddress)
Expand Down Expand Up @@ -308,15 +301,7 @@ private static IWorld Buy_Order(PurchaseInfo purchaseInfo, IActionContext contex
var taxedPrice = order.Price - tax;

// Transfer tax.
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(
context,
Expand Down
11 changes: 1 addition & 10 deletions Lib9c/Action/CombinationEquipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,7 @@ public override IWorld Execute(IActionContext context)
if (costNcg > 0L)
{
// Transfer tax.
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}

var feeAddress = states.GetFeeAddress(context.BlockIndex);
states = states.TransferAsset(
context,
context.Signer,
Expand Down
8 changes: 3 additions & 5 deletions Lib9c/Action/CostumeSummon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Libplanet.Action.State;
using Libplanet.Crypto;
using Nekoyume.Action.Exceptions;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Extensions;
using Nekoyume.Helper;
Expand Down Expand Up @@ -161,15 +162,12 @@ public override IWorld Execute(IActionContext context)
// Transfer Cost NCG first for fast-fail
if (summonRow.CostNcg > 0L)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
var feeStoreAddress =
ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(
context,
context.Signer,
feeStoreAddress,
feeAddress,
states.GetGoldCurrency() * summonRow.CostNcg * SummonCount
);
}
Expand Down
8 changes: 3 additions & 5 deletions Lib9c/Action/CustomEquipmentCraft/CustomEquipmentCraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Libplanet.Action.State;
using Libplanet.Crypto;
using Nekoyume.Action.Exceptions;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Battle;
using Nekoyume.Exceptions;
Expand Down Expand Up @@ -192,11 +193,8 @@ public override IWorld Execute(IActionContext context)

if (ncgCost > 0)
{
var arenaData = sheets.GetSheet<ArenaSheet>()
.GetRoundByBlockIndex(context.BlockIndex);
states = states.TransferAsset(context, context.Signer,
ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round),
ncgCost * states.GetGoldCurrency());
var feeAddress = states.GetFeeAddress(context.BlockIndex);
states = states.TransferAsset(context, context.Signer, feeAddress, ncgCost * states.GetGoldCurrency());
}

foreach (var (itemId, amount) in materialCosts)
Expand Down
Loading

0 comments on commit 7c0496c

Please sign in to comment.