Repository navigation
Expand file tree
/
Copy pathscript_commitment_tests.cpp
More file actions
63 lines (46 loc) · 1.66 KB
/
Copy pathscript_commitment_tests.cpp
File metadata and controls
63 lines (46 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2017-2019 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <script/script.h>
#include <chainparams.h>
#include <config.h>
#include <consensus/validation.h>
#include <validation.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <string>
#include <vector>
BOOST_FIXTURE_TEST_SUITE(script_commitment_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(test_is_commitment) {
std::vector<uint8_t> data{};
// Empty commitment.
auto s = CScript() << OP_RETURN << data;
BOOST_CHECK(s.IsCommitment(data));
// Commitment to a value of the wrong size.
data.push_back(42);
BOOST_CHECK(!s.IsCommitment(data));
// Not a commitment.
s = CScript() << data;
BOOST_CHECK(!s.IsCommitment(data));
// Non empty commitment.
s = CScript() << OP_RETURN << data;
BOOST_CHECK(s.IsCommitment(data));
// Commitment to the wrong value.
data[0] = 0x42;
BOOST_CHECK(!s.IsCommitment(data));
// Commitment to a larger value.
std::string str = "Bitcoin: A peer-to-peer Electronic Cash System";
data = std::vector<uint8_t>(str.begin(), str.end());
BOOST_CHECK(!s.IsCommitment(data));
s = CScript() << OP_RETURN << data;
BOOST_CHECK(s.IsCommitment(data));
// 64 bytes commitment, still valid.
data.resize(64);
s = CScript() << OP_RETURN << data;
BOOST_CHECK(s.IsCommitment(data));
// Commitment is too large.
data.push_back(23);
s = CScript() << OP_RETURN << data;
BOOST_CHECK(!s.IsCommitment(data));
}
BOOST_AUTO_TEST_SUITE_END()