Line data Source code
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 1 : void URITests::uriTests() 13 : { 14 1 : SendCoinsRecipient rv; 15 1 : QUrl uri; 16 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist=")); 17 1 : QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); 18 : 19 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist=")); 20 1 : QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); 21 1 : QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); 22 1 : QVERIFY(rv.label == QString()); 23 1 : QVERIFY(rv.amount == 0); 24 : 25 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address")); 26 1 : QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); 27 1 : QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); 28 1 : QVERIFY(rv.label == QString("Wikipedia Example Address")); 29 1 : QVERIFY(rv.amount == 0); 30 : 31 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001")); 32 1 : QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); 33 1 : QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); 34 1 : QVERIFY(rv.label == QString()); 35 1 : QVERIFY(rv.amount == 100000); 36 : 37 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001")); 38 1 : QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); 39 1 : QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); 40 1 : QVERIFY(rv.label == QString()); 41 1 : QVERIFY(rv.amount == 100100000); 42 : 43 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example")); 44 1 : QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); 45 1 : QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); 46 1 : QVERIFY(rv.amount == 10000000000LL); 47 1 : QVERIFY(rv.label == QString("Wikipedia Example")); 48 : 49 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address")); 50 1 : QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); 51 1 : QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); 52 1 : QVERIFY(rv.label == QString()); 53 : 54 1 : QVERIFY(GUIUtil::parseBitcoinURI("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address", &rv)); 55 1 : QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); 56 1 : QVERIFY(rv.label == QString()); 57 : 58 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address")); 59 1 : QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); 60 : 61 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example")); 62 1 : QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); 63 : 64 1 : uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example")); 65 1 : QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); 66 1 : }