Skip to content

Commit

Permalink
chore: impl suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Apr 16, 2024
1 parent a5ed095 commit 061cf2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions backend/src/routes/generateClaimLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getGenerateClaimLinkRoute(fastify: FastifyInstance): void {
type: 'object',
required: ['address', 'amount', 'signature'],
properties: {
amount: { type: 'string', pattern: '^[0-9]{1,78}.[0-9]{6}$' },
amount: { type: 'string', pattern: '^[0-9]{1,78}.[0-9]{1,6}$' },
address: { type: 'string', pattern: '^0x0[0-9a-fA-F]{63}$' },
signature: {
type: 'array',
Expand All @@ -30,7 +30,7 @@ export function getGenerateClaimLinkRoute(fastify: FastifyInstance): void {
const { amount, address, signature } = request.body;

// Validate the input
if (/^0{1,78}.000000$/.test(amount)) {
if (/^0{1,78}.0{1,6}$/.test(amount)) {
return reply.status(400).send({ message: "Amount can't be zero." });
}
if (!signature.length) {
Expand Down
26 changes: 22 additions & 4 deletions backend/test/generateClaimLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ describe('POST /generate_claim_link route', () => {
);
});

test('should fail for invalid amount', async () => {
test('should fail for negative amount', async () => {
const response = await app.inject({
method: 'POST',
url: '/generate_claim_link',
body: {
amount: '123.2',
amount: '-123.2',
address: testAddress,
signature: [testAddress, testAddress],
},
Expand All @@ -78,7 +78,25 @@ describe('POST /generate_claim_link route', () => {
expect(response.statusCode).toBe(400);
expect(response.json()).toHaveProperty(
'message',
'body/amount must match pattern "^[0-9]{1,78}.[0-9]{6}$"',
'body/amount must match pattern "^[0-9]{1,78}.[0-9]{1,6}$"',
);
});

test('should fail for too many decimals amount', async () => {
const response = await app.inject({
method: 'POST',
url: '/generate_claim_link',
body: {
amount: '123.4567891',
address: testAddress,
signature: [testAddress, testAddress],
},
});

expect(response.statusCode).toBe(400);
expect(response.json()).toHaveProperty(
'message',
'body/amount must match pattern "^[0-9]{1,78}.[0-9]{1,6}$"',
);
});

Expand All @@ -87,7 +105,7 @@ describe('POST /generate_claim_link route', () => {
method: 'POST',
url: '/generate_claim_link',
body: {
amount: '0.000000',
amount: '0.0000',
address: testAddress,
signature: [testAddress, testAddress],
},
Expand Down

0 comments on commit 061cf2e

Please sign in to comment.