forked from RavenProject/Ravencoin
-
Notifications
You must be signed in to change notification settings - Fork 8
/
script_P2PKH_tests.cpp
63 lines (48 loc) · 2.65 KB
/
script_P2PKH_tests.cpp
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) 2018 The Bitcoin Core developers
// Copyright (c) 2017 The Raven Core developers
// Copyright (c) 2018 The Rito Core 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 "test/test_rito.h"
#include <boost/test/unit_test.hpp>
using namespace std;
BOOST_FIXTURE_TEST_SUITE(script_P2PKH_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(ispaytopublickeyhash_test)
{
BOOST_TEST_MESSAGE("Running IsPayToPubKeyHash Test");
// Test CScript::IsPayToPublicKeyHash()
uint160 dummy;
CScript p2pkh;
p2pkh << OP_DUP << OP_HASH160 << ToByteVector(dummy) << OP_EQUALVERIFY << OP_CHECKSIG;
BOOST_CHECK(p2pkh.IsPayToPublicKeyHash());
static const unsigned char direct[] = {
OP_DUP, OP_HASH160, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, OP_EQUALVERIFY, OP_CHECKSIG
};
BOOST_CHECK(CScript(direct, direct + sizeof(direct)).IsPayToPublicKeyHash());
static const unsigned char notp2pkh1[] = {
OP_DUP, OP_HASH160, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, OP_EQUALVERIFY, OP_CHECKSIG, OP_CHECKSIG
};
BOOST_CHECK(!CScript(notp2pkh1, notp2pkh1 + sizeof(notp2pkh1)).IsPayToPublicKeyHash());
static const unsigned char p2sh[] = {
OP_HASH160, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, OP_EQUAL
};
BOOST_CHECK(!CScript(p2sh, p2sh + sizeof(p2sh)).IsPayToPublicKeyHash());
static const unsigned char extra[] = {
OP_DUP, OP_HASH160, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, OP_EQUALVERIFY, OP_CHECKSIG, OP_CHECKSIG
};
BOOST_CHECK(!CScript(extra, extra + sizeof(extra)).IsPayToPublicKeyHash());
static const unsigned char missing[] = {
OP_HASH160, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, OP_EQUALVERIFY, OP_CHECKSIG, OP_RETURN
};
BOOST_CHECK(!CScript(missing, missing + sizeof(missing)).IsPayToPublicKeyHash());
static const unsigned char missing2[] = {
OP_DUP, OP_HASH160, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
BOOST_CHECK(!CScript(missing2, missing2 + sizeof(missing)).IsPayToPublicKeyHash());
static const unsigned char tooshort[] = {
OP_DUP, OP_HASH160, 2, 0, 0, OP_EQUALVERIFY, OP_CHECKSIG
};
BOOST_CHECK(!CScript(tooshort, tooshort + sizeof(direct)).IsPayToPublicKeyHash());
}
BOOST_AUTO_TEST_SUITE_END()