Skip to content

Commit

Permalink
Merge pull request #2395 from planetarium/main-merge-dev-92
Browse files Browse the repository at this point in the history
🔀 Main merge dev 92
  • Loading branch information
greymistcube authored Jan 31, 2024
2 parents abc0068 + d4476a4 commit 285d5e9
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 396 deletions.
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 86 files
+8 −8 .Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs
+0 −4 .Lib9c.Tests/Action/ActionEvaluationTest.cs
+0 −299 .Lib9c.Tests/Action/ClaimMonsterCollectionReward0Test.cs
+0 −349 .Lib9c.Tests/Action/ClaimMonsterCollectionReward2Test.cs
+0 −358 .Lib9c.Tests/Action/ClaimMonsterCollectionRewardTest.cs
+56 −0 .Lib9c.Tests/Action/ClaimStakeRewardTest.cs
+2 −2 .Lib9c.Tests/Action/Common/Doomfist.cs
+43 −29 .Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs
+36 −19 .Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs
+1 −1 .Lib9c.Tests/Action/HitHelperTest.cs
+0 −229 .Lib9c.Tests/Action/MonsterCollect0Test.cs
+0 −157 .Lib9c.Tests/Action/MonsterCollect2Test.cs
+0 −178 .Lib9c.Tests/Action/MonsterCollectTest.cs
+6 −0 .Lib9c.Tests/Fixtures/TableCSV/Stake/StakePolicySheetFixtures.cs
+10 −0 .Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularFixedRewardSheetFixtures.cs
+54 −0 .Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularRewardSheetFixtures.cs
+29 −0 .Lib9c.Tests/TableData/StakeRegularRewardSheetTest.cs
+1 −1 .Libplanet
+0 −109 Lib9c/Action/ClaimMonsterCollectionReward.cs
+0 −123 Lib9c/Action/ClaimMonsterCollectionReward0.cs
+0 −95 Lib9c/Action/ClaimMonsterCollectionReward2.cs
+14 −17 Lib9c/Action/Garages/LoadIntoMyGarages.cs
+67 −1 Lib9c/Action/MigrateMonsterCollection.cs
+0 −125 Lib9c/Action/MonsterCollect.cs
+0 −115 Lib9c/Action/MonsterCollect0.cs
+0 −111 Lib9c/Action/MonsterCollect2.cs
+2 −2 Lib9c/Action/Raid.cs
+4 −4 Lib9c/Battle/CriticalHelper.cs
+19 −19 Lib9c/Battle/HitHelper.cs
+1 −1 Lib9c/Battle/RaidSimulator.cs
+1 −1 Lib9c/Battle/RaidSimulatorV1.cs
+1 −1 Lib9c/Battle/RaidSimulatorV2.cs
+6 −6 Lib9c/Helper/ItemOptionHelper.cs
+2 −2 Lib9c/Helper/WorldBossHelper.cs
+4 −4 Lib9c/Model/BattleStatus/Arena/ArenaSkill.cs
+3 −3 Lib9c/Model/BattleStatus/Skill.cs
+2 −2 Lib9c/Model/Buff/Bleed.cs
+2 −2 Lib9c/Model/Buff/Vampiric.cs
+28 −28 Lib9c/Model/Character/ArenaCharacter.cs
+19 −19 Lib9c/Model/Character/CharacterBase.cs
+4 −4 Lib9c/Model/Character/Player.cs
+2 −2 Lib9c/Model/Elemental/ElementalType.cs
+1 −1 Lib9c/Model/Skill/AreaAttack.cs
+1 −1 Lib9c/Model/Skill/Arena/ArenaAreaAttack.cs
+4 −4 Lib9c/Model/Skill/Arena/ArenaAttackSkill.cs
+1 −1 Lib9c/Model/Skill/Arena/ArenaBlowAttack.cs
+1 −1 Lib9c/Model/Skill/Arena/ArenaBuffRemovalAttack.cs
+1 −1 Lib9c/Model/Skill/Arena/ArenaBuffSkill.cs
+1 −1 Lib9c/Model/Skill/Arena/ArenaDoubleAttack.cs
+1 −1 Lib9c/Model/Skill/Arena/ArenaHealSkill.cs
+1 −1 Lib9c/Model/Skill/Arena/ArenaNormalAttack.cs
+4 −4 Lib9c/Model/Skill/Arena/ArenaSkill.cs
+5 −5 Lib9c/Model/Skill/AttackSkill.cs
+1 −1 Lib9c/Model/Skill/BlowAttack.cs
+1 −1 Lib9c/Model/Skill/BuffRemovalAttack.cs
+1 −1 Lib9c/Model/Skill/BuffSkill.cs
+1 −1 Lib9c/Model/Skill/DoubleAttack.cs
+1 −1 Lib9c/Model/Skill/HealSkill.cs
+2 −2 Lib9c/Model/Skill/ISkill.cs
+1 −1 Lib9c/Model/Skill/NormalAttack.cs
+4 −4 Lib9c/Model/Skill/Skill.cs
+1 −1 Lib9c/Model/Skill/SkillCustomField.cs
+3 −3 Lib9c/Model/Skill/SkillFactory.cs
+32 −32 Lib9c/Model/Stat/CharacterStats.cs
+6 −6 Lib9c/Model/Stat/DecimalStat.cs
+25 −25 Lib9c/Model/Stat/IBaseAndAdditionalStats.cs
+12 −12 Lib9c/Model/Stat/IStats.cs
+58 −58 Lib9c/Model/Stat/StatMap.cs
+8 −8 Lib9c/Model/Stat/StatModifier.cs
+20 −20 Lib9c/Model/Stat/Stats.cs
+43 −43 Lib9c/Model/Stat/StatsMap.cs
+5 −5 Lib9c/Model/State/RaiderState.cs
+11 −5 Lib9c/Model/State/StakeRewardCalculator.cs
+6 −1 Lib9c/TableCSV/Garages/LoadIntoMyGaragesCostSheet.csv
+4 −4 Lib9c/TableCSV/Stake/StakePolicySheet.csv
+1 −1 Lib9c/TableCSV/StakeRegularFixedRewardSheet_V1.csv.meta
+1 −1 Lib9c/TableCSV/StakeRegularFixedRewardSheet_V2.csv.meta
+9 −0 Lib9c/TableCSV/StakeRegularFixedRewardSheet_V3.csv
+1 −1 Lib9c/TableCSV/StakeRegularRewardSheet_V1.csv.meta
+1 −1 Lib9c/TableCSV/StakeRegularRewardSheet_V2.csv.meta
+1 −1 Lib9c/TableCSV/StakeRegularRewardSheet_V3.csv.meta
+1 −1 Lib9c/TableCSV/StakeRegularRewardSheet_V4.csv.meta
+1 −1 Lib9c/TableCSV/StakeRegularRewardSheet_V5.csv.meta
+52 −0 Lib9c/TableCSV/StakeRegularRewardSheet_V6.csv
+2 −2 Lib9c/TableData/Skill/StatBuffSheet.cs
+12 −0 Lib9c/TableData/StakeRegularRewardSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,6 @@ public void ActivateAccount(bool invalid, int expectedCode)
}
}

