Changeset View
Changeset View
Standalone View
Standalone View
src/qt/test/uritests.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | void URITests::uriTestsCashAddr() { | ||||
QVERIFY(!GUIUtil::parseBitcoinURI(scheme, uri, &rv)); | QVERIFY(!GUIUtil::parseBitcoinURI(scheme, uri, &rv)); | ||||
uri.setUrl(QString( | uri.setUrl(QString( | ||||
"bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a?amount=1," | "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a?amount=1," | ||||
"000.0&label=Wikipedia Example")); | "000.0&label=Wikipedia Example")); | ||||
QVERIFY(!GUIUtil::parseBitcoinURI(scheme, uri, &rv)); | QVERIFY(!GUIUtil::parseBitcoinURI(scheme, uri, &rv)); | ||||
} | } | ||||
namespace { | |||||
class UriTestConfig : public DummyConfig { | |||||
public: | |||||
UriTestConfig(bool useCashAddrIn) | |||||
: DummyConfig(CBaseChainParams::MAIN), useCashAddr(useCashAddrIn) {} | |||||
bool UseCashAddrEncoding() const override { return useCashAddr; } | |||||
private: | |||||
bool useCashAddr; | |||||
}; | |||||
} // namespace | |||||
void URITests::uriTestFormatURI() { | void URITests::uriTestFormatURI() { | ||||
{ | { | ||||
UriTestConfig cfg(true); | |||||
SendCoinsRecipient r; | SendCoinsRecipient r; | ||||
r.address = "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"; | r.address = "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"; | ||||
r.message = "test"; | r.message = "test"; | ||||
QString uri = GUIUtil::formatBitcoinURI(cfg, r); | QString uri = GUIUtil::formatBitcoinURI(r); | ||||
QVERIFY(uri == "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a?" | QVERIFY(uri == "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a?" | ||||
"message=test"); | "message=test"); | ||||
} | } | ||||
{ | { | ||||
UriTestConfig cfg(false); | // Garbage goes through (address checksum is invalid) | ||||
SendCoinsRecipient r; | SendCoinsRecipient r; | ||||
r.address = "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"; | r.address = "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"; | ||||
r.message = "test"; | r.message = "test"; | ||||
QString uri = GUIUtil::formatBitcoinURI(cfg, r); | QString uri = GUIUtil::formatBitcoinURI(r); | ||||
QVERIFY(uri == | QVERIFY(uri == "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=test"); | ||||
"bitcoincash:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=test"); | } | ||||
{ | |||||
// Legacy addresses are converted. | |||||
SendCoinsRecipient r; | |||||
r.address = "12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX"; | |||||
r.message = "test"; | |||||
QString uri = GUIUtil::formatBitcoinURI(r); | |||||
QVERIFY(uri == "bitcoincash:qqgekzvw96vq5g57zwdfa5q6g609rrn0ycp33uc325?" | |||||
"message=test"); | |||||
} | } | ||||
} | } | ||||
namespace { | |||||
class UriTestConfig : public DummyConfig { | |||||
public: | |||||
UriTestConfig(bool useCashAddrIn) | |||||
: DummyConfig(CBaseChainParams::MAIN), useCashAddr(useCashAddrIn) {} | |||||
bool UseCashAddrEncoding() const override { return useCashAddr; } | |||||
private: | |||||
bool useCashAddr; | |||||
}; | |||||
} // namespace | |||||
void URITests::uriTestScheme() { | void URITests::uriTestScheme() { | ||||
{ | { | ||||
// cashaddr - scheme depends on selected chain params | // cashaddr - scheme depends on selected chain params | ||||
UriTestConfig config(true); | UriTestConfig config(true); | ||||
config.SetChainParams(CBaseChainParams::MAIN); | config.SetChainParams(CBaseChainParams::MAIN); | ||||
QVERIFY("bitcoincash" == GUIUtil::bitcoinURIScheme(config)); | QVERIFY("bitcoincash" == GUIUtil::bitcoinURIScheme(config)); | ||||
config.SetChainParams(CBaseChainParams::TESTNET); | config.SetChainParams(CBaseChainParams::TESTNET); | ||||
QVERIFY("bchtest" == GUIUtil::bitcoinURIScheme(config)); | QVERIFY("bchtest" == GUIUtil::bitcoinURIScheme(config)); | ||||
Show All 14 Lines |