fix unit tests, make them pass

pull/1306/head
Jeff Becker 4 years ago
parent 1779f33506
commit e95b9d530e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -377,7 +377,7 @@ namespace llarp
(void)params;
constexpr bool DefaultRPCEnabled = true;
constexpr auto DefaultRPCBindAddr = "127.0.0.1:1190";
constexpr auto DefaultRPCBindAddr = "tcp://127.0.0.1:1190";
conf.defineOption<bool>(
"api", "enabled", false, DefaultRPCEnabled, AssignmentAcceptor(m_enableRPCServer));
@ -395,7 +395,7 @@ namespace llarp
(void)params;
constexpr bool DefaultWhitelistRouters = false;
constexpr auto DefaultLokidRPCAddr = "127.0.0.1:22023";
constexpr auto DefaultLokidRPCAddr = "tcp://127.0.0.1:22023";
conf.defineOption<std::string>(
"lokid", "service-node-seed", false, our_identity_filename, [this](std::string arg) {

@ -28,7 +28,6 @@ add_executable(testAll
dht/test_llarp_dht_tx.cpp
dht/test_llarp_dht_txowner.cpp
dns/test_llarp_dns_dns.cpp
exit/test_llarp_exit_context.cpp
llarp_test.cpp
net/test_llarp_net.cpp
router/test_llarp_router_version.cpp
@ -74,6 +73,7 @@ add_executable(catchAll
config/test_llarp_config_output.cpp
net/test_ip_address.cpp
net/test_sock_addr.cpp
exit/test_llarp_exit_context.cpp
iwp/test_iwp_session.cpp
check_main.cpp)

@ -1,44 +1,55 @@
#include <exit/context.hpp>
#include <config/config.hpp>
#include <router/router.hpp>
#include <exit/context.hpp>
#include "config/config.hpp"
#include <gtest/gtest.h>
#include <crypto/types.hpp>
#include <llarp.h>
#include <llarp.hpp>
#include <catch2/catch.hpp>
struct ExitTest : public ::testing::Test
static llarp_main*
make_context()
{
ExitTest() : r(nullptr, nullptr), context(&r)
{
r.Configure(nullptr, false, nullptr);
}
llarp::Router r;
llarp::exit::Context context;
};
// make config
auto config = llarp_default_relay_config();
// set testing defaults
config->impl.network.m_endpointType = "null";
config->impl.bootstrap.skipBootstrap = true;
config->impl.api.m_enableRPCServer = false;
// make a fake inbound link
config->impl.links.m_InboundLinks.emplace_back();
auto& link = config->impl.links.m_InboundLinks.back();
link.interface = llarp::net::LoopbackInterfaceName();
link.addressFamily = AF_INET;
link.port = 0;
// configure
auto ptr = llarp_main_init_from_config(config, true);
llarp_config_free(config);
return ptr;
}
TEST_F(ExitTest, AddMultipleIP)
TEST_CASE("ensure snode address allocation", "[snode]")
{
llarp::PubKey pk;
pk.Randomize();
llarp::PathID_t firstPath, secondPath;
firstPath.Randomize();
secondPath.Randomize();
// TODO: exit and type
// llarp::exit::Context::Config_t conf;
// conf.emplace("exit", "true");
// conf.emplace("type", "null");
llarp::LogSilencer shutup;
auto ctx = make_context();
REQUIRE(llarp_main_setup(ctx, true) == 0);
auto ctx_pp = llarp::Context::Get(ctx);
ctx_pp->CallSafe([ctx_pp]() {
REQUIRE(ctx_pp->router->IsServiceNode());
auto& context = ctx_pp->router->exitContext();
llarp::PubKey pk;
pk.Randomize();
llarp::NetworkConfig networkConfig;
networkConfig.m_endpointType = "null";
networkConfig.m_ifname = "lokitunX";
networkConfig.m_ifaddr = "10.0.0.1/24";
llarp::PathID_t firstPath, secondPath;
firstPath.Randomize();
secondPath.Randomize();
ASSERT_NO_THROW(context.AddExitEndpoint("test-exit", networkConfig, {}));
ASSERT_TRUE(context.ObtainNewExit(pk, firstPath, false));
ASSERT_TRUE(context.ObtainNewExit(pk, secondPath, false));
ASSERT_TRUE(
context.FindEndpointForPath(firstPath)->LocalIP()
== context.FindEndpointForPath(secondPath)->LocalIP());
REQUIRE(context.ObtainNewExit(pk, firstPath, false));
REQUIRE(context.ObtainNewExit(pk, secondPath, false));
REQUIRE(
context.FindEndpointForPath(firstPath)->LocalIP()
== context.FindEndpointForPath(secondPath)->LocalIP());
ctx_pp->CloseAsync();
});
REQUIRE(llarp_main_run(ctx, llarp_main_runtime_opts{isRelay: true}) == 0);
llarp_main_free(ctx);
}

@ -17,6 +17,7 @@ make_context(std::optional<fs::path> keyfile)
context->config->network.m_endpointType = "null";
context->config->network.m_keyfile = keyfile;
context->config->bootstrap.skipBootstrap = true;
context->config->api.m_enableRPCServer = false;
return context;
}

Loading…
Cancel
Save