Skip to content

Commit

Permalink
Merge pull request #3723 from greymistcube/chore/cleanup
Browse files Browse the repository at this point in the history
🧹 Removed RecordRandom from DumbAction
  • Loading branch information
greymistcube authored Apr 2, 2024
2 parents 438df37 + 1612dc0 commit 03c1a63
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 60 deletions.
31 changes: 1 addition & 30 deletions Libplanet.Action.Tests/Common/DumbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public sealed class DumbAction : IAction

public static readonly Text TypeId = new Text(nameof(DumbAction));

public static readonly Address RandomRecordsAddress =
new Address("7811C3fAa0f9Cc41F7971c3d9b031B1095b20AB2");

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

Expand All @@ -32,8 +29,6 @@ public DumbAction()

public ImmutableList<Validator>? Validators { get; private set; }

public bool RecordRandom { get; private set; }

public IValue PlainValue
{
get
Expand Down Expand Up @@ -61,13 +56,6 @@ public IValue PlainValue
.Add("validators", new List(validators.Select(v => v.Bencoded)));
}

if (RecordRandom)
{
// In order to avoid changing tx signatures in many test
// fixtures, adds field only if RecordRandom = true.
plainValue = plainValue.Add("record_random", true);
}

return plainValue;
}
}
Expand All @@ -90,7 +78,6 @@ public static DumbAction Create(
Append = append,
Transfer = transfer,
Validators = validators?.ToImmutableList(),
RecordRandom = recordRandom,
};
}

Expand Down Expand Up @@ -137,15 +124,6 @@ public IWorld Execute(IActionContext context)
(current, validator) => current.SetValidator(validator));
}

if (RecordRandom)
{
IAccount account = world.GetAccount(ReservedAddresses.LegacyAccount);
account = account.SetState(
RandomRecordsAddress,
(Integer)context.GetRandom().Next());
world = world.SetAccount(ReservedAddresses.LegacyAccount, account);
}

return world;
}

Expand Down Expand Up @@ -182,16 +160,10 @@ public void LoadPlainValue(Dictionary plainValue)
.Select(value => new Validator(value))
.ToImmutableList();
}

RecordRandom =
plainValue.ContainsKey((Text)"record_random") &&
plainValue["record_random"] is Boolean r &&
r.Value;
}

public override string ToString()
{
const string T = "true", F = "false";
const string N = "null";
const string E = "empty";
string append = Append is { } a
Expand All @@ -206,8 +178,7 @@ public override string ToString()
return $"{nameof(DumbAction)} {{ " +
$"{nameof(Append)} = {append}, " +
$"{nameof(Transfer)} = {transfer}, " +
$"{nameof(Validators)} = {validators}, " +
$"{nameof(RecordRandom)} = {(RecordRandom ? T : F)}, " +
$"{nameof(Validators)} = {validators} " +
$"}}";
}
}
Expand Down
31 changes: 1 addition & 30 deletions Libplanet.Action.Tests/Common/DumbModernAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public sealed class DumbModernAction : IAction
public static readonly Address DumbModernAddress =
new Address("0123456789abcdef0123456789abcdef12345678");

public static readonly Address RandomRecordsAddress =
new Address("7811C3fAa0f9Cc41F7971c3d9b031B1095b20AB2");

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

Expand All @@ -35,8 +32,6 @@ public DumbModernAction()

public ImmutableList<Validator>? Validators { get; private set; }

public bool RecordRandom { get; private set; }

public IValue PlainValue
{
get
Expand Down Expand Up @@ -64,13 +59,6 @@ public IValue PlainValue
.Add("validators", new List(validators.Select(v => v.Bencoded)));
}

if (RecordRandom)
{
// In order to avoid changing tx signatures in many test
// fixtures, adds field only if RecordRandom = true.
plainValue = plainValue.Add("record_random", true);
}

return plainValue;
}
}
Expand All @@ -93,7 +81,6 @@ public static DumbModernAction Create(
Append = append,
Transfer = transfer,
Validators = validators?.ToImmutableList(),
RecordRandom = recordRandom,
};
}

Expand Down Expand Up @@ -140,15 +127,6 @@ public IWorld Execute(IActionContext context)
(current, validator) => current.SetValidator(validator));
}

if (RecordRandom)
{
IAccount account = world.GetAccount(ReservedAddresses.LegacyAccount);
account = account.SetState(
RandomRecordsAddress,
(Integer)context.GetRandom().Next());
world = world.SetAccount(ReservedAddresses.LegacyAccount, account);
}

return world;
}

Expand Down Expand Up @@ -185,16 +163,10 @@ public void LoadPlainValue(Dictionary plainValue)
.Select(value => new Validator(value))
.ToImmutableList();
}

RecordRandom =
plainValue.ContainsKey((Text)"record_random") &&
plainValue["record_random"] is Boolean r &&
r.Value;
}

public override string ToString()
{
const string T = "true", F = "false";
const string N = "null";
const string E = "empty";
string append = Append is { } a
Expand All @@ -209,8 +181,7 @@ public override string ToString()
return $"{nameof(DumbModernAction)} {{ " +
$"{nameof(Append)} = {append}, " +
$"{nameof(Transfer)} = {transfer}, " +
$"{nameof(Validators)} = {validators}, " +
$"{nameof(RecordRandom)} = {(RecordRandom ? T : F)}, " +
$"{nameof(Validators)} = {validators} " +
$"}}";
}
}
Expand Down

0 comments on commit 03c1a63

Please sign in to comment.