Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/delegation_tests.cpp
Show All 17 Lines | |||||
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 Proof &p, | ||||
const CPubKey &expected_pubkey) { | const CPubKey &expected_pubkey) { | ||||
DelegationState state; | DelegationState state; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
BOOST_CHECK(dg.verify(state, p, pubkey)); | BOOST_CHECK(dg.verify(state, p.getMaster(), p.getLimitedId(), pubkey)); | ||||
BOOST_CHECK(state.GetResult() == DelegationResult::NONE); | BOOST_CHECK(state.GetResult() == DelegationResult::NONE); | ||||
BOOST_CHECK(pubkey == expected_pubkey); | BOOST_CHECK(pubkey == expected_pubkey); | ||||
const Proof altp = buildRandomProof(654321); | const Proof altp = buildRandomProof(654321); | ||||
BOOST_CHECK(!dg.verify(state, altp, pubkey)); | BOOST_CHECK( | ||||
!dg.verify(state, altp.getMaster(), altp.getLimitedId(), pubkey)); | |||||
BOOST_CHECK(state.GetResult() == DelegationResult::INCORRECT_PROOF); | BOOST_CHECK(state.GetResult() == DelegationResult::INCORRECT_PROOF); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(verify_random) { | BOOST_AUTO_TEST_CASE(verify_random) { | ||||
CKey key; | CKey key; | ||||
key.MakeNewKey(true); | key.MakeNewKey(true); | ||||
const Proof p = buildRandomProof(123456, key.GetPubKey()); | const Proof p = buildRandomProof(123456, key.GetPubKey()); | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(deserialization) { | ||||
for (auto &c : testcases) { | for (auto &c : testcases) { | ||||
CDataStream stream(ParseHex(c.hex), SER_NETWORK, 0); | CDataStream stream(ParseHex(c.hex), SER_NETWORK, 0); | ||||
Delegation dg; | Delegation dg; | ||||
stream >> dg; | stream >> dg; | ||||
BOOST_CHECK_EQUAL(dg.getId(), DelegationId::fromHex(c.dgid)); | BOOST_CHECK_EQUAL(dg.getId(), DelegationId::fromHex(c.dgid)); | ||||
DelegationState state; | DelegationState state; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
BOOST_CHECK_EQUAL(dg.verify(state, p, pubkey), | BOOST_CHECK_EQUAL( | ||||
dg.verify(state, p.getMaster(), p.getLimitedId(), pubkey), | |||||
c.result == DelegationResult::NONE); | c.result == DelegationResult::NONE); | ||||
BOOST_CHECK(state.GetResult() == c.result); | BOOST_CHECK(state.GetResult() == c.result); | ||||
BOOST_CHECK(pubkey == CPubKey(ParseHex(c.pubkey))); | BOOST_CHECK(pubkey == CPubKey(ParseHex(c.pubkey))); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |