Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/proof_tests.cpp
Show All 20 Lines | |||||
BOOST_FIXTURE_TEST_SUITE(proof_tests, TestingSetup) | BOOST_FIXTURE_TEST_SUITE(proof_tests, TestingSetup) | ||||
BOOST_AUTO_TEST_CASE(proof_random) { | BOOST_AUTO_TEST_CASE(proof_random) { | ||||
for (int i = 0; i < 1000; i++) { | for (int i = 0; i < 1000; i++) { | ||||
const uint32_t score = InsecureRand32(); | const uint32_t score = InsecureRand32(); | ||||
const Proof p = buildRandomProof(score); | const Proof p = buildRandomProof(score); | ||||
BOOST_CHECK_EQUAL(p.getScore(), score); | BOOST_CHECK_EQUAL(p.getScore(), score); | ||||
ProofValidationResult expected_state = | |||||
(score < LOWEST_VALID_SCORE) ? ProofValidationResult::DUST_THRESOLD | |||||
deadalnix: What you want here is NOT the lowest valid score.
Please. These two things have the same value… | |||||
: ProofValidationResult::NONE; | |||||
ProofValidationState state; | ProofValidationState state; | ||||
BOOST_CHECK(p.verify(state)); | |||||
BOOST_CHECK(state.GetResult() == ProofValidationResult::NONE); | BOOST_CHECK_EQUAL(p.verify(state), | ||||
state.GetResult() == ProofValidationResult::NONE); | |||||
BOOST_CHECK(state.GetResult() == expected_state); | |||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(proofbuilder) { | BOOST_AUTO_TEST_CASE(proofbuilder) { | ||||
CKey key; | CKey key; | ||||
// Master key. | // Master key. | ||||
key.MakeNewKey(true); | key.MakeNewKey(true); | ||||
▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | |||||
BOOST_AUTO_TEST_CASE(verify) { | BOOST_AUTO_TEST_CASE(verify) { | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
CKey key; | CKey key; | ||||
key.MakeNewKey(true); | key.MakeNewKey(true); | ||||
const CPubKey pubkey = key.GetPubKey(); | const CPubKey pubkey = key.GetPubKey(); | ||||
const Amount value = 12345 * SATOSHI; | const Amount value = 123 * PROOF_DUST_THRESHOLD; | ||||
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); | ||||
COutPoint nonstd_outpoint(TxId(InsecureRand256()), InsecureRand32()); | COutPoint nonstd_outpoint(TxId(InsecureRand256()), InsecureRand32()); | ||||
CTxOut nonstd_output(value, CScript() << OP_TRUE); | CTxOut nonstd_output(value, CScript() << OP_TRUE); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | // Dust thresold | ||||
pb.addUTXO(pkh_outpoint, Amount::zero(), height, false, key); | pb.addUTXO(pkh_outpoint, Amount::zero(), height, false, key); | ||||
Proof p = pb.build(); | Proof p = pb.build(); | ||||
ProofValidationState state; | ProofValidationState state; | ||||
BOOST_CHECK(!p.verify(state, coins)); | BOOST_CHECK(!p.verify(state, coins)); | ||||
BOOST_CHECK(state.GetResult() == ProofValidationResult::DUST_THRESOLD); | BOOST_CHECK(state.GetResult() == ProofValidationResult::DUST_THRESOLD); | ||||
} | } | ||||
{ | |||||
ProofBuilder pb(0, 0, pubkey); | |||||
pb.addUTXO(pkh_outpoint, PROOF_DUST_THRESHOLD - 1 * Amount::satoshi(), | |||||
height, false, key); | |||||
Proof p = pb.build(); | |||||
ProofValidationState state; | |||||
BOOST_CHECK(!p.verify(state, coins)); | |||||
BOOST_CHECK(state.GetResult() == ProofValidationResult::DUST_THRESOLD); | |||||
} | |||||
// Duplicated input | // Duplicated input | ||||
{ | { | ||||
ProofBuilder pb(0, 0, pubkey); | ProofBuilder pb(0, 0, pubkey); | ||||
pb.addUTXO(pkh_outpoint, value, height, false, key); | pb.addUTXO(pkh_outpoint, value, height, false, key); | ||||
pb.addUTXO(pkh_outpoint, value, height, false, key); | pb.addUTXO(pkh_outpoint, value, height, false, key); | ||||
Proof p = pb.build(); | Proof p = pb.build(); | ||||
ProofValidationState state; | ProofValidationState state; | ||||
BOOST_CHECK(!p.verify(state, coins)); | BOOST_CHECK(!p.verify(state, coins)); | ||||
BOOST_CHECK(state.GetResult() == | BOOST_CHECK(state.GetResult() == | ||||
ProofValidationResult::DUPLICATE_STAKE); | ProofValidationResult::DUPLICATE_STAKE); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |
What you want here is NOT the lowest valid score.
Please. These two things have the same value, but they are NOT the same thing. The whole reason you give it a name to begin with is to identify what that is.