Skip to content

Commit

Permalink
Merge pull request #3534 from OnedgeLee/test/remove-t
Browse files Browse the repository at this point in the history
Replace <T> with IActionLoader param
  • Loading branch information
OnedgeLee authored Dec 12, 2023
2 parents 85f1868 + c445f16 commit 7480b13
Show file tree
Hide file tree
Showing 20 changed files with 186 additions and 83 deletions.
5 changes: 3 additions & 2 deletions Libplanet.Explorer.Tests/Queries/TransactionQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
using Libplanet.Types.Assets;
using Libplanet.Types.Consensus;
using Libplanet.Types.Tx;
using Libplanet.Consensus;
using Libplanet.Explorer.Queries;
using Libplanet.Store;
using Libplanet.Store.Trie;
using Xunit;
using static Libplanet.Explorer.Tests.GraphQLTestUtils;
using Libplanet.Action.Loader;

namespace Libplanet.Explorer.Tests.Queries;

Expand All @@ -32,10 +32,11 @@ public class TransactionQueryTest

public TransactionQueryTest()
{
Chain = Libplanet.Tests.TestUtils.MakeBlockChain<NullAction>(
Chain = Libplanet.Tests.TestUtils.MakeBlockChain(
new BlockPolicy(),
new MemoryStore(),
new TrieStateStore(new MemoryKeyValueStore()),
new SingleActionLoader(typeof(NullAction)),
privateKey: new PrivateKey(),
timestamp: DateTimeOffset.UtcNow
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public async void NewHeightWithLastCommit()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[2]);
blockChain.TipChanged += (_, __) => tipChanged.Set();
consensusContext.MessagePublished += (_, eventArgs) =>
Expand Down Expand Up @@ -119,6 +120,7 @@ public async void HandleMessageFromHigherHeight()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
newHeightDelay,
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[2]);

consensusContext.StateChanged += (_, eventArgs) =>
Expand Down Expand Up @@ -247,6 +249,7 @@ public async void UseLastCommitCacheIfHeightContextIsEmpty()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[2]);

consensusContext.MessageConsumed += (_, eventArgs) =>
Expand Down Expand Up @@ -287,6 +290,7 @@ public async void NewHeightDelay()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
newHeightDelay,
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[2]);
consensusContext.StateChanged += (_, eventArgs) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public async void IncreaseRoundWhenTimeout()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[1]);

var timeoutProcessed = new AsyncAutoResetEvent();
Expand Down
9 changes: 9 additions & 0 deletions Libplanet.Net.Tests/Consensus/ConsensusContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public async void NewHeightIncreasing()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[3]);

AsyncAutoResetEvent heightThreeStepChangedToPropose = new AsyncAutoResetEvent();
Expand Down Expand Up @@ -113,6 +114,7 @@ public void Ctor()
var (_, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[1]);

Assert.Equal(ConsensusStep.Null, consensusContext.Step);
Expand All @@ -126,6 +128,7 @@ public async void NewHeightWhenTipChanged()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
newHeightDelay,
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[1]);

Assert.Equal(-1, consensusContext.Height);
Expand All @@ -142,6 +145,7 @@ public void IgnoreMessagesFromLowerHeight()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[1]);

consensusContext.NewHeight(blockChain.Tip.Index + 1);
Expand All @@ -159,6 +163,7 @@ public void RemoveOldContexts()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[1]);

// Create context of index 1.
Expand Down Expand Up @@ -197,6 +202,7 @@ public async void VoteSetGetOnlyProposeCommitHash()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[1]);

consensusContext.StateChanged += (sender, tuple) =>
Expand Down Expand Up @@ -264,6 +270,7 @@ public async void GetVoteSetBits()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[0]);
consensusContext.NewHeight(1);
var block = blockChain.ProposeBlock(proposer);
Expand Down Expand Up @@ -336,6 +343,7 @@ public async void HandleVoteSetBits()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[0]);
consensusContext.NewHeight(1);
consensusContext.StateChanged += (_, eventArgs) =>
Expand Down Expand Up @@ -405,6 +413,7 @@ public async void HandleProposalClaim()
var (blockChain, consensusContext) = TestUtils.CreateDummyConsensusContext(
TimeSpan.FromSeconds(1),
TestUtils.Policy,
TestUtils.ActionLoader,
TestUtils.PrivateKeys[0]);
consensusContext.NewHeight(1);
consensusContext.StateChanged += (_, eventArgs) =>
Expand Down
4 changes: 3 additions & 1 deletion Libplanet.Net.Tests/Consensus/ContextNonProposerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.Json;
using System.Threading.Tasks;
using Bencodex.Types;
using Libplanet.Action.Loader;
using Libplanet.Action.Tests.Common;
using Libplanet.Blockchain;
using Libplanet.Blockchain.Policies;
Expand Down Expand Up @@ -295,7 +296,8 @@ public async Task EnterPreVoteNilOnInvalidBlockContent()

using var fx = new MemoryStoreFixture(policy.BlockAction);
var diffPolicyBlockChain =
TestUtils.CreateDummyBlockChain(fx, policy, blockChain.Genesis);
TestUtils.CreateDummyBlockChain(
fx, policy, new SingleActionLoader(typeof(DumbAction)), blockChain.Genesis);

var invalidTx = diffPolicyBlockChain.MakeTransaction(invalidKey, new DumbAction[] { });

Expand Down
6 changes: 4 additions & 2 deletions Libplanet.Net.Tests/Consensus/ContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Bencodex;
using Bencodex.Types;
using Libplanet.Action;
using Libplanet.Action.Loader;
using Libplanet.Action.Tests.Common;
using Libplanet.Blockchain.Policies;
using Libplanet.Consensus;
Expand Down Expand Up @@ -292,10 +293,11 @@ public async Task CanPreCommitOnEndCommit()
blockAction: new MinerReward(1),
getMaxTransactionsBytes: _ => 50 * 1024);
var fx = new MemoryStoreFixture(policy.BlockAction);
var blockChain = Libplanet.Tests.TestUtils.MakeBlockChain<DelayAction>(
var blockChain = Libplanet.Tests.TestUtils.MakeBlockChain(
policy,
fx.Store,
new TrieStateStore(new MemoryKeyValueStore()));
new TrieStateStore(new MemoryKeyValueStore()),
new SingleActionLoader(typeof(DelayAction)));

Context? context = null;

Expand Down
6 changes: 4 additions & 2 deletions Libplanet.Net.Tests/Messages/NetMQMessageCodecTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Immutable;
using System.Net;
using Bencodex;
using Libplanet.Action.Loader;
using Libplanet.Action.Tests.Common;
using Libplanet.Blockchain;
using Libplanet.Blockchain.Policies;
Expand Down Expand Up @@ -78,10 +79,11 @@ private MessageContent CreateMessage(MessageContent.MessageType type)
var privateKey = new PrivateKey();
var boundPeer = new BoundPeer(privateKey.PublicKey, new DnsEndPoint("127.0.0.1", 1000));
IBlockPolicy policy = new BlockPolicy();
BlockChain chain = MakeBlockChain<DumbAction>(
BlockChain chain = MakeBlockChain(
policy,
new MemoryStore(),
new TrieStateStore(new MemoryKeyValueStore())
new TrieStateStore(new MemoryKeyValueStore()),
new SingleActionLoader(typeof(DumbAction))
);
var codec = new Codec();
Block genesis = chain.Genesis;
Expand Down
12 changes: 8 additions & 4 deletions Libplanet.Net.Tests/SwarmTest.Broadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public async Task BroadcastBlockToReconnectedPeer()
var miner = new PrivateKey();
var policy = new NullBlockPolicy();
var fx = new MemoryStoreFixture(policy.BlockAction);
var minerChain = MakeBlockChain<DumbAction>(policy, fx.Store, fx.StateStore);
var minerChain = MakeBlockChain(
policy, fx.Store, fx.StateStore, new SingleActionLoader(typeof(DumbAction)));
foreach (int i in Enumerable.Range(0, 10))
{
Block block = minerChain.ProposeBlock(
Expand Down Expand Up @@ -183,10 +184,11 @@ public async Task BroadcastIgnoreFromDifferentGenesisHash()
BlockChain receiverChain = receiverSwarm.BlockChain;
var seedStateStore = new TrieStateStore(new MemoryKeyValueStore());
IBlockPolicy policy = receiverChain.Policy;
BlockChain seedChain = MakeBlockChain<DumbAction>(
BlockChain seedChain = MakeBlockChain(
policy,
new MemoryStore(),
seedStateStore,
new SingleActionLoader(typeof(DumbAction)),
privateKey: receiverKey);
var seedMiner = new PrivateKey();
Swarm seedSwarm =
Expand Down Expand Up @@ -700,7 +702,8 @@ public async Task BroadcastBlockWithSkip()
{
var policy = new BlockPolicy(new MinerReward(1));
var fx1 = new MemoryStoreFixture();
var blockChain = MakeBlockChain<DumbAction>(policy, fx1.Store, fx1.StateStore);
var blockChain = MakeBlockChain(
policy, fx1.Store, fx1.StateStore, new SingleActionLoader(typeof(DumbAction)));
var privateKey = new PrivateKey();
var minerSwarm =
await CreateSwarm(blockChain, privateKey).ConfigureAwait(false);
Expand All @@ -709,10 +712,11 @@ public async Task BroadcastBlockWithSkip()
var loggedRenderer = new LoggedActionRenderer(
receiverRenderer,
_logger);
var receiverChain = MakeBlockChain<DumbAction>(
var receiverChain = MakeBlockChain(
policy,
fx2.Store,
fx2.StateStore,
new SingleActionLoader(typeof(DumbAction)),
renderers: new[] { loggedRenderer });
Swarm receiverSwarm =
await CreateSwarm(receiverChain).ConfigureAwait(false);
Expand Down
10 changes: 8 additions & 2 deletions Libplanet.Net.Tests/SwarmTest.Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Libplanet.Action.Loader;
using Libplanet.Action.Tests.Common;
using Libplanet.Blockchain;
using Libplanet.Blockchain.Policies;
Expand Down Expand Up @@ -36,7 +37,11 @@ private static (Address, Block[])
using (var storeFx = new MemoryStoreFixture())
{
var chain =
MakeBlockChain<DumbAction>(policy, storeFx.Store, storeFx.StateStore);
MakeBlockChain(
policy,
storeFx.Store,
storeFx.StateStore,
new SingleActionLoader(typeof(DumbAction)));
var miner = new PrivateKey();
var signer = new PrivateKey();
Address address = signer.Address;
Expand Down Expand Up @@ -113,10 +118,11 @@ private async Task<Swarm> CreateSwarm(
{
policy = policy ?? new BlockPolicy(new MinerReward(1));
var fx = new MemoryStoreFixture(policy.BlockAction);
var blockchain = MakeBlockChain<DumbAction>(
var blockchain = MakeBlockChain(
policy,
fx.Store,
fx.StateStore,
new SingleActionLoader(typeof(DumbAction)),
genesisBlock: genesis
);
appProtocolVersionOptions ??= new AppProtocolVersionOptions();
Expand Down
Loading

0 comments on commit 7480b13

Please sign in to comment.