diff options
Diffstat (limited to 'packages/taler-util/src/taleruri.test.ts')
-rw-r--r-- | packages/taler-util/src/taleruri.test.ts | 82 |
1 files changed, 54 insertions, 28 deletions
diff --git a/packages/taler-util/src/taleruri.test.ts b/packages/taler-util/src/taleruri.test.ts index dbd175fe5..b92366fb3 100644 --- a/packages/taler-util/src/taleruri.test.ts +++ b/packages/taler-util/src/taleruri.test.ts @@ -17,6 +17,7 @@ import test from "ava"; import { AmountString } from "./taler-types.js"; import { + parseAddExchangeUri, parseDevExperimentUri, parsePayPullUri, parsePayPushUri, @@ -26,6 +27,7 @@ import { parseRestoreUri, parseWithdrawExchangeUri, parseWithdrawUri, + stringifyAddExchange, stringifyDevExperimentUri, stringifyPayPullUri, stringifyPayPushUri, @@ -312,7 +314,7 @@ test("taler peer to peer pull URI (stringify)", (t) => { test("taler pay template URI (parsing)", (t) => { const url1 = - "taler://pay-template/merchant.example.com/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY?amount=KUDOS:5"; + "taler://pay-template/merchant.example.com/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY"; const r1 = parsePayTemplateUri(url1); if (!r1) { t.fail(); @@ -320,12 +322,11 @@ test("taler pay template URI (parsing)", (t) => { } t.deepEqual(r1.merchantBaseUrl, "https://merchant.example.com/"); t.deepEqual(r1.templateId, "FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY"); - t.deepEqual(r1.templateParams.amount, "KUDOS:5"); }); test("taler pay template URI (parsing, http with port)", (t) => { const url1 = - "taler+http://pay-template/merchant.example.com:1234/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY?amount=KUDOS:5"; + "taler+http://pay-template/merchant.example.com:1234/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY"; const r1 = parsePayTemplateUri(url1); if (!r1) { t.fail(); @@ -333,20 +334,16 @@ test("taler pay template URI (parsing, http with port)", (t) => { } t.deepEqual(r1.merchantBaseUrl, "http://merchant.example.com:1234/"); t.deepEqual(r1.templateId, "FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY"); - t.deepEqual(r1.templateParams.amount, "KUDOS:5"); }); test("taler pay template URI (stringify)", (t) => { const url1 = stringifyPayTemplateUri({ merchantBaseUrl: "http://merchant.example.com:1234/", templateId: "FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY", - templateParams: { - amount: "KUDOS:5", - }, }); t.deepEqual( url1, - "taler+http://pay-template/merchant.example.com:1234/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY?amount=KUDOS%3A5", + "taler+http://pay-template/merchant.example.com:1234/FEGHYJY48FEGU6WETYIOIDEDE2QW3OCZVY", ); }); @@ -421,24 +418,27 @@ test("taler dev exp URI (stringify)", (t) => { */ test("taler withdraw exchange URI (parse)", (t) => { + // Pubkey has been phased out, may no longer be specified. { - const r1 = parseWithdrawExchangeUri( + const rx1 = parseWithdrawExchangeUri( "taler://withdraw-exchange/exchange.demo.taler.net/someroot/GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0?a=KUDOS%3A2", ); - if (!r1) { + if (rx1) { t.fail(); return; } - t.deepEqual( - r1.exchangePub, - "GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0", - ); - t.deepEqual( - r1.exchangeBaseUrl, - "https://exchange.demo.taler.net/someroot/", + } + { + const rx2 = parseWithdrawExchangeUri( + "taler://withdraw-exchange/exchange.demo.taler.net/GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0", ); - t.deepEqual(r1.amount, "KUDOS:2"); + if (rx2) { + t.fail(); + return; + } } + + // Now test well-formed URIs { const r2 = parseWithdrawExchangeUri( "taler://withdraw-exchange/exchange.demo.taler.net/someroot/", @@ -447,7 +447,6 @@ test("taler withdraw exchange URI (parse)", (t) => { t.fail(); return; } - t.deepEqual(r2.exchangePub, undefined); t.deepEqual(r2.amount, undefined); t.deepEqual( r2.exchangeBaseUrl, @@ -463,7 +462,6 @@ test("taler withdraw exchange URI (parse)", (t) => { t.fail(); return; } - t.deepEqual(r3.exchangePub, undefined); t.deepEqual(r3.amount, undefined); t.deepEqual(r3.exchangeBaseUrl, "https://exchange.demo.taler.net/"); } @@ -477,7 +475,6 @@ test("taler withdraw exchange URI (parse)", (t) => { t.fail(); return; } - t.deepEqual(r4.exchangePub, undefined); t.deepEqual(r4.amount, undefined); t.deepEqual(r4.exchangeBaseUrl, "https://exchange.demo.taler.net/"); } @@ -486,27 +483,56 @@ test("taler withdraw exchange URI (parse)", (t) => { test("taler withdraw exchange URI (stringify)", (t) => { const url = stringifyWithdrawExchange({ exchangeBaseUrl: "https://exchange.demo.taler.net", - exchangePub: "GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0", }); - t.deepEqual( - url, - "taler://withdraw-exchange/exchange.demo.taler.net/GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0", - ); + t.deepEqual(url, "taler://withdraw-exchange/exchange.demo.taler.net/"); }); test("taler withdraw exchange URI with amount (stringify)", (t) => { const url = stringifyWithdrawExchange({ exchangeBaseUrl: "https://exchange.demo.taler.net", - exchangePub: "GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0", amount: "KUDOS:19" as AmountString, }); t.deepEqual( url, - "taler://withdraw-exchange/exchange.demo.taler.net/GJKG23V4ZBHEH45YRK7TWQE8ZTY7JWTY5094TQJSRZN5DSDBX8E0?a=KUDOS%3A19", + "taler://withdraw-exchange/exchange.demo.taler.net/?a=KUDOS%3A19", ); }); /** + * 5.13 action: add-exchange https://lsd.gnunet.org/lsd0006/#name-action-add-exchange + */ + +test("taler add exchange URI (parse)", (t) => { + { + const r1 = parseAddExchangeUri( + "taler://add-exchange/exchange.example.com/", + ); + if (!r1) { + t.fail(); + return; + } + t.deepEqual(r1.exchangeBaseUrl, "https://exchange.example.com/"); + } + { + const r2 = parseAddExchangeUri( + "taler://add-exchange/exchanges.example.com/api/", + ); + if (!r2) { + t.fail(); + return; + } + t.deepEqual(r2.exchangeBaseUrl, "https://exchanges.example.com/api/"); + } +}); + +test("taler add exchange URI (stringify)", (t) => { + const url = stringifyAddExchange({ + exchangeBaseUrl: "https://exchange.demo.taler.net", + }); + t.deepEqual(url, "taler://add-exchange/exchange.demo.taler.net/"); +}); + +/** * wrong uris */ test("taler pay url parsing: wrong scheme", (t) => { |