Fix mempool regtest
MODIFY
MagicalCryptoWallet.Tests/RegTests.cs
MagicalCryptoWallet.Tests/RegTests.cs
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using NBitcoin;
using NBitcoin.Protocol;
+using NBitcoin.Protocol.Behaviors;
using NBitcoin.RPC;
using Newtonsoft.Json;
using System;
@@ -26,7 +27,7 @@ namespace MagicalCryptoWallet.Tests
{
private SharedFixture Fixture { get; }
- private CoreNode SharedRegTestNode { get; }
+ private static CoreNode SharedRegTestNode { get; set; }
public RegTests(SharedFixture fixture)
{
@@ -104,6 +105,7 @@ namespace MagicalCryptoWallet.Tests
[Fact]
public async void BroadcastWithOutMinFeeAsync()
{
+ await Global.RpcClient.GenerateAsync(1);
var utxos = await Global.RpcClient.ListUnspentAsync();
var utxo = utxos[0];
var addr = await Global.RpcClient.GetNewAddressAsync();
@@ -125,6 +127,7 @@ namespace MagicalCryptoWallet.Tests
[Fact]
public async void BroadcastReplayTxAsync()
{
+ await Global.RpcClient.GenerateAsync(1);
var utxos = await Global.RpcClient.ListUnspentAsync();
var utxo = utxos[0];
var tx = await Global.RpcClient.GetRawTransactionAsync(utxo.OutPoint.Hash);
@@ -217,24 +220,15 @@ namespace MagicalCryptoWallet.Tests
[Fact]
public async Task MempoolAsync()
{
- var connectionParameters = new NodeConnectionParameters();
var memPoolService = new MemPoolService();
- connectionParameters.TemplateBehaviors.Add(new MemPoolBehavior(memPoolService));
- using (var nodes = new NodesGroup(Global.Config.Network, connectionParameters,
- new NodeRequirement
- {
- RequiredServices = NodeServices.Network,
- MinVersion = ProtocolVersion.WITNESS_VERSION
- }))
- {
- nodes.ConnectedNodes.Add(SharedRegTestNode.CreateNodeClient());
+ Node node = SharedRegTestNode.CreateNodeClient();
+ node.Behaviors.Add(new MemPoolBehavior(memPoolService));
+ node.VersionHandshake();
try
{
memPoolService.TransactionReceived += MemPoolService_TransactionReceived;
- nodes.Connect();
-
// Using the interlocked, not because it makes sense in this context, but to
// set an example that these values are often concurrency sensitive
for (int i = 0; i < 10; i++)
@@ -245,7 +239,7 @@ namespace MagicalCryptoWallet.Tests
}
var times = 0;
- while (Interlocked.Read(ref _mempoolTransactionCount) < 1)
+ while (Interlocked.Read(ref _mempoolTransactionCount) < 10)
{
if (times > 100) // 10 seconds
{
@@ -260,7 +254,6 @@ namespace MagicalCryptoWallet.Tests
memPoolService.TransactionReceived -= MemPoolService_TransactionReceived;
}
}
- }
private long _mempoolTransactionCount = 0;
private void MemPoolService_TransactionReceived(object sender, SmartTransaction e)

Fix mempool regtest