Skip to content

Commit

Permalink
Apply common 'prettier' formatting rules across the entire repo (#358)
Browse files Browse the repository at this point in the history
Update the individual services in the repo to reference the shared
`@projectlibertylabs/prettier-config` package that lives in
[packages/prettier-config](./packages/prettier-config), and apply
formatting.
  • Loading branch information
JoeCap08055 authored Aug 9, 2024
1 parent 9a9d250 commit dcb8211
Show file tree
Hide file tree
Showing 61 changed files with 510 additions and 798 deletions.
11 changes: 1 addition & 10 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2,
"useTabs": false
}
"@projectlibertylabs/prettier-config"
8 changes: 1 addition & 7 deletions services/account/apps/api/src/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ import { BlockchainModule } from '#lib/blockchain/blockchain.module';
import { redisEventsToEventEmitter } from '#lib/utils/redis';
import { EnqueueService } from '#lib/services/enqueue-request.service';
import { QueueModule, QueueConstants } from '#lib/queues';
import {
AccountsControllerV1,
DelegationControllerV1,
HandlesControllerV1,
KeysControllerV1,
HealthController,
} from './controllers';
import { AccountsControllerV1, DelegationControllerV1, HandlesControllerV1, KeysControllerV1, HealthController } from './controllers';
import { ApiService, AccountsService, HandlesService, DelegationService, KeysService } from './services';

