psbt_tests.cpp raw
1 // Copyright (c) 2026-present The Limenka developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://opensource.org/license/mit/.
4
5 #include <psbt.h>
6 #include <test/util/setup_common.h>
7
8 #include <boost/test/unit_test.hpp>
9
10 BOOST_FIXTURE_TEST_SUITE(psbt_tests, BasicTestingSetup)
11
12 static PSBTProprietary MakeProprietary(uint64_t subtype, uint8_t key_data, uint8_t value)
13 {
14 return PSBTProprietary{
15 .subtype = subtype,
16 .identifier = {'p', 's', 'b', 't'},
17 .key = {key_data},
18 .value = {value},
19 };
20 }
21
22 BOOST_AUTO_TEST_CASE(merge_proprietary_fields)
23 {
24 CMutableTransaction tx;
25 tx.vin.emplace_back(COutPoint{});
26 tx.vout.emplace_back(0, CScript{});
27
28 PartiallySignedTransaction left(tx);
29 PartiallySignedTransaction right(tx);
30
31 const auto left_prop = MakeProprietary(/*subtype=*/1, /*key_data=*/0x01, /*value=*/0xaa);
32 const auto right_prop = MakeProprietary(/*subtype=*/2, /*key_data=*/0x02, /*value=*/0xbb);
33
34 left.m_proprietary.insert(left_prop);
35 left.inputs[0].m_proprietary.insert(left_prop);
36 left.outputs[0].m_proprietary.insert(left_prop);
37
38 right.m_proprietary.insert(right_prop);
39 right.inputs[0].m_proprietary.insert(right_prop);
40 right.outputs[0].m_proprietary.insert(right_prop);
41
42 BOOST_REQUIRE(left.Merge(right));
43
44 BOOST_REQUIRE_EQUAL(left.m_proprietary.size(), 2U);
45 BOOST_REQUIRE_EQUAL(left.inputs[0].m_proprietary.size(), 2U);
46 BOOST_REQUIRE_EQUAL(left.outputs[0].m_proprietary.size(), 2U);
47
48 const auto global_it = left.m_proprietary.find(right_prop);
49 BOOST_REQUIRE(global_it != left.m_proprietary.end());
50 BOOST_CHECK(global_it->value == right_prop.value);
51
52 const auto input_it = left.inputs[0].m_proprietary.find(right_prop);
53 BOOST_REQUIRE(input_it != left.inputs[0].m_proprietary.end());
54 BOOST_CHECK(input_it->value == right_prop.value);
55
56 const auto output_it = left.outputs[0].m_proprietary.find(right_prop);
57 BOOST_REQUIRE(output_it != left.outputs[0].m_proprietary.end());
58 BOOST_CHECK(output_it->value == right_prop.value);
59 }
60
61 BOOST_AUTO_TEST_SUITE_END()
62