Skip to content

Commit

Permalink
test: add test for evaluation when policy actions fails [skip changelog]
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Apr 24, 2024
1 parent bed82d6 commit cef0151
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Libplanet.Tests/Action/ActionEvaluatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,55 @@ public void EvaluateWithPolicyActions()
.GetState(_endTxValueAddress));
}

[Fact]
public void EvaluateWithPolicyActionsWithException()
{
var store = new MemoryStore();
var stateStore = new TrieStateStore(new MemoryKeyValueStore());
var policyWithExceptions = new BlockPolicy(
beginBlockActions: new IAction[]
{
new UpdateValueAction(_beginBlockValueAddress, 1),
new ThrowException { ThrowOnExecution = true },
}.ToImmutableArray(),
endBlockActions: new IAction[]
{
new UpdateValueAction(_endBlockValueAddress, 1),
new ThrowException { ThrowOnExecution = true },
}.ToImmutableArray(),
beginTxActions: new IAction[]
{
new UpdateValueAction(_beginTxValueAddress, 1),
new ThrowException { ThrowOnExecution = true },
}.ToImmutableArray(),
endTxActions: new IAction[]
{
new UpdateValueAction(_endTxValueAddress, 1),
new ThrowException { ThrowOnExecution = true },
}.ToImmutableArray());

var (chain, actionEvaluator) =
TestUtils.MakeBlockChainAndActionEvaluator(
policy: policyWithExceptions,
store: store,
stateStore: stateStore,
actionLoader: new SingleActionLoader(typeof(DumbAction)));

(_, Transaction[] txs) = MakeFixturesForAppendTests();
var block = chain.ProposeBlock(
GenesisProposer, txs.ToImmutableList(), CreateBlockCommit(chain.Tip));
var evaluations = actionEvaluator.Evaluate(
block, chain.Store.GetStateRootHash(chain.Tip.Hash)).ToArray();

// BeginBlockAction + (BeginTxAction + #Action + EndTxAction) * #Tx + EndBlockAction
Assert.Equal(
4 + txs.Length * 4 + txs.Sum(tx => tx.Actions.Count),
evaluations.Length);
Assert.Equal(
2 + txs.Length * 2,
evaluations.Count(e => e.Exception != null));
}

[Fact]
public void EvaluateWithException()
{
Expand Down

0 comments on commit cef0151

Please sign in to comment.