Skip to content

Commit

Permalink
Added suggested changes
Browse files Browse the repository at this point in the history
Co-authored-by: ilgyu <[email protected]>
  • Loading branch information
greymistcube and OnedgeLee committed Jun 21, 2024
1 parent 0b86001 commit 48e13a9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Libplanet.Net.Tests/Consensus/ContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void BroadcastMessage(ConsensusMsg message) =>
1L,
TestUtils.PrivateKeys[0],
blockChain
.GetNextWorldState(0)
.GetNextWorldState(0L)
.GetValidatorSet(),
contextTimeoutOptions: new ContextTimeoutOption());

Expand Down
15 changes: 8 additions & 7 deletions Libplanet.Tests/Action/WorldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,13 @@ public virtual void TransferAssetInBlock()
chain.Append(block1, TestUtils.CreateBlockCommit(block1));
Assert.Equal(
DumbAction.DumbCurrency * 0,
GetLatestWorldState(chain)
chain
.GetNextWorldState()
.GetBalance(_addr[0], DumbAction.DumbCurrency));
Assert.Equal(
DumbAction.DumbCurrency * 20,
GetLatestWorldState(chain)
chain
.GetNextWorldState()
.GetBalance(_addr[1], DumbAction.DumbCurrency));

// Transfer
Expand All @@ -288,11 +290,13 @@ public virtual void TransferAssetInBlock()
chain.Append(block2, TestUtils.CreateBlockCommit(block2));
Assert.Equal(
DumbAction.DumbCurrency * 5,
GetLatestWorldState(chain)
chain
.GetNextWorldState()
.GetBalance(_addr[0], DumbAction.DumbCurrency));
Assert.Equal(
DumbAction.DumbCurrency * 15,
GetLatestWorldState(chain)
chain
.GetNextWorldState()
.GetBalance(_addr[1], DumbAction.DumbCurrency));

// Transfer bugged
Expand Down Expand Up @@ -504,9 +508,6 @@ public virtual void TotalSupplyTracking()
world.GetTotalSupply(_currencies[4]));
}

protected static IWorldState GetLatestWorldState(BlockChain blockChain) =>
blockChain.GetNextWorldState();

protected FungibleAssetValue Value(int currencyIndex, BigInteger quantity) =>
new FungibleAssetValue(_currencies[currencyIndex], quantity, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Tests/Blockchain/BlockChainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2314,15 +2314,15 @@ private void ValidateNextBlockCommitOnValidatorSetChange()

Assert.Equal(
blockChain
.GetNextWorldState(0)
.GetNextWorldState(0L)
.GetValidatorSet(),
new ValidatorSet(
ValidatorPrivateKeys.Select(
pk => new Validator(pk.PublicKey, BigInteger.One)).ToList()));

Assert.Equal(
blockChain
.GetNextWorldState(1)
.GetNextWorldState(1L)
.GetValidatorSet(),
new ValidatorSet(
newValidators.Select(
Expand Down
6 changes: 3 additions & 3 deletions Libplanet/Blockchain/BlockChain.States.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public IWorldState GetWorldState(HashDigest<SHA256>? stateRootHash)
/// <returns>The next world state. If it does not exist, returns null.</returns>
public IWorldState? GetNextWorldState()
{
if (GetNextStateRootHash() is { } srh)
if (GetNextStateRootHash() is { } nsrh)
{
var trie = StateStore.GetStateRoot(srh);
var trie = StateStore.GetStateRoot(nsrh);
return trie.Recorded
? new WorldBaseState(trie, StateStore)
: throw new InvalidOperationException(
$"Could not find state root {srh} in {nameof(StateStore)} for " +
$"Could not find state root {nsrh} in {nameof(StateStore)} for " +
$"the current tip.");
}
else
Expand Down

0 comments on commit 48e13a9

Please sign in to comment.