Skip to content

Commit

Permalink
Removed clutter
Browse files Browse the repository at this point in the history
  • Loading branch information
greymistcube committed May 2, 2024
1 parent 308c3c3 commit 4ead92e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
6 changes: 0 additions & 6 deletions Libplanet.Action/ActionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,6 @@ internal ActionEvaluation EvaluatePolicyBlockAction(
logger: _logger).Single();
}

internal IWorld PrepareInitialDelta(HashDigest<SHA256>? stateRootHash)
{
return new World(
new WorldBaseState(_stateStore.GetStateRoot(stateRootHash), _stateStore));
}

internal IReadOnlyList<ICommittedActionEvaluation>
ToCommittedEvaluation(
IPreEvaluationBlock block,
Expand Down
19 changes: 10 additions & 9 deletions Libplanet.Tests/Action/ActionEvaluatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void EvaluateWithCriticalException()
txHash: BlockContent.DeriveTxHash(txs),
lastCommit: null),
transactions: txs).Propose();
IWorld previousState = actionEvaluator.PrepareInitialDelta(genesis.StateRootHash);
IWorld previousState = stateStore.GetWorld(genesis.StateRootHash);

Assert.Throws<OutOfMemoryException>(
() => actionEvaluator.EvaluateTx(
Expand Down Expand Up @@ -366,7 +366,7 @@ DumbAction MakeAction(Address address, char identifier, Address? transferTo = nu
genesis,
GenesisProposer,
block1Txs);
IWorld previousState = actionEvaluator.PrepareInitialDelta(genesis.StateRootHash);
IWorld previousState = stateStore.GetWorld(genesis.StateRootHash);
var evals = actionEvaluator.EvaluateBlock(
block1,
previousState).ToImmutableArray();
Expand Down Expand Up @@ -395,7 +395,7 @@ DumbAction MakeAction(Address address, char identifier, Address? transferTo = nu
Assert.Equal(block1.Index, eval.InputContext.BlockIndex);
}

previousState = actionEvaluator.PrepareInitialDelta(genesis.StateRootHash);
previousState = stateStore.GetWorld(genesis.StateRootHash);
ActionEvaluation[] evals1 =
actionEvaluator.EvaluateBlock(block1, previousState).ToArray();
var output1 = new WorldBaseState(evals1.Last().OutputState.Trie, stateStore);
Expand Down Expand Up @@ -572,7 +572,7 @@ public void EvaluateTx()
stateStore: stateStore,
actionTypeLoader: new SingleActionLoader(typeof(DumbAction)));

IWorld previousState = actionEvaluator.PrepareInitialDelta(initTrie.Hash);
IWorld previousState = stateStore.GetWorld(initTrie.Hash);
var evaluations = actionEvaluator.EvaluateTx(
block: block,
tx: tx,
Expand Down Expand Up @@ -638,7 +638,7 @@ prevEval is null
.GetBalance(a, currency).RawValue));
}

previousState = actionEvaluator.PrepareInitialDelta(initTrie.Hash);
previousState = stateStore.GetWorld(initTrie.Hash);
IWorld delta = actionEvaluator.EvaluateTx(
block: block,
tx: tx,
Expand All @@ -660,9 +660,10 @@ public void EvaluateTxResultThrowingException()
DateTimeOffset.UtcNow);
var txs = new Transaction[] { tx };
var hash = new BlockHash(GetRandomBytes(BlockHash.Size));
IStateStore stateStore = new TrieStateStore(new MemoryKeyValueStore());
var actionEvaluator = new ActionEvaluator(
policyBlockActionGetter: _ => null,
stateStore: new TrieStateStore(new MemoryKeyValueStore()),
stateStore: stateStore,
actionTypeLoader: new SingleActionLoader(typeof(ThrowException))
);
var block = new BlockContent(
Expand All @@ -674,7 +675,7 @@ public void EvaluateTxResultThrowingException()
txHash: BlockContent.DeriveTxHash(txs),
lastCommit: CreateBlockCommit(hash, 122, 0)),
transactions: txs).Propose();
IWorld previousState = actionEvaluator.PrepareInitialDelta(null);
IWorld previousState = stateStore.GetWorld(null);
var nextState = actionEvaluator.EvaluateTx(
block: block,
tx: tx,
Expand Down Expand Up @@ -825,7 +826,7 @@ public void EvaluatePolicyBlockAction()
var block = chain.ProposeBlock(
GenesisProposer, txs.ToImmutableList(), CreateBlockCommit(chain.Tip));

IWorld previousState = actionEvaluator.PrepareInitialDelta(null);
IWorld previousState = _storeFx.StateStore.GetWorld(null);
var evaluation = actionEvaluator.EvaluatePolicyBlockAction(genesis, previousState);

Assert.Equal(chain.Policy.BlockAction, evaluation.Action);
Expand All @@ -848,7 +849,7 @@ public void EvaluatePolicyBlockAction()
Assert.Equal(block.Transactions, evaluation.InputContext.Txs);

chain.Append(block, CreateBlockCommit(block), render: true);
previousState = actionEvaluator.PrepareInitialDelta(genesis.StateRootHash);
previousState = _storeFx.StateStore.GetWorld(genesis.StateRootHash);
var txEvaluations = actionEvaluator.EvaluateBlock(
block,
previousState).ToList();
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Tests/Blockchain/BlockChainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ void BuildIndex(Guid id, Block block)

// Build a store with incomplete states
Block b = chain.Genesis;
IWorld previousState = actionEvaluator.PrepareInitialDelta(null);
IWorld previousState = stateStore.GetWorld(null);
const int accountsCount = 5;
Address[] addresses = Enumerable.Repeat<object>(null, accountsCount)
.Select(_ => new PrivateKey().Address)
Expand Down

0 comments on commit 4ead92e

Please sign in to comment.