Skip to content

Commit

Permalink
Merge pull request #2354 from planetarium/release/1.7.2
Browse files Browse the repository at this point in the history
main merge release/1.7.2
  • Loading branch information
ipdae authored Jan 30, 2024
2 parents a9cca56 + 2b089a0 commit e482c59
Show file tree
Hide file tree
Showing 70 changed files with 743 additions and 425 deletions.
56 changes: 56 additions & 0 deletions .Lib9c.Tests/Action/ClaimStakeRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Lib9c.Tests.Action
using Libplanet.Types.Assets;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Model.Item;
using Nekoyume.Model.Stake;
using Nekoyume.Model.State;
using Nekoyume.TableData.Stake;
Expand Down Expand Up @@ -661,6 +662,61 @@ public void Execute_Success_With_StakeStateV2(
}
}

[Fact]
public void Execute_V6()
{
var prevState = _initialStates[1];
var stakeAddr = StakeStateV2.DeriveAddress(AgentAddr);
var stakePolicySheet = new StakePolicySheet();
stakePolicySheet.Set(StakePolicySheetFixtures.V6);
var stakeStateV2 = PrepareStakeStateV2(
stakePolicySheet,
0L,
0L);
prevState = prevState
.SetState(
Addresses.GetSheetAddress<StakePolicySheet>(),
StakePolicySheetFixtures.V6.Serialize())
.SetState(
Addresses.GetSheetAddress("StakeRegularRewardSheet_V6"),
StakeRegularRewardSheetFixtures.V6.Serialize())
.SetState(
Addresses.GetSheetAddress("StakeRegularRewardFixedRewardSheet_V3"),
StakeRegularFixedRewardSheetFixtures.V3.Serialize())
.SetState(stakeAddr, stakeStateV2.Serialize())
.MintAsset(
new ActionContext(),
stakeAddr,
_ncg * 10000000);
var agentAddr = AgentAddr;
var avatarAddr = AvatarAddr;
var blockIndex = stakePolicySheet.RewardIntervalValue;
var nextState = Execute(prevState, agentAddr, avatarAddr, blockIndex);
var avatarState = nextState.GetAvatarStateV2(AvatarAddr);
var expected = new[]
{
(400000, 25000000, true),
(500000, 125002, true),
(600201, 200000, false),
(800201, 200000, false),
(800202, 200000, false),
};
foreach (var (itemId, count, tradable) in expected)
{
Assert.True(avatarState.inventory.TryGetItem(itemId, out var inventoryItem));
Assert.Equal(count, inventoryItem.count);
if (tradable)
{
Assert.IsType<TradableMaterial>(inventoryItem.item);
}
else
{
Assert.IsNotType<TradableMaterial>(inventoryItem.item);
Assert.IsType<Material>(inventoryItem.item);
}
}
}

private static StakeStateV2 PrepareStakeStateV2(
StakePolicySheet stakePolicySheet,
long startedBlockIndex,
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/Common/Doomfist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public static Equipment GetOne(
.Aggregate((row1, row2) =>
{
var row1Value = row1.Stat.StatType == statType
? row1.Stat.BaseValueAsInt
? row1.Stat.BaseValueAsLong
: 0;
var row2Value = row2.Stat.StatType == statType
? row2.Stat.BaseValueAsInt
? row2.Stat.BaseValueAsLong
: 0;
return row1Value > row2Value
? row1
Expand Down
72 changes: 43 additions & 29 deletions .Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DeliverToOthersGaragesTest
private readonly Address _recipientAgentAddr;
private readonly FungibleAssetValue[] _fungibleAssetValues;
private readonly (HashDigest<SHA256> fungibleId, int count)[] _fungibleIdAndCounts;
private readonly ITradableFungibleItem[] _tradableFungibleItems;
private readonly IFungibleItem[] _fungibleItems;
private readonly IAccount _previousStates;

public DeliverToOthersGaragesTest()
Expand All @@ -52,7 +52,7 @@ public DeliverToOthersGaragesTest()
_recipientAgentAddr,
_fungibleAssetValues,
_fungibleIdAndCounts,
_tradableFungibleItems,
_fungibleItems,
_previousStates
) = GetSuccessfulPreviousStatesWithPlainValue();
}
Expand Down Expand Up @@ -168,9 +168,9 @@ public void Execute_Success()
var recipientGarageAddr = Addresses.GetGarageAddress(
_recipientAgentAddr,
fungibleId);
Assert.Equal(
count,
new FungibleItemGarage(nextStates.GetState(recipientGarageAddr)).Count);
var garage = new FungibleItemGarage(nextStates.GetState(recipientGarageAddr));
Assert.Equal(count, garage.Count);
Assert.IsType<Material>(garage.Item);
}
}

