Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/proof_tests.cpp
Show All 32 Lines | for (int i = 0; i < 1000; i++) { | ||||
ProofValidationState state; | ProofValidationState state; | ||||
BOOST_CHECK_EQUAL(p.verify(state), | BOOST_CHECK_EQUAL(p.verify(state), | ||||
state.GetResult() == ProofValidationResult::NONE); | state.GetResult() == ProofValidationResult::NONE); | ||||
BOOST_CHECK(state.GetResult() == expected_state); | BOOST_CHECK(state.GetResult() == expected_state); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(proofbuilder) { | BOOST_AUTO_TEST_CASE(proofbuilder) { | ||||
CKey key; | |||||
// Master key. | // Master key. | ||||
key.MakeNewKey(true); | auto key = CKey::MakeCompressedKey(); | ||||
const CPubKey master = key.GetPubKey(); | const CPubKey master = key.GetPubKey(); | ||||
const uint64_t sequence = InsecureRandBits(64); | const uint64_t sequence = InsecureRandBits(64); | ||||
const int64_t expiration = InsecureRandBits(64); | const int64_t expiration = InsecureRandBits(64); | ||||
ProofBuilder pb(sequence, expiration, master); | ProofBuilder pb(sequence, expiration, master); | ||||
for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
▲ Show 20 Lines • Show All 270 Lines • ▼ Show 20 Lines | for (auto &c : testcases) { | ||||
BOOST_TEST_MESSAGE(c.proofid); | BOOST_TEST_MESSAGE(c.proofid); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(verify) { | BOOST_AUTO_TEST_CASE(verify) { | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
CKey key; | auto key = CKey::MakeCompressedKey(); | ||||
key.MakeNewKey(true); | |||||
const CPubKey pubkey = key.GetPubKey(); | const CPubKey pubkey = key.GetPubKey(); | ||||
const Amount value = 12345 * COIN; | const Amount value = 12345 * COIN; | ||||
const uint32_t height = 10; | const uint32_t height = 10; | ||||
COutPoint pkh_outpoint(TxId(InsecureRand256()), InsecureRand32()); | COutPoint pkh_outpoint(TxId(InsecureRand256()), InsecureRand32()); | ||||
CTxOut pkh_output(value, GetScriptForRawPubKey(pubkey)); | CTxOut pkh_output(value, GetScriptForRawPubKey(pubkey)); | ||||
coins.AddCoin(pkh_outpoint, Coin(pkh_output, height, false), false); | coins.AddCoin(pkh_outpoint, Coin(pkh_output, height, false), false); | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | runCheck(ProofValidationResult::NON_STANDARD_DESTINATION, nonstd_outpoint, | ||||
value, height, false, key); | value, height, false, key); | ||||
// Non PKHhash destination | // Non PKHhash destination | ||||
runCheck(ProofValidationResult::DESTINATION_NOT_SUPPORTED, p2sh_outpoint, | runCheck(ProofValidationResult::DESTINATION_NOT_SUPPORTED, p2sh_outpoint, | ||||
value, height, false, key); | value, height, false, key); | ||||
// Mismatching key | // Mismatching key | ||||
{ | { | ||||
CKey altkey; | |||||
altkey.MakeNewKey(true); | |||||
runCheck(ProofValidationResult::DESTINATION_MISMATCH, pkh_outpoint, | runCheck(ProofValidationResult::DESTINATION_MISMATCH, pkh_outpoint, | ||||
value, height, false, altkey); | value, height, false, CKey::MakeCompressedKey()); | ||||
} | } | ||||
// No stake | // No stake | ||||
{ | { | ||||
Proof p = ProofBuilder(0, 0, pubkey).build(); | Proof p = ProofBuilder(0, 0, pubkey).build(); | ||||
ProofValidationState state; | ProofValidationState state; | ||||
BOOST_CHECK(!p.verify(state, coins)); | BOOST_CHECK(!p.verify(state, coins)); | ||||
Show All 40 Lines |