Bitcoin Core  22.99.0
P2P Digital Currency
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 
13 {
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  uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example"));
62  QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
63 
64  uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example"));
65  QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
66 }
SendCoinsRecipient::amount
CAmount amount
Definition: sendcoinsrecipient.h:33
URITests::uriTests
void uriTests()
Definition: uritests.cpp:12
walletmodel.h
SendCoinsRecipient::label
QString label
Definition: sendcoinsrecipient.h:32
GUIUtil::parseBitcoinURI
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:131
SendCoinsRecipient
Definition: sendcoinsrecipient.h:19
guiutil.h
SendCoinsRecipient::address
QString address
Definition: sendcoinsrecipient.h:31
uritests.h