[Fact]
public void MonsterCollect()
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var resultCode = _command.MonsterCollect(1, filePath);
Assert.Equal(0, resultCode);
var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
string type = (Text)decoded[0];
Assert.Equal(nameof(Nekoyume.Action.MonsterCollect), type);

Dictionary plainValue = (Dictionary)decoded[1];
var action = new MonsterCollect();
action.LoadPlainValue(plainValue);
Assert.Equal(1, action.level);
}

[Theory]
[InlineData("0xab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d", -1)]
[InlineData("ab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d", 0)]
public void ClaimMonsterCollectReward(string addressString, int expectedCode)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var resultCode = _command.ClaimMonsterCollectionReward(addressString, filePath);
Assert.Equal(expectedCode, resultCode);

if (resultCode == 0)
{
var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
string type = (Text)decoded[0];
Assert.Equal(nameof(ClaimMonsterCollectionReward), type);

Dictionary plainValue = (Dictionary)decoded[1];
var action = new ClaimMonsterCollectionReward();
action.LoadPlainValue(plainValue);
Assert.Equal(new Address(addressString), action.avatarAddress);
}
else
{
Assert.Contains("System.FormatException: Input string was not in a correct format.", _console.Error.ToString());
}
}

[Theory]
[InlineData(10, 0, "transfer asset test1.")]
Expand Down
19 changes: 0 additions & 19 deletions NineChronicles.Headless.Executable.Tests/Commands/TxCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ public void Sign_ActivateAccount(int txNonce)
Assert_Tx(txNonce, filePath, false);
}

[Fact]
public void Sign_MonsterCollect()
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var actionCommand = new ActionCommand(_console);
actionCommand.MonsterCollect(1, filePath);
Assert_Tx(1, filePath, false);
}

