Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/delegation_tests.cpp
Show All 13 Lines | |||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
using namespace avalanche; | using namespace avalanche; | ||||
BOOST_FIXTURE_TEST_SUITE(delegation_tests, TestingSetup) | BOOST_FIXTURE_TEST_SUITE(delegation_tests, TestingSetup) | ||||
static void CheckDelegation(const Delegation &dg, const Proof &p, | static void CheckDelegation(const Delegation &dg, | ||||
const std::shared_ptr<Proof> &p, | |||||
const CPubKey &expected_pubkey) { | const CPubKey &expected_pubkey) { | ||||
DelegationState state; | DelegationState state; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
BOOST_CHECK(dg.verify(state, pubkey)); | BOOST_CHECK(dg.verify(state, pubkey)); | ||||
BOOST_CHECK(state.GetResult() == DelegationResult::NONE); | BOOST_CHECK(state.GetResult() == DelegationResult::NONE); | ||||
BOOST_CHECK(pubkey == expected_pubkey); | BOOST_CHECK(pubkey == expected_pubkey); | ||||
BOOST_CHECK(dg.getProofId() == p.getId()); | BOOST_CHECK(dg.getProofId() == p->getId()); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(verify_random) { | BOOST_AUTO_TEST_CASE(verify_random) { | ||||
auto key = CKey::MakeCompressedKey(); | auto key = CKey::MakeCompressedKey(); | ||||
const Proof p = buildRandomProof(123456, key); | auto p = buildRandomProof(123456, key); | ||||
DelegationBuilder dgb(p); | DelegationBuilder dgb(*p); | ||||
{ | { | ||||
Delegation dg = dgb.build(); | Delegation dg = dgb.build(); | ||||
BOOST_CHECK_EQUAL(dg.getId(), p.getId()); | BOOST_CHECK_EQUAL(dg.getId(), p->getId()); | ||||
CheckDelegation(dg, p, p.getMaster()); | CheckDelegation(dg, p, p->getMaster()); | ||||
} | } | ||||
auto l1key = CKey::MakeCompressedKey(); | auto l1key = CKey::MakeCompressedKey(); | ||||
BOOST_CHECK(!dgb.addLevel(l1key, key.GetPubKey())); | BOOST_CHECK(!dgb.addLevel(l1key, key.GetPubKey())); | ||||
dgb.addLevel(key, l1key.GetPubKey()); | dgb.addLevel(key, l1key.GetPubKey()); | ||||
CheckDelegation(dgb.build(), p, l1key.GetPubKey()); | CheckDelegation(dgb.build(), p, l1key.GetPubKey()); | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |