Skip to content

Commit

Permalink
better expectation and review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brady.ouren committed Jul 23, 2024
1 parent 2e519da commit 04c24c6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
1 change: 0 additions & 1 deletion api/src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ const RuneDetailResponseSchema = Type.Object({
{
id: RuneIdResponseSchema,
name: RuneNameResponseSchema,
// number: RuneNumberResponseSchema,
spaced_name: RuneSpacedNameResponseSchema,
},
{ title: 'Rune detail', description: 'Details of the rune affected by this activity' }
Expand Down
47 changes: 41 additions & 6 deletions api/tests/api/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { ENV } from '../../src/env';
import { PgStore } from '../../src/pg/pg-store';
import { DbLedgerEntry } from '../../src/pg/types';
import {
dropDatabase,
insertDbEntry,
insertDbLedgerEntry,
insertRune,
sampleRune,
runMigrations,
startTestApiServer,
TestFastifyServer,
insertSupply,
insertSupplyChange,
sampleLedgerEntry,
} from '../helpers';

Expand All @@ -27,8 +26,8 @@ describe('Etchings', () => {
await runMigrations(db);
await insertRune(db, rune);
const event_index = 0;
await insertDbEntry(db, ledgerEntry, event_index);
await insertSupply(db, rune.id, 1);
await insertDbLedgerEntry(db, ledgerEntry, event_index);
await insertSupplyChange(db, rune.id, 1);
});

afterEach(async () => {
Expand All @@ -41,6 +40,40 @@ describe('Etchings', () => {
});

test('lists runes', async () => {
const expected = {
divisibility: 0,
id: '1:1',
location: {
block_hash: '0000000000000000000320283a032748cef8227873ff4872689bf23f1cda83a5',
block_height: 840000,
timestamp: 0,
tx_id: '2bb85f4b004be6da54f766c17c1e855187327112c231ef2ff35ebad0ea67c69e',
tx_index: 1,
},
mint_terms: {
amount: '100',
cap: '5000000',
height_end: null,
height_start: null,
offset_end: null,
offset_start: null,
},
name: 'Sample Rune',
number: 1,
spaced_name: 'Sample•Rune',
supply: {
burned: '0',
current: '0',
mint_percentage: '0.0000',
mintable: false,
minted: '0',
premine: '0',
total_burns: '0',
total_mints: '0',
},
symbol: 'ᚠ',
turbo: false,
};
const runesResponse = await fastify.inject({
method: 'GET',
url: '/runes/v1/etchings',
Expand All @@ -53,8 +86,9 @@ describe('Etchings', () => {
url: '/runes/v1/etchings/' + ledgerEntry.rune_id,
});
expect(response.statusCode).toBe(200);
expect(response.json().name).toEqual(rune.name);
expect(response.json()).toStrictEqual(expected);
});

test('can fetch by spaced name', async () => {
const url = '/runes/v1/etchings/' + rune.spaced_name;
const response = await fastify.inject({
Expand All @@ -64,6 +98,7 @@ describe('Etchings', () => {
expect(response.statusCode).toBe(200);
expect(response.json().spaced_name).toEqual(rune.spaced_name);
});

test('can not fetch by spaced name if lacking bullets', async () => {
const url = '/runes/v1/etchings/' + rune.spaced_name.replaceAll('•', '-');
const response = await fastify.inject({
Expand Down
6 changes: 3 additions & 3 deletions api/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function toSpacedName(name: string | null): string | null {
export function sampleRune(id: string, name?: string): DbRune {
return {
id: '1:1',
name: name || 'SAMPLE RUNE NAME',
name: name || 'SAMPLERUNENAME',
spaced_name: (name && toSpacedName(name)) || 'SAMPLE•RUNE•NAME',
number: 1,
block_hash: '0000000000000000000320283a032748cef8227873ff4872689bf23f1cda83a5',
Expand All @@ -107,7 +107,7 @@ export function sampleRune(id: string, name?: string): DbRune {
};
}

export async function insertDbEntry(
export async function insertDbLedgerEntry(
db: PgStore,
payload: DbLedgerEntry,
event_index: number
Expand Down Expand Up @@ -139,7 +139,7 @@ export async function insertDbEntry(
});
}

export async function insertSupply(
export async function insertSupplyChange(
db: PgStore,
rune_id: string,
block_height: number,
Expand Down

0 comments on commit 04c24c6

Please sign in to comment.