Skip to content

Commit

Permalink
Delete removed action api
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Jan 30, 2024
1 parent 109bb43 commit 707bc3e
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 395 deletions.
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 707bc3e

Please sign in to comment.