Skip to content

Commit 9bc336a

Browse files
author
ulismoon (hyeon)
authored
Merge pull request #2781 from planetarium/release/1.16.0
1.16.0
2 parents a0dcd80 + fa9332f commit 9bc336a

22 files changed

+407
-79
lines changed

.Lib9c.Tests/Action/ActionEvaluationTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Lib9c.Tests.Action
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Numerics;
56
using Bencodex.Types;
67
using Lib9c.Formatters;
78
using Libplanet.Action.State;
@@ -93,6 +94,7 @@ public ActionEvaluationTest()
9394
[InlineData(typeof(RuneSummon))]
9495
[InlineData(typeof(ActivateCollection))]
9596
[InlineData(typeof(RetrieveAvatarAssets))]
97+
[InlineData(typeof(MigrateFee))]
9698
public void Serialize_With_MessagePack(Type actionType)
9799
{
98100
var action = GetAction(actionType);
@@ -479,6 +481,14 @@ private ActionBase GetAction(Type type)
479481
},
480482
},
481483
RetrieveAvatarAssets _ => new RetrieveAvatarAssets(avatarAddress: new PrivateKey().Address),
484+
MigrateFee _ => new MigrateFee
485+
{
486+
TransferData = new List<(Address sender, Address recipient, BigInteger amount)>
487+
{
488+
(new PrivateKey().Address, new PrivateKey().Address, 1),
489+
(new PrivateKey().Address, new PrivateKey().Address, 2),
490+
},
491+
},
482492
_ => throw new InvalidCastException(),
483493
};
484494
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
namespace Lib9c.Tests.Action;
2+
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Numerics;
6+
using Libplanet.Action.State;
7+
using Libplanet.Crypto;
8+
using Libplanet.Mocks;
9+
using Libplanet.Types.Assets;
10+
using Nekoyume.Action;
11+
using Nekoyume.Model.State;
12+
using Nekoyume.Module;
13+
using Xunit;
14+
15+
public class MigrateFeeTest
16+
{
17+
private readonly Currency _ncgCurrency;
18+
19+
public MigrateFeeTest()
20+
{
21+
#pragma warning disable CS0618
22+
_ncgCurrency = Currency.Legacy("NCG", 2, null);
23+
#pragma warning restore CS0618
24+
}
25+
26+
[Fact]
27+
public void Execute()
28+
{
29+
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
30+
var context = new ActionContext();
31+
var state = new World(MockUtil.MockModernWorldState)
32+
.SetLegacyState(AdminState.Address, new AdminState(admin, 100).Serialize())
33+
.SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(_ncgCurrency).Serialize());
34+
var recipient = new PrivateKey().Address;
35+
var transferData = new List<(Address sender, Address recipient, BigInteger amount)>();
36+
var amount = FungibleAssetValue.Parse(_ncgCurrency, 0.1m.ToString(CultureInfo.InvariantCulture));
37+
for (int i = 1; i < 10; i++)
38+
{
39+
var address = new PrivateKey().Address;
40+
var balance = 0.1m * i;
41+
var fav = FungibleAssetValue.Parse(_ncgCurrency, balance.ToString(CultureInfo.InvariantCulture));
42+
state = state.MintAsset(context, address, fav);
43+
transferData.Add((address, recipient, amount.RawValue));
44+
}
45+
46+
var action = new MigrateFee
47+
{
48+
TransferData = transferData,
49+
Memo = "memo",
50+
};
51+
52+
var nextState = action.Execute(new ActionContext
53+
{
54+
BlockIndex = 1L,
55+
PreviousState = state,
56+
RandomSeed = 0,
57+
Signer = admin,
58+
});
59+
60+
foreach (var (sender, _, _) in transferData)
61+
{
62+
var prevBalance = state.GetBalance(sender, _ncgCurrency);
63+
Assert.Equal(prevBalance - amount, nextState.GetBalance(sender, _ncgCurrency));
64+
}
65+
66+
Assert.Equal(FungibleAssetValue.Parse(_ncgCurrency, "0.9"), nextState.GetBalance(recipient, _ncgCurrency));
67+
}
68+
69+
[Theory]
70+
[InlineData(true)]
71+
[InlineData(false)]
72+
public void PlainValue(bool memo)
73+
{
74+
var transferData = new List<(Address sender, Address recipient, BigInteger amount)>();
75+
// 0.9
76+
// 1.0
77+
// 1.1
78+
for (int i = 9; i < 12; i++)
79+
{
80+
var sender = new PrivateKey().Address;
81+
var recipient = new PrivateKey().Address;
82+
var amount = FungibleAssetValue.Parse(_ncgCurrency, (0.1m * i).ToString(CultureInfo.InvariantCulture));
83+
transferData.Add((sender, recipient, amount.RawValue));
84+
}
85+
86+
var action = new MigrateFee
87+
{
88+
TransferData = transferData,
89+
Memo = memo ? "memo" : null,
90+
};
91+
92+
var des = new MigrateFee();
93+
des.LoadPlainValue(action.PlainValue);
94+
95+
for (int i = 0; i < action.TransferData.Count; i++)
96+
{
97+
var data = action.TransferData[i];
98+
Assert.Equal(des.TransferData[i].sender, data.sender);
99+
Assert.Equal(des.TransferData[i].recipient, data.recipient);
100+
Assert.Equal(des.TransferData[i].amount, data.amount);
101+
}
102+
103+
Assert.Equal(memo, !string.IsNullOrEmpty(des.Memo));
104+
}
105+
106+
[Fact]
107+
public void Execute_Throw_InsufficientBalanceException()
108+
{
109+
var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7");
110+
var context = new ActionContext();
111+
var state = new World(MockUtil.MockModernWorldState)
112+
.SetLegacyState(AdminState.Address, new AdminState(admin, 100).Serialize())
113+
.SetLegacyState(GoldCurrencyState.Address, new GoldCurrencyState(_ncgCurrency).Serialize());
114+
var recipient = new PrivateKey().Address;
115+
var transferData = new List<(Address sender, Address recipient, BigInteger amount)>();
116+
var amount = 1 * _ncgCurrency;
117+
var address = new PrivateKey().Address;
118+
var balance = 0.1m;
119+
var fav = FungibleAssetValue.Parse(_ncgCurrency, balance.ToString(CultureInfo.InvariantCulture));
120+
state = state.MintAsset(context, address, fav);
121+
transferData.Add((address, recipient, amount.RawValue));
122+
123+
var action = new MigrateFee
124+
{
125+
TransferData = transferData,
126+
Memo = "memo",
127+
};
128+
129+
Assert.Throws<InsufficientBalanceException>(() => action.Execute(new ActionContext
130+
{
131+
BlockIndex = 1L,
132+
PreviousState = state,
133+
RandomSeed = 0,
134+
Signer = admin,
135+
}));
136+
}
137+
}

