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); | ||||||||||||||||||||||||||
ProofValidationState state; | ProofValidationState state; | ||||||||||||||||||||||||||
if (score >= SCORE_DUST_THRESHOLD) { | |||||||||||||||||||||||||||
BOOST_CHECK(p.verify(state)); | BOOST_CHECK(p.verify(state)); | ||||||||||||||||||||||||||
BOOST_CHECK(state.GetResult() == ProofValidationResult::NONE); | BOOST_CHECK(state.GetResult() == ProofValidationResult::NONE); | ||||||||||||||||||||||||||
} else { | |||||||||||||||||||||||||||
BOOST_CHECK(!p.verify(state)); | |||||||||||||||||||||||||||
BOOST_CHECK(state.GetResult() == | |||||||||||||||||||||||||||
ProofValidationResult::DUST_THRESOLD); | |||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||
deadalnixUnsubmitted Not Done Inline Actions
deadalnix: | |||||||||||||||||||||||||||
deadalnixUnsubmitted Not Done Inline Actions
You could make this way more generic without doing much of anything. deadalnix: You could make this way more generic without doing much of anything. | |||||||||||||||||||||||||||
} | } | ||||||||||||||||||||||||||
} | } | ||||||||||||||||||||||||||
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(), | |||||||||||||||||||||||||||
deadalnixUnsubmitted Not Done Inline ActionsNow you are testing the dust threshold, so this is what you want. deadalnix: Now you are testing the dust threshold, so this is what you want. | |||||||||||||||||||||||||||
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() |