[Fact]
public void Sign_ClaimMonsterCollectionReward()
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var actionCommand = new ActionCommand(_console);
var avatarAddress = new Address();
actionCommand.ClaimMonsterCollectionReward(avatarAddress.ToHex(), filePath);
Assert_Tx(1, filePath, false);
}

[Theory]
[InlineData(1, false)]
[InlineData(10, true)]
Expand Down
83 changes: 0 additions & 83 deletions NineChronicles.Headless.Executable/Commands/ActionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,89 +123,6 @@ bool IsTarget(Type type)
return typeIds.OrderBy(type => type);
}


[Command(Description = "Create MonsterCollect action.")]
public int MonsterCollect(
[Range(0, 7)] int level,
[Argument("PATH", Description = "A file path of base64 encoded action.")]
string? filePath = null
)
{
try
{
Nekoyume.Action.MonsterCollect action = new MonsterCollect
{
level = level
};

byte[] raw = Codec.Encode(new List(
new[]
{
(Text) nameof(Nekoyume.Action.MonsterCollect),
action.PlainValue
}
));
string encoded = Convert.ToBase64String(raw);
if (filePath is null)
{
_console.Out.Write(encoded);
}
else
{
File.WriteAllText(filePath, encoded);
}

return 0;
}
catch (Exception e)
{
_console.Error.WriteLine(e);
return -1;
}
}

[Command(Description = "Create ClaimMonsterCollectionReward action.")]
public int ClaimMonsterCollectionReward(
[Argument("AVATAR-ADDRESS", Description = "A hex-encoded avatar address.")]
string encodedAddress,
[Argument("PATH", Description = "A file path of base64 encoded action.")]
string? filePath = null
)
{
try
{
Address avatarAddress = new Address(ByteUtil.ParseHex(encodedAddress));
Nekoyume.Action.ClaimMonsterCollectionReward action = new ClaimMonsterCollectionReward
{
avatarAddress = avatarAddress
};

byte[] raw = Codec.Encode(new List(
new[]
{
(Text) nameof(Nekoyume.Action.ClaimMonsterCollectionReward),
action.PlainValue
}
));
string encoded = Convert.ToBase64String(raw);
if (filePath is null)
{
_console.Out.Write(encoded);
}
else
{
File.WriteAllText(filePath, encoded);
}

return 0;
}
catch (Exception e)
{
_console.Error.WriteLine(e);
return -1;
}
}

[Command(Description = "Create TransferAsset action.")]
public int TransferAsset(
[Argument("SENDER-ADDRESS", Description = "A hex-encoded sender address.")]
Expand Down
2 changes: 0 additions & 2 deletions NineChronicles.Headless.Executable/Commands/TxCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public void Sign(
ActionBase action = type switch
{
nameof(ActivateAccount) => new ActivateAccount(),
nameof(MonsterCollect) => new MonsterCollect(),
nameof(ClaimMonsterCollectionReward) => new ClaimMonsterCollectionReward(),
nameof(Stake) => new Stake(),
// FIXME: This `ClaimStakeReward` cases need to reduce to one case.
nameof(ClaimStakeReward1) => new ClaimStakeReward1(),
Expand Down
90 changes: 0 additions & 90 deletions NineChronicles.Headless.Tests/GraphTypes/StandaloneMutationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,96 +713,6 @@ public async Task CombinationConsumable(Address avatarAddress, int recipeId, int
},
};

[Fact]
public async Task MonsterCollect()
{
const string query = @"mutation {
action {
monsterCollect(level: 1)
}
}";

ActionBase createAvatar = new CreateAvatar
{
index = 0,
hair = 0,
lens = 0,
ear = 0,
tail = 0,
name = "avatar",
};
var playerPrivateKey = StandaloneContextFx.NineChroniclesNodeService!.MinerPrivateKey!;
BlockChain.MakeTransaction(playerPrivateKey, new[] { createAvatar });
Block block = BlockChain.ProposeBlock(playerPrivateKey);
BlockChain.Append(block, GenerateBlockCommit(block.Index, block.Hash, GenesisValidators));

Assert.NotNull(BlockChain.GetState(playerPrivateKey.Address));
var result = await ExecuteQueryAsync(query);
var data = (Dictionary<string, object>)((ExecutionNode)result.Data!).ToValue()!;
Assert.Null(result.Errors);

var txIds = BlockChain.GetStagedTransactionIds();
Assert.Single(txIds);
var tx = BlockChain.GetTransaction(txIds.First());
var expected = new Dictionary<string, object>
{
["action"] = new Dictionary<string, object>
{
["monsterCollect"] = tx.Id.ToString(),
}
};
Assert.Equal(expected, data);
Assert.Single(tx.Actions);
var action = (MonsterCollect)ToAction(tx.Actions!.First());
Assert.Equal(1, action.level);
}

[Fact]
public async Task ClaimMonsterCollectionReward()
{
var playerPrivateKey = StandaloneContextFx.NineChroniclesNodeService!.MinerPrivateKey!;
var avatarAddress = playerPrivateKey.Address;
string query = $@"mutation {{
action {{
claimMonsterCollectionReward(avatarAddress: ""{avatarAddress}"")
}}
}}";

ActionBase createAvatar = new CreateAvatar
{
index = 0,
hair = 0,
lens = 0,
ear = 0,
tail = 0,
name = "avatar",
};
BlockChain.MakeTransaction(playerPrivateKey, new[] { createAvatar });
Block block = BlockChain.ProposeBlock(playerPrivateKey);
BlockChain.Append(block, GenerateBlockCommit(block.Index, block.Hash, GenesisValidators));

Assert.NotNull(BlockChain.GetState(playerPrivateKey.Address));

var result = await ExecuteQueryAsync(query);
var data = (Dictionary<string, object>)((ExecutionNode)result.Data!).ToValue()!;
Assert.Null(result.Errors);

var txIds = BlockChain.GetStagedTransactionIds();
Assert.Single(txIds);
var tx = BlockChain.GetTransaction(txIds.First());
var expected = new Dictionary<string, object>
{
["action"] = new Dictionary<string, object>
{
["claimMonsterCollectionReward"] = tx.Id.ToString(),
}
};
Assert.Equal(expected, data);
Assert.Single(tx.Actions);
var action = (ClaimMonsterCollectionReward)ToAction(tx.Actions!.First());
Assert.Equal(avatarAddress, action.avatarAddress);
}

// [Fact]
// public async Task CancelMonsterCollect()
// {
Expand Down
90 changes: 0 additions & 90 deletions NineChronicles.Headless/GraphTypes/ActionMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,96 +438,6 @@ public ActionMutation(NineChroniclesNodeService service)
}
}
);

Field<NonNullGraphType<TxIdType>>(nameof(MonsterCollect),
description: "Start monster collect.",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<IntGraphType>>
{
Name = "level",
Description = "The monster collection level.(1 ~ 7)"
}
),
resolve: context =>
{
try
{
BlockChain? blockChain = service.BlockChain;
if (blockChain is null)
{
throw new InvalidOperationException($"{nameof(blockChain)} is null.");
}

if (service.MinerPrivateKey is null)
{
throw new InvalidOperationException($"{nameof(service.MinerPrivateKey)} is null.");
}

int level = context.GetArgument<int>("level");
var action = new MonsterCollect
{
level = level,
};

var actions = new ActionBase[] { action };
Transaction tx = blockChain.MakeTransaction(service.MinerPrivateKey, actions);
return tx.Id;
}
catch (Exception e)
{
var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}";
context.Errors.Add(new ExecutionError(msg, e));
throw;
}
}
);

Field<NonNullGraphType<TxIdType>>(nameof(ClaimMonsterCollectionReward),
description: "Get monster collection reward.",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<AddressType>>
{
Name = "avatarAddress",
Description = "Address of avatar for get reward."
}
),
resolve: context =>
{
try
{
BlockChain? blockChain = service.BlockChain;
if (blockChain is null)
{
throw new InvalidOperationException($"{nameof(blockChain)} is null.");
}


if (service.MinerPrivateKey is null)
{
throw new InvalidOperationException($"{nameof(service.MinerPrivateKey)} is null.");
}

Address avatarAddress = context.GetArgument<Address>("avatarAddress");
Address agentAddress = service.MinerPrivateKey.Address;
AgentState agentState = new AgentState((Dictionary)service.BlockChain.GetState(agentAddress));

var action = new ClaimMonsterCollectionReward
{
avatarAddress = avatarAddress,
};

var actions = new ActionBase[] { action };
Transaction tx = blockChain.MakeTransaction(service.MinerPrivateKey, actions);
return tx.Id;
}
catch (Exception e)
{
var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}";
context.Errors.Add(new ExecutionError(msg, e));
throw;
}
}
);
}
}
}
Loading

0 comments on commit 285d5e9

Please sign in to comment.