Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/proof_tests.cpp
Show All 16 Lines | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
using namespace avalanche; | using namespace avalanche; | ||||
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 = std::min(InsecureRand32(), LOWEST_VALID_SCORE); | ||||
deadalnix: This is going to skew the distribution quite considerably.
I don't think there a major issue… | |||||
PiRKAuthorUnsubmitted Done Inline ActionsMy idea was not to change the actual meaning of this test. With the previous change, it tested more stuff than previously. Instead of just testing that valid proofs verify successfuly, it tested ProofValidationStates of invalid proofs. But I see what you mean, now it's not as random anymore. I'm still not sure what name[[ https://reviews.bitcoinabc.org/D9345?id=28083#inline-46121 | you think would be better for the threshold ]], if we go back to testing dust thresholds. PiRK: My idea was not to change the actual meaning of this test. With the previous change, it tested… | |||||
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; | ||||
BOOST_CHECK(p.verify(state)); | BOOST_CHECK(p.verify(state)); | ||||
BOOST_CHECK(state.GetResult() == ProofValidationResult::NONE); | BOOST_CHECK(state.GetResult() == ProofValidationResult::NONE); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 301 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; | ||||
deadalnixUnsubmitted Not Done Inline ActionsIs there a reason to make this amount dependent on the dust threshold? deadalnix: Is there a reason to make this amount dependent on the dust threshold? | |||||
PiRKAuthorUnsubmitted Done Inline ActionsIt's a guarantee that it will remain valid in the future if the threshold is changes. PiRK: It's a guarantee that it will remain valid in the future if the threshold is changes. | |||||
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 ActionsWhy not 1 * SATOSHI ? deadalnix: Why not `1 * 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() |
This is going to skew the distribution quite considerably.
I don't think there a major issue with tripping the dust threshold error path with randomly generated proofs. is there a reason we want to avoid doing that?