Skip to content

Commit 1aab466

Browse files
authored
Merge pull request #273 from hirosystems/master
merge master into develop
2 parents 84252a7 + ae4c71f commit 1aab466

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [1.1.4](https://github.com/hirosystems/token-metadata-api/compare/v1.1.3...v1.1.4) (2024-09-23)
2+
3+
4+
### Bug Fixes
5+
6+
* 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))
7+
8+
## [1.1.3](https://github.com/hirosystems/token-metadata-api/compare/v1.1.2...v1.1.3) (2024-09-23)
9+
10+
11+
### Bug Fixes
12+
13+
* 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))
14+
115
## [1.1.2](https://github.com/hirosystems/token-metadata-api/compare/v1.1.1...v1.1.2) (2024-08-30)
216

317

src/token-processor/util/metadata-helpers.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ function parseJsonMetadata(url: string, content?: string): RawMetadata {
318318
try {
319319
const result = JSON5.parse(content);
320320
if (RawMetadataCType.Check(result)) {
321+
if (result.name === undefined) {
322+
throw new MetadataParseError(`Metadata does not contain a 'name' value: ${url}`);
323+
}
321324
return result;
322325
} else {
323326
throw new MetadataParseError(`Invalid raw metadata JSON schema: ${url}`);
@@ -356,15 +359,6 @@ export function getFetchableDecentralizedStorageUrl(uri: string): URL {
356359
throw new MetadataParseError(`Unsupported uri protocol: ${uri}`);
357360
}
358361

359-
function isUriFromDecentralizedStorage(uri: string): boolean {
360-
return (
361-
uri.startsWith('ipfs:') ||
362-
uri.startsWith('ipns:') ||
363-
uri.startsWith('ar:') ||
364-
uri.startsWith('https://cloudflare-ipfs.com')
365-
);
366-
}
367-
368362
export function parseDataUrl(
369363
s: string
370364
):

tests/token-queue/metadata-helpers.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MockAgent, setGlobalDispatcher } from 'undici';
22
import { ENV } from '../../src/env';
3-
import { MetadataHttpError } from '../../src/token-processor/util/errors';
3+
import { MetadataHttpError, MetadataParseError } from '../../src/token-processor/util/errors';
44
import {
55
getFetchableDecentralizedStorageUrl,
66
getMetadataFromUri,
@@ -100,6 +100,27 @@ describe('Metadata Helpers', () => {
100100
).resolves.not.toThrow();
101101
});
102102

103+
test('throws when metadata does not contain a name', async () => {
104+
const crashPunks1 = {
105+
sip: 16,
106+
image: 'ipfs://Qmb84UcaMr1MUwNbYBnXWHM3kEaDcYrKuPWwyRLVTNKELC/294.png',
107+
};
108+
const agent = new MockAgent();
109+
agent.disableNetConnect();
110+
agent
111+
.get('http://test.io')
112+
.intercept({
113+
path: '/1.json',
114+
method: 'GET',
115+
})
116+
.reply(200, crashPunks1);
117+
setGlobalDispatcher(agent);
118+
119+
await expect(getMetadataFromUri('http://test.io/1.json', 'ABCD.test', 1n)).rejects.toThrow(
120+
MetadataParseError
121+
);
122+
});
123+
103124
test('fetches typed raw metadata', async () => {
104125
const json = {
105126
version: 1,

tests/token-queue/process-token-job.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { RetryableJobError } from '../../src/token-processor/queue/errors';
1717
import { TooManyRequestsHttpError } from '../../src/token-processor/util/errors';
1818
import { cycleMigrations } from '@hirosystems/api-toolkit';
1919
import { insertAndEnqueueTestContractWithTokens } from '../helpers';
20+
import { InvalidTokenError } from '../../src/pg/errors';
2021

2122
describe('ProcessTokenJob', () => {
2223
let db: PgStore;
@@ -683,7 +684,7 @@ describe('ProcessTokenJob', () => {
683684
);
684685
});
685686

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

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

721-
const bundle = await db.getTokenMetadataBundle({
722-
contractPrincipal: 'ABCD.test-nft',
723-
tokenNumber: 1,
724-
});
725-
expect(bundle?.metadataLocale).toBeUndefined();
722+
await expect(
723+
db.getTokenMetadataBundle({
724+
contractPrincipal: 'ABCD.test-nft',
725+
tokenNumber: 1,
726+
})
727+
).rejects.toThrow(InvalidTokenError);
726728
});
727729
});
728730

0 commit comments

Comments
 (0)