Skip to content

Commit

Permalink
Merge pull request #263 from hirosystems/master
Browse files Browse the repository at this point in the history
merge master to develop
  • Loading branch information
rafaelcr authored Sep 23, 2024
2 parents b1b8f4b + 0a04aab commit 353fb7b
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 55 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
## [1.1.2](https://github.com/hirosystems/token-metadata-api/compare/v1.1.1...v1.1.2) (2024-08-30)


### Bug Fixes

* handle updated chain tip on rollbacks correctly ([#261](https://github.com/hirosystems/token-metadata-api/issues/261)) ([b85b1d3](https://github.com/hirosystems/token-metadata-api/commit/b85b1d3903a336d5691e05387140fcc1e8a41f16))

## [1.1.1](https://github.com/hirosystems/token-metadata-api/compare/v1.1.0...v1.1.1) (2024-08-30)


### Bug Fixes

* allow boolean metadata properties ([#260](https://github.com/hirosystems/token-metadata-api/issues/260)) ([d52861a](https://github.com/hirosystems/token-metadata-api/commit/d52861a1434d51ffd340063ca2cc5ccc4bb03676))

## [1.1.0](https://github.com/hirosystems/token-metadata-api/compare/v1.0.3...v1.1.0) (2024-08-30)


### Features

* add configurable delay for retrying jobs ([#257](https://github.com/hirosystems/token-metadata-api/issues/257)) ([20d753a](https://github.com/hirosystems/token-metadata-api/commit/20d753a82a4e7f214cf9dc8cb2fee333ac5a4f4c))


### Bug Fixes

* add chain tip etag generator ([#255](https://github.com/hirosystems/token-metadata-api/issues/255)) ([2b993cd](https://github.com/hirosystems/token-metadata-api/commit/2b993cd34484e156db9e24be8571c0e0e5b4bde0))
* retry when a contract is not yet found ([#256](https://github.com/hirosystems/token-metadata-api/issues/256)) ([46d8fc8](https://github.com/hirosystems/token-metadata-api/commit/46d8fc892790d64e2a2646efbc64d97be4a109e3))

## [1.0.3](https://github.com/hirosystems/token-metadata-api/compare/v1.0.2...v1.0.3) (2024-08-27)


Expand Down
4 changes: 1 addition & 3 deletions src/api/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export function parseMetadataLocaleBundle(
if (locale.properties.length > 0) {
const mergedProperties: MetadataPropertiesType = {};
for (const property of locale.properties) {
if (property.value) {
mergedProperties[property.name] = property.value as MetadataValueType;
}
mergedProperties[property.name] = property.value as MetadataValueType;
}
response.properties = mergedProperties;
}
Expand Down
6 changes: 5 additions & 1 deletion src/pg/chainhook/chainhook-pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export class ChainhookPgStore extends BasePgStoreModule {
} finished in ${time.getElapsedSeconds()}s`
);
}
if (payload.rollback.length) {
const earliestRolledBack = Math.min(...payload.rollback.map(r => r.block_identifier.index));
await this.updateChainTipBlockHeight(earliestRolledBack - 1);
}
for (const block of payload.apply) {
if (block.block_identifier.index <= (await this.getLastIngestedBlockHeight())) {
logger.info(
Expand Down Expand Up @@ -114,7 +118,7 @@ export class ChainhookPgStore extends BasePgStoreModule {
}

async updateChainTipBlockHeight(blockHeight: number): Promise<void> {
await this.sql`UPDATE chain_tip SET block_height = GREATEST(${blockHeight}, block_height)`;
await this.sql`UPDATE chain_tip SET block_height = ${blockHeight}`;
}

private async getLastIngestedBlockHeight(): Promise<number> {
Expand Down
6 changes: 5 additions & 1 deletion src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ export class PgStore extends BasePgStore {
}
if (locale.properties && locale.properties.length > 0) {
const values = locale.properties.map(property => ({
...property,
name: property.name,
value:
typeof property.value == 'boolean'
? sql`TO_JSONB(${property.value})`
: property.value,
metadata_id: metadataId,
}));
await sql`INSERT INTO metadata_properties ${sql(values)}`;
Expand Down
18 changes: 8 additions & 10 deletions src/token-processor/util/metadata-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,14 @@ async function parseMetadataForInsertion(
const properties: DbMetadataPropertyInsert[] = defaultInsert?.properties ?? [];
if (RawMetadataPropertiesCType.Check(metadata.properties)) {
for (const [key, value] of Object.entries(metadata.properties)) {
if (key && value) {
const defaultProp = properties.find(p => p.name === key);
if (defaultProp) {
defaultProp.value = value;
} else {
properties.push({
name: key,
value: value,
});
}
const defaultProp = properties.find(p => p.name === key);
if (defaultProp) {
defaultProp.value = value;
} else {
properties.push({
name: key,
value: value,
});
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/api/nft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ describe('NFT routes', () => {
name: 'prop2',
value: 1,
},
{
name: 'prop3',
value: true,
},
{
name: 'prop4',
value: false,
},
],
},
],
Expand Down Expand Up @@ -251,6 +259,8 @@ describe('NFT routes', () => {
properties: {
prop1: 'ABC',
prop2: 1,
prop3: true,
prop4: false,
},
},
});
Expand Down
14 changes: 11 additions & 3 deletions tests/api/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ describe('Status routes', () => {
db,
'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS.hello-world',
DbSipNumber.sip009,
1n
4n
);
await db.chainhook.updateChainTipBlockHeight(100);
await db.sql`UPDATE jobs SET status = 'failed' WHERE id = 2`;
await db.sql`UPDATE jobs SET status = 'invalid' WHERE id = 3`;
await db.sql`UPDATE jobs SET status = 'queued' WHERE id = 4`;
await db.sql`UPDATE jobs SET status = 'done' WHERE id = 5`;

const response = await fastify.inject({ method: 'GET', url: '/metadata/v1/' });
const json = response.json();
Expand All @@ -57,13 +61,17 @@ describe('Status routes', () => {
block_height: 100,
},
job_queue: {
pending: 2,
pending: 1,
failed: 1,
invalid: 1,
queued: 1,
done: 1,
},
token_contracts: {
'sip-009': 1,
},
tokens: {
nft: 1,
nft: 4,
},
});
});
Expand Down
36 changes: 0 additions & 36 deletions tests/chainhook/chainhook-observer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,6 @@ describe('Chainhook observer', () => {
await expect(db.getChainTipBlockHeight()).resolves.toBe(101);
});

test('keeps only the highest chain tip value', async () => {
await db.chainhook.processPayload(
new TestChainhookPayloadBuilder()
.apply()
.block({ height: 100 })
.transaction({ hash: '0x01', sender: 'SP1K1A1PMGW2ZJCNF46NWZWHG8TS1D23EGH1KNK60' })
.contractDeploy('SP1K1A1PMGW2ZJCNF46NWZWHG8TS1D23EGH1KNK60.friedger-pool-nft', {
maps: [],
functions: [],
variables: [],
fungible_tokens: [],
non_fungible_tokens: [],
})
.build()
);
await expect(db.getChainTipBlockHeight()).resolves.toBe(100);

await db.chainhook.processPayload(
new TestChainhookPayloadBuilder()
.apply()
.block({ height: 65 })
.transaction({ hash: '0x01', sender: 'SP1K1A1PMGW2ZJCNF46NWZWHG8TS1D23EGH1KNK60' })
.event({
type: 'SmartContractEvent',
position: { index: 0 },
data: {
contract_identifier: 'SP1K1A1PMGW2ZJCNF46NWZWHG8TS1D23EGH1KNK60.friedger-pool-nft',
topic: 'print',
raw_value: cvToHex(stringUtf8CV('test')),
},
})
.build()
);
await expect(db.getChainTipBlockHeight()).resolves.toBe(100);
});

test('enqueues dynamic tokens for refresh with standard interval', async () => {
const address = 'SP1K1A1PMGW2ZJCNF46NWZWHG8TS1D23EGH1KNK60';
const contractId = `${address}.friedger-pool-nft`;
Expand Down
5 changes: 4 additions & 1 deletion tests/token-queue/metadata-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Metadata Helpers', () => {
await expect(fetchMetadata(url, 'ABCD.test', 1n)).rejects.toThrow(MetadataHttpError);
});

test('does not throw on raw metadata with null or stringable values', async () => {
test('does not throw on raw metadata with null, stringable, or boolean values', async () => {
const crashPunks1 = {
version: '1',
name: 'Crash Punk 294',
Expand All @@ -74,6 +74,9 @@ describe('Metadata Helpers', () => {
external_url:
'https://thisisnumberone.com/nfts/SP3QSAJQ4EA8WXEDSRRKMZZ29NH91VZ6C5X88FGZQ.crashpunks-v2/294',
animation_url: null,
allow_multiple_claims: true,
whitelisted: false,
minted: 160,
},
localization: {
uri: null,
Expand Down
6 changes: 6 additions & 0 deletions tests/token-queue/process-token-job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ describe('ProcessTokenJob', () => {
collection_size: 5000,
artist: 'Bitcoin Monkeys',
prop: { a: 1, b: 2 },
allow_multiple_claims: true,
whitelisted: false,
},
};
const agent = new MockAgent();
Expand Down Expand Up @@ -441,6 +443,10 @@ describe('ProcessTokenJob', () => {
expect(properties[4].value).toBe(5000);
expect(properties[6].name).toBe('prop');
expect(properties[6].value).toStrictEqual({ a: 1, b: 2 });
expect(properties[7].name).toBe('allow_multiple_claims');
expect(properties[7].value).toStrictEqual(true);
expect(properties[8].name).toBe('whitelisted');
expect(properties[8].value).toStrictEqual(false);
});

test('parses metadata with localizations', async () => {
Expand Down

0 comments on commit 353fb7b

Please sign in to comment.