Skip to content

Commit

Permalink
Merge pull request #5658 from LiskHQ/5598-fix-data-path
Browse files Browse the repository at this point in the history
Plugins data should be associated to the data path of the application - Closes #5598
  • Loading branch information
ManuGowda committed Aug 18, 2020
2 parents b1d9b1e + 08b0aaa commit a07b493
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
3 changes: 1 addition & 2 deletions framework-plugins/lisk-framework-forger-plugin/src/db.ts
Expand Up @@ -29,8 +29,7 @@ export const getDBInstance = async (
dataPath: string,
dbName = 'lisk-framework-forger-plugin.db',
): Promise<KVStore> => {
const resolvedPath = dataPath.replace('~', os.homedir());
const dirPath = join(resolvedPath, dbName);
const dirPath = join(dataPath.replace('~', os.homedir()), 'plugins/data', dbName);
await ensureDir(dirPath);

return new KVStore(dirPath);
Expand Down
Expand Up @@ -29,15 +29,6 @@ export const defaultConfig = {
description:
'Explicitly allowing some identified entities access to forger plugin endpoints.',
},
dataPath: {
type: 'string',
format: 'path',
minLength: 1,
maxLength: 50,
example: '~/.lisk/plugins/data',
description:
'The data path for storing forging related information captured from application.',
},
webhook: {
type: 'array',
description: 'Third party API endpoints with configurable events to emit.',
Expand Down Expand Up @@ -71,6 +62,13 @@ export const defaultConfig = {
},
required: ['origin'],
},
dataPath: {
type: 'string',
format: 'path',
example: '~/.lisk/forger',
description:
'The data path for storing forging related information captured from application.',
},
limits: {
type: 'object',
properties: {
Expand Down Expand Up @@ -105,7 +103,6 @@ export const defaultConfig = {
port: 4001,
whiteList: ['127.0.0.1'],
webhook: [],
dataPath: '~/.lisk/plugins/data',
cors: {
origin: '*',
methods: ['GET', 'POST', 'PUT'],
Expand Down
@@ -0,0 +1,45 @@
/*
* Copyright © 2020 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import * as fs from 'fs-extra';
import { homedir } from 'os';
import { join } from 'path';
import { getDBInstance } from '../../src/db';

jest.mock('fs-extra');
jest.mock('@liskhq/lisk-db');
const mockedFsExtra = fs as jest.Mocked<typeof fs>;

describe('Plugins DB', () => {
const unresolvedRootPath = '~/.lisk/devnet';
const dbName = 'lisk-framework-forger-plugin.db';

it('should resolve to data directory', async () => {
await getDBInstance(unresolvedRootPath);
const rootPath = unresolvedRootPath.replace('~', homedir());
const dirPath = join(rootPath, 'plugins/data', dbName);

expect(mockedFsExtra.ensureDir).toBeCalledWith(dirPath);
});

it('should resolve to default plugin data path', async () => {
const customUnresolvedRootPath = '~/.lisk/devnet/custom/path';

await getDBInstance(customUnresolvedRootPath);
const rootPath = customUnresolvedRootPath.replace('~', homedir());
const dirPath = join(rootPath, 'plugins/data', dbName);

expect(mockedFsExtra.ensureDir).toBeCalledWith(dirPath);
});
});
2 changes: 1 addition & 1 deletion framework/src/controller/controller.ts
Expand Up @@ -119,7 +119,7 @@ export class Controller {

for (const alias of Object.keys(plugins)) {
const klass = plugins[alias];
const options = pluginOptions[alias];
const options = { dataPath: this.config.rootPath, ...pluginOptions[alias] };

if (options.loadAsChildProcess) {
if (this.config.ipc.enabled) {
Expand Down
4 changes: 2 additions & 2 deletions framework/test/unit/specs/controller/controller.spec.ts
Expand Up @@ -191,8 +191,8 @@ describe('Controller Class', () => {
};

pluginOptions = {
plugin1: { option: '#OPTIONS1' },
plugin2: { option2: '#OPTIONS2' },
plugin1: { option: '#OPTIONS1', dataPath: '~/.lisk/#LABEL' },
plugin2: { option2: '#OPTIONS2', dataPath: '~/.lisk/#LABEL' },
};

await controller.load();
Expand Down

0 comments on commit a07b493

Please sign in to comment.