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

Commit

Permalink
Merge branch 'hotfix/3.0.1' of github.com:LiskHQ/lisk-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuGowda committed Jan 24, 2020
2 parents 6cff472 + 503d055 commit 26da27f
Show file tree
Hide file tree
Showing 59 changed files with 287 additions and 241 deletions.
9 changes: 7 additions & 2 deletions commander/src/commands/core/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ import {
startDatabase,
stopDatabase,
} from '../../utils/core/database';
import { describeApplication, registerApplication } from '../../utils/core/pm2';
import {
describeApplication,
registerApplication,
unRegisterApplication,
} from '../../utils/core/pm2';
import { getReleaseInfo } from '../../utils/core/release';
import { download, downloadAndValidate, extract } from '../../utils/download';
import { flags as commonFlags } from '../../utils/flags';
Expand Down Expand Up @@ -318,12 +322,13 @@ export default class InstallCommand extends BaseCommand {
return;
}
} catch (error) {
this.error(JSON.stringify(error));
await unRegisterApplication(name);
const { installDir }: Options = error.context.options;
const dirPath = installDir.substr(0, installDir.length - 1);

fsExtra.emptyDirSync(installDir);
fsExtra.rmdirSync(dirPath);
this.error(JSON.stringify(error));
}
}
}
11 changes: 5 additions & 6 deletions commander/src/commands/network-identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import { flags as commonFlags } from '../utils/flags';

