Skip to content

Commit ce436f8

Browse files
committed
Move mining from docker to code
1 parent a8d80d3 commit ce436f8

8 files changed

Lines changed: 57 additions & 58 deletions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using NUnit.Framework;
2+
3+
namespace Monero.IntegrationTests;
4+
5+
[SetUpFixture]
6+
public class MiningFixture : MoneroIntegrationTestBase
7+
{
8+
[OneTimeSetUp]
9+
public async Task RunBeforeAnyTests()
10+
{
11+
await MineToHeight(10);
12+
}
13+
14+
[OneTimeTearDown]
15+
public async Task RunAfterAllTests()
16+
{
17+
await TestUtils.GetDaemonRpc().StopMining();
18+
}
19+
20+
private static async Task MineToHeight(ulong targetHeight)
21+
{
22+
var daemon = TestUtils.GetDaemonRpc();
23+
24+
var currentHeight = await daemon.GetHeight();
25+
if (currentHeight >= targetHeight) return;
26+
27+
var miningStatus = await daemon.GetMiningStatus();
28+
if (miningStatus.IsActive != true)
29+
{
30+
await daemon.StartMining(
31+
"9xSyMy1r9h3BVjMrF3CTqQCQy36yCfkpn7uVfMyTUbez3hhumqBUqGUNNALjcd7f1HJBRdeH82bCC3veFHW7z3xm28gug4d",
32+
1,
33+
false,
34+
false
35+
);
36+
}
37+
while (true)
38+
{
39+
var height = await daemon.GetHeight();
40+
if (height >= targetHeight)
41+
{
42+
break;
43+
}
44+
await Task.Delay(1000);
45+
}
46+
}
47+
}

Monero.IntegrationTests/MoneroDaemonRpcIntegrationTest.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,30 @@
22
using Monero.Daemon;
33
using Monero.Daemon.Common;
44
using Monero.Daemon.Rpc;
5-
using Monero.IntegrationTests.Utils;
65

76
using NUnit.Framework;
87

98
namespace Monero.IntegrationTests;
109

1110
public class MoneroDaemonRpcIntegrationTest : MoneroIntegrationTestBase
1211
{
13-
1412
#region Notification Tests
1513

1614
// Can notify listeners when a new block is added to the chain
1715
[Test]
1816
public async Task TestBlockListener()
1917
{
20-
try
21-
{
22-
// register a listener
23-
MoneroDaemonListener listener = new();
24-
Daemon.AddListener(listener);
18+
// register a listener
19+
MoneroDaemonListener listener = new();
20+
Daemon.AddListener(listener);
2521

26-
// wait for the next block notification
27-
MoneroBlockHeader header = await Daemon.WaitForNextBlockHeader();
28-
Daemon.RemoveListener(listener); // unregister listener so daemon does not keep polling
29-
TestBlockHeader(header, true);
22+
// wait for the next block notification
23+
MoneroBlockHeader header = await Daemon.WaitForNextBlockHeader();
24+
Daemon.RemoveListener(listener); // unregister listener so daemon does not keep polling
25+
TestBlockHeader(header, true);
3026

31-
// test that listener was called with the equivalent header
32-
Assert.That(header.Equals(listener.GetLastBlockHeader()));
33-
}
34-
finally
35-
{
36-
// stop mining
37-
try { await Daemon.StopMining(); }
38-
catch (MoneroError)
39-
{
40-
// ignore
41-
}
42-
}
27+
// test that listener was called with the equivalent header
28+
Assert.That(header.Equals(listener.GetLastBlockHeader()));
4329
}
4430

4531
#endregion

Monero.IntegrationTests/MoneroIntegrationTestBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Monero.Daemon;
2-
using Monero.IntegrationTests.Utils;
32
using Monero.Wallet;
43

54
namespace Monero.IntegrationTests;

Monero.IntegrationTests/MoneroWalletRpcIntegrationTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Monero.Common;
2-
using Monero.IntegrationTests.Utils;
32
using Monero.Wallet;
43
using Monero.Wallet.Common;
54

Monero.IntegrationTests/Utils/TestUtils.cs renamed to Monero.IntegrationTests/TestUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using NUnit.Framework;
99

10-
namespace Monero.IntegrationTests.Utils;
10+
namespace Monero.IntegrationTests;
1111

1212
internal abstract class TestUtils
1313
{

Monero.IntegrationTests/Utils/StartMining.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

Monero.IntegrationTests/Utils/StopMining.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

Monero.IntegrationTests/docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ services:
4848
"--rpc-max-connections=1000",
4949
"--max-connections-per-ip=10",
5050
"--rpc-max-connections-per-private-ip=1000",
51-
"--start-mining=9xSyMy1r9h3BVjMrF3CTqQCQy36yCfkpn7uVfMyTUbez3hhumqBUqGUNNALjcd7f1HJBRdeH82bCC3veFHW7z3xm28gug4d",
52-
"--mining-threads=1",
5351
"--non-interactive"
5452
]
5553
volumes:

0 commit comments

Comments
 (0)