.Lib9c.Tests/Action/UnlockRuneSlotTest.cs

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,19 @@ namespace Lib9c.Tests.Action
1717

1818
public class UnlockRuneSlotTest
1919
{
20-
private readonly Currency _goldCurrency;
21-
22-
public UnlockRuneSlotTest()
23-
{
24-
_goldCurrency = Currency.Legacy("NCG", 2, null);
25-
}
20+
private readonly Currency _goldCurrency = Currency.Legacy("NCG", 2, null);
2621

22+
// ReSharper disable once MemberCanBePrivate.Global
2723
public IWorld Init(out Address agentAddress, out Address avatarAddress, out long blockIndex)
2824
{
2925
agentAddress = new PrivateKey().Address;
3026
avatarAddress = new PrivateKey().Address;
3127
var sheets = TableSheetsImporter.ImportSheets();
3228
var tableSheets = new TableSheets(sheets);
33-
blockIndex = tableSheets.WorldBossListSheet.Values
34-
.OrderBy(x => x.StartedBlockIndex)
29+
blockIndex = tableSheets.ArenaSheet.Values.First().Round
30+
.OrderBy(x => x.StartBlockIndex)
3531
.First()
36-
.StartedBlockIndex;
32+
.StartBlockIndex;
3733

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

4844
var gameConfigState = new GameConfigState(sheets[nameof(GameConfigSheet)]);
49-
var avatarState = new AvatarState(
50-
avatarAddress,
51-
agentAddress,
52-
0,
53-
tableSheets.GetAvatarSheets(),
54-
default
55-
);
5645
return state.SetLegacyState(gameConfigState.address, gameConfigState.Serialize());
5746
}
5847

@@ -125,14 +114,6 @@ public void Execute_InsufficientBalanceException()
125114
SlotIndex = 1,
126115
};
127116

128-
var ctx = new ActionContext
129-
{
130-
BlockIndex = blockIndex,
131-
PreviousState = state,
132-
RandomSeed = 0,
133-
Signer = agentAddress,
134-
};
135-
136117
Assert.Throws<InsufficientBalanceException>(() =>
137118
action.Execute(new ActionContext()
138119
{
@@ -153,14 +134,6 @@ public void Execute_SlotNotFoundException()
153134
SlotIndex = 99,
154135
};
155136

156-
var ctx = new ActionContext
157-
{
158-
BlockIndex = blockIndex,
159-
PreviousState = state,
160-
RandomSeed = 0,
161-
Signer = agentAddress,
162-
};
163-
164137
Assert.Throws<SlotNotFoundException>(() =>
165138
action.Execute(new ActionContext()
166139
{
@@ -181,14 +154,6 @@ public void Execute_MismatchRuneSlotTypeException()
181154
SlotIndex = 0,
182155
};
183156

184-
var ctx = new ActionContext
185-
{
186-
BlockIndex = blockIndex,
187-
PreviousState = state,
188-
RandomSeed = 0,
189-
Signer = agentAddress,
190-
};
191-
192157
Assert.Throws<MismatchRuneSlotTypeException>(() =>
193158
action.Execute(new ActionContext()
194159
{

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
if: github.event_name != 'pull_request'
3434
run: |
3535
if [[ "$NUGET_API_KEY" != "" ]]; then
36-
for project in Lib9c Lib9c.Abstractions
36+
for project in Lib9c Lib9c.Abstractions Lib9c.MessagePack Lib9c.Renderers
3737
do
3838
dotnet nuget push ./$project/.bin/Lib9c.*.nupkg \
3939
--api-key "$NUGET_API_KEY" \

Lib9c.Abstractions/Lib9c.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
<OutputPath>.bin</OutputPath>
88
<IntermediateOutputPath>.obj</IntermediateOutputPath>
9+
<VersionPrefix>1.17.0</VersionPrefix>
910
</PropertyGroup>
1011

1112
<ItemGroup>

Lib9c.MessagePack/Lib9c.MessagePack.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Platforms>AnyCPU</Platforms>
99
<OutputPath>.bin</OutputPath>
1010
<IntermediateOutputPath>.obj</IntermediateOutputPath>
11+
<VersionPrefix>1.17.0</VersionPrefix>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

Lib9c.Policy/Policy/MaxTransactionsBytesPolicy.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ private MaxTransactionsBytesPolicy(
4646
// Issued for v100098.
4747
.Add(new SpannedSubPolicy<long>(
4848
startIndex: 3_150_001L,
49-
value: 1024L * 500L)); // 500 KiB
49+
value: 1024L * 500L)) // 500 KiB
50+
// Note: Limit increase to patch table with big CSV.
51+
// Issued for v200220
52+
.Add(new SpannedSubPolicy<long>(
53+
startIndex: 11_637_001L,
54+
value: 1024L * 1024L)); // 1 MiB
5055

5156
public static IVariableSubPolicy<long> Heimdall =>
5257
Default
@@ -57,7 +62,12 @@ private MaxTransactionsBytesPolicy(
5762
// Note: Heimdall has been started after v100098
5863
.Add(new SpannedSubPolicy<long>(
5964
startIndex: 1L,
60-
value: 1024L * 500L)); // 500 KiB
65+
value: 1024L * 500L)) // 500 KiB
66+
// Note: Limit increase to patch table with big CSV.
67+
// Issued for v200220
68+
.Add(new SpannedSubPolicy<long>(
69+
startIndex: 3_031_001L,
70+
value: 1024L * 1024L)); // 1 MiB
6171

6272
// Note: For internal testing.
6373
public static IVariableSubPolicy<long> OdinInternal =>
@@ -79,6 +89,11 @@ private MaxTransactionsBytesPolicy(
7989
value: 1024L * 100L)) // 100 KiB
8090
.Add(new SpannedSubPolicy<long>(
8191
startIndex: 3_150_001L,
82-
value: 1024L * 500L)); // 500 KiB
92+
value: 1024L * 500L)) // 500 KiB
93+
// Note: Limit increase to patch table with big CSV.
94+
// Issued for v200220
95+
.Add(new SpannedSubPolicy<long>(
96+
startIndex: 11_556_001L,
97+
value: 1024L * 1024L)); // 1 MiB
8398
}
8499
}

Lib9c.Renderers/Lib9c.Renderers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Nullable>enable</Nullable>
77
<OutputPath>.bin</OutputPath>
88
<IntermediateOutputPath>.obj</IntermediateOutputPath>
9+
<VersionPrefix>1.17.0</VersionPrefix>
910
<RootNamespace>Lib9c</RootNamespace>
1011
</PropertyGroup>
1112

0 commit comments

Comments
 (0)