Skip to content

Commit

Permalink
fix: allow genesis with null address (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr authored Jun 26, 2023
1 parent 6330ea7 commit 9769028
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ export const InscriptionResponse = Type.Object(
examples: ['bc1pvwh2dl6h388x65rqq47qjzdmsqgkatpt4hye6daf7yxvl0z3xjgq247aq8'],
})
),
genesis_address: Type.String({
examples: ['bc1pvwh2dl6h388x65rqq47qjzdmsqgkatpt4hye6daf7yxvl0z3xjgq247aq8'],
}),
genesis_address: Nullable(
Type.String({
examples: ['bc1pvwh2dl6h388x65rqq47qjzdmsqgkatpt4hye6daf7yxvl0z3xjgq247aq8'],
})
),
genesis_block_height: Type.Integer({ examples: [778921] }),
genesis_block_hash: Type.String({
examples: ['0000000000000000000452773967cdd62297137cdaf79950c5e8bb0c62075133'],
Expand Down
4 changes: 2 additions & 2 deletions src/chainhook/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const InscriptionRevealedSchema = Type.Object({
inscription_fee: Type.Integer(),
inscription_id: Type.String(),
inscription_output_value: Type.Integer(),
inscriber_address: Type.String(),
inscriber_address: Nullable(Type.String()),
ordinal_number: Type.Integer(),
ordinal_block_height: Type.Integer(),
ordinal_offset: Type.Integer(),
Expand All @@ -32,7 +32,7 @@ const CursedInscriptionRevealedSchema = Type.Object({
inscription_fee: Type.Integer(),
inscription_id: Type.String(),
inscription_output_value: Type.Integer(),
inscriber_address: Type.String(),
inscriber_address: Nullable(Type.String()),
ordinal_number: Type.Integer(),
ordinal_block_height: Type.Integer(),
ordinal_offset: Type.Integer(),
Expand Down
71 changes: 71 additions & 0 deletions tests/inscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,77 @@ describe('/inscriptions', () => {
expect(response2.json()).toStrictEqual(expected);
});

test('shows inscription with null genesis address', async () => {
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
.apply()
.block({
height: 775617,
hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
timestamp: 1676913207,
})
.transaction({
hash: '0x38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
})
.inscriptionRevealed({
content_bytes: '0x48656C6C6F',
content_type: 'image/png',
content_length: 5,
inscription_number: 7,
inscription_fee: 2805,
inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
inscription_output_value: 10000,
inscriber_address: null,
ordinal_number: 257418248345364,
ordinal_block_height: 51483,
ordinal_offset: 0,
satpoint_post_inscription:
'38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0',
})
.build()
);
const expected = {
address: null,
genesis_address: null,
genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
genesis_block_height: 775617,
content_length: 5,
mime_type: 'image/png',
content_type: 'image/png',
genesis_fee: '2805',
id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
offset: '0',
number: 7,
value: '10000',
tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
sat_ordinal: '257418248345364',
sat_coinbase_height: 51483,
output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0',
location: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0',
sat_rarity: 'common',
timestamp: 1676913207000,
genesis_timestamp: 1676913207000,
genesis_tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
curse_type: null,
};

// By inscription id
const response = await fastify.inject({
method: 'GET',
url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
});
expect(response.statusCode).toBe(200);
expect(response.json()).toStrictEqual(expected);

// By inscription number
const response2 = await fastify.inject({
method: 'GET',
url: '/ordinals/v1/inscriptions/7',
});
expect(response2.statusCode).toBe(200);
expect(response2.json()).toStrictEqual(expected);
});

test('shows cursed inscription', async () => {
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
Expand Down

0 comments on commit 9769028

Please sign in to comment.