aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2023-07-19 16:28:24 -0400
committerRyan Ofsky <ryan@ofsky.org>2023-07-19 16:43:12 -0400
commit5608e1d3b4ba3a23c05937918046e428be890505 (patch)
tree77186d3a53f0af0c1349149c3854cb45ff1793cf /src
parent4d828ef427b26a0e36a34779b2567821f898d690 (diff)
parentf1d807e383942ae20e080174d33ac17afd649351 (diff)
Merge bitcoin/bitcoin#27928: test: Add more tests for the BIP21 implementation
f1d807e383942ae20e080174d33ac17afd649351 Add more tests for the BIP21 implementation (Kiminuo) Pull request description: This PR is an attempt to make it clear how the current BIP21 implementation behaves in Bitcoin Core. Especially, I'm interested whether one can specify multiple `amount` (`message`, etc.) parameters. My primary end goal is to answer [this question of mine](https://bitcoin.stackexchange.com/questions/118654/how-to-interpret-bip21-uri-with-amount-specified-twice/) but I figured that maybe it's worth a PR. If not, I'll close the PR. ACKs for top commit: MarcoFalke: lgtm ACK f1d807e383942ae20e080174d33ac17afd649351 kevkevinpal: ACK [f1d807e](https://github.com/bitcoin/bitcoin/pull/27928/commits/f1d807e383942ae20e080174d33ac17afd649351) Tree-SHA512: d287809d47c5cfc667f850927bfd969bd345a996d3d53a4c26ef0ffd29eb75ef53358692a15f9a0493ec9e1c101123b6584572e25f87bcb98ff67f6b6c166de4
Diffstat (limited to 'src')
-rw-r--r--src/qt/test/uritests.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/qt/test/uritests.cpp b/src/qt/test/uritests.cpp
index b87d3b21ca..935f078e3d 100644
--- a/src/qt/test/uritests.cpp
+++ b/src/qt/test/uritests.cpp
@@ -58,9 +58,35 @@ void URITests::uriTests()
uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address"));
QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
+ // Commas in amounts are not allowed.
uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example"));
QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example"));
QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
+
+ // There are two amount specifications. The last value wins.
+ uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&amount=200&label=Wikipedia Example"));
+ QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
+ QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
+ QVERIFY(rv.amount == 20000000000LL);
+ QVERIFY(rv.label == QString("Wikipedia Example"));
+
+ // The first amount value is correct. However, the second amount value is not valid. Hence, the URI is not valid.
+ uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&amount=1,000&label=Wikipedia Example"));
+ QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
+
+ // Test label containing a question mark ('?').
+ uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=?"));
+ QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
+ QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
+ QVERIFY(rv.amount == 10000000000LL);
+ QVERIFY(rv.label == QString("?"));
+
+ // Escape sequences are not supported.
+ uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=%3F"));
+ QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
+ QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
+ QVERIFY(rv.amount == 10000000000LL);
+ QVERIFY(rv.label == QString("%3F"));
}