export default class NetworkIdentifierCommand extends BaseCommand {
static description = `
Creates Network identifier for the given nethash and community identifier.
Creates Network identifier for the given genesis payload hash and community identifier.
`;

static examples = [
'network-identifier --nethash=da3ed6a45429278bac2666961289ca17ad86595d33b31037615d4b8e8f158bba',
'network-identifier da3ed6a45429278bac2666961289ca17ad86595d33b31037615d4b8e8f158bba',
];

static args = [
{
name: 'nethash',
name: 'genesisPayloadHash',
description: 'Payload hash of genesis block from the network.',
required: true,
},
Expand All @@ -48,11 +48,10 @@ export default class NetworkIdentifierCommand extends BaseCommand {
async run(): Promise<void> {
const {
flags: { 'community-identifier': communityIdentifier },
args: { nethash },
args: { genesisPayloadHash },
} = this.parse(NetworkIdentifierCommand);

const networkIdentifier = getNetworkIdentifier(
nethash as string,
genesisPayloadHash as string,
communityIdentifier as string,
);
this.print({ networkIdentifier });
Expand Down
4 changes: 2 additions & 2 deletions commander/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const getAPIClient = ({
nodes,
network,
}: APIClientOptions): APIClient => {
const nethash = NETHASHES[network] || network;
const genesisBlockPayloadHash = NETHASHES[network] || network;
const clientNodes = nodes && nodes.length > 0 ? nodes : seedNodes[network];

return new APIClient(clientNodes, { nethash });
return new APIClient(clientNodes, { genesisBlockPayloadHash });
};
29 changes: 16 additions & 13 deletions commander/test/commands/config/set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,22 @@ describe('config:set', () => {
setupTest()
.stdout()
.command(['config:set', 'api.network', validNethash])
.it('should set api.network to the custom nethash', () => {
const newConfig = {
...defaultConfig,
api: {
network: validNethash,
nodes: defaultConfig.api.nodes,
},
};
return expect(config.setConfig).to.be.calledWith(
defaultDir,
newConfig,
);
});
.it(
'should set api.network to the custom genesisBlockPayloadHash',
() => {
const newConfig = {
...defaultConfig,
api: {
network: validNethash,
nodes: defaultConfig.api.nodes,
},
};
return expect(config.setConfig).to.be.calledWith(
defaultDir,
newConfig,
);
},
);

setupTest()
.stdout()
Expand Down
6 changes: 3 additions & 3 deletions commander/test/commands/network-identifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import NetworkIdentifierCommand from '../../src/commands/network-identifier';
describe('network-identifier command', () => {
const networkIdentifier = {
networkIdentifier:
'00adc544a063705a317d573ac2c2d88df717b9b7d472880ed4de7a830f611818',
'7dbdc2b4694bd5ab6663c4d078aa628ae032cb91ce0fe03a5077d7ef3ba2e8bc',
};

const networkIdentifierStub = sandbox.stub();
Expand Down Expand Up @@ -55,9 +55,9 @@ describe('network-identifier command', () => {
.it('should throw an error');
});

describe('network-identifier --nethash=123', () => {
describe('network-identifier 123', () => {
setupTest()
.command(['network-identifier', '--nethash=123'])
.command(['network-identifier', '123'])
.it('should show networkIdentifier', () => {
return expect(printMethodStub).to.be.calledWithExactly(
networkIdentifier,
Expand Down
8 changes: 5 additions & 3 deletions elements/lisk-api-client/src/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ export class APIClient {

public static createMainnetAPIClient(options?: InitOptions): APIClient {
return new APIClient(constants.MAINNET_NODES, {
nethash: constants.MAINNET_NETHASH,
genesisBlockPayloadHash: constants.MAINNET_NETHASH,
...options,
});
}

public static createTestnetAPIClient(options?: InitOptions): APIClient {
return new APIClient(constants.TESTNET_NODES, {
nethash: constants.TESTNET_NETHASH,
genesisBlockPayloadHash: constants.TESTNET_NETHASH,
...options,
});
}
Expand Down Expand Up @@ -173,7 +173,9 @@ export class APIClient {

this.headers = {
...commonHeaders,
...(options.nethash ? { nethash: options.nethash } : {}),
...(options.genesisBlockPayloadHash
? { nethash: options.genesisBlockPayloadHash }
: {}),
...(options.client ? getClientHeaders(options.client) : {}),
};

Expand Down
2 changes: 1 addition & 1 deletion elements/lisk-api-client/src/api_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface HashMap {
export interface InitOptions {
readonly bannedNodes?: ReadonlyArray<string>;
readonly client?: object;
readonly nethash?: string;
readonly genesisBlockPayloadHash?: string;
readonly node?: string;
readonly randomizeNodes?: boolean;
}
Expand Down
6 changes: 3 additions & 3 deletions elements/lisk-api-client/test/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('APIClient module', () => {

it('should call initialize with the nodes and provided options', () => {
const providedOptions = {
nethash:
genesisBlockPayloadHash:
'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
};
apiClient = new APIClient(defaultNodes, providedOptions);
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('APIClient module', () => {

it('should set custom headers with supplied options', () => {
apiClient = new APIClient(defaultNodes, {
nethash: testnetHash,
genesisBlockPayloadHash: testnetHash,
client: {
name: 'LiskHub',
version: '5.0',
Expand All @@ -216,7 +216,7 @@ describe('APIClient module', () => {

it('should not set User-Agent header when client options were not given', () => {
apiClient = new APIClient(defaultNodes, {
nethash: testnetHash,
genesisBlockPayloadHash: testnetHash,
});
return expect(apiClient.headers).to.not.have.property('User-Agent');
});
Expand Down
5 changes: 3 additions & 2 deletions elements/lisk-cryptography/src/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const hash = (data: Buffer | string, format?: string): Buffer => {
};

export const getNetworkIdentifier = (
nethash: string,
genesisBlockPayloadHash: string,
communityIdentifier: string,
) => hash(nethash + communityIdentifier, 'utf8').toString('hex');
) =>
hash(genesisBlockPayloadHash + communityIdentifier, 'utf8').toString('hex');
6 changes: 3 additions & 3 deletions elements/lisk-cryptography/test/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ describe('hash', () => {
});

describe('#getNetworkIdentifier', () => {
const nethash =
const genesisBlockPayloadHash =
'ed14889723f24ecc54871d058d98ce91ff2f973192075c0155ba2b7b70ad2511';
const communityIdentifier = 'LISK';
const expectedHash =
'30d7505655f5a04d9238aa324b38ef729d1139791b67815c5e6306328b6a44a2';

it('should generate a sha256 hash from nethash and community identifier', () => {
it('should generate a sha256 hash from Genesis Block Payload Hash and community identifier', () => {
const networkIdentifier = getNetworkIdentifier(
nethash,
genesisBlockPayloadHash,
communityIdentifier,
);

Expand Down
6 changes: 6 additions & 0 deletions elements/lisk-elements/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions elements/lisk-elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,20 @@
"@liskhq/lisk-api-client": "3.0.0",
"@liskhq/lisk-constants": "1.3.0",
"@liskhq/lisk-cryptography": "2.4.0",
"@liskhq/lisk-p2p": "0.4.0",
"@liskhq/lisk-passphrase": "3.0.0",
"@liskhq/lisk-transaction-pool": "0.2.0",
"@liskhq/lisk-transactions": "3.0.0",
"@liskhq/lisk-validator": "0.3.0",
"@types/node": "12.12.11"
},
"devDependencies": {
"@types/chai": "4.1.7",
"@types/expect": "1.20.3",
"@types/jquery": "3.3.29",
"@types/mocha": "5.2.5",
"@babel/preset-env": "7.8.3",
"babelify": "10.0.0",
"browserify": "16.2.3",
"chai": "4.2.0",
"cypress": "3.4.1",
Expand Down
9 changes: 6 additions & 3 deletions elements/lisk-elements/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
import { APIClient } from '@liskhq/lisk-api-client';
import * as constants from '@liskhq/lisk-constants';
import * as cryptography from '@liskhq/lisk-cryptography';
import * as p2p from '@liskhq/lisk-p2p';
import * as passphrase from '@liskhq/lisk-passphrase';
import * as transacationPool from '@liskhq/lisk-transaction-pool';
import * as transactions from '@liskhq/lisk-transactions';
import * as validator from '@liskhq/lisk-validator';

export {
APIClient,
constants,
cryptography,
passphrase,
p2p,
transactions,
// Also export as `transacation` for backward compatibility.
// See https://github.com/LiskHQ/lisk-sdk/issues/3925#issuecomment-508664703
transactions as transaction,
transacationPool,
validator,
};
16 changes: 13 additions & 3 deletions elements/lisk-elements/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import {
APIClient,
constants,
cryptography,
p2p,
passphrase,
transacationPool,
transactions,
transaction,
validator,
} from '../src';

describe('lisk-elements', () => {
Expand All @@ -35,15 +37,23 @@ describe('lisk-elements', () => {
return expect(cryptography).to.be.an('object');
});

it('p2p should be an object', () => {
return expect(p2p).to.be.an('object');
});

it('passphrase should be an object', () => {
return expect(passphrase).to.be.an('object');
});

it('transactionPool should be an object', () => {
return expect(transacationPool).to.be.an('object');
});

it('transactions should be an object', () => {
return expect(transactions).to.be.an('object');
});

it('transaction should be an object', () => {
return expect(transaction).to.be.an('object');
it('validator should be an object', () => {
return expect(validator).to.be.an('object');
});
});
14 changes: 8 additions & 6 deletions elements/lisk-p2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
export * from './constants';
export * from './errors';
export * from './events';
export * from './p2p_request';
export * from './p2p_types';
export * from './p2p';
import * as constants from './constants';
import * as errors from './errors';
import * as events from './events';
import { P2P } from './p2p';
import * as p2p_request from './p2p_request';
import * as p2p_types from './p2p_types';

export { constants, errors, events, p2p_request, p2p_types, P2P };
8 changes: 3 additions & 5 deletions elements/lisk-p2p/test/functional/actions/apply_node_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import {
P2P,
EVENT_MESSAGE_RECEIVED,
REMOTE_EVENT_POST_NODE_INFO,
} from '../../../src/index';
import { P2P, events } from '../../../src/index';
import { InvalidNodeInfoError } from '../../../src/errors';
import { wait } from '../../utils/helpers';
import { platform } from 'os';
import { createNetwork, destroyNetwork } from '../../utils/network_setup';

const { EVENT_MESSAGE_RECEIVED, REMOTE_EVENT_POST_NODE_INFO } = events;

describe('P2P.applyNodeInfo', () => {
let p2pNodeList: P2P[] = [];
let collectedMessages: Array<any> = [];
Expand Down
11 changes: 4 additions & 7 deletions elements/lisk-p2p/test/functional/actions/peer_banning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import { P2P, ProtocolPeerInfo } from '../../../src/index';
import { wait } from '../../utils/helpers';
import {
createNetwork,
destroyNetwork,
SEED_PEER_IP,
} from '../../utils/network_setup';
import {
EVENT_BAN_PEER,
EVENT_UNBAN_PEER,
EVENT_CLOSE_INBOUND,
} from '../../../src/index';
import { P2P, events, p2p_types } from '../../../src/index';

const { EVENT_BAN_PEER, EVENT_UNBAN_PEER, EVENT_CLOSE_INBOUND } = events;

describe('Peer banning mechanism', () => {
let p2pNodeList: ReadonlyArray<P2P> = [];
Expand Down Expand Up @@ -59,7 +56,7 @@ describe('Peer banning mechanism', () => {
});

describe('when penalty is 100 or more', () => {
let badPeer: ProtocolPeerInfo;
let badPeer: p2p_types.ProtocolPeerInfo;

beforeEach(async () => {
const firstNode = p2pNodeList[0];
Expand Down
Loading

0 comments on commit 26da27f

Please sign in to comment.