From b30f16ac5ab7f3c3cd1e1a66e815013a268bfc4f 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] 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 }); });