Skip to content

Commit

Permalink
Merge pull request #273 from hirosystems/master
Browse files Browse the repository at this point in the history
merge master into develop
  • Loading branch information
rafaelcr authored Oct 9, 2024
2 parents 84252a7 + ae4c71f commit 1aab466
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [1.1.4](https://github.com/hirosystems/token-metadata-api/compare/v1.1.3...v1.1.4) (2024-09-23)


### Bug Fixes

* treat non-compliant SIP-016 metadata as invalid ([#266](https://github.com/hirosystems/token-metadata-api/issues/266)) ([288723d](https://github.com/hirosystems/token-metadata-api/commit/288723d577d35ecd38c75c26d572a28f548388fc))

## [1.1.3](https://github.com/hirosystems/token-metadata-api/compare/v1.1.2...v1.1.3) (2024-09-23)


### Bug Fixes

* ignore events from failed transactions ([#264](https://github.com/hirosystems/token-metadata-api/issues/264)) ([84252a7](https://github.com/hirosystems/token-metadata-api/commit/84252a7d218de39f5c9379f933af99d49186c9fe))

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


Expand Down
12 changes: 3 additions & 9 deletions src/token-processor/util/metadata-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ function parseJsonMetadata(url: string, content?: string): RawMetadata {
try {
const result = JSON5.parse(content);
if (RawMetadataCType.Check(result)) {
if (result.name === undefined) {
throw new MetadataParseError(`Metadata does not contain a 'name' value: ${url}`);
}
return result;
} else {
throw new MetadataParseError(`Invalid raw metadata JSON schema: ${url}`);
Expand Down Expand Up @@ -356,15 +359,6 @@ export function getFetchableDecentralizedStorageUrl(uri: string): URL {
throw new MetadataParseError(`Unsupported uri protocol: ${uri}`);
}

function isUriFromDecentralizedStorage(uri: string): boolean {
return (
uri.startsWith('ipfs:') ||
uri.startsWith('ipns:') ||
uri.startsWith('ar:') ||
uri.startsWith('https://cloudflare-ipfs.com')
);
}

export function parseDataUrl(
s: string
):
Expand Down
23 changes: 22 additions & 1 deletion tests/token-queue/metadata-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MockAgent, setGlobalDispatcher } from 'undici';
import { ENV } from '../../src/env';
import { MetadataHttpError } from '../../src/token-processor/util/errors';
import { MetadataHttpError, MetadataParseError } from '../../src/token-processor/util/errors';
import {
getFetchableDecentralizedStorageUrl,
getMetadataFromUri,
Expand Down Expand Up @@ -100,6 +100,27 @@ describe('Metadata Helpers', () => {
).resolves.not.toThrow();
});

test('throws when metadata does not contain a name', async () => {
const crashPunks1 = {
sip: 16,
image: 'ipfs://Qmb84UcaMr1MUwNbYBnXWHM3kEaDcYrKuPWwyRLVTNKELC/294.png',
};
const agent = new MockAgent();
agent.disableNetConnect();
agent
.get('http://test.io')
.intercept({
path: '/1.json',
method: 'GET',
})
.reply(200, crashPunks1);
setGlobalDispatcher(agent);

await expect(getMetadataFromUri('http://test.io/1.json', 'ABCD.test', 1n)).rejects.toThrow(
MetadataParseError
);
});

test('fetches typed raw metadata', async () => {
const json = {
version: 1,
Expand Down
14 changes: 8 additions & 6 deletions tests/token-queue/process-token-job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { RetryableJobError } from '../../src/token-processor/queue/errors';
import { TooManyRequestsHttpError } from '../../src/token-processor/util/errors';
import { cycleMigrations } from '@hirosystems/api-toolkit';
import { insertAndEnqueueTestContractWithTokens } from '../helpers';
import { InvalidTokenError } from '../../src/pg/errors';

describe('ProcessTokenJob', () => {
let db: PgStore;
Expand Down Expand Up @@ -683,7 +684,7 @@ describe('ProcessTokenJob', () => {
);
});

test('SIP-016 non-compliant metadata is ignored', async () => {
test('SIP-016 non-compliant metadata throws error', async () => {
const metadata = {
id: '62624cc0065e986192fb9f33',
media: 'https://sf-stage-s3.s3.us-west-1.amazonaws.com/riyasen_suit.png',
Expand Down Expand Up @@ -718,11 +719,12 @@ describe('ProcessTokenJob', () => {

await new ProcessTokenJob({ db, job: tokenJob }).work();

const bundle = await db.getTokenMetadataBundle({
contractPrincipal: 'ABCD.test-nft',
tokenNumber: 1,
});
expect(bundle?.metadataLocale).toBeUndefined();
await expect(
db.getTokenMetadataBundle({
contractPrincipal: 'ABCD.test-nft',
tokenNumber: 1,
})
).rejects.toThrow(InvalidTokenError);
});
});

Expand Down

0 comments on commit 1aab466

Please sign in to comment.