| 46 | BOOST_FIXTURE_TEST_SUITE(pegin_witness_tests, FedpegSetup) |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(witness_valid) |
| 49 | { |
| 50 | CScriptWitness witness; |
| 51 | witness.stack = witness_stack; |
| 52 | |
| 53 | std::string err; |
| 54 | |
| 55 | std::vector<unsigned char> fedpegscript_bytes = ParseHex(fedpegscript_str); |
| 56 | CScript fedpegscript(fedpegscript_bytes.begin(), fedpegscript_bytes.end()); |
| 57 | // Test sample was generated as "legacy" with p2sh-p2wsh fedpegscript |
| 58 | CScript fedpeg_program(GetScriptForDestination(ScriptHash(GetScriptForDestination(WitnessV0ScriptHash(fedpegscript))))); |
| 59 | std::vector<std::pair<CScript, CScript>> fedpegscripts; |
| 60 | // TODO test with additional scripts |
| 61 | fedpegscripts.push_back(std::make_pair(fedpeg_program, fedpegscript)); |
| 62 | |
| 63 | bool valid = IsValidPeginWitness(witness, fedpegscripts, prevout, err, false); |
| 64 | BOOST_CHECK(err == ""); |
| 65 | BOOST_CHECK(valid); |
| 66 | |
| 67 | // Missing byte on each field to make claim ill-formatted |
| 68 | // This will break deserialization and other data-matching checks |
| 69 | for (unsigned int i = 0; i < witness.stack.size(); i++) { |
| 70 | witness.stack[i].pop_back(); |
| 71 | BOOST_CHECK(!IsValidPeginWitness(witness, fedpegscripts, prevout, err, false)); |
| 72 | witness.stack = witness_stack; |
| 73 | BOOST_CHECK(IsValidPeginWitness(witness, fedpegscripts, prevout, err, false)); |
| 74 | } |
| 75 | |
| 76 | // Test mismatched but valid nOut to proof |
| 77 | COutPoint fake_prevout = prevout; |
| 78 | fake_prevout.n = 0; |
| 79 | BOOST_CHECK(!IsValidPeginWitness(witness, fedpegscripts, fake_prevout, err, false)); |
| 80 | |
| 81 | // Test mismatched but valid txid |
| 82 | fake_prevout = prevout; |
| 83 | fake_prevout.hash = uint256S("2f103ee04a5649eecb932b4da4ca9977f53a12bbe04d9d1eb5ccc0f4a06334"); |
| 84 | BOOST_CHECK(!IsValidPeginWitness(witness, fedpegscripts, fake_prevout, err, false)); |
| 85 | |
| 86 | // Ensure that all witness stack sizes are handled |
| 87 | BOOST_CHECK(IsValidPeginWitness(witness, fedpegscripts, prevout, err, false)); |
| 88 | for (unsigned int i = 0; i < witness.stack.size(); i++) { |
| 89 | witness.stack.pop_back(); |
| 90 | BOOST_CHECK(!IsValidPeginWitness(witness, fedpegscripts, prevout, err, false)); |
| 91 | } |
| 92 | witness.stack = witness_stack; |
| 93 | |
| 94 | // Extra element causes failure |
| 95 | witness.stack.push_back(witness.stack.back()); |
| 96 | BOOST_CHECK(!IsValidPeginWitness(witness, fedpegscripts, prevout, err, false)); |
| 97 | witness.stack = witness_stack; |
| 98 | |
| 99 | // Check validation of peg-in transaction's inputs and balance |
| 100 | CDataStream ssTx(pegin_transaction, SER_NETWORK, PROTOCOL_VERSION); |
| 101 | CTransactionRef txRef; |
| 102 | try { |
| 103 | ssTx >> txRef; |
| 104 | } catch (...) { |
| 105 | BOOST_CHECK(false); |
nothing calls this directly
no test coverage detected