Skip to content

Commit b30f16a

Browse files
committed
feat: adjust rBTC default amount, add xlarge url param, add tests
1 parent ced8242 commit b30f16a

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/api/routes/faucets.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ export const FaucetRoutes: FastifyPluginAsync<
9292
large: Type.Optional(
9393
Type.Boolean({
9494
description:
95-
'Request a larger amount of regtest BTC than the default',
95+
'Request a large amount of regtest BTC than the default',
96+
default: false,
97+
})
98+
),
99+
xlarge: Type.Optional(
100+
Type.Boolean({
101+
description:
102+
'Request an extra large amount of regtest BTC than the default',
96103
default: false,
97104
})
98105
),
@@ -132,7 +139,21 @@ export const FaucetRoutes: FastifyPluginAsync<
132139
async (req, reply) => {
133140
await btcFaucetRequestQueue.add(async () => {
134141
const address = req.query.address || req.body?.address;
135-
const btcAmount = req.query.large ? 0.5 : 0.01;
142+
let btcAmount = 0.0001;
143+
144+
if (req.query.large && req.query.xlarge) {
145+
return await reply.status(400).send({
146+
error: 'cannot simultaneously request a large and xlarge amount',
147+
success: false,
148+
});
149+
}
150+
151+
if (req.query.large) {
152+
btcAmount = 0.01;
153+
} else if (req.query.xlarge) {
154+
btcAmount = 0.5;
155+
}
156+
136157
if (!address) {
137158
return await reply.status(400).send({
138159
error: 'address required',

tests/btc-faucet/faucet-btc.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,40 @@ describe('btc faucet', () => {
156156
`/extended/v1/faucets/btc/${addr}`
157157
);
158158
expect(balanceResponse.status).toBe(200);
159+
expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.0001 });
160+
});
161+
162+
test('faucet http balance endpoint large', async () => {
163+
const addr = getKeyAddress(ECPair.makeRandom({ network: regtest }));
164+
const response = await supertest(apiServer.server).post(
165+
`/extended/v1/faucets/btc?address=${addr}&large=true`
166+
);
167+
expect(response.status).toBe(200);
168+
await getRpcClient().generatetoaddress({
169+
address: getKeyAddress(ECPair.makeRandom({ network: regtest })),
170+
nblocks: 1,
171+
});
172+
const balanceResponse = await supertest(apiServer.server).get(
173+
`/extended/v1/faucets/btc/${addr}`
174+
);
175+
expect(balanceResponse.status).toBe(200);
176+
expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.01 });
177+
});
178+
179+
test('faucet http balance endpoint xlarge', async () => {
180+
const addr = getKeyAddress(ECPair.makeRandom({ network: regtest }));
181+
const response = await supertest(apiServer.server).post(
182+
`/extended/v1/faucets/btc?address=${addr}&xlarge=true`
183+
);
184+
expect(response.status).toBe(200);
185+
await getRpcClient().generatetoaddress({
186+
address: getKeyAddress(ECPair.makeRandom({ network: regtest })),
187+
nblocks: 1,
188+
});
189+
const balanceResponse = await supertest(apiServer.server).get(
190+
`/extended/v1/faucets/btc/${addr}`
191+
);
192+
expect(balanceResponse.status).toBe(200);
159193
expect(JSON.parse(balanceResponse.text)).toEqual({ balance: 0.5 });
160194
});
161195

0 commit comments

Comments
 (0)