Skip to content

Commit

Permalink
feat: /ordinals prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Feb 28, 2023
1 parent 1028a13 commit 38d6c6b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/api/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export async function buildApiServer(args: { db: PgStore }) {

fastify.decorate('db', args.db);
await fastify.register(FastifyCors);
await fastify.register(Api);
await fastify.register(Api, { prefix: '/ordinals/v1' });
await fastify.register(Api, { prefix: '/ordinals' });

return fastify;
}
12 changes: 6 additions & 6 deletions tests/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('ETag cache', () => {
});
const response = await fastify.inject({
method: 'GET',
url: '/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
});
expect(response.statusCode).toBe(200);
expect(response.headers.etag).not.toBeUndefined();
Expand All @@ -58,7 +58,7 @@ describe('ETag cache', () => {
// Cached response
const cached = await fastify.inject({
method: 'GET',
url: '/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
headers: { 'if-none-match': etag },
});
expect(cached.statusCode).toBe(304);
Expand All @@ -67,7 +67,7 @@ describe('ETag cache', () => {
await db.sql`UPDATE locations SET timestamp = NOW() WHERE true`;
const cached2 = await fastify.inject({
method: 'GET',
url: '/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
headers: { 'if-none-match': etag },
});
expect(cached2.statusCode).toBe(200);
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('ETag cache', () => {
// ETag response
const response = await fastify.inject({
method: 'GET',
url: '/inscriptions',
url: '/ordinals/v1/inscriptions',
});
expect(response.statusCode).toBe(200);
expect(response.headers.etag).not.toBeUndefined();
Expand All @@ -139,7 +139,7 @@ describe('ETag cache', () => {
// Cached
const cached = await fastify.inject({
method: 'GET',
url: '/inscriptions',
url: '/ordinals/v1/inscriptions',
headers: { 'if-none-match': etag },
});
expect(cached.statusCode).toBe(304);
Expand All @@ -148,7 +148,7 @@ describe('ETag cache', () => {
await db.updateChainTipBlockHeight({ blockHeight: 5 });
const cached2 = await fastify.inject({
method: 'GET',
url: '/inscriptions',
url: '/ordinals/v1/inscriptions',
headers: { 'if-none-match': etag },
});
expect(cached2.statusCode).toBe(200);
Expand Down
34 changes: 17 additions & 17 deletions tests/inscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('/inscriptions', () => {
});
const response = await fastify.inject({
method: 'GET',
url: '/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
});
expect(response.statusCode).toBe(200);
expect(response.json()).toStrictEqual({
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?mime_type=text/plain',
url: '/ordinals/v1/inscriptions?mime_type=text/plain',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand All @@ -155,7 +155,7 @@ describe('/inscriptions', () => {

const response2 = await fastify.inject({
method: 'GET',
url: '/inscriptions?mime_type=image/png',
url: '/ordinals/v1/inscriptions?mime_type=image/png',
});
expect(response2.statusCode).toBe(200);
const responseJson2 = response2.json();
Expand All @@ -182,7 +182,7 @@ describe('/inscriptions', () => {

const response3 = await fastify.inject({
method: 'GET',
url: '/inscriptions?mime_type=image/png&mime_type=text/plain',
url: '/ordinals/v1/inscriptions?mime_type=image/png&mime_type=text/plain',
});
expect(response3.statusCode).toBe(200);
const responseJson3 = response3.json();
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?rarity=common',
url: '/ordinals/v1/inscriptions?rarity=common',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand All @@ -256,7 +256,7 @@ describe('/inscriptions', () => {

const response2 = await fastify.inject({
method: 'GET',
url: '/inscriptions?rarity=epic',
url: '/ordinals/v1/inscriptions?rarity=epic',
});
expect(response2.statusCode).toBe(200);
const responseJson2 = response2.json();
Expand Down Expand Up @@ -320,7 +320,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?genesis_block=775617',
url: '/ordinals/v1/inscriptions?genesis_block=775617',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand Down Expand Up @@ -384,7 +384,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?genesis_block=000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7',
url: '/ordinals/v1/inscriptions?genesis_block=000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand Down Expand Up @@ -450,7 +450,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?output=9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0',
url: '/ordinals/v1/inscriptions?output=9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand Down Expand Up @@ -516,7 +516,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?address=bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
url: '/ordinals/v1/inscriptions?address=bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand Down Expand Up @@ -608,7 +608,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?order_by=rarity&order=asc',
url: '/ordinals/v1/inscriptions?order_by=rarity&order=asc',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand All @@ -619,7 +619,7 @@ describe('/inscriptions', () => {

const response2 = await fastify.inject({
method: 'GET',
url: '/inscriptions?order_by=rarity&order=desc',
url: '/ordinals/v1/inscriptions?order_by=rarity&order=desc',
});
expect(response2.statusCode).toBe(200);
const responseJson2 = response2.json();
Expand Down Expand Up @@ -711,7 +711,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?order_by=ordinal&order=asc',
url: '/ordinals/v1/inscriptions?order_by=ordinal&order=asc',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand All @@ -722,7 +722,7 @@ describe('/inscriptions', () => {

const response2 = await fastify.inject({
method: 'GET',
url: '/inscriptions?order_by=ordinal&order=desc',
url: '/ordinals/v1/inscriptions?order_by=ordinal&order=desc',
});
expect(response2.statusCode).toBe(200);
const responseJson2 = response2.json();
Expand Down Expand Up @@ -814,7 +814,7 @@ describe('/inscriptions', () => {

const response1 = await fastify.inject({
method: 'GET',
url: '/inscriptions?order_by=genesis_block_height&order=asc',
url: '/ordinals/v1/inscriptions?order_by=genesis_block_height&order=asc',
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
Expand All @@ -825,7 +825,7 @@ describe('/inscriptions', () => {

const response2 = await fastify.inject({
method: 'GET',
url: '/inscriptions?order_by=genesis_block_height&order=desc',
url: '/ordinals/v1/inscriptions?order_by=genesis_block_height&order=desc',
});
expect(response2.statusCode).toBe(200);
const responseJson2 = response2.json();
Expand All @@ -838,7 +838,7 @@ describe('/inscriptions', () => {
test('returns not found for invalid inscriptions', async () => {
const response = await fastify.inject({
method: 'GET',
url: '/inscriptions/ff4503ab9048d6d0ff4e23def81b614d5270d341ce993992e93902ceb0d4ed79i0',
url: '/ordinals/v1/inscriptions/ff4503ab9048d6d0ff4e23def81b614d5270d341ce993992e93902ceb0d4ed79i0',
});
expect(response.statusCode).toBe(404);
});
Expand Down
8 changes: 4 additions & 4 deletions tests/sats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('/sats', () => {
test('returns valid sat', async () => {
const response = await fastify.inject({
method: 'GET',
url: '/sats/10080000000001',
url: '/ordinals/v1/sats/10080000000001',
});
expect(response.statusCode).toBe(200);
expect(response.json()).toStrictEqual({
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('/sats', () => {
});
const response = await fastify.inject({
method: 'GET',
url: '/sats/257418248345364',
url: '/ordinals/v1/sats/257418248345364',
});
expect(response.statusCode).toBe(200);
expect(response.json().inscription_id).toBe(
Expand All @@ -80,13 +80,13 @@ describe('/sats', () => {
test('returns not found on invalid sats', async () => {
const response1 = await fastify.inject({
method: 'GET',
url: '/sats/2099999997690000',
url: '/ordinals/v1/sats/2099999997690000',
});
expect(response1.statusCode).toBe(400);

const response2 = await fastify.inject({
method: 'GET',
url: '/sats/-1',
url: '/ordinals/v1/sats/-1',
});
expect(response2.statusCode).toBe(400);
});
Expand Down
2 changes: 1 addition & 1 deletion util/openapi-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ApiGenerator: FastifyPluginAsync<
TypeBoxTypeProvider
> = async (fastify, options) => {
await fastify.register(FastifySwagger, ApiSwaggerOptions);
await fastify.register(Api);
await fastify.register(Api, { prefix: '/ordinals/v1' });
if (!existsSync('./tmp')) {
mkdirSync('./tmp');
}
Expand Down

0 comments on commit 38d6c6b

Please sign in to comment.