Skip to content

Commit

Permalink
test: fix tests [skip changelog]
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Nov 15, 2023
1 parent e555add commit 33e84fa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
11 changes: 6 additions & 5 deletions Libplanet.Action.Tests/ActionEvaluationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ public ActionEvaluationTest(ITestOutputHelper output)
[Fact]
public void Constructor()
{
var txid = new System.Random().NextTxId();
Address address = new PrivateKey().ToAddress();
IWorld world = new World(new MockWorldState());
world = world.SetAccount(
ReservedAddresses.LegacyAccount,
world.GetAccount(ReservedAddresses.LegacyAccount).SetState(address, (Text)"item"));
var txid = new System.Random().NextTxId();
var evaluation = new ActionEvaluation(
new DumbAction(address, "item"),
new ActionContext(
Expand All @@ -41,10 +45,7 @@ public void Constructor()
123,
0,
false),
new World(
new MockWorldState().SetAccountState(
ReservedAddresses.LegacyAccount,
new Account(new MockAccountState().SetState(address, (Text)"item"))))
world
);
var action = (DumbAction)evaluation.Action;

Expand Down
10 changes: 7 additions & 3 deletions Libplanet.Action.Tests/Mocks/MockWorldState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public MockWorldState()
IStateStore stateStore,
HashDigest<SHA256>? stateRootHash = null)
{
_stateStore = stateStore;
Trie = stateStore.GetStateRoot(stateRootHash);
Legacy = Trie
.Get(new[]
Expand All @@ -37,9 +38,12 @@ public MockWorldState()

public IAccount GetAccount(Address address)
=> Legacy && address.Equals(ReservedAddresses.LegacyAccount)
? new Account(new MockAccountState(_stateStore, Trie.Hash))
: new Account(new MockAccountState(
_stateStore, new HashDigest<SHA256>(Trie.Get(ToStateKey(address)))));
? new Account(new MockAccountState(_stateStore, Trie.Hash))
: new Account(new MockAccountState(
_stateStore,
Trie.Get(ToStateKey(address)) is { } stateRootNotNull
? new HashDigest<SHA256>(stateRootNotNull)
: null));

public IWorldState SetAccountState(Address address, IAccount account)
=> Legacy && address.Equals(ReservedAddresses.LegacyAccount)
Expand Down
8 changes: 3 additions & 5 deletions Libplanet.Action.Tests/Sys/InitializeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Execute()
nextState.GetAccount(ReservedAddresses.LegacyAccount).GetValidatorSet());
Assert.Equal(
_states[default],
nextState.GetAccount(default).GetState(default));
nextState.GetAccount(ReservedAddresses.LegacyAccount).GetState(default));
}

[Fact]
Expand Down Expand Up @@ -113,8 +113,7 @@ public void Serialize()
_validatorSet.Bencoded,
Dictionary.Empty.Add(
default(Address).ToByteArray(),
Dictionary.Empty.Add(default(Address).ToByteArray(), "initial value"
)))),
"initial value"))),
action.PlainValue);
}

Expand All @@ -129,8 +128,7 @@ public void Deserialize()
_validatorSet.Bencoded,
Dictionary.Empty.Add(
default(Address).ToByteArray(),
Dictionary.Empty.Add(default(Address).ToByteArray(), "initial value"
))));
"initial value")));
var action = new Initialize();
action.LoadPlainValue(encoded);

Expand Down
6 changes: 2 additions & 4 deletions Libplanet.Action.Tests/Sys/RegistryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public void Deserialize()
_validatorSet.Bencoded,
Dictionary.Empty.Add(
default(Address).ToByteArray(),
Dictionary.Empty.Add(default(Address).ToByteArray(), "initial value"
))));
"initial value")));
IAction action = Registry.Deserialize(value);
var initialize = Assert.IsType<Initialize>(action);
Assert.Equal(_validatorSet, initialize.ValidatorSet);
Expand Down Expand Up @@ -88,8 +87,7 @@ public void Serialize()
_validatorSet.Bencoded,
Dictionary.Empty.Add(
default(Address).ToByteArray(),
Dictionary.Empty.Add(default(Address).ToByteArray(), "initial value"
))));
"initial value")));
TestUtils.AssertBencodexEqual(expected, actual);
}

Expand Down

0 comments on commit 33e84fa

Please sign in to comment.