Expand Down Expand Up @@ -261,7 +261,7 @@ public void Execute_Throws_Exception()
var (fungibleId, _) = _fungibleIdAndCounts[i];
var addr = Addresses.GetGarageAddress(_recipientAgentAddr, fungibleId);
var nextIndex = (i + 1) % _fungibleIdAndCounts.Length;
var garage = new FungibleItemGarage(_tradableFungibleItems[nextIndex], 1);
var garage = new FungibleItemGarage(_fungibleItems[nextIndex], 1);
var previousStatesWithInvalidGarageState =
_previousStates.SetState(addr, garage.Serialize());
Assert.Throws<ArgumentException>(() => Execute(
Expand Down Expand Up @@ -301,7 +301,7 @@ public void Execute_Throws_Exception()
{
var (fungibleId, _) = _fungibleIdAndCounts[i];
var addr = Addresses.GetGarageAddress(_recipientAgentAddr, fungibleId);
var garage = new FungibleItemGarage(_tradableFungibleItems[i], int.MaxValue);
var garage = new FungibleItemGarage(_fungibleItems[i], int.MaxValue);
var previousStatesWithInvalidGarageState =
_previousStates.SetState(addr, garage.Serialize());
Assert.Throws<ArgumentOutOfRangeException>(() => Execute(
Expand Down Expand Up @@ -353,7 +353,7 @@ private static FungibleAssetValue[] GetFungibleAssetValues()
Address recipientAddr,
FungibleAssetValue[] fungibleAssetValues,
(HashDigest<SHA256> fungibleId, int count)[] fungibleIdAndCounts,
ITradableFungibleItem[] _tradableFungibleItems,
IFungibleItem[] _fungibleItems,
IAccount previousStates)
GetSuccessfulPreviousStatesWithPlainValue()
{
Expand All @@ -380,33 +380,47 @@ private static FungibleAssetValue[] GetFungibleAssetValues()
fav);
}

var fungibleIdAndCounts = _tableSheets.MaterialItemSheet.OrderedList!
.Take(3)
.Select(ItemFactory.CreateTradableMaterial)
.Select((tradableMaterial, index) =>
{
var senderGarageAddr = Addresses.GetGarageAddress(
SenderAgentAddr,
tradableMaterial.FungibleId);
var garageState = previousStates.GetState(senderGarageAddr);
var garage = garageState is null
? new FungibleItemGarage(tradableMaterial, 0)
: new FungibleItemGarage(garageState);
garage.Load(index + 1);
previousStates = previousStates
.SetState(senderGarageAddr, garage.Serialize());
var fungibleIdAndCounts = new List<(IFungibleItem fungibleItem, int count)>();
var tradableIds = new[] { 400000, 500000 };
var nonTradableIds = new[] { 600201, 800201, 800202 };
for (int i = 0; i < tradableIds.Count(); i++)
{
var id = tradableIds[i];
var row = _tableSheets.MaterialItemSheet[id];
fungibleIdAndCounts.Add((ItemFactory.CreateTradableMaterial(row), i + 1));
}

for (int i = 0; i < nonTradableIds.Count(); i++)
{
var id = nonTradableIds[i];
var row = _tableSheets.MaterialItemSheet[id];
fungibleIdAndCounts.Add((ItemFactory.CreateMaterial(row), i + 1));
}

foreach (var (fungibleItem, count) in fungibleIdAndCounts)
{
var senderGarageAddr = Addresses.GetGarageAddress(
SenderAgentAddr,
fungibleItem.FungibleId);
var garageState = previousStates.GetState(senderGarageAddr);
Material material = fungibleItem is TradableMaterial tradableMaterial
? new Material(tradableMaterial)
: (Material)fungibleItem;
var garage = garageState is null
? new FungibleItemGarage(material, 0)
: new FungibleItemGarage(garageState);
garage.Load(count);
previousStates = previousStates
.SetState(senderGarageAddr, garage.Serialize());
}

return (
tradableFungibleItem: (ITradableFungibleItem)tradableMaterial,
count: index + 1);
}).ToArray();
return (
new PrivateKey().Address,
fungibleAssetValues,
fungibleIdAndCounts
.Select(tuple => (tuple.tradableFungibleItem.FungibleId, tuple.count))
.Select(tuple => (tuple.fungibleItem.FungibleId, tuple.count))
.ToArray(),
fungibleIdAndCounts.Select(tuple => tuple.tradableFungibleItem).ToArray(),
fungibleIdAndCounts.Select(tuple => tuple.fungibleItem).ToArray(),
previousStates);
}
}
Expand Down
55 changes: 36 additions & 19 deletions .Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ public class LoadIntoMyGaragesTest
private readonly Address? _inventoryAddr;
private readonly (HashDigest<SHA256> fungibleId, int count)[] _fungibleIdAndCounts;
private readonly FungibleAssetValue _cost;
private readonly ITradableFungibleItem[] _tradableFungibleItems;
private readonly IFungibleItem[] _fungibleItems;
private readonly IAccount _previousStates;
private readonly int[] _nonTradableIds = new[]
{
600201,
800201,
800202,
};

public LoadIntoMyGaragesTest()
{
Expand All @@ -55,7 +61,7 @@ public LoadIntoMyGaragesTest()
_inventoryAddr,
_fungibleIdAndCounts,
_cost,
_tradableFungibleItems,
_fungibleItems,
_previousStates
) = GetSuccessfulPreviousStatesWithPlainValue();
}
Expand Down Expand Up @@ -170,9 +176,8 @@ public void Execute_Success()
var inventory = new Inventory((List)inventoryState);
foreach (var (fungibleId, count) in action.FungibleIdAndCounts)
{
Assert.False(inventory.HasTradableFungibleItem(
Assert.False(inventory.HasFungibleItem(
fungibleId,
requiredBlockIndex: null,
blockIndex: 0,
1));
var garageAddr = Addresses.GetGarageAddress(
Expand All @@ -181,6 +186,7 @@ public void Execute_Success()
var garage = new FungibleItemGarage(nextStates.GetState(garageAddr));
Assert.Equal(fungibleId, garage.Item.FungibleId);
Assert.Equal(count, garage.Count);
Assert.IsType<Material>(garage.Item);
}
}

Expand Down Expand Up @@ -364,7 +370,7 @@ public void Execute_Throws_Exception()
var (fungibleId, _) = _fungibleIdAndCounts[i];
var addr = Addresses.GetGarageAddress(AgentAddr, fungibleId);
var nextIndex = (i + 1) % _fungibleIdAndCounts.Length;
var garage = new FungibleItemGarage(_tradableFungibleItems[nextIndex], 1);
var garage = new FungibleItemGarage(_fungibleItems[nextIndex], 1);
var previousStatesWithInvalidGarageState =
_previousStates.SetState(addr, garage.Serialize());
Assert.Throws<Exception>(() => Execute(
Expand All @@ -382,7 +388,7 @@ public void Execute_Throws_Exception()
{
var (fungibleId, _) = _fungibleIdAndCounts[i];
var addr = Addresses.GetGarageAddress(AgentAddr, fungibleId);
var garage = new FungibleItemGarage(_tradableFungibleItems[i], int.MaxValue);
var garage = new FungibleItemGarage(_fungibleItems[i], int.MaxValue);
var previousStatesWithInvalidGarageState =
_previousStates.SetState(addr, garage.Serialize());
Assert.Throws<ArgumentOutOfRangeException>(() => Execute(
Expand Down Expand Up @@ -453,7 +459,7 @@ private static (Address balanceAddr, FungibleAssetValue value)[]
Address? inventoryAddr,
(HashDigest<SHA256> fungibleId, int count)[] fungibleIdAndCounts,
FungibleAssetValue cost,
ITradableFungibleItem[] _tradableFungibleItems,
IFungibleItem[] _fungibleItems,
IAccount previousStates)
GetSuccessfulPreviousStatesWithPlainValue()
{
Expand Down Expand Up @@ -484,20 +490,31 @@ private static (Address balanceAddr, FungibleAssetValue value)[]
var inventoryAddr = Addresses.GetInventoryAddress(AgentAddr, AvatarIndex);
var inventoryState = (List)previousStates.GetState(inventoryAddr)!;
var inventory = new Inventory(inventoryState);
var fungibleItemAndCounts = _tableSheets.MaterialItemSheet.OrderedList!
.Where(row => _tableSheets.LoadIntoMyGaragesCostSheet.HasCost(row.ItemId))
.Select(ItemFactory.CreateTradableMaterial)
.Select((tradableMaterial, index) =>
var fungibleItemAndCounts = new List<(IFungibleItem fungibleItem, int count)>();
var rows = _tableSheets.MaterialItemSheet.OrderedList!.Where(row =>
_tableSheets.LoadIntoMyGaragesCostSheet.HasCost(row.ItemId)).ToList();
for (int i = 0; i < rows.Count; i++)
{
var row = rows[i];
IFungibleItem item;
if (_nonTradableIds.Contains(row.Id))
{
item = ItemFactory.CreateMaterial(row);
}
else
{
inventory.AddFungibleItem(tradableMaterial, index + 1);
return (
tradableFungibleItem: (ITradableFungibleItem)tradableMaterial,
count: index + 1);
}).ToArray();
item = ItemFactory.CreateTradableMaterial(row);
}

var count = i + 1;
inventory.AddFungibleItem((ItemBase)item, count);
fungibleItemAndCounts.Add((item, count));
}

var garageCost = _tableSheets.LoadIntoMyGaragesCostSheet.GetGarageCost(
fungibleAssetValues.Select(tuple => tuple.value),
fungibleItemAndCounts
.Select(tuple => (tuple.tradableFungibleItem.FungibleId, tuple.count)));
.Select(tuple => (tuple.fungibleItem.FungibleId, tuple.count)));
previousStates = previousStates.MintAsset(
new ActionContext { Signer = AgentAddr },
AgentAddr,
Expand All @@ -506,10 +523,10 @@ private static (Address balanceAddr, FungibleAssetValue value)[]
fungibleAssetValues,
inventoryAddr,
fungibleItemAndCounts
.Select(tuple => (tuple.tradableFungibleItem.FungibleId, tuple.count))
.Select(tuple => (tuple.fungibleItem.FungibleId, tuple.count))
.ToArray(),
garageCost,
fungibleItemAndCounts.Select(tuple => tuple.tradableFungibleItem).ToArray(),
fungibleItemAndCounts.Select(tuple => tuple.fungibleItem).ToArray(),
previousStates.SetState(inventoryAddr, inventory.Serialize())
);
}
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/HitHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class HitHelperTest
public void GetHitStep2()
{
// copy from previous logic
int GetHitStep2Legacy(int attackerHit, int defenderHit)
long GetHitStep2Legacy(int attackerHit, int defenderHit)
{
attackerHit = Math.Max(1, attackerHit);
defenderHit = Math.Max(1, defenderHit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ public static class StakePolicySheetFixtures
StakeRegularRewardSheet,StakeRegularRewardSheet_V1
RewardInterval,40
LockupInterval,150";

public const string V6 = @"attr_name,value
StakeRegularFixedRewardSheet,StakeRegularFixedRewardSheet_V3
StakeRegularRewardSheet,StakeRegularRewardSheet_V6
RewardInterval,75600
LockupInterval,302400";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@ public static class StakeRegularFixedRewardSheetFixtures
5,500000,500000,2
6,5000000,500000,2
7,10000000,500000,2";

public const string V3 = @"level,required_gold,item_id,count
1,50,500000,1
2,500,500000,2
3,5000,500000,2
4,50000,500000,2
5,500000,500000,2
6,1000000,500000,2
7,5000000,500000,2
8,10000000,500000,2";
}
}
Loading

0 comments on commit e482c59

Please sign in to comment.