Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: don't spin up token registry server, mock func instead #146

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/cache/fsevents-patch-21ad2b1333-8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- node_modules
- yarn
- updated vitest
- removed token registry mock server, using function mocking instead

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"supertest": "^6.3.3",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"vitest": "^0.27"
"vitest": "^1.2.2"
},
"packageManager": "[email protected]",
"type": "module",
Expand Down
13 changes: 5 additions & 8 deletions src/routes/assets/asset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,11 @@ async function route(fastify: FastifyInstance) {

// retrieve off-chain metadata
const metadata = await fetchAssetMetadata(request.params.asset);
// @ts-expect-error due to using ESM with vitest and some weirdness with cip14 lib we need to call .default
// otherwise unit test fails on ""...is not a function".
const fingerprint = AssetFingerprint.default
.fromParts(
Uint8Array.from(Buffer.from(rows[0].policy_id, 'hex')),
Uint8Array.from(Buffer.from(rows[0].asset_name ?? '', 'hex')),
)
.fingerprint();

const fingerprint = AssetFingerprint.fromParts(
Uint8Array.from(Buffer.from(rows[0].policy_id, 'hex')),
Uint8Array.from(Buffer.from(rows[0].asset_name ?? '', 'hex')),
).fingerprint();

return reply.send({
...rows[0],
Expand Down
234 changes: 117 additions & 117 deletions test/unit/fixtures/token-registry.fixtures.ts

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions test/unit/server-token-registry.ts

This file was deleted.

9 changes: 8 additions & 1 deletion test/unit/tests/routes/addresses.unit.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import * as databaseUtils from '../../../../src/utils/database.js';
import * as tokenRegistryUtils from '../../../../src/utils/token-registry.js';
import sinon from 'sinon';
import supertest from 'supertest';
import fixtures from '../../fixtures/addresses.fixtures.js';
import buildFastify from '../../../../src/app.js';
import { describe, expect, test, vi } from 'vitest';
import { beforeEach, describe, expect, test, vi } from 'vitest';

import * as config from '../../../../src/config.js';

describe('address service', () => {
beforeEach(() => {
vi.spyOn(tokenRegistryUtils, 'fetchAssetMetadata').mockImplementation(() => {
return Promise.resolve(null);
});
});

fixtures.map(fixture => {
test(fixture.name, async () => {
const fastify = buildFastify({ maxParamLength: 32_768 });
Expand Down
3 changes: 2 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { defineConfig, defaultInclude } from 'vitest/config';

export default defineConfig({
test: {
// https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker
pool: 'forks',
reporters: ['verbose'],
globalSetup: ['./test/unit/server-token-registry.ts'],
testTimeout: 20_000,
root: '.',
mockReset: true,
Expand Down
137 changes: 94 additions & 43 deletions yarn-project.nix

Large diffs are not rendered by default.

Loading
Loading