2
0
mirror of synced 2025-01-23 23:08:52 +00:00

Setting up basic test for waku

This commit is contained in:
benbierens 2023-09-25 15:43:16 +02:00
parent 12f6710a56
commit 3776f46c02
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 30 additions and 8 deletions

View File

@ -32,8 +32,6 @@ namespace WakuPlugin
{ {
AddEnvVar("WAKUNODE2_DISCV5_BOOTSTRAP_NODE", config.BootstrapEnr); AddEnvVar("WAKUNODE2_DISCV5_BOOTSTRAP_NODE", config.BootstrapEnr);
} }
AddEnvVar("WAKUNODE2_TOPICS", "test_topics_plz");
} }
} }
} }

View File

@ -6,6 +6,9 @@ namespace WakuPlugin
public interface IWakuNode : IHasContainer public interface IWakuNode : IHasContainer
{ {
DebugInfoResponse DebugInfo(); DebugInfoResponse DebugInfo();
void SubscribeToTopic(string topic);
void SendMessage(string topic, string message);
string[] GetMessages(string topic);
} }
public class WakuNode : IWakuNode public class WakuNode : IWakuNode
@ -25,6 +28,22 @@ namespace WakuPlugin
return Http().HttpGetJson<DebugInfoResponse>("debug/v1/info"); return Http().HttpGetJson<DebugInfoResponse>("debug/v1/info");
} }
public void SubscribeToTopic(string topic)
{
var response = Http().HttpPostString("relay/v1/subscriptions", topic);
}
public void SendMessage(string topic, string message)
{
var response = Http().HttpPostString($"relay/v1/messages/{topic}", message);
}
public string[] GetMessages(string topic)
{
var response = Http().HttpGetString($"relay/v1/messages/{topic}");
return new[] { "" };
}
private IHttp Http() private IHttp Http()
{ {
return tools.CreateHttp(Container.Address, ""); return tools.CreateHttp(Container.Address, "");

View File

@ -2,6 +2,7 @@
{ {
public interface IWakuSetup public interface IWakuSetup
{ {
IWakuSetup WithName(string name);
IWakuSetup WithBootstrapNode(IWakuNode node); IWakuSetup WithBootstrapNode(IWakuNode node);
} }

View File

@ -8,16 +8,20 @@ namespace WakuTests
[Test] [Test]
public void Hi() public void Hi()
{ {
var node1 = Ci.StartWakuNode(); var bootNode = Ci.StartWakuNode(s => s.WithName("BootstrapNode"));
var node = Ci.StartWakuNode(s => s.WithName("Waku1").WithBootstrapNode(bootNode));
var info1 = node1.DebugInfo(); var topic = "cheeseWheels";
Assert.That(info1.enrUri, Is.Not.Empty); var message = "hmm, cheese...";
var node2 = Ci.StartWakuNode(s => s.WithBootstrapNode(node1)); bootNode.SubscribeToTopic(topic);
var info2 = node2.DebugInfo(); node.SubscribeToTopic(topic);
Assert.That(info2.enrUri, Is.Not.Empty);
node.SendMessage(topic, message);
var received = bootNode.GetMessages(topic);
CollectionAssert.Contains(received, message);
} }
} }
} }