@Module({
Expand Down
3 changes: 1 addition & 2 deletions services/account/apps/api/src/build-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { NestFactory } from '@nestjs/core';
process.env.REDIS_URL = 'http://127.0.0.1';
process.env.FREQUENCY_URL = 'http://127.0.0.1';
process.env.FREQUENCY_HTTP_URL = 'http://127.0.0.1';
process.env.PROVIDER_ACCOUNT_SEED_PHRASE =
'offer debate skin describe light badge fish turtle actual inject struggle border';
process.env.PROVIDER_ACCOUNT_SEED_PHRASE = 'offer debate skin describe light badge fish turtle actual inject struggle border';
process.env.PROVIDER_ID = '0';
process.env.WEBHOOK_BASE_URL = 'http://127.0.0.1';
process.env.CAPACITY_LIMIT = '{"type":"amount","value":0}';
Expand Down
41 changes: 10 additions & 31 deletions services/account/apps/api/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
/* eslint-disable */
export default async () => {
const t = {
['../../../libs/common/src/types/dtos/wallet.login.request.dto']: await import(
'../../../libs/common/src/types/dtos/wallet.login.request.dto'
),
['../../../libs/common/src/types/dtos/accounts.response.dto']: await import(
'../../../libs/common/src/types/dtos/accounts.response.dto'
),
['../../../libs/common/src/types/dtos/wallet.login.request.dto']: await import('../../../libs/common/src/types/dtos/wallet.login.request.dto'),
['../../../libs/common/src/types/dtos/accounts.response.dto']: await import('../../../libs/common/src/types/dtos/accounts.response.dto'),
['@polkadot/types-codec/primitive/U32']: await import('@polkadot/types-codec/primitive/U32'),
['../../../libs/common/src/types/dtos/wallet.login.config.response.dto']: await import(
'../../../libs/common/src/types/dtos/wallet.login.config.response.dto'
),
['../../../libs/common/src/types/dtos/wallet.login.response.dto']: await import(
'../../../libs/common/src/types/dtos/wallet.login.response.dto'
),
['../../../libs/common/src/types/dtos/delegation.response.dto']: await import(
'../../../libs/common/src/types/dtos/delegation.response.dto'
),
['../../../libs/common/src/types/dtos/transaction.response.dto']: await import(
'../../../libs/common/src/types/dtos/transaction.response.dto'
),
['../../../libs/common/src/types/dtos/keys.response.dto']: await import(
'../../../libs/common/src/types/dtos/keys.response.dto'
),
['../../../libs/common/src/types/dtos/wallet.login.config.response.dto']: await import('../../../libs/common/src/types/dtos/wallet.login.config.response.dto'),
['../../../libs/common/src/types/dtos/wallet.login.response.dto']: await import('../../../libs/common/src/types/dtos/wallet.login.response.dto'),
['../../../libs/common/src/types/dtos/delegation.response.dto']: await import('../../../libs/common/src/types/dtos/delegation.response.dto'),
['../../../libs/common/src/types/dtos/transaction.response.dto']: await import('../../../libs/common/src/types/dtos/transaction.response.dto'),
['../../../libs/common/src/types/dtos/keys.response.dto']: await import('../../../libs/common/src/types/dtos/keys.response.dto'),
};
return {
'@nestjs/swagger': {
Expand Down Expand Up @@ -109,10 +95,7 @@ export default async () => {
MsaIdResponse: { msaId: { required: true, type: () => String } },
},
],
[
import('../../../libs/common/src/types/dtos/transaction.response.dto'),
{ TransactionResponse: { referenceId: { required: true, type: () => String } } },
],
[import('../../../libs/common/src/types/dtos/transaction.response.dto'), { TransactionResponse: { referenceId: { required: true, type: () => String } } }],
[
import('../../../libs/common/src/types/dtos/wallet.login.response.dto'),
{
Expand Down Expand Up @@ -143,19 +126,15 @@ export default async () => {
},
},
],
[
import('../../../libs/common/src/types/dtos/keys.response.dto'),
{ KeysResponse: { msaKeys: { required: true } } },
],
[import('../../../libs/common/src/types/dtos/keys.response.dto'), { KeysResponse: { msaKeys: { required: true } } }],
],
controllers: [
[
import('./controllers/v1/accounts-v1.controller'),
{
AccountsControllerV1: {
getSIWFConfig: {
type: t['../../../libs/common/src/types/dtos/wallet.login.config.response.dto']
.WalletLoginConfigResponse,
type: t['../../../libs/common/src/types/dtos/wallet.login.config.response.dto'].WalletLoginConfigResponse,
},
getAccountForMsa: {
type: t['../../../libs/common/src/types/dtos/accounts.response.dto'].AccountResponse,
Expand Down
5 changes: 1 addition & 4 deletions services/account/apps/api/src/services/delegation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ export class DelegationService {
if (isValidMsaId) {
const { providerId } = this.configService;

const commonPrimitivesMsaDelegation = await this.blockchainService.getCommonPrimitivesMsaDelegation(
msaId,
providerId,
);
const commonPrimitivesMsaDelegation = await this.blockchainService.getCommonPrimitivesMsaDelegation(msaId, providerId);

if (commonPrimitivesMsaDelegation) {
const delegationResponse: DelegationResponse = {
Expand Down
12 changes: 2 additions & 10 deletions services/account/apps/api/test/accounts.controller.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ describe('Account Controller', () => {
try {
await Promise.allSettled([
...users.map((u) => ExtrinsicHelper.retireHandle(u.keypair).signAndSend()),
ExtrinsicHelper.claimHandleWithProvider(
users[0].keypair,
provider.keypair,
handlePayload.proof,
handlePayload.payload,
).payWithCapacity(),
ExtrinsicHelper.claimHandleWithProvider(users[0].keypair, provider.keypair, handlePayload.proof, handlePayload.payload).payWithCapacity(),
]);
} catch (e) {
// do nothing
Expand Down Expand Up @@ -80,10 +75,7 @@ describe('Account Controller', () => {

it('(GET) /v1/accounts/:msaId with invalid msaId', async () => {
const invalidMsaId = BigInt(maxMsaId) + 1000n;
await request(app.getHttpServer())
.get(`/v1/accounts/${invalidMsaId.toString()}`)
.expect(400)
.expect({ statusCode: 400, message: 'Failed to find the account' });
await request(app.getHttpServer()).get(`/v1/accounts/${invalidMsaId.toString()}`).expect(400).expect({ statusCode: 400, message: 'Failed to find the account' });
});

it('(GET) /v1/accounts/:msaId with valid msaId and handle', async () => {
Expand Down
12 changes: 4 additions & 8 deletions services/account/apps/api/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ describe('Account Service E2E request verification!', () => {
await app.init();
});

it('(GET) /healthz', () =>
request(app.getHttpServer()).get('/healthz').expect(200).expect({ status: 200, message: 'Service is healthy' }));
it('(GET) /healthz', () => request(app.getHttpServer()).get('/healthz').expect(200).expect({ status: 200, message: 'Service is healthy' }));

it('(GET) /livez', () =>
request(app.getHttpServer()).get('/livez').expect(200).expect({ status: 200, message: 'Service is live' }));
it('(GET) /livez', () => request(app.getHttpServer()).get('/livez').expect(200).expect({ status: 200, message: 'Service is live' }));

it('(GET) /readyz', () =>
request(app.getHttpServer()).get('/readyz').expect(200).expect({ status: 200, message: 'Service is ready' }));
it('(GET) /readyz', () => request(app.getHttpServer()).get('/readyz').expect(200).expect({ status: 200, message: 'Service is ready' }));

describe('(POST) /accounts/siwf', () => {
it('Sign Up With Frequency request should work', async () => {
Expand Down Expand Up @@ -66,8 +63,7 @@ describe('Account Service E2E request verification!', () => {
siwsPayload: {
message:
'localhost wants you to sign in with your Frequency account:\n5Fghb4Wt3sg9cF6Q2Qucp5jXV5pL2U9uaYXwR9R8W8SYe9np\n\nThe domain localhost wants you to sign in with your Frequency account via localhost\n\nURI: http://localhost:5173/signin/confirm\nNonce: N6rLwqyz34oUxJEXJ\nIssued At: 2024-03-05T23:18:03.041Z\nExpiration Time: 2024-03-05T23:23:03.041Z',
signature:
'0x38faa2fc6f59bef8ffccfc929fb966e1d53ba45e3af7a029ea1d636eaddcbe78a4be0f89eaf7ff7bbaef20a070ad65f9d0f876889686687ef623214fddddb18b',
signature: '0x38faa2fc6f59bef8ffccfc929fb966e1d53ba45e3af7a029ea1d636eaddcbe78a4be0f89eaf7ff7bbaef20a070ad65f9d0f876889686687ef623214fddddb18b',
},
},
signUp: {
Expand Down
23 changes: 4 additions & 19 deletions services/account/apps/api/test/e2e-setup.mock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ export async function setupProviderAndUsers() {
* Generate an array of extrinsics to remove all but the "primary" control key
* from an MSA.
*/
export async function removeExtraKeysFromMsa({
msaId,
keypair,
}: {
msaId?: MessageSourceId | undefined;
keypair: KeyringPair;
}): Promise<void> {
export async function removeExtraKeysFromMsa({ msaId, keypair }: { msaId?: MessageSourceId | undefined; keypair: KeyringPair }): Promise<void> {
if (!msaId) {
return;
}
Expand All @@ -64,24 +58,15 @@ export async function removeExtraKeysFromMsa({
}

export async function generateSignedAddKeyPayload(user: ChainUser, newKeys: KeyringPair, currentBlockNumber?: number) {
const payload = await generateAddKeyPayload(
{ msaId: user.msaId!, newPublicKey: newKeys.publicKey },
undefined,
currentBlockNumber,
);
const payload = await generateAddKeyPayload({ msaId: user.msaId!, newPublicKey: newKeys.publicKey }, undefined, currentBlockNumber);
const addKeyData = ExtrinsicHelper.api.registry.createType('PalletMsaAddKeyData', payload);
const ownerProof = signPayloadSr25519(user.keypair, addKeyData);
const newKeyProof = signPayloadSr25519(newKeys, addKeyData);

return { payload, ownerProof, newKeyProof };
}

export async function generateAddPublicKeyExtrinsic(
user: ChainUser,
newKeys: KeyringPair,
currentBlockNumber?: number,
) {
export async function generateAddPublicKeyExtrinsic(user: ChainUser, newKeys: KeyringPair, currentBlockNumber?: number) {
const { payload, ownerProof, newKeyProof } = await generateSignedAddKeyPayload(user, newKeys, currentBlockNumber);
return () =>
ExtrinsicHelper.apiPromise.tx.msa.addPublicKeyToMsa(user.keypair.publicKey, ownerProof, newKeyProof, payload);
return () => ExtrinsicHelper.apiPromise.tx.msa.addPublicKeyToMsa(user.keypair.publicKey, ownerProof, newKeyProof, payload);
}
28 changes: 5 additions & 23 deletions services/account/apps/api/test/handles.controller.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ describe('Handles Controller', () => {
let users: ChainUser[];
let provider: ChainUser;
let currentBlockNumber: number;
const handles = new Array(2)
.fill(0)
.map(() => uniqueNamesGenerator({ dictionaries: [colors, names], separator: '', length: 2, style: 'capital' }));
const handles = new Array(2).fill(0).map(() => uniqueNamesGenerator({ dictionaries: [colors, names], separator: '', length: 2, style: 'capital' }));
let maxMsaId: string;

beforeAll(async () => {
Expand All @@ -33,18 +31,8 @@ describe('Handles Controller', () => {
try {
await Promise.allSettled([
...users.map((u) => ExtrinsicHelper.retireHandle(u.keypair).signAndSend()),
ExtrinsicHelper.claimHandleWithProvider(
users[0].keypair,
provider.keypair,
handlePayloads[0].proof,
handlePayloads[0].payload,
).payWithCapacity(),
ExtrinsicHelper.claimHandleWithProvider(
users[1].keypair,
provider.keypair,
handlePayloads[1].proof,
handlePayloads[1].payload,
).payWithCapacity(),
ExtrinsicHelper.claimHandleWithProvider(users[0].keypair, provider.keypair, handlePayloads[0].proof, handlePayloads[0].payload).payWithCapacity(),
ExtrinsicHelper.claimHandleWithProvider(users[1].keypair, provider.keypair, handlePayloads[1].proof, handlePayloads[1].payload).payWithCapacity(),
]);
} catch (e) {
// do nothing
Expand Down Expand Up @@ -125,18 +113,12 @@ describe('Handles Controller', () => {
// User users[3], known to have no handle
const user = users[3];
const msaIdWithNoHandle = user.msaId?.toString();
await request(HTTP_SERVER)
.get(`/v1/handles/${msaIdWithNoHandle}`)
.expect(404)
.expect({ statusCode: 404, message: 'No handle found for MSA' });
await request(HTTP_SERVER).get(`/v1/handles/${msaIdWithNoHandle}`).expect(404).expect({ statusCode: 404, message: 'No handle found for MSA' });
});

it('(GET) /handles/:msaId with invalid msaId', async () => {
const invalidMsaId = BigInt(maxMsaId) + 1000n;
await request(HTTP_SERVER)
.get(`/v1/handles/${invalidMsaId.toString()}`)
.expect(400)
.expect({ statusCode: 400, message: 'Invalid msaId.' });
await request(HTTP_SERVER).get(`/v1/handles/${invalidMsaId.toString()}`).expect(400).expect({ statusCode: 400, message: 'Invalid msaId.' });
});
});
});
13 changes: 2 additions & 11 deletions services/account/apps/api/test/keys.controller.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { KeysRequest } from '#lib/types/dtos/keys.request.dto';
import { AddKeyData, ChainUser, ExtrinsicHelper, createKeys } from '@projectlibertylabs/frequency-scenario-template';
import { KeyringPair } from '@polkadot/keyring/types';
import { ApiModule } from '../src/api.module';
import {
generateAddPublicKeyExtrinsic,
removeExtraKeysFromMsa,
generateSignedAddKeyPayload,
setupProviderAndUsers,
} from './e2e-setup.mock.spec';
import { generateAddPublicKeyExtrinsic, removeExtraKeysFromMsa, generateSignedAddKeyPayload, setupProviderAndUsers } from './e2e-setup.mock.spec';

let HTTP_SERVER: any = process.env.HTTP_SERVER || 'http://0.0.0.0:3000';

Expand Down Expand Up @@ -76,11 +71,7 @@ describe('Keys Controller', () => {
// users[2] should have a single key, this will (eventually) add another
const user = users[2];
const newKeypair = createKeys();
const { payload, ownerProof, newKeyProof } = await generateSignedAddKeyPayload(
user,
newKeypair,
currentBlockNumber,
);
const { payload, ownerProof, newKeyProof } = await generateSignedAddKeyPayload(user, newKeypair, currentBlockNumber);
const keysRequest: KeysRequest = {
msaOwnerAddress: user.keypair.address,
msaOwnerSignature: ownerProof.Sr25519,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,10 @@ import {
} from '#lib/types/dtos/transaction.request.dto';
import { ITxStatus } from '#lib/interfaces/tx-status.interface';

export function createWebhookRsp(
txStatus: ITxStatus,
msaId: string,
options: PublishHandleOpts,
): PublishHandleWebhookRsp;
export function createWebhookRsp(txStatus: ITxStatus, msaId: string, options: PublishHandleOpts): PublishHandleWebhookRsp;
export function createWebhookRsp(txStatus: ITxStatus, msaId: string, options: SIWFOpts): SIWFWebhookRsp;
export function createWebhookRsp(txStatus: ITxStatus, msaId: string, options: PublishKeysOpts): PublishKeysWebhookRsp;
export function createWebhookRsp(
{ type: transactionType, providerId, referenceId }: ITxStatus,
msaId: string,
options: TxWebhookOpts,
): unknown {
export function createWebhookRsp({ type: transactionType, providerId, referenceId }: ITxStatus, msaId: string, options: TxWebhookOpts): unknown {
return {
transactionType,
providerId,
Expand Down
Loading

0 comments on commit dcb8211

Please sign in to comment.