Skip to content

Commit 673a814

Browse files
committed
build: Fix build errors in test projects or etc.
1 parent b858a67 commit 673a814

36 files changed

+530
-142
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Bencodex.Types;
2+
using Libplanet.Action.State;
3+
using Libplanet.Crypto;
4+
5+
namespace Libplanet.Action.Tests.Common
6+
{
7+
public sealed class IncrementAction : IAction
8+
{
9+
public static readonly Address IncrementAddress =
10+
new Address("0000000000000000000000000000000000000123");
11+
12+
public IncrementAction()
13+
{
14+
}
15+
16+
public IValue PlainValue => Bencodex.Types.Dictionary.Empty;
17+
18+
public void LoadPlainValue(IValue plainValue)
19+
{
20+
}
21+
22+
public IWorld Execute(IActionContext ctx)
23+
{
24+
IWorld states = ctx.PreviousState;
25+
IAccount account = states.GetAccount(ReservedAddresses.LegacyAccount);
26+
int value = 0;
27+
28+
if (account.GetState(IncrementAddress) is Integer integer)
29+
{
30+
value = (int)integer.Value + 1;
31+
}
32+
33+
account = account.SetState(IncrementAddress, new Integer(value));
34+
return states.SetAccount(ReservedAddresses.LegacyAccount, account);
35+
}
36+
}
37+
}

Libplanet.Benchmarks/AppendBlock.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Libplanet.Types.Blocks;
99
using Libplanet.Tests;
1010
using Libplanet.Tests.Store;
11+
using System.Collections.Immutable;
1112

1213
namespace Libplanet.Benchmarks
1314
{
@@ -29,7 +30,8 @@ public AppendBlock()
2930
fx.StateStore,
3031
fx.GenesisBlock,
3132
new ActionEvaluator(
32-
policyBlockActionGetter: _ => null,
33+
policyBeginBlockActionGetter: _ => ImmutableArray<IAction>.Empty,
34+
policyEndBlockActionGetter: _ => ImmutableArray<IAction>.Empty,
3335
stateStore: fx.StateStore,
3436
actionTypeLoader: new SingleActionLoader(typeof(DumbAction))));
3537
_privateKey = new PrivateKey();

Libplanet.Benchmarks/BlockChain.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Immutable;
12
using BenchmarkDotNet.Attributes;
23
using Libplanet.Action;
34
using Libplanet.Action.Loader;
@@ -35,7 +36,8 @@ public void SetupChain()
3536
_fx.StateStore,
3637
_fx.GenesisBlock,
3738
new ActionEvaluator(
38-
policyBlockActionGetter: _ => null,
39+
policyBeginBlockActionGetter: _ => ImmutableArray<IAction>.Empty,
40+
policyEndBlockActionGetter: _ => ImmutableArray<IAction>.Empty,
3941
stateStore: _fx.StateStore,
4042
actionTypeLoader: new SingleActionLoader(typeof(DumbAction))));
4143
var key = new PrivateKey();

Libplanet.Benchmarks/ProposeBlock.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Libplanet.Types.Blocks;
99
using Libplanet.Tests;
1010
using Libplanet.Tests.Store;
11+
using System.Collections.Immutable;
1112

1213
namespace Libplanet.Benchmarks
1314
{
@@ -28,7 +29,8 @@ public ProposeBlock()
2829
fx.StateStore,
2930
fx.GenesisBlock,
3031
new ActionEvaluator(
31-
policyBlockActionGetter: _ => null,
32+
policyBeginBlockActionGetter: _ => ImmutableArray<IAction>.Empty,
33+
policyEndBlockActionGetter: _ => ImmutableArray<IAction>.Empty,
3234
stateStore: fx.StateStore,
3335
actionTypeLoader: new SingleActionLoader(typeof(DumbAction))));
3436
_privateKey = new PrivateKey();

Libplanet.Explorer.Executable/Program.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ If omitted (default) explorer only the local blockchain store.")]
200200
options.GetGenesisBlock(policy),
201201
blockChainStates,
202202
new ActionEvaluator(
203-
_ => policy.BlockAction,
203+
_ => policy.BeginBlockActions,
204+
_ => policy.EndBlockActions,
204205
stateStore,
205206
new SingleActionLoader(typeof(NullAction))));
206207
Startup.PreloadedSingleton = false;
@@ -341,7 +342,8 @@ private static IStore LoadStore(Options options)
341342
private static BlockPolicy LoadBlockPolicy(Options options)
342343
{
343344
return new BlockPolicy(
344-
blockAction: null,
345+
beginBlockActions: ImmutableArray<IAction>.Empty,
346+
endBlockActions: ImmutableArray<IAction>.Empty,
345347
blockInterval: TimeSpan.FromMilliseconds(options.BlockIntervalMilliseconds),
346348
getMaxTransactionsBytes: i => i > 0
347349
? options.MaxTransactionsBytes
@@ -384,7 +386,9 @@ public DumbBlockPolicy(BlockPolicy blockPolicy)
384386
_impl = blockPolicy;
385387
}
386388

387-
public IAction BlockAction => _impl.BlockAction;
389+
public ImmutableArray<IAction> BeginBlockActions => _impl.BeginBlockActions;
390+
391+
public ImmutableArray<IAction> EndBlockActions => _impl.EndBlockActions;
388392

389393
public int GetMinTransactionsPerBlock(long index) =>
390394
_impl.GetMinTransactionsPerBlock(index);

Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public GeneratedBlockChainFixture(
7171
getMaxTransactionsPerBlock: _ => int.MaxValue,
7272
getMaxTransactionsBytes: _ => long.MaxValue);
7373
var actionEvaluator = new ActionEvaluator(
74-
_ => policy.BlockAction,
74+
_ => policy.BeginBlockActions,
75+
_ => policy.EndBlockActions,
7576
stateStore,
7677
TypedActionLoader.Create(typeof(SimpleAction).Assembly, typeof(SimpleAction)));
7778
Block genesisBlock = BlockChain.ProposeGenesisBlock(

Libplanet.Extensions.Cocona.Tests/BlockPolicyParamsTest.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public void DefaultState()
1313
{
1414
var blockPolicyParams = new BlockPolicyParams();
1515
Assert.Null(blockPolicyParams.GetBlockPolicy());
16-
Assert.Null(blockPolicyParams.GetBlockAction());
16+
Assert.Empty(blockPolicyParams.GetBeginBlockActions());
17+
Assert.Empty(blockPolicyParams.GetEndBlockActions());
1718
}
1819

1920
[Fact]
@@ -26,7 +27,10 @@ public void GetBlockPolicy()
2627
BlockPolicy blockPolicy = Assert.IsType<BlockPolicy>(
2728
blockPolicyParams.GetBlockPolicy(new[] { GetType().Assembly })
2829
);
29-
Assert.IsType<NullAction>(blockPolicy.BlockAction);
30+
Assert.Single(blockPolicy.BeginBlockActions);
31+
Assert.IsType<NullAction>(blockPolicy.BeginBlockActions[0]);
32+
Assert.Single(blockPolicy.EndBlockActions);
33+
Assert.IsType<NullAction>(blockPolicy.EndBlockActions[0]);
3034
}
3135

3236
[Fact]
@@ -123,18 +127,34 @@ public void GetBlockPolicy_FactoryReturningNull()
123127
}
124128

125129
[Fact]
126-
public void GetBlockAction()
130+
public void GetBeginBlockActions()
127131
{
128132
var blockPolicyParams = new BlockPolicyParams
129133
{
130134
PolicyFactory = $"{GetType().FullName}.{nameof(BlockPolicyFactory)}",
131135
};
132-
var blockAction = blockPolicyParams.GetBlockAction(new[] { GetType().Assembly });
133-
Assert.IsType<NullAction>(blockAction);
136+
var blockActions = blockPolicyParams.GetBeginBlockActions(new[] { GetType().Assembly });
137+
Assert.Single(blockActions);
138+
Assert.IsType<NullAction>(blockActions[0]);
139+
}
140+
141+
[Fact]
142+
public void GetEndBlockActions()
143+
{
144+
var blockPolicyParams = new BlockPolicyParams
145+
{
146+
PolicyFactory = $"{GetType().FullName}.{nameof(BlockPolicyFactory)}",
147+
};
148+
var blockActions = blockPolicyParams.GetEndBlockActions(new[] { GetType().Assembly });
149+
Assert.Single(blockActions);
150+
Assert.IsType<NullAction>(blockActions[0]);
134151
}
135152

136153
internal static BlockPolicy BlockPolicyFactory() =>
137-
new BlockPolicy(blockAction: new NullAction());
154+
new BlockPolicy(
155+
beginBlockActions: new IAction[] { new NullAction() }.ToImmutableArray(),
156+
endBlockActions: new IAction[] { new NullAction() }.ToImmutableArray()
157+
);
138158

139159
internal static BlockPolicy BlockPolicyFactoryWithParams(bool param) =>
140160
new BlockPolicy();

Libplanet.Extensions.Cocona/BlockPolicyParams.cs

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ public Assembly[] LoadAssemblies()
7171
public object? GetBlockPolicy() =>
7272
GetBlockPolicy(LoadAssemblies());
7373

74-
public IAction? GetBlockAction() =>
75-
GetBlockAction(LoadAssemblies());
74+
public ImmutableArray<IAction> GetBeginBlockActions() =>
75+
GetBeginBlockActions(LoadAssemblies());
76+
77+
public ImmutableArray<IAction> GetEndBlockActions() =>
78+
GetEndBlockActions(LoadAssemblies());
7679

7780
[SuppressMessage(
7881
"Major Code Smell",
@@ -132,17 +135,65 @@ public Assembly[] LoadAssemblies()
132135
);
133136
}
134137

135-
internal IAction? GetBlockAction(Assembly[] assemblies)
138+
internal ImmutableArray<IAction> GetBeginBlockActions(Assembly[] assemblies)
136139
{
137140
object? policy = GetBlockPolicy(assemblies);
138141
if (policy is null)
139142
{
140-
return null;
143+
return ImmutableArray<IAction>.Empty;
141144
}
142145

143-
PropertyInfo? prop = policy
146+
PropertyInfo? propertyInfo = policy
144147
.GetType()
145-
.GetProperty(nameof(IBlockPolicy.BlockAction));
146-
return (IAction?)prop!.GetValue(policy);
148+
.GetProperty(nameof(IBlockPolicy.BeginBlockActions));
149+
if (propertyInfo is null)
150+
{
151+
var message = $"The policy type "
152+
+ $"'{policy.GetType().FullName}' does not have a "
153+
+ $"'{nameof(IBlockPolicy.BeginBlockActions)}' property.";
154+
throw new InvalidOperationException(message);
155+
}
156+
157+
var value = propertyInfo.GetValue(policy);
158+
if (value is null)
159+
{
160+
var message = $"The value of property "
161+
+ $"'{nameof(IBlockPolicy.BeginBlockActions)}' of type "
162+
+ $"'{policy.GetType().FullName}' cannot be null.";
163+
throw new InvalidOperationException(message);
164+
}
165+
166+
return (ImmutableArray<IAction>)value;
167+
}
168+
169+
internal ImmutableArray<IAction> GetEndBlockActions(Assembly[] assemblies)
170+
{
171+
object? policy = GetBlockPolicy(assemblies);
172+
if (policy is null)
173+
{
174+
return ImmutableArray<IAction>.Empty;
175+
}
176+
177+
PropertyInfo? propertyInfo = policy
178+
.GetType()
179+
.GetProperty(nameof(IBlockPolicy.EndBlockActions));
180+
if (propertyInfo is null)
181+
{
182+
var message = $"The policy type "
183+
+ $"'{policy.GetType().FullName}' does not have a "
184+
+ $"'{nameof(IBlockPolicy.EndBlockActions)}' property.";
185+
throw new InvalidOperationException(message);
186+
}
187+
188+
var value = propertyInfo.GetValue(policy);
189+
if (value is null)
190+
{
191+
var message = $"The value of property "
192+
+ $"'{nameof(IBlockPolicy.EndBlockActions)}' of type "
193+
+ $"'{policy.GetType().FullName}' cannot be null.";
194+
throw new InvalidOperationException(message);
195+
}
196+
197+
return (ImmutableArray<IAction>)value;
147198
}
148199
}

Libplanet.Extensions.Cocona/Commands/BlockCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ public void GenerateGenesis(
156156
}.Select(x => x.PlainValue)))
157157
.ToImmutableList();
158158

159-
var blockAction = blockPolicyParams.GetBlockAction();
159+
var beginBlockActions = blockPolicyParams.GetBeginBlockActions();
160+
var endBlockActions = blockPolicyParams.GetEndBlockActions();
160161
var actionEvaluator = new ActionEvaluator(
161-
_ => blockAction,
162+
_ => beginBlockActions,
163+
_ => endBlockActions,
162164
new TrieStateStore(new DefaultKeyValueStore(null)),
163165
new SingleActionLoader(typeof(NullAction)));
164166
Block genesis = BlockChain.ProposeGenesisBlock(

Libplanet.Net.Tests/Consensus/ConsensusReactorTest.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ public async void StartAsync()
4747
var consensusReactors = new ConsensusReactor[4];
4848
var stores = new IStore[4];
4949
var blockChains = new BlockChain[4];
50-
var fx = new MemoryStoreFixture(TestUtils.Policy.BlockAction);
50+
var fx = new MemoryStoreFixture(
51+
TestUtils.Policy.BeginBlockActions,
52+
TestUtils.Policy.EndBlockActions
53+
);
5154
var validatorPeers = new List<BoundPeer>();
5255
var cancellationTokenSource = new CancellationTokenSource();
5356

@@ -66,7 +69,8 @@ public async void StartAsync()
6669
stateStore,
6770
fx.GenesisBlock,
6871
new ActionEvaluator(
69-
policyBlockActionGetter: _ => TestUtils.Policy.BlockAction,
72+
policyBeginBlockActionGetter: _ => TestUtils.Policy.BeginBlockActions,
73+
policyEndBlockActionGetter: _ => TestUtils.Policy.EndBlockActions,
7074
stateStore: stateStore,
7175
actionTypeLoader: new SingleActionLoader(typeof(DumbAction))));
7276
}

0 commit comments

Comments
 (0)