From 13615a6dd26417a3ebfc7db5e12c0aa11dd4c9ed Mon Sep 17 00:00:00 2001 From: CharlieC3 <2747302+CharlieC3@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:53:17 -0500 Subject: [PATCH 1/3] feat: change tbtc faucet default, allow user to request more than default --- src/api/routes/faucets.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/api/routes/faucets.ts b/src/api/routes/faucets.ts index c9b2b04e8..a0e154bc6 100644 --- a/src/api/routes/faucets.ts +++ b/src/api/routes/faucets.ts @@ -75,7 +75,7 @@ export const FaucetRoutes: FastifyPluginAsync< schema: { operationId: 'run_faucet_btc', summary: 'Add testnet BTC tokens to address', - description: `Add 1 BTC token to the specified testnet BTC address. + description: `Add 0.01 BTC token to the specified testnet BTC address. The endpoint returns the transaction ID, which you can use to view the transaction in a testnet Bitcoin block explorer. The tokens are delivered once the transaction has been included in a block. @@ -89,6 +89,13 @@ export const FaucetRoutes: FastifyPluginAsync< examples: ['2N4M94S1ZPt8HfxydXzL2P7qyzgVq7MHWts'], }) ), + large: Type.Optional( + Type.Boolean({ + description: + 'Request a larger amount of testnet BTC than the default', + default: false, + }) + ), }), body: OptionalNullable( Type.Object({ @@ -125,6 +132,7 @@ export const FaucetRoutes: FastifyPluginAsync< async (req, reply) => { await btcFaucetRequestQueue.add(async () => { const address = req.query.address || req.body?.address; + const tbtcAmount = req.query.large ? 0.5 : 0.01; if (!address) { return await reply.status(400).send({ error: 'address required', @@ -156,7 +164,7 @@ export const FaucetRoutes: FastifyPluginAsync< }); } - const tx = await makeBtcFaucetPayment(btc.networks.regtest, address, 0.5); + const tx = await makeBtcFaucetPayment(btc.networks.regtest, address, tbtcAmount); await fastify.writeDb?.insertFaucetRequest({ ip: `${ip}`, address: address, From 84e40ba1d3a0c6b2b7b6c890011351e3db7c6105 Mon Sep 17 00:00:00 2001 From: CharlieC3 <2747302+CharlieC3@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:02:29 -0500 Subject: [PATCH 2/3] fix: update BTC faucet comments to use regtest instead of testnet --- src/api/routes/faucets.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/api/routes/faucets.ts b/src/api/routes/faucets.ts index a0e154bc6..507532fed 100644 --- a/src/api/routes/faucets.ts +++ b/src/api/routes/faucets.ts @@ -74,25 +74,25 @@ export const FaucetRoutes: FastifyPluginAsync< preHandler: missingBtcConfigMiddleware, schema: { operationId: 'run_faucet_btc', - summary: 'Add testnet BTC tokens to address', - description: `Add 0.01 BTC token to the specified testnet BTC address. + summary: 'Add regtest BTC tokens to address', + description: `Add 0.01 BTC token to the specified regtest BTC address. - The endpoint returns the transaction ID, which you can use to view the transaction in a testnet Bitcoin block + The endpoint returns the transaction ID, which you can use to view the transaction in a regtest Bitcoin block explorer. The tokens are delivered once the transaction has been included in a block. - **Note:** This is a testnet only endpoint. This endpoint will not work on the mainnet.`, + **Note:** This is a Bitcoin regtest-only endpoint. This endpoint will not work on the Bitcoin mainnet.`, tags: ['Faucets'], querystring: Type.Object({ address: Type.Optional( Type.String({ - description: 'A valid testnet BTC address', + description: 'A valid regtest BTC address', examples: ['2N4M94S1ZPt8HfxydXzL2P7qyzgVq7MHWts'], }) ), large: Type.Optional( Type.Boolean({ description: - 'Request a larger amount of testnet BTC than the default', + 'Request a larger amount of regtest BTC than the default', default: false, }) ), @@ -101,7 +101,7 @@ export const FaucetRoutes: FastifyPluginAsync< Type.Object({ address: Type.Optional( Type.String({ - description: 'A valid testnet BTC address', + description: 'A valid regtest BTC address', examples: ['2N4M94S1ZPt8HfxydXzL2P7qyzgVq7MHWts'], }) ), @@ -119,7 +119,7 @@ export const FaucetRoutes: FastifyPluginAsync< { title: 'RunFaucetResponse', description: - 'POST request that initiates a transfer of tokens to a specified testnet address', + 'POST request that initiates a transfer of tokens to a specified Bitcoin regtest address', } ), '4xx': Type.Object({ @@ -132,7 +132,7 @@ export const FaucetRoutes: FastifyPluginAsync< async (req, reply) => { await btcFaucetRequestQueue.add(async () => { const address = req.query.address || req.body?.address; - const tbtcAmount = req.query.large ? 0.5 : 0.01; + const btcAmount = req.query.large ? 0.5 : 0.01; if (!address) { return await reply.status(400).send({ error: 'address required', @@ -164,7 +164,7 @@ export const FaucetRoutes: FastifyPluginAsync< }); } - const tx = await makeBtcFaucetPayment(btc.networks.regtest, address, tbtcAmount); + const tx = await makeBtcFaucetPayment(btc.networks.regtest, address, btcAmount); await fastify.writeDb?.insertFaucetRequest({ ip: `${ip}`, address: address, @@ -191,7 +191,7 @@ export const FaucetRoutes: FastifyPluginAsync< tags: ['Faucets'], params: Type.Object({ address: Type.String({ - description: 'A valid testnet BTC address', + description: 'A valid regtest BTC address', examples: ['2N4M94S1ZPt8HfxydXzL2P7qyzgVq7MHWts'], }), }), From a741538a10a7dabda744331fcb0f686a828a2f86 Mon Sep 17 00:00:00 2001 From: CharlieC3 <2747302+CharlieC3@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:27:26 -0500 Subject: [PATCH 3/3] feat: adjust rBTC default amount, add xlarge url param, add tests --- src/api/routes/faucets.ts | 25 +++++++++++++++++++-- tests/btc-faucet/faucet-btc.test.ts | 34 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/api/routes/faucets.ts b/src/api/routes/faucets.ts index 507532fed..5d7b55016 100644 --- a/src/api/routes/faucets.ts +++ b/src/api/routes/faucets.ts @@ -92,7 +92,14 @@ export const FaucetRoutes: FastifyPluginAsync< large: Type.Optional( Type.Boolean({ description: - 'Request a larger amount of regtest BTC than the default', + 'Request a large amount of regtest BTC than the default', + default: false, + }) + ), + xlarge: Type.Optional( + Type.Boolean({ + description: + 'Request an extra large amount of regtest BTC than the default', default: false, }) ), @@ -132,7 +139,21 @@ export const FaucetRoutes: FastifyPluginAsync< async (req, reply) => { await btcFaucetRequestQueue.add(async () => { const address = req.query.address || req.body?.address; - const btcAmount = req.query.large ? 0.5 : 0.01; + let btcAmount = 0.0001; + + if (req.query.large && req.query.xlarge) { + return await reply.status(400).send({ + error: 'cannot simultaneously request a large and xlarge amount', + success: false, + }); + } + + if (req.query.large) { + btcAmount = 0.01; + } else if (req.query.xlarge) { + btcAmount = 0.5; + } + if (!address) { return await reply.status(400).send({ error: 'address required', diff --git a/tests/btc-faucet/faucet-btc.test.ts b/tests/btc-faucet/faucet-btc.test.ts index 5d2ae10d0..60e000255 100644 --- a/tests/btc-faucet/faucet-btc.test.ts +++ b/tests/btc-faucet/faucet-btc.test.ts @@ -156,6 +156,40 @@ describe('btc faucet', () => { `/extended/v1/faucets/btc/${addr}` ); expect(balanceResponse.status).toBe(200); + expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.0001 }); + }); + + test('faucet http balance endpoint large', async () => { + const addr = getKeyAddress(ECPair.makeRandom({ network: regtest })); + const response = await supertest(apiServer.server).post( + `/extended/v1/faucets/btc?address=${addr}&large=true` + ); + expect(response.status).toBe(200); + await getRpcClient().generatetoaddress({ + address: getKeyAddress(ECPair.makeRandom({ network: regtest })), + nblocks: 1, + }); + const balanceResponse = await supertest(apiServer.server).get( + `/extended/v1/faucets/btc/${addr}` + ); + expect(balanceResponse.status).toBe(200); + expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.01 }); + }); + + test('faucet http balance endpoint xlarge', async () => { + const addr = getKeyAddress(ECPair.makeRandom({ network: regtest })); + const response = await supertest(apiServer.server).post( + `/extended/v1/faucets/btc?address=${addr}&xlarge=true` + ); + expect(response.status).toBe(200); + await getRpcClient().generatetoaddress({ + address: getKeyAddress(ECPair.makeRandom({ network: regtest })), + nblocks: 1, + }); + const balanceResponse = await supertest(apiServer.server).get( + `/extended/v1/faucets/btc/${addr}` + ); + expect(balanceResponse.status).toBe(200); expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.5 }); });