Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Fix duplicate schema $id and add github action check (#8594)
Browse files Browse the repository at this point in the history
* 🌱 Fix duplicate schema $id and add github action check

* ✅ Fix tests

* ✅ Fix tests

* ♻️ Update script
  • Loading branch information
shuse2 committed Jun 19, 2023
1 parent c4e9d75 commit 89085a6
Show file tree
Hide file tree
Showing 23 changed files with 145 additions and 290 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
exit 1
fi
- run: yarn lint:since --base ${{ github.base_ref }}
- name: Check duplicate schema
run: |
node scripts/duplicate_schema_id.js ./
unit-test:
runs-on: ubuntu-latest
Expand Down
26 changes: 1 addition & 25 deletions commander/src/bootstrapping/commands/keys/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,7 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import { flagsWithParser } from '../../../utils/flags';
import { getPassphraseFromPrompt, getPasswordFromPrompt } from '../../../utils/reader';
import { OWNER_READ_WRITE } from '../../../constants';

export const plainGeneratorKeysSchema = {
$id: '/commander/plainGeneratorKeys',
type: 'object',
required: ['generatorKey', 'generatorPrivateKey', 'blsKey', 'blsPrivateKey'],
properties: {
generatorKey: {
dataType: 'bytes',
fieldNumber: 1,
},
generatorPrivateKey: {
dataType: 'bytes',
fieldNumber: 2,
},
blsKey: {
dataType: 'bytes',
fieldNumber: 3,
},
blsPrivateKey: {
dataType: 'bytes',
fieldNumber: 4,
},
},
};
import { OWNER_READ_WRITE, plainGeneratorKeysSchema } from '../../../constants';

export class CreateCommand extends Command {
static description = 'Return keys corresponding to the given passphrase.';
Expand Down
26 changes: 1 addition & 25 deletions commander/src/bootstrapping/commands/keys/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Command, Flags as flagParser } from '@oclif/core';
import * as fs from 'fs-extra';
import { flagsWithParser } from '../../../utils/flags';
import { getPasswordFromPrompt } from '../../../utils/reader';
import { OWNER_READ_WRITE } from '../../../constants';
import { OWNER_READ_WRITE, plainGeneratorKeysSchema } from '../../../constants';

interface KeysWithoutEncryption {
keys: [
Expand All @@ -35,30 +35,6 @@ interface KeysWithoutEncryption {
];
}

const plainGeneratorKeysSchema = {
$id: '/commander/plainGeneratorKeys',
type: 'object',
required: ['generatorKey', 'generatorPrivateKey', 'blsKey', 'blsPrivateKey'],
properties: {
generatorKey: {
dataType: 'bytes',
fieldNumber: 1,
},
generatorPrivateKey: {
dataType: 'bytes',
fieldNumber: 2,
},
blsKey: {
dataType: 'bytes',
fieldNumber: 3,
},
blsPrivateKey: {
dataType: 'bytes',
fieldNumber: 4,
},
},
};

export class EncryptCommand extends Command {
static description = 'Encrypt keys from a file and overwrite the file';

Expand Down
23 changes: 23 additions & 0 deletions commander/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,26 @@ export enum NETWORK {
export const DEFAULT_NETWORK = NETWORK.DEFAULT;
export const RELEASE_URL = 'https://downloads.lisk.com/lisk';
export const OWNER_READ_WRITE = 0o600;

export const plainGeneratorKeysSchema = {
$id: '/commander/plainGeneratorKeys',
type: 'object',
properties: {
generatorKey: {
dataType: 'bytes',
fieldNumber: 1,
},
generatorPrivateKey: {
dataType: 'bytes',
fieldNumber: 2,
},
blsKey: {
dataType: 'bytes',
fieldNumber: 3,
},
blsPrivateKey: {
dataType: 'bytes',
fieldNumber: 4,
},
},
};
3 changes: 1 addition & 2 deletions commander/test/bootstrapping/commands/keys/export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import * as fs from 'fs-extra';
import * as appUtils from '../../../../src/utils/application';
import { ExportCommand } from '../../../../src/bootstrapping/commands/keys/export';
import { getConfig } from '../../../helpers/config';
import { plainGeneratorKeysSchema } from '../../../../src/bootstrapping/commands/keys/create';
import { Awaited } from '../../../types';
import { OWNER_READ_WRITE } from '../../../../src/constants';
import { OWNER_READ_WRITE, plainGeneratorKeysSchema } from '../../../../src/constants';

describe('keys:export', () => {
const defaultPassword = 'elephant tree paris dragon chair galaxy';
Expand Down
2 changes: 1 addition & 1 deletion commander/test/bootstrapping/commands/keys/import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import * as fs from 'fs-extra';
import * as appUtils from '../../../../src/utils/application';
import { ImportCommand } from '../../../../src/bootstrapping/commands/keys/import';
import { getConfig } from '../../../helpers/config';
import { plainGeneratorKeysSchema } from '../../../../src/bootstrapping/commands/keys/create';
import { Awaited } from '../../../types';
import { plainGeneratorKeysSchema } from '../../../../src/constants';

describe('keys:import', () => {
const defaultPassword = 'elephant tree paris dragon chair galaxy';
Expand Down
13 changes: 10 additions & 3 deletions commander/test/bootstrapping/commands/transaction/prompt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '../../../../src/utils/reader';
import {
tokenTransferParamsSchema,
keysRegisterParamsSchema,
registerMultisignatureParamsSchema,
posVoteParamsSchema,
} from '../../../helpers/transactions';

Expand All @@ -43,11 +43,12 @@ describe('prompt', () => {

describe('transformAsset', () => {
it('should transform result according to asset schema', () => {
const questions = prepareQuestions(keysRegisterParamsSchema);
const transformedAsset = transformAsset(keysRegisterParamsSchema, {
const questions = prepareQuestions(registerMultisignatureParamsSchema);
const transformedAsset = transformAsset(registerMultisignatureParamsSchema, {
numberOfSignatures: '4',
mandatoryKeys: 'a,b',
optionalKeys: 'c,d',
signatures: '',
});
expect(questions).toEqual([
{
Expand All @@ -65,11 +66,17 @@ describe('prompt', () => {
name: 'optionalKeys',
message: 'Please enter: optionalKeys(comma separated values (a,b)): ',
},
{
type: 'input',
name: 'signatures',
message: 'Please enter: signatures(comma separated values (a,b)): ',
},
]);
expect(transformedAsset).toEqual({
numberOfSignatures: 4,
mandatoryKeys: ['a', 'b'],
optionalKeys: ['c', 'd'],
signatures: [''],
});
});
});
Expand Down
43 changes: 4 additions & 39 deletions commander/test/helpers/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const account = {
address: '9cabee3d27426676b852ce6b804cb2fdff7cd0b5',
};
export const multisigRegMsgSchema = {
$id: '/auth/command/regMultisigMsg',
$id: '/test/auth/command/regMultisigMsg',
type: 'object',
required: ['address', 'nonce', 'numberOfSignatures', 'mandatoryKeys', 'optionalKeys'],
properties: {
Expand Down Expand Up @@ -64,7 +64,7 @@ export const multisigRegMsgSchema = {
};

export const registerMultisignatureParamsSchema = {
$id: '/auth/command/regMultisig',
$id: '/test/auth/command/regMultisig',
type: 'object',
properties: {
numberOfSignatures: {
Expand Down Expand Up @@ -109,7 +109,7 @@ export const registerMultisignatureParamsSchema = {
};

export const tokenTransferParamsSchema = {
$id: '/lisk/transferCommand',
$id: '/test/lisk/transferCommand',
title: 'Transfer transaction command',
type: 'object',
required: ['tokenID', 'amount', 'recipientAddress', 'data'],
Expand All @@ -136,43 +136,8 @@ export const tokenTransferParamsSchema = {
},
};

export const keysRegisterParamsSchema = {
$id: '/auth/command/regMultisig',
type: 'object',
properties: {
numberOfSignatures: {
dataType: 'uint32',
fieldNumber: 1,
minimum: 1,
maximum: 64,
},
mandatoryKeys: {
type: 'array',
items: {
dataType: 'bytes',
minLength: 32,
maxLength: 32,
},
fieldNumber: 2,
minItems: 0,
maxItems: 64,
},
optionalKeys: {
type: 'array',
items: {
dataType: 'bytes',
minLength: 32,
maxLength: 32,
},
fieldNumber: 3,
minItems: 0,
maxItems: 64,
},
},
required: ['numberOfSignatures', 'mandatoryKeys', 'optionalKeys'],
};
export const posVoteParamsSchema = {
$id: '/pos/command/stakeParams',
$id: '/test/pos/command/stakeParams',
type: 'object',
required: ['stakes'],
properties: {
Expand Down
2 changes: 1 addition & 1 deletion elements/lisk-api-client/src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
const EVENT_COMMAND_EXECUTION_RESULT = 'commandExecutionResult';

const standardEventDataSchema = {
$id: '/block/event/standard',
$id: '/block/event/standard/ui',
type: 'object',
required: ['success'],
properties: {
Expand Down
2 changes: 1 addition & 1 deletion elements/lisk-api-client/test/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const metadata: ModuleMetadata[] = [
{
name: 'validatorStaked',
data: {
$id: '/pos/events/validatorStakedData',
$id: '/test/pos/events/validatorStakedData',
type: 'object',
required: ['senderAddress', 'validatorAddress', 'amount', 'result'],
properties: {
Expand Down
2 changes: 1 addition & 1 deletion elements/lisk-chain/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const signingBlockHeaderSchema = {

export const blockHeaderSchema = {
...signingBlockHeaderSchema,
$id: '/block/header/3',
$id: '/block/header/3/without-id',
required: [...signingBlockHeaderSchema.required, 'signature'],
properties: {
...signingBlockHeaderSchema.properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`block_header blockHeaderSchema should be valid schema with signature but without id 1`] = `
{
"$id": "/block/header/3",
"$id": "/block/header/3/without-id",
"properties": {
"aggregateCommit": {
"fieldNumber": 14,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const MIN_MODULE_NAME_LENGTH = 1;
export const MAX_MODULE_NAME_LENGTH = 32;

const userStoreSchema = {
$id: '/token/store/user',
$id: '/recover-lsk-plugin/token/store/user',
type: 'object',
required: ['availableBalance', 'lockedBalances'],
properties: {
Expand Down
2 changes: 1 addition & 1 deletion framework/src/abi/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
export { blockHeaderSchema, blockSchema };

export const eventSchema = {
$id: '/block/event',
$id: '/abi/block/event',
type: 'object',
required: ['module', 'name', 'data', 'topics', 'height', 'index'],
properties: {
Expand Down
2 changes: 1 addition & 1 deletion framework/src/controller/jsonrpc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const requestSchema = {
};

const notificationSchema = {
$id: '/jsonRPCRequestSchema',
$id: '/jsonRPCNotificationSchema',
type: 'object',
required: ['jsonrpc', 'method'],
properties: {
Expand Down
40 changes: 0 additions & 40 deletions framework/src/modules/auth/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,6 @@ import {
MAX_NUMBER_OF_SIGNATURES,
} from './constants';

export const authAccountSchema = {
$id: '/auth/account',
type: 'object',
properties: {
nonce: {
dataType: 'uint64',
fieldNumber: 1,
},
numberOfSignatures: {
dataType: 'uint32',
fieldNumber: 2,
minimum: 0,
maximum: MAX_NUMBER_OF_SIGNATURES,
},
mandatoryKeys: {
type: 'array',
items: {
dataType: 'bytes',
minLength: ED25519_PUBLIC_KEY_LENGTH,
maxLength: ED25519_PUBLIC_KEY_LENGTH,
},
minItems: 0,
maxItems: MAX_NUMBER_OF_SIGNATURES,
fieldNumber: 3,
},
optionalKeys: {
type: 'array',
items: {
dataType: 'bytes',
minLength: ED25519_PUBLIC_KEY_LENGTH,
maxLength: ED25519_PUBLIC_KEY_LENGTH,
},
minItems: 0,
maxItems: MAX_NUMBER_OF_SIGNATURES,
fieldNumber: 4,
},
},
required: ['nonce', 'numberOfSignatures', 'mandatoryKeys', 'optionalKeys'],
};

export const registerMultisignatureParamsSchema = {
$id: '/auth/command/regMultisig',
type: 'object',
Expand Down
Loading

0 comments on commit 89085a6

Please sign in to comment.