From 707bc3efe42ddf662a421d37f67421dedef6eac4 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Tue, 30 Jan 2024 14:59:40 +0900 Subject: [PATCH] Delete removed action api --- .../Commands/ActionCommandTest.cs | 43 --------- .../Commands/TxCommandTest.cs | 19 ---- .../Commands/ActionCommand.cs | 83 ----------------- .../Commands/TxCommand.cs | 2 - .../GraphTypes/StandaloneMutationTest.cs | 90 ------------------- .../GraphTypes/ActionMutation.cs | 90 ------------------- .../GraphTypes/StandaloneSubscription.cs | 68 -------------- 7 files changed, 395 deletions(-) diff --git a/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs b/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs index 6853ee931..c4502e5f1 100644 --- a/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs +++ b/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs @@ -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.")] diff --git a/NineChronicles.Headless.Executable.Tests/Commands/TxCommandTest.cs b/NineChronicles.Headless.Executable.Tests/Commands/TxCommandTest.cs index d9697dd19..5a970cbee 100644 --- a/NineChronicles.Headless.Executable.Tests/Commands/TxCommandTest.cs +++ b/NineChronicles.Headless.Executable.Tests/Commands/TxCommandTest.cs @@ -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)] diff --git a/NineChronicles.Headless.Executable/Commands/ActionCommand.cs b/NineChronicles.Headless.Executable/Commands/ActionCommand.cs index 086308aa5..eeea168db 100644 --- a/NineChronicles.Headless.Executable/Commands/ActionCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/ActionCommand.cs @@ -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.")] diff --git a/NineChronicles.Headless.Executable/Commands/TxCommand.cs b/NineChronicles.Headless.Executable/Commands/TxCommand.cs index 07482d9b6..0e77fd33b 100644 --- a/NineChronicles.Headless.Executable/Commands/TxCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/TxCommand.cs @@ -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(), diff --git a/NineChronicles.Headless.Tests/GraphTypes/StandaloneMutationTest.cs b/NineChronicles.Headless.Tests/GraphTypes/StandaloneMutationTest.cs index 18af236b6..9b362c973 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/StandaloneMutationTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/StandaloneMutationTest.cs @@ -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)((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 - { - ["action"] = new Dictionary - { - ["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)((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 - { - ["action"] = new Dictionary - { - ["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() // { diff --git a/NineChronicles.Headless/GraphTypes/ActionMutation.cs b/NineChronicles.Headless/GraphTypes/ActionMutation.cs index 03da59e92..41fbbe19c 100644 --- a/NineChronicles.Headless/GraphTypes/ActionMutation.cs +++ b/NineChronicles.Headless/GraphTypes/ActionMutation.cs @@ -438,96 +438,6 @@ public ActionMutation(NineChroniclesNodeService service) } } ); - - Field>(nameof(MonsterCollect), - description: "Start monster collect.", - arguments: new QueryArguments( - new QueryArgument> - { - 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("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>(nameof(ClaimMonsterCollectionReward), - description: "Get monster collection reward.", - arguments: new QueryArguments( - new QueryArgument> - { - 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
("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; - } - } - ); } } } diff --git a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs index d0c10c9b0..90f43e81c 100644 --- a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs +++ b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs @@ -227,39 +227,6 @@ public StandaloneSubscription(StandaloneContext standaloneContext, IConfiguratio blockRenderer.BlockSubject .ObserveOn(NewThreadScheduler.Default) .Subscribe(RenderBlock); - - ActionRenderer actionRenderer = standaloneContext.NineChroniclesNodeService!.ActionRenderer; - actionRenderer.EveryRender() - .ObserveOn(NewThreadScheduler.Default) - .Subscribe(RenderMonsterCollectionStateSubject); - actionRenderer.EveryRender() - .ObserveOn(NewThreadScheduler.Default) - .Subscribe(RenderMonsterCollectionStateSubject); - actionRenderer.EveryRender() - .ObserveOn(NewThreadScheduler.Default) - .Subscribe(RenderMonsterCollectionStateSubject); - } - - private IObservable SubscribeMonsterCollectionState(IResolveEventStreamContext context) - { - var address = context.GetArgument
("address"); - - StandaloneContext.AgentAddresses.TryAdd(address, - (new ReplaySubject(), new ReplaySubject(), - new ReplaySubject())); - StandaloneContext.AgentAddresses.TryGetValue(address, out var subjects); - return subjects.stateSubject.AsObservable(); - } - - private IObservable SubscribeMonsterCollectionStatus(IResolveEventStreamContext context) - { - var address = context.GetArgument
("address"); - - StandaloneContext.AgentAddresses.TryAdd(address, - (new ReplaySubject(), new ReplaySubject(), - new ReplaySubject())); - StandaloneContext.AgentAddresses.TryGetValue(address, out var subjects); - return subjects.statusSubject.AsObservable(); } private IObservable SubscribeBalance(IResolveEventStreamContext context) @@ -435,40 +402,5 @@ private void RenderForAgent( } } } - - private void RenderMonsterCollectionStateSubject(ActionEvaluation eval) - where T : ActionBase - { - if (!(StandaloneContext.NineChroniclesNodeService is { } service)) - { - throw new InvalidOperationException( - $"{nameof(NineChroniclesNodeService)} is null."); - } - - // Skip when error. - if (eval.Exception is { }) - { - return; - } - - foreach (var (address, subjects) in StandaloneContext.AgentAddresses) - { - if (eval.Signer.Equals(address) && - service.BlockChain.GetStates(new[] { address }, _tipHeader?.Hash)[0] is Dictionary agentDict) - { - var agentState = new AgentState(agentDict); - Address deriveAddress = MonsterCollectionState.DeriveAddress(address, agentState.MonsterCollectionRound); - var subject = subjects.stateSubject; - if (service.BlockChain.GetAccountState(eval.OutputState).GetState(deriveAddress) is Dictionary state) - { - subject.OnNext(new MonsterCollectionState(state)); - } - else - { - subject.OnNext(null!); - } - } - } - } } }