mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
106 lines
2.5 KiB
C++
106 lines
2.5 KiB
C++
#include <dht/txowner.hpp>
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
namespace
|
|
{
|
|
using llarp::dht::Key_t;
|
|
using llarp::dht::TXOwner;
|
|
|
|
struct TxOwnerData
|
|
{
|
|
Key_t node;
|
|
uint64_t id;
|
|
size_t expectedHash;
|
|
|
|
TxOwnerData(const Key_t& k, uint64_t i, size_t h) : node(k), id(i), expectedHash(h)
|
|
{}
|
|
};
|
|
|
|
TEST_CASE("TxOwner default construct", "[dht]")
|
|
{
|
|
TXOwner dc;
|
|
REQUIRE(dc.node.IsZero());
|
|
REQUIRE(0u == dc.txid);
|
|
REQUIRE(0u == TXOwner::Hash()(dc));
|
|
}
|
|
|
|
std::vector<TxOwnerData>
|
|
makeData()
|
|
{
|
|
std::vector<TxOwnerData> result;
|
|
|
|
Key_t zero;
|
|
zero.Zero();
|
|
Key_t one;
|
|
one.Fill(0x01);
|
|
Key_t two;
|
|
two.Fill(0x02);
|
|
|
|
uint64_t max = std::numeric_limits<uint64_t>::max();
|
|
|
|
result.emplace_back(zero, 0, 0ull);
|
|
result.emplace_back(zero, 1, 1ull);
|
|
result.emplace_back(one, 0, 144680345676153346ull);
|
|
result.emplace_back(one, 1, 144680345676153347ull);
|
|
result.emplace_back(two, 0, 289360691352306692ull);
|
|
result.emplace_back(two, 2, 289360691352306694ull);
|
|
result.emplace_back(zero, max, 18446744073709551615ull);
|
|
result.emplace_back(one, max, 18302063728033398269ull);
|
|
result.emplace_back(two, max, 18157383382357244923ull);
|
|
|
|
return result;
|
|
}
|
|
|
|
TEST_CASE("TxOwner hash", "[dht]")
|
|
{
|
|
// test single interactions (constructor and hash)
|
|
auto d = GENERATE(from_range(makeData()));
|
|
TXOwner constructor(d.node, d.id);
|
|
|
|
REQUIRE(d.expectedHash == TXOwner::Hash()(constructor));
|
|
}
|
|
|
|
struct TxOwnerCmpData
|
|
{
|
|
TXOwner lhs;
|
|
TXOwner rhs;
|
|
bool equal;
|
|
bool less;
|
|
|
|
TxOwnerCmpData(const TXOwner& l, const TXOwner& r, bool e, bool ls)
|
|
: lhs(l), rhs(r), equal(e), less(ls)
|
|
{}
|
|
};
|
|
|
|
std::vector<TxOwnerCmpData>
|
|
makeCmpData()
|
|
{
|
|
std::vector<TxOwnerCmpData> result;
|
|
|
|
Key_t zero;
|
|
zero.Fill(0x00);
|
|
Key_t one;
|
|
one.Fill(0x01);
|
|
Key_t two;
|
|
two.Fill(0x02);
|
|
|
|
result.emplace_back(TXOwner(zero, 0), TXOwner(zero, 0), true, false);
|
|
result.emplace_back(TXOwner(one, 0), TXOwner(one, 0), true, false);
|
|
result.emplace_back(TXOwner(two, 0), TXOwner(two, 0), true, false);
|
|
|
|
result.emplace_back(TXOwner(zero, 0), TXOwner(one, 0), false, true);
|
|
result.emplace_back(TXOwner(two, 0), TXOwner(one, 0), false, false);
|
|
|
|
return result;
|
|
}
|
|
|
|
TEST_CASE("TxOwner ops", "[dht]")
|
|
{
|
|
// test single interactions (constructor and hash)
|
|
auto d = GENERATE(from_range(makeCmpData()));
|
|
|
|
REQUIRE((d.lhs == d.rhs) == d.equal);
|
|
REQUIRE((d.lhs < d.rhs) == d.less);
|
|
}
|
|
} // namespace
|