Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backmerges from 1.22.1 to 1.23.0 #3156

Open
wants to merge 8 commits into
base: release/1.23.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
namespace Lib9c.Tests.Action.Guild.Migration
{
using System;
using System.Linq;
using System.Numerics;
using Bencodex.Types;
using Lib9c.Tests.Util;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Action.Guild;
using Nekoyume.Action.Guild.Migration;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Extensions;
using Nekoyume.Model.Guild;
using Nekoyume.Model.State;
using Nekoyume.Module;
using Nekoyume.Module.Guild;
using Nekoyume.TypedAddress;
using Xunit;

public class MigrateStakeAndJoinGuildTest : GuildTestBase
{
[Fact]
public void Execute()
{
var guildAddress = AddressUtil.CreateGuildAddress();
var validatorKey = new PrivateKey();
var adminAddress = new PrivateKey().Address;
var height = 100L;
var world = World.SetLegacyState(Addresses.Admin, new AdminState(adminAddress, 100L).Serialize());
world = EnsureToInitializeValidator(world, validatorKey, NCG * 100, height++);
world = EnsureToMakeGuild(world, guildAddress, GuildConfig.PlanetariumGuildOwner, validatorKey, height++);
var guildMemberCount = 10;
var migratedGuildMemberCount = 5;
var guildMemberAddresses = Enumerable.Range(0, guildMemberCount).Select(
_ => AddressUtil.CreateAgentAddress()).ToList();
for (var i = 0; i < guildMemberCount; i++)
{
world = EnsureJoinLegacyPlanetariumGuild(world, guildMemberAddresses[i]);
}

for (var i = 0; i < migratedGuildMemberCount; i++)
{
var action = new MigrateStakeAndJoinGuild(guildMemberAddresses[i]);
var actionContext = new ActionContext
{
PreviousState = world,
Signer = adminAddress,
BlockIndex = height++,
};

world = action.Execute(actionContext);
}

var repo = new GuildRepository(world, new ActionContext());
var guild = repo.GetGuild(guildAddress);

for (var i = 0; i < migratedGuildMemberCount; i++)
{
repo.GetGuildParticipant(guildMemberAddresses[i]);
}

for (var i = migratedGuildMemberCount; i < guildMemberCount; i++)
{
Assert.Throws<FailedLoadStateException>(() => repo.GetGuildParticipant(guildMemberAddresses[i]));
}
}

private static IWorld EnsureJoinLegacyPlanetariumGuild(IWorld world, AgentAddress guildParticipantAddress)
{
var planetariumGuildAddress = new GuildRepository(world, new ActionContext { })
.GetJoinedGuild(GuildConfig.PlanetariumGuildOwner);
var legacyParticipant = new LegacyGuildParticipant(planetariumGuildAddress.Value);

return world
.MutateAccount(Addresses.GuildParticipant, account => account.SetState(guildParticipantAddress, legacyParticipant.Bencoded))
.MutateAccount(
Addresses.GuildMemberCounter,
account =>
{
BigInteger count = account.GetState(planetariumGuildAddress.Value) switch
{
Integer i => i.Value,
null => 0,
_ => throw new InvalidCastException(),
};

return account.SetState(planetariumGuildAddress.Value, (Integer)(count + 1));
});
}
}
}
2 changes: 1 addition & 1 deletion Lib9c.Abstractions/Lib9c.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<LangVersion>9</LangVersion>
<CodeAnalysisRuleSet>..\Lib9c.Common.ruleset</CodeAnalysisRuleSet>
<VersionPrefix>1.20.1</VersionPrefix>
<VersionPrefix>1.22.1</VersionPrefix>
</PropertyGroup>

<ItemGroup Condition="!'$(UseLocalLibplanet)'">
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.MessagePack/Lib9c.MessagePack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Platforms>AnyCPU</Platforms>
<OutputPath>.bin</OutputPath>
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<VersionPrefix>1.20.1</VersionPrefix>
<VersionPrefix>1.22.1</VersionPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.Renderers/Lib9c.Renderers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<OutputPath>.bin</OutputPath>
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<VersionPrefix>1.20.1</VersionPrefix>
<VersionPrefix>1.22.1</VersionPrefix>
<RootNamespace>Lib9c</RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using Bencodex;
using Bencodex.Types;
using Nekoyume.TypedAddress;

namespace Nekoyume.Action.Guild.Migration.LegacyModels
{
// TODO: [GuildMigration] Remove this class when the migration is done.
/// <summary>
/// The legacy model for GuildParticipant.
/// </summary>
public class LegacyGuildParticipant : IBencodable, IEquatable<LegacyGuildParticipant>
{
/// <summary>
/// The type name of the state.
/// </summary>
private const string StateTypeName = "guild_participant";

/// <summary>
/// The version of the state.
/// </summary>
private const long StateVersion = 1;

/// <summary>
/// The guild address.
/// </summary>
public readonly GuildAddress GuildAddress;

/// <summary>
/// Constructor of LegacyGuildParticipant.
/// </summary>
/// <param name="guildAddress">
/// The guild address.
/// </param>
public LegacyGuildParticipant(GuildAddress guildAddress)
{
GuildAddress = guildAddress;
}

/// <summary>
/// Constructor of LegacyGuildParticipant.
/// </summary>
/// <param name="list">
/// The serialized data.
/// </param>
/// <exception cref="InvalidCastException">
/// Throws when the deserialization failed.
/// </exception>
/// <exception cref="FailedLoadStateException">
/// Throws when the state is un-deserializable.
/// </exception>
public LegacyGuildParticipant(List list) : this(new GuildAddress(list[2]))
{
if (list[0] is not Text text || text != StateTypeName || list[1] is not Integer integer)
{
throw new InvalidCastException();
}

if (integer > StateVersion)
{
throw new FailedLoadStateException("Un-deserializable state.");
}
}

/// <summary>
/// Serialize the state.
/// </summary>
public List Bencoded => List.Empty
.Add(StateTypeName)
.Add(StateVersion)
.Add(GuildAddress.Bencoded);

/// <inheritdoc/>
IValue IBencodable.Bencoded => Bencoded;

/// <inheritdoc/>
public bool Equals(LegacyGuildParticipant other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return GuildAddress.Equals(other.GuildAddress);
}

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((LegacyGuildParticipant)obj);
}

/// <inheritdoc/>
public override int GetHashCode()
{
return GuildAddress.GetHashCode();
}
}
}
Loading
Loading