Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/proof_tests.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | struct TestVector { | ||||
std::string name; | std::string name; | ||||
std::string hex; | std::string hex; | ||||
ProofId proofid; | ProofId proofid; | ||||
uint32_t score; | uint32_t score; | ||||
ProofValidationResult result; | ProofValidationResult result; | ||||
}; | }; | ||||
BOOST_AUTO_TEST_CASE(deserialization) { | BOOST_AUTO_TEST_CASE(deserialization) { | ||||
std::vector<TestVector> testcases{ | // All stakes signed using the key: | ||||
// KydYrKDNsVnY5uhpLyC4UmazuJvUjNoKJhEEv9f1mdK1D5zcnMSM | |||||
std::vector<TestVector> legacyFormatTestCases{ | |||||
{"No utxo staked", | {"No utxo staked", | ||||
"96527eae083f1f24625f049d9e54bb9a2102a93d98bf42ab90cfc0bf9e7c634ed76a7" | "96527eae083f1f24625f049d9e54bb9a2102a93d98bf42ab90cfc0bf9e7c634ed76a7" | ||||
"3e95b02cacfd357b64e4fb6c92e92dd00", | "3e95b02cacfd357b64e4fb6c92e92dd00", | ||||
ProofId::fromHex("19f6631738a5a0196bf6152dcdb40de4675954567b444631cdec" | ProofId::fromHex("19f6631738a5a0196bf6152dcdb40de4675954567b444631cdec" | ||||
"52d4c39b5316"), | "52d4c39b5316"), | ||||
0, ProofValidationResult::NO_STAKE}, | 0, ProofValidationResult::NO_STAKE}, | ||||
{"1 utxo staked", | {"1 utxo staked", | ||||
"a6d66db9fe9378fdd37a0ad2c01c2acd2103648144bb6a0c1d09b0f04d0df6d55f914" | "a6d66db9fe9378fdd37a0ad2c01c2acd2103648144bb6a0c1d09b0f04d0df6d55f914" | ||||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | std::vector<TestVector> legacyFormatTestCases{ | ||||
"5237efe8f647d32e8b64f06c22d1d40368eaca2a71ffc6a13ecc8bce68065cd42e0e6" | "5237efe8f647d32e8b64f06c22d1d40368eaca2a71ffc6a13ecc8bce68065cd42e0e6" | ||||
"9d511ad24ecb3c3af07176bcf890caa7cfc64039dc65e51014dd99d11bd00ffbfbcc1" | "9d511ad24ecb3c3af07176bcf890caa7cfc64039dc65e51014dd99d11bd00ffbfbcc1" | ||||
"9619ca502bfd4dd6dbc0967692ff6d2211b0bd9b9f05e1298", | "9619ca502bfd4dd6dbc0967692ff6d2211b0bd9b9f05e1298", | ||||
ProofId::fromHex("38f7c9696f9c2c07db3f23024d550a6b0b7f851013074280dbe3" | ProofId::fromHex("38f7c9696f9c2c07db3f23024d550a6b0b7f851013074280dbe3" | ||||
"49f42a2a5a00"), | "49f42a2a5a00"), | ||||
0, ProofValidationResult::DUST_THRESOLD}, | 0, ProofValidationResult::DUST_THRESOLD}, | ||||
}; | }; | ||||
std::vector<TestVector> regularFormatTestCases{ | |||||
{"Properly signed 1 UTXO proof", | |||||
"d97587e6c882615796011ec8f9a7b1c6410469ab5a892ffa4bb104a3d5760dd893a55" | |||||
"02512eea4ba32a6d6672767be4959c0f70489b803a47a3abf83f30e8d9da978de4027" | |||||
"c70ce7e0d3b0ad62eb08edd8f90169a79ff23e1d58c64afad42ad81cffe53967e16be" | |||||
"b692fc5776bb442c79c5d91de00cf21804712806594010038e168a32102449fb5237e" | |||||
"fe8f647d32e8b64f06c22d1d40368eaca2a71ffc6a13ecc8bce6801ad9e09ccae0af5" | |||||
"424597526aa4af42f0c7c808e593c4fd5fef43a2e59046cf7053ca0fcdc11e2e3ae66" | |||||
"8088a131df62289a0071623541180b7b49cc1faa82fc001476a04053bda0a88bda517" | |||||
"7b86a15c3b29f559873", | |||||
ProofId::fromHex("4bf415ede6e79ffaae30041d0d6a096703af2baeb3857eaa21f5" | |||||
"fa7c657c17a3"), | |||||
444638638, ProofValidationResult::NONE}, | |||||
{"Invalid payout address", | |||||
"d97587e6c882615796011ec8f9a7b1c6410469ab5a892ffa4bb104a3d5760dd893a55" | |||||
"02512eea4ba32a6d6672767be4959c0f70489b803a47a3abf83f30e8d9da978de4027" | |||||
"c70ce7e0d3b0ad62eb08edd8f90169a79ff23e1d58c64afad42ad81cffe53967e16be" | |||||
"b692fc5776bb442c79c5d91de00cf21804712806594010038e168a32102449fb5237e" | |||||
"fe8f647d32e8b64f06c22d1d40368eaca2a71ffc6a13ecc8bce6801ad9e09ccae0af5" | |||||
"424597526aa4af42f0c7c808e593c4fd5fef43a2e59046cf7053ca0fcdc11e2e3ae66" | |||||
"8088a131df62289a0071623541180b7b49cc1faa82fc021476a04053bda0a88bda517" | |||||
"7b86a15c3b29f559873", | |||||
ProofId::fromHex("a5ec616118b8768f37efc529f6cacba21307fa91357551e7142b" | |||||
"bc7b06c60b0c"), | |||||
444638638, ProofValidationResult::INVALID_PAYOUT_ADDRESS}, | |||||
{"Changing the payout address changes the ProofId", | |||||
"d97587e6c882615796011ec8f9a7b1c6410469ab5a892ffa4bb104a3d5760dd893a55" | |||||
"02512eea4ba32a6d6672767be4959c0f70489b803a47a3abf83f30e8d9da978de4027" | |||||
"c70ce7e0d3b0ad62eb08edd8f90169a79ff23e1d58c64afad42ad81cffe53967e16be" | |||||
"b692fc5776bb442c79c5d91de00cf21804712806594010038e168a32102449fb5237e" | |||||
"fe8f647d32e8b64f06c22d1d40368eaca2a71ffc6a13ecc8bce6801ad9e09ccae0af5" | |||||
"424597526aa4af42f0c7c808e593c4fd5fef43a2e59046cf7053ca0fcdc11e2e3ae66" | |||||
"8088a131df62289a0071623541180b7b49cc1faa82fc001476a04053bda0a88bda517" | |||||
"7b86a15c3b29f559874", | |||||
ProofId::fromHex("cae8a1c867fed93120ec6a903c438ea2d758e2f3a16de0d44561" | |||||
"d0c6d62239c4"), | |||||
444638638, ProofValidationResult::INVALID_STAKE_SIGNATURE}, | |||||
}; | |||||
auto checkCases = [&](const std::vector<TestVector> &testcases) { | |||||
for (auto &c : testcases) { | for (auto &c : testcases) { | ||||
CDataStream stream(ParseHex(c.hex), SER_NETWORK, 0); | CDataStream stream(ParseHex(c.hex), SER_NETWORK, 0); | ||||
Proof p; | Proof p; | ||||
stream >> p; | stream >> p; | ||||
BOOST_CHECK_EQUAL(p.getId(), c.proofid); | BOOST_CHECK_EQUAL(p.getId(), c.proofid); | ||||
BOOST_CHECK_EQUAL(p.getScore(), c.score); | BOOST_CHECK_EQUAL(p.getScore(), c.score); | ||||
ProofValidationState state; | ProofValidationState state; | ||||
BOOST_CHECK_EQUAL(p.verify(state), | BOOST_CHECK_EQUAL(p.verify(state), | ||||
c.result == ProofValidationResult::NONE); | c.result == ProofValidationResult::NONE); | ||||
BOOST_CHECK(state.GetResult() == c.result); | BOOST_CHECK(state.GetResult() == c.result); | ||||
BOOST_TEST_MESSAGE(c.proofid); | BOOST_TEST_MESSAGE(c.proofid); | ||||
} | } | ||||
}; | |||||
checkCases(legacyFormatTestCases); | |||||
gArgs.ForceSetArg("-legacyavaproof", "0"); | |||||
BOOST_CHECK(!Proof::useLegacy(gArgs)); | |||||
checkCases(regularFormatTestCases); | |||||
gArgs.ClearForcedArg("-legacyavaproof"); | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(verify) { | BOOST_AUTO_TEST_CASE(verify) { | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
auto key = CKey::MakeCompressedKey(); | auto key = CKey::MakeCompressedKey(); | ||||
const CPubKey pubkey = key.GetPubKey(); | const CPubKey pubkey = key.GetPubKey(); | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |