lokinet/test/dht/test_llarp_dht_node.cpp

117 lines
2.5 KiB
C++
Raw Normal View History

2019-01-29 00:24:11 +00:00
#include <dht/node.hpp>
#include <test_util.hpp>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace llarp;
using namespace ::testing;
using test::makeBuf;
struct TestDhtRCNode : public ::testing::Test
{
};
TEST_F(TestDhtRCNode, construct)
{
dht::RCNode node;
ASSERT_THAT(node.ID, Property(&dht::Key_t::IsZero, true));
node.ID.Fill(0xCA);
2020-02-24 19:40:45 +00:00
node.rc.last_updated = 101s;
2019-01-29 00:24:11 +00:00
dht::RCNode other{node};
ASSERT_EQ(node.ID, other.ID);
ASSERT_EQ(node.rc, other.rc);
RouterContact contact;
contact.pubkey.Randomize();
dht::RCNode fromContact{contact};
ASSERT_EQ(fromContact.ID.as_array(), contact.pubkey.as_array());
}
TEST_F(TestDhtRCNode, lt)
{
dht::RCNode one;
dht::RCNode two;
dht::RCNode three;
dht::RCNode eqThree;
2020-02-24 19:40:45 +00:00
one.rc.last_updated = 1s;
two.rc.last_updated = 2s;
three.rc.last_updated = 3s;
eqThree.rc.last_updated = 3s;
2019-01-29 00:24:11 +00:00
// LT cases
ASSERT_THAT(one, Lt(two));
ASSERT_THAT(one, Lt(three));
ASSERT_THAT(one, Lt(eqThree));
ASSERT_THAT(two, Lt(three));
ASSERT_THAT(two, Lt(eqThree));
// !LT cases
ASSERT_THAT(one, Not(Lt(one)));
ASSERT_THAT(two, Not(Lt(one)));
ASSERT_THAT(two, Not(Lt(two)));
ASSERT_THAT(three, Not(Lt(one)));
ASSERT_THAT(three, Not(Lt(two)));
ASSERT_THAT(three, Not(Lt(three)));
ASSERT_THAT(three, Not(Lt(eqThree)));
}
struct TestDhtISNode : public ::testing::Test
{
};
TEST_F(TestDhtISNode, construct)
{
dht::ISNode node;
ASSERT_THAT(node.ID, Property(&dht::Key_t::IsZero, true));
node.ID.Fill(0xCA);
2020-01-27 21:30:41 +00:00
node.introset.derivedSigningKey.Fill(0xDB);
2019-01-29 00:24:11 +00:00
dht::ISNode other{node};
ASSERT_EQ(node.ID, other.ID);
ASSERT_EQ(node.introset, other.introset);
2020-01-27 21:30:41 +00:00
service::EncryptedIntroSet introSet;
introSet.derivedSigningKey.Randomize();
2019-01-29 00:24:11 +00:00
dht::ISNode fromIntro{introSet};
2020-01-27 21:30:41 +00:00
ASSERT_EQ(fromIntro.ID.as_array(), introSet.derivedSigningKey);
2019-01-29 00:24:11 +00:00
}
TEST_F(TestDhtISNode, lt)
{
dht::ISNode one;
dht::ISNode two;
dht::ISNode three;
dht::ISNode eqThree;
2020-02-24 19:40:45 +00:00
one.introset.signedAt = 1s;
two.introset.signedAt = 2s;
three.introset.signedAt = 3s;
eqThree.introset.signedAt = 3s;
2019-01-29 00:24:11 +00:00
// LT cases
ASSERT_THAT(one, Lt(two));
ASSERT_THAT(one, Lt(three));
ASSERT_THAT(one, Lt(eqThree));
ASSERT_THAT(two, Lt(three));
ASSERT_THAT(two, Lt(eqThree));
// !LT cases
ASSERT_THAT(one, Not(Lt(one)));
ASSERT_THAT(two, Not(Lt(one)));
ASSERT_THAT(two, Not(Lt(two)));
ASSERT_THAT(three, Not(Lt(one)));
ASSERT_THAT(three, Not(Lt(two)));
ASSERT_THAT(three, Not(Lt(three)));
ASSERT_THAT(three, Not(Lt(eqThree)));
}