Skip to content

Commit

Permalink
Merge pull request #2781 from planetarium/release/1.16.0
Browse files Browse the repository at this point in the history
1.16.0
  • Loading branch information
U-lis authored Aug 27, 2024
2 parents a0dcd80 + fa9332f commit 9bc336a
Show file tree
Hide file tree
Showing 22 changed files with 407 additions and 79 deletions.
10 changes: 10 additions & 0 deletions .Lib9c.Tests/Action/ActionEvaluationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace Lib9c.Tests.Action
{
using System;
using System.Collections.Generic;
using System.Numerics;
using Bencodex.Types;
using Lib9c.Formatters;
using Libplanet.Action.State;
Expand Down Expand Up @@ -93,6 +94,7 @@ public ActionEvaluationTest()
[InlineData(typeof(RuneSummon))]
[InlineData(typeof(ActivateCollection))]
[InlineData(typeof(RetrieveAvatarAssets))]
[InlineData(typeof(MigrateFee))]
public void Serialize_With_MessagePack(Type actionType)
{
var action = GetAction(actionType);
Expand Down Expand Up @@ -479,6 +481,14 @@ private ActionBase GetAction(Type type)
},
},
RetrieveAvatarAssets _ => new RetrieveAvatarAssets(avatarAddress: new PrivateKey().Address),
MigrateFee _ => new MigrateFee
{
TransferData = new List<(Address sender, Address recipient, BigInteger amount)>
{
(new PrivateKey().Address, new PrivateKey().Address, 1),
(new PrivateKey().Address, new PrivateKey().Address, 2),
},
},
_ => throw new InvalidCastException(),
};
}
Expand Down
137 changes: 137 additions & 0 deletions .Lib9c.Tests/Action/MigrateFeeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
namespace Lib9c.Tests.Action;

using System.Collections.Generic;
using System.Globalization;
using System.Numerics;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Mocks;
using Libplanet.Types.Assets;
using Nekoyume.Action;
using Nekoyume.Model.State;
using Nekoyume.Module;
using Xunit;

