-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be3e4b5
commit 250c0be
Showing
12 changed files
with
51 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { DomainError } from "@/domain/shared" | ||
import { DomainError, ErrorLevel } from "@/domain/shared" | ||
|
||
export class LnurlError extends DomainError {} | ||
|
||
export class ErrorFetchingLnurlInvoice extends LnurlError {} | ||
export class UnknownLnurlError extends LnurlError { | ||
level = ErrorLevel.Critical | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
type LnurlError = import("@/domain/bitcoin/lnurl/errors").LnurlError | ||
interface ILnurlPayService { | ||
fetchInvoiceFromLnAddressOrLnurl(args: { | ||
amount: BtcPaymentAmount | ||
lnAddressOrLnurl: string | ||
}): Promise<string | ApplicationError> | ||
}): Promise<string | LnurlError> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
import { decodeInvoice } from "@/domain/bitcoin/lightning" | ||
import { ErrorFetchingLnurlInvoice } from "@/domain/bitcoin/lnurl/errors" | ||
import { LnurlPayService } from "@/services/lnurl-pay" | ||
import { createRandomUserAndWallets } from "test/helpers" | ||
import { setUsername, usernameAvailable } from "@/app/accounts" | ||
import { checkedToUsername } from "@/domain/accounts" | ||
|
||
const usernameForLnAddress = checkedToUsername("lnurl_test_user") | ||
const lnurlForUsername = | ||
"lnurl1dp68gup69uhkcmmrv9kxsmmnwsarxvpsxghjuam9d3kz66mwdamkutmvde6hymrs9akxuatjd30hgetnw30h2um9wg3wjc63" // http://localhost:3002/.well-known/lnurlp/lnurl_test_user | ||
if (usernameForLnAddress instanceof Error) { | ||
throw usernameForLnAddress | ||
} | ||
|
||
beforeAll(async () => { | ||
const isUsernameAvailable = await usernameAvailable(usernameForLnAddress) | ||
if (isUsernameAvailable instanceof Error) { | ||
throw isUsernameAvailable | ||
} | ||
if (isUsernameAvailable) { | ||
const newUser = await createRandomUserAndWallets() | ||
const setUsernameRes = await setUsername({ | ||
accountId: newUser.btcWalletDescriptor.accountId, | ||
username: usernameForLnAddress, | ||
}) | ||
|
||
if (setUsernameRes instanceof Error) { | ||
throw setUsernameRes | ||
} | ||
} | ||
}) | ||
|
||
describe("LnurlPayService", () => { | ||
const lnurlPayService = LnurlPayService() | ||
|
@@ -12,30 +40,7 @@ describe("LnurlPayService", () => { | |
amount: BigInt(1000), | ||
currency: "BTC", | ||
} as BtcPaymentAmount, | ||
lnAddressOrLnurl: | ||
"lnurl1dp68gurn8ghj7urp0yhxymrfde4juumk9uh8wetvdskkkmn0wahz7mrww4excup0w3jhxaqlq07tq", // https://pay.blink.sv/.well-known/lnurlp/test | ||
}) | ||
|
||
if (invoice instanceof Error) { | ||
throw invoice | ||
} | ||
|
||
const decodedInvoice = await decodeInvoice(invoice) | ||
|
||
if (decodedInvoice instanceof Error) { | ||
throw decodedInvoice | ||
} | ||
|
||
expect(decodedInvoice.amount).toEqual(1000) | ||
}) | ||
|
||
it("fetches an invoice from an ln address", async () => { | ||
const invoice = await lnurlPayService.fetchInvoiceFromLnAddressOrLnurl({ | ||
amount: { | ||
amount: BigInt(1000), | ||
currency: "BTC", | ||
} as BtcPaymentAmount, | ||
lnAddressOrLnurl: "[email protected]", | ||
lnAddressOrLnurl: lnurlForUsername, | ||
}) | ||
|
||
if (invoice instanceof Error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters