Skip to content

Commit

Permalink
Add test for admin_addTrustedPeer
Browse files Browse the repository at this point in the history
  • Loading branch information
richardgreg committed Dec 11, 2024
1 parent 96e43b4 commit 17efc98
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,46 @@ public async Task Test_admin_dataDir()
response.Result!.ToString().Should().Be(_exampleDataDir);
}

[Test]
public async Task Test_admin_addTrustedPeer()
{
// trustedNodesManager and peerPool mocks initialized in Setup()
// We'll configure the trustedNodesManager mock to return true when adding a trusted node.

ITrustedNodesManager trustedNodesManager = Substitute.For<ITrustedNodesManager>();
trustedNodesManager.AddAsync(_enodeString, true).Returns(Task.FromResult(true));

IPeerPool peerPool = Substitute.For<IPeerPool>();
NetworkNode node = new(_enodeString);

// The AdminRpcModule requires the full constructor call with ITrustedNodesManager:
ChainSpec chainSpec = new() { Parameters = new ChainParameters() };
IAdminRpcModule adminRpcModule = new AdminRpcModule(
_blockTree,
_networkConfig,
peerPool,
Substitute.For<IStaticNodesManager>(),
new Enode(_enodeString),
_exampleDataDir,
new ManualPruningTrigger(),
chainSpec.Parameters,
trustedNodesManager);

// Invoke admin_addTrustedPeer
string serialized = await RpcTest.TestSerializedRequest(adminRpcModule, "admin_addTrustedPeer", _enodeString);

// Check the response to ensure it succeeded
JsonRpcSuccessResponse response = _serializer.Deserialize<JsonRpcSuccessResponse>(serialized);
bool result = ((JsonElement)response.Result!).Deserialize<bool>(EthereumJsonSerializer.JsonOptions);
result.Should().BeTrue();

// Verify that AddAsync was called
await trustedNodesManager.Received(1).AddAsync(_enodeString, Arg.Any<bool>());

// Verify that peerPool.GetOrAdd was called for that node
peerPool.ReceivedWithAnyArgs(1).GetOrAdd(node);
}

[Test]
public async Task Smoke_solc()
{
Expand Down

0 comments on commit 17efc98

Please sign in to comment.