Bitcoin Core
28.99.0
P2P Digital Currency
src
qt
test
uritests.cpp
Go to the documentation of this file.
1
// Copyright (c) 2009-2018 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <
qt/test/uritests.h
>
6
7
#include <
qt/guiutil.h
>
8
#include <
qt/walletmodel.h
>
9
10
#include <QUrl>
11
12
void
URITests::uriTests
()
13
{
14
SendCoinsRecipient
rv;
15
QUrl uri;
16
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist="
));
17
QVERIFY(!
GUIUtil::parseBitcoinURI
(uri, &rv));
18
19
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist="
));
20
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
21
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
22
QVERIFY(rv.
label
== QString());
23
QVERIFY(rv.
amount
== 0);
24
25
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address"
));
26
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
27
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
28
QVERIFY(rv.
label
== QString(
"Wikipedia Example Address"
));
29
QVERIFY(rv.
amount
== 0);
30
31
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001"
));
32
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
33
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
34
QVERIFY(rv.
label
== QString());
35
QVERIFY(rv.
amount
== 100000);
36
37
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001"
));
38
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
39
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
40
QVERIFY(rv.
label
== QString());
41
QVERIFY(rv.
amount
== 100100000);
42
43
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example"
));
44
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
45
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
46
QVERIFY(rv.
amount
== 10000000000LL);
47
QVERIFY(rv.
label
== QString(
"Wikipedia Example"
));
48
49
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address"
));
50
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
51
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
52
QVERIFY(rv.
label
== QString());
53
54
QVERIFY(
GUIUtil::parseBitcoinURI
(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address"
, &rv));
55
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
56
QVERIFY(rv.
label
== QString());
57
58
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address"
));
59
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
60
61
// Commas in amounts are not allowed.
62
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example"
));
63
QVERIFY(!
GUIUtil::parseBitcoinURI
(uri, &rv));
64
65
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example"
));
66
QVERIFY(!
GUIUtil::parseBitcoinURI
(uri, &rv));
67
68
// There are two amount specifications. The last value wins.
69
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&amount=200&label=Wikipedia Example"
));
70
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
71
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
72
QVERIFY(rv.
amount
== 20000000000LL);
73
QVERIFY(rv.
label
== QString(
"Wikipedia Example"
));
74
75
// The first amount value is correct. However, the second amount value is not valid. Hence, the URI is not valid.
76
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&amount=1,000&label=Wikipedia Example"
));
77
QVERIFY(!
GUIUtil::parseBitcoinURI
(uri, &rv));
78
79
// Test label containing a question mark ('?').
80
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=?"
));
81
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
82
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
83
QVERIFY(rv.
amount
== 10000000000LL);
84
QVERIFY(rv.
label
== QString(
"?"
));
85
86
// Escape sequences are not supported.
87
uri.setUrl(QString(
"bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=%3F"
));
88
QVERIFY(
GUIUtil::parseBitcoinURI
(uri, &rv));
89
QVERIFY(rv.
address
== QString(
"175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"
));
90
QVERIFY(rv.
amount
== 10000000000LL);
91
QVERIFY(rv.
label
== QString(
"%3F"
));
92
}
SendCoinsRecipient
Definition:
sendcoinsrecipient.h:16
SendCoinsRecipient::label
QString label
Definition:
sendcoinsrecipient.h:28
SendCoinsRecipient::amount
CAmount amount
Definition:
sendcoinsrecipient.h:29
SendCoinsRecipient::address
QString address
Definition:
sendcoinsrecipient.h:27
URITests::uriTests
void uriTests()
Definition:
uritests.cpp:12
guiutil.h
GUIUtil::parseBitcoinURI
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
Definition:
guiutil.cpp:149
uritests.h
walletmodel.h
Generated on Wed Dec 18 2024 20:00:11 for Bitcoin Core by
1.9.4