public class MigrateFeeTest
{
private readonly Currency _ncgCurrency;

public MigrateFeeTest()
{
#pragma warning disable CS0618
_ncgCurrency = Currency.Legacy("NCG", 2, null);
#pragma warning restore CS0618
}

[Fact]
public void Execute()
{
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
var context = new ActionContext();
var state = new World(MockUtil.MockModernWorldState)
.SetLegacyState(AdminState.Address, new AdminState(admin, 100).Serialize())
.SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(_ncgCurrency).Serialize());
var recipient = new PrivateKey().Address;
var transferData = new List<(Address sender, Address recipient, BigInteger amount)>();
var amount = FungibleAssetValue.Parse(_ncgCurrency, 0.1m.ToString(CultureInfo.InvariantCulture));
for (int i = 1; i < 10; i++)
{
var address = new PrivateKey().Address;
var balance = 0.1m * i;
var fav = FungibleAssetValue.Parse(_ncgCurrency, balance.ToString(CultureInfo.InvariantCulture));
state = state.MintAsset(context, address, fav);
transferData.Add((address, recipient, amount.RawValue));
}

var action = new MigrateFee
{
TransferData = transferData,
Memo = "memo",
};

var nextState = action.Execute(new ActionContext
{
BlockIndex = 1L,
PreviousState = state,
RandomSeed = 0,
Signer = admin,
});

foreach (var (sender, _, _) in transferData)
{
var prevBalance = state.GetBalance(sender, _ncgCurrency);
Assert.Equal(prevBalance - amount, nextState.GetBalance(sender, _ncgCurrency));
}

Assert.Equal(FungibleAssetValue.Parse(_ncgCurrency, "0.9"), nextState.GetBalance(recipient, _ncgCurrency));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void PlainValue(bool memo)
{
var transferData = new List<(Address sender, Address recipient, BigInteger amount)>();
// 0.9
// 1.0
// 1.1
for (int i = 9; i < 12; i++)
{
var sender = new PrivateKey().Address;
var recipient = new PrivateKey().Address;
var amount = FungibleAssetValue.Parse(_ncgCurrency, (0.1m * i).ToString(CultureInfo.InvariantCulture));
transferData.Add((sender, recipient, amount.RawValue));
}

var action = new MigrateFee
{
TransferData = transferData,
Memo = memo ? "memo" : null,
};

var des = new MigrateFee();
des.LoadPlainValue(action.PlainValue);

for (int i = 0; i < action.TransferData.Count; i++)
{
var data = action.TransferData[i];
Assert.Equal(des.TransferData[i].sender, data.sender);
Assert.Equal(des.TransferData[i].recipient, data.recipient);
Assert.Equal(des.TransferData[i].amount, data.amount);
}

Assert.Equal(memo, !string.IsNullOrEmpty(des.Memo));
}

[Fact]
public void Execute_Throw_InsufficientBalanceException()
{
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
var context = new ActionContext();
var state = new World(MockUtil.MockModernWorldState)
.SetLegacyState(AdminState.Address, new AdminState(admin, 100).Serialize())
.SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(_ncgCurrency).Serialize());
var recipient = new PrivateKey().Address;
var transferData = new List<(Address sender, Address recipient, BigInteger amount)>();
var amount = 1 * _ncgCurrency;
var address = new PrivateKey().Address;
var balance = 0.1m;
var fav = FungibleAssetValue.Parse(_ncgCurrency, balance.ToString(CultureInfo.InvariantCulture));
state = state.MintAsset(context, address, fav);
transferData.Add((address, recipient, amount.RawValue));

var action = new MigrateFee
{
TransferData = transferData,
Memo = "memo",
};

Assert.Throws<InsufficientBalanceException>(() => action.Execute(new ActionContext
{
BlockIndex = 1L,
PreviousState = state,
RandomSeed = 0,
Signer = admin,
}));
}
}
45 changes: 5 additions & 40 deletions .Lib9c.Tests/Action/UnlockRuneSlotTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@ namespace Lib9c.Tests.Action

public class UnlockRuneSlotTest
{
private readonly Currency _goldCurrency;

public UnlockRuneSlotTest()
{
_goldCurrency = Currency.Legacy("NCG", 2, null);
}
private readonly Currency _goldCurrency = Currency.Legacy("NCG", 2, null);

// ReSharper disable once MemberCanBePrivate.Global
public IWorld Init(out Address agentAddress, out Address avatarAddress, out long blockIndex)
{
agentAddress = new PrivateKey().Address;
avatarAddress = new PrivateKey().Address;
var sheets = TableSheetsImporter.ImportSheets();
var tableSheets = new TableSheets(sheets);
blockIndex = tableSheets.WorldBossListSheet.Values
.OrderBy(x => x.StartedBlockIndex)
blockIndex = tableSheets.ArenaSheet.Values.First().Round
.OrderBy(x => x.StartBlockIndex)
.First()
.StartedBlockIndex;
.StartBlockIndex;

var goldCurrencyState = new GoldCurrencyState(_goldCurrency);
var state = new World(MockUtil.MockModernWorldState)
Expand All @@ -46,13 +42,6 @@ public IWorld Init(out Address agentAddress, out Address avatarAddress, out long
}

var gameConfigState = new GameConfigState(sheets[nameof(GameConfigSheet)]);
var avatarState = new AvatarState(
avatarAddress,
agentAddress,
0,
tableSheets.GetAvatarSheets(),
default
);
return state.SetLegacyState(gameConfigState.address, gameConfigState.Serialize());
}

Expand Down Expand Up @@ -125,14 +114,6 @@ public void Execute_InsufficientBalanceException()
SlotIndex = 1,
};

var ctx = new ActionContext
{
BlockIndex = blockIndex,
PreviousState = state,
RandomSeed = 0,
Signer = agentAddress,
};

Assert.Throws<InsufficientBalanceException>(() =>
action.Execute(new ActionContext()
{
Expand All @@ -153,14 +134,6 @@ public void Execute_SlotNotFoundException()
SlotIndex = 99,
};

var ctx = new ActionContext
{
BlockIndex = blockIndex,
PreviousState = state,
RandomSeed = 0,
Signer = agentAddress,
};

Assert.Throws<SlotNotFoundException>(() =>
action.Execute(new ActionContext()
{
Expand All @@ -181,14 +154,6 @@ public void Execute_MismatchRuneSlotTypeException()
SlotIndex = 0,
};

var ctx = new ActionContext
{
BlockIndex = blockIndex,
PreviousState = state,
RandomSeed = 0,
Signer = agentAddress,
};

Assert.Throws<MismatchRuneSlotTypeException>(() =>
action.Execute(new ActionContext()
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
if: github.event_name != 'pull_request'
run: |
if [[ "$NUGET_API_KEY" != "" ]]; then
for project in Lib9c Lib9c.Abstractions
for project in Lib9c Lib9c.Abstractions Lib9c.MessagePack Lib9c.Renderers
do
dotnet nuget push ./$project/.bin/Lib9c.*.nupkg \
--api-key "$NUGET_API_KEY" \
Expand Down
1 change: 1 addition & 0 deletions Lib9c.Abstractions/Lib9c.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<OutputPath>.bin</OutputPath>
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<VersionPrefix>1.17.0</VersionPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Lib9c.MessagePack/Lib9c.MessagePack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Platforms>AnyCPU</Platforms>
<OutputPath>.bin</OutputPath>
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<VersionPrefix>1.17.0</VersionPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 18 additions & 3 deletions Lib9c.Policy/Policy/MaxTransactionsBytesPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ private MaxTransactionsBytesPolicy(
// Issued for v100098.
.Add(new SpannedSubPolicy<long>(
startIndex: 3_150_001L,
value: 1024L * 500L)); // 500 KiB
value: 1024L * 500L)) // 500 KiB
// Note: Limit increase to patch table with big CSV.
// Issued for v200220
.Add(new SpannedSubPolicy<long>(
startIndex: 11_637_001L,
value: 1024L * 1024L)); // 1 MiB

public static IVariableSubPolicy<long> Heimdall =>
Default
Expand All @@ -57,7 +62,12 @@ private MaxTransactionsBytesPolicy(
// Note: Heimdall has been started after v100098
.Add(new SpannedSubPolicy<long>(
startIndex: 1L,
value: 1024L * 500L)); // 500 KiB
value: 1024L * 500L)) // 500 KiB
// Note: Limit increase to patch table with big CSV.
// Issued for v200220
.Add(new SpannedSubPolicy<long>(
startIndex: 3_031_001L,
value: 1024L * 1024L)); // 1 MiB

// Note: For internal testing.
public static IVariableSubPolicy<long> OdinInternal =>
Expand All @@ -79,6 +89,11 @@ private MaxTransactionsBytesPolicy(
value: 1024L * 100L)) // 100 KiB
.Add(new SpannedSubPolicy<long>(
startIndex: 3_150_001L,
value: 1024L * 500L)); // 500 KiB
value: 1024L * 500L)) // 500 KiB
// Note: Limit increase to patch table with big CSV.
// Issued for v200220
.Add(new SpannedSubPolicy<long>(
startIndex: 11_556_001L,
value: 1024L * 1024L)); // 1 MiB
}
}
1 change: 1 addition & 0 deletions Lib9c.Renderers/Lib9c.Renderers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<OutputPath>.bin</OutputPath>
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<VersionPrefix>1.17.0</VersionPrefix>
<RootNamespace>Lib9c</RootNamespace>
</PropertyGroup>

Expand Down
Loading

0 comments on commit 9bc336a

Please sign in to comment.