Skip to content

Commit

Permalink
Merge pull request #2744 from moreal/main-to-dev-1.16.0
Browse files Browse the repository at this point in the history
Backmerge 1.16.0 release
  • Loading branch information
moreal authored Aug 8, 2024
2 parents 9f65dc7 + 5878d42 commit 79186d0
Show file tree
Hide file tree
Showing 61 changed files with 1,789 additions and 224 deletions.
1 change: 1 addition & 0 deletions .Lib9c.Benchmarks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BenchmarkDotNet.Artifacts/
88 changes: 88 additions & 0 deletions .Lib9c.Benchmarks/Actions/AutoJoinGuild.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using BenchmarkDotNet.Attributes;
using Bencodex.Types;
using Lib9c.Tests.Action;
using Lib9c.Tests.Util;
using Libplanet.Action.State;
using Libplanet.Mocks;
using Nekoyume;
using Nekoyume.Action.Guild;
using Nekoyume.Extensions;
using Nekoyume.Module;
using Nekoyume.Module.Guild;
using Nekoyume.TypedAddress;

namespace Lib9c.Benchmarks.Actions;

public class AutoJoinGuild
{
private AgentAddress signer = AddressUtil.CreateAgentAddress();
private IWorld worldEmpty;
private IWorld worldWithPledge;
private IWorld worldWithPledgeAndGuild;
private IWorld worldAfterMigration;

[GlobalSetup]
public void Setup()
{
worldEmpty = new World(MockUtil.MockModernWorldState);
worldWithPledge = worldEmpty
.SetLegacyState(
signer.GetPledgeAddress(),
new List(MeadConfig.PatronAddress.Bencoded, (Boolean)true, (Integer)4));

var guildMasterAddress = GuildConfig.PlanetariumGuildOwner;
var guildAddress = AddressUtil.CreateGuildAddress();
worldWithPledgeAndGuild = worldWithPledge
.MakeGuild(guildAddress, guildMasterAddress);
worldAfterMigration = worldWithPledgeAndGuild
.JoinGuild(guildAddress, signer);
}

[Benchmark]
public void Execute_WithoutPledge()
{
var action = new Nekoyume.PolicyAction.Tx.Begin.AutoJoinGuild();
action.Execute(new ActionContext
{
IsPolicyAction = true,
PreviousState = worldEmpty,
Signer = signer,
});
}

[Benchmark]
public void Execute_WithPledge_WithoutGuild()
{
var action = new Nekoyume.PolicyAction.Tx.Begin.AutoJoinGuild();
action.Execute(new ActionContext
{
IsPolicyAction = true,
PreviousState = worldWithPledge,
Signer = signer,
});
}

[Benchmark]
public void Execute_WithPledge_WithGuild()
{
var action = new Nekoyume.PolicyAction.Tx.Begin.AutoJoinGuild();
action.Execute(new ActionContext
{
IsPolicyAction = true,
PreviousState = worldWithPledgeAndGuild,
Signer = signer,
});
}

[Benchmark]
public void Execute_AfterMigration()
{
var action = new Nekoyume.PolicyAction.Tx.Begin.AutoJoinGuild();
action.Execute(new ActionContext
{
IsPolicyAction = true,
PreviousState = worldAfterMigration,
Signer = signer,
});
}
}
110 changes: 110 additions & 0 deletions .Lib9c.Benchmarks/Actions/MigratePledgeToGuild.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using BenchmarkDotNet.Attributes;
using Bencodex.Types;
using Lib9c.Tests.Action;
using Lib9c.Tests.Util;
using Libplanet.Action.State;
using Libplanet.Mocks;
using Nekoyume;
using Nekoyume.Action.Guild;
using Nekoyume.Extensions;
using Nekoyume.Module;
using Nekoyume.Module.Guild;
using Nekoyume.TypedAddress;

namespace Lib9c.Benchmarks.Actions;

public class MigratePledgeToGuild
{
private AgentAddress signer = AddressUtil.CreateAgentAddress();
private AgentAddress target = AddressUtil.CreateAgentAddress();
private IWorld worldEmpty;
private IWorld worldWithPledge;
private IWorld worldWithPledgeAndGuild;
private IWorld worldAfterMigration;

[GlobalSetup]
public void Setup()
{
worldEmpty = new World(MockUtil.MockModernWorldState);
worldWithPledge = worldEmpty
.SetLegacyState(
target.GetPledgeAddress(),
new List(MeadConfig.PatronAddress.Bencoded, (Boolean)true, (Integer)4));

var guildMasterAddress = GuildConfig.PlanetariumGuildOwner;
var guildAddress = AddressUtil.CreateGuildAddress();
worldWithPledgeAndGuild = worldWithPledge
.MakeGuild(guildAddress, guildMasterAddress);
worldAfterMigration = worldWithPledgeAndGuild
.JoinGuild(guildAddress, signer);
}

[Benchmark]
public void Execute_WithoutPledge()
{
var action = new Nekoyume.Action.Guild.Migration.MigratePledgeToGuild(target);
try
{
action.Execute(new ActionContext
{
IsPolicyAction = false,
PreviousState = worldEmpty,
Signer = signer,
});
}
catch
{
// Do nothing.
}
}

[Benchmark]
public void Execute_WithPledge_WithoutGuild()
{
var action = new Nekoyume.Action.Guild.Migration.MigratePledgeToGuild(target);
try
{
action.Execute(new ActionContext
{
IsPolicyAction = false,
PreviousState = worldWithPledge,
Signer = signer,
});
}
catch
{
// Do nothing.
}
}

[Benchmark]
public void Execute_WithPledge_WithGuild()
{
var action = new Nekoyume.Action.Guild.Migration.MigratePledgeToGuild(target);
action.Execute(new ActionContext
{
IsPolicyAction = false,
PreviousState = worldWithPledgeAndGuild,
Signer = signer,
});
}

[Benchmark]
public void Execute_AfterMigration()
{
var action = new Nekoyume.Action.Guild.Migration.MigratePledgeToGuild(target);
try
{
action.Execute(new ActionContext
{
IsPolicyAction = false,
PreviousState = worldAfterMigration,
Signer = signer,
});
}
catch
{
// Do nothing.
}
}
}
42 changes: 42 additions & 0 deletions .Lib9c.Benchmarks/Actions/TransferAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using BenchmarkDotNet.Attributes;
using Bencodex.Types;
using Lib9c.Tests.Action;
using Lib9c.Tests.Util;
using Libplanet.Action.State;
using Libplanet.Mocks;
using Libplanet.Types.Assets;
using Nekoyume;
using Nekoyume.Action.Guild;
using Nekoyume.Extensions;
using Nekoyume.Module;
using Nekoyume.Module.Guild;
using Nekoyume.TypedAddress;

namespace Lib9c.Benchmarks.Actions;

public class TransferAsset
{
private AgentAddress signer = AddressUtil.CreateAgentAddress();
private AgentAddress recipient = AddressUtil.CreateAgentAddress();
private Currency currency = Currency.Uncapped("NCG", 2, null);
private IWorld world;

[GlobalSetup]
public void Setup()
{
world = new World(MockUtil.MockModernWorldState)
.MintAsset(new ActionContext(), signer, currency * 100);
}

[Benchmark]
public void Execute()
{
var action = new Nekoyume.Action.TransferAsset(signer, recipient, currency * 100);
action.Execute(new ActionContext
{
Signer = signer,
PreviousState = world,
IsPolicyAction = false,
});
}
}
6 changes: 6 additions & 0 deletions .Lib9c.Benchmarks/Lib9c.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\.Lib9c.Tests\Lib9c.Tests.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet.RocksDBStore\Libplanet.RocksDBStore.csproj" />
<ProjectReference Include="..\.Libplanet\src\Libplanet\Libplanet.csproj" />
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
<ProjectReference Include="..\Lib9c.Policy\Lib9c.Policy.csproj" />
<ProjectReference Include="..\Libplanet.Crypto.Secp256k1\Libplanet.Crypto.Secp256k1.csproj" />
<ProjectReference Include="..\.Libplanet\test\Libplanet.Mocks\Libplanet.Mocks.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 79186d0

Please sign in to comment.