Skip to content

Commit

Permalink
Merge pull request #3717 from greymistcube/chore/cleanup
Browse files Browse the repository at this point in the history
🧹 Minor cleanup
  • Loading branch information
greymistcube authored Mar 29, 2024
2 parents 362de2c + 0847c1f commit ad08e71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
24 changes: 8 additions & 16 deletions Libplanet.Action.Tests/Common/DumbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class DumbAction : IAction, IEquatable<DumbAction>
new Address("7811C3fAa0f9Cc41F7971c3d9b031B1095b20AB2");

public static readonly Currency DumbCurrency =
Currency.Uncapped("DUMB", 0, null);
Currency.Uncapped("DUMB", 0, null);

public DumbAction()
{
Expand Down Expand Up @@ -66,15 +66,12 @@ public IValue PlainValue
{
get
{
var plainValue = Bencodex.Types.Dictionary.Empty;
if (!(Item is null))
var plainValue = Dictionary.Empty;
if (Item is { })
{
plainValue = new Bencodex.Types.Dictionary(
new Dictionary<string, IValue>
{
["item"] = (Text)Item,
["target_address"] = TargetAddress.Bencoded,
});
plainValue = plainValue
.Add("item", Item)
.Add("target_address", TargetAddress.Bencoded);
}

if (RecordRandom)
Expand All @@ -84,15 +81,15 @@ public IValue PlainValue
plainValue = plainValue.Add("record_random", true);
}

if (!(Transfer is null))
if (Transfer is { })
{
plainValue = plainValue
.Add("transfer_from", Transfer.Item1.Bencoded)
.Add("transfer_to", Transfer.Item2.Bencoded)
.Add("transfer_amount", Transfer.Item3);
}

if (!(Validators is null))
if (Validators is { })
{
plainValue = plainValue
.Add("validators", new List(Validators.Select(p => p.Format(false))));
Expand Down Expand Up @@ -123,11 +120,6 @@ public IWorld Execute(IActionContext context)
);
}

if (Item.Equals("D"))
{
Item = Item.ToUpperInvariant();
}

account = account.SetState(TargetAddress, (Text)items);
world = world.SetAccount(ReservedAddresses.LegacyAccount, account);

Expand Down
21 changes: 6 additions & 15 deletions Libplanet.Action.Tests/Common/DumbModernAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ public IValue PlainValue
get
{
var plainValue = Bencodex.Types.Dictionary.Empty;
if (!(Item is null))
if (Item is { })
{
plainValue = new Bencodex.Types.Dictionary(
new Dictionary<string, IValue>
{
["item"] = (Text)Item,
["target_address"] = TargetAddress.Bencoded,
});
plainValue = plainValue
.Add("item", Item)
.Add("target_address", TargetAddress.Bencoded);
}

if (RecordRandom)
Expand All @@ -87,15 +84,15 @@ public IValue PlainValue
plainValue = plainValue.Add("record_random", true);
}

if (!(Transfer is null))
if (Transfer is { })
{
plainValue = plainValue
.Add("transfer_from", Transfer.Item1.Bencoded)
.Add("transfer_to", Transfer.Item2.Bencoded)
.Add("transfer_amount", Transfer.Item3);
}

if (!(Validators is null))
if (Validators is { })
{
plainValue = plainValue
.Add("validators", new List(Validators.Select(p => p.Format(false))));
Expand Down Expand Up @@ -126,13 +123,7 @@ public IWorld Execute(IActionContext context)
);
}

if (Item.Equals("D"))
{
Item = Item.ToUpperInvariant();
}

account = account.SetState(TargetAddress, (Text)items);

world = world.SetAccount(DumbModernAddress, account);

if (!(Validators is null))
Expand Down

0 comments on commit ad08e71

Please sign in to comment.