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

feat(dashmate): add protocol version to the status command #2255

Merged
merged 10 commits into from
Oct 19, 2024
6 changes: 6 additions & 0 deletions packages/dashmate/src/commands/status/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export default class PlatformStatusCommand extends ConfigBaseCommand {
'Drive Service Status': 'n/a',
'Network': 'n/a',
'Tenderdash Version': 'n/a',
'Protocol Version': 'n/a',
'Desired Protocol Version': 'n/a',
'Block height': 'n/a',
'Peer count': 'n/a',
'App hash': 'n/a',
Expand Down Expand Up @@ -92,6 +94,8 @@ export default class PlatformStatusCommand extends ConfigBaseCommand {
if (tenderdash.version) {
const {
version: tenderdashVersion,
protocolVersion,
desiredProtocolVersion,
latestBlockHeight: platformBlockHeight,
latestAppHash: platformLatestAppHash,
peers: platformPeers,
Expand All @@ -100,6 +104,8 @@ export default class PlatformStatusCommand extends ConfigBaseCommand {

plain['Network'] = tenderdashNetwork || 'n/a';
plain['Tenderdash Version'] = tenderdashVersion || 'n/a';
plain['Protocol Version'] = protocolVersion || 'n/a';
plain['Desired Protocol Version'] = desiredProtocolVersion || 'n/a';
plain['Block height'] = platformBlockHeight || 'n/a';
plain['Peer count'] = platformPeers || 'n/a';
plain['App hash'] = platformLatestAppHash || 'n/a';
Expand Down
17 changes: 15 additions & 2 deletions packages/dashmate/src/status/scopes/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export default function getPlatformScopeFactory(
dockerStatus: null,
serviceStatus: null,
version: null,
protocolVersion: null,
desiredProtocolVersion: null,
listening: null,
catchingUp: null,
latestBlockHash: null,
Expand Down Expand Up @@ -107,14 +109,20 @@ export default function getPlatformScopeFactory(

const port = config.get('platform.drive.tenderdash.rpc.port');

const [tenderdashStatusResponse, tenderdashNetInfoResponse] = await Promise.all([
const [
tenderdashStatusResponse,
tenderdashNetInfoResponse,
tenderdashAbciInfoResponse,
] = await Promise.all([
shumkov marked this conversation as resolved.
Show resolved Hide resolved
fetch(`http://${tenderdashHost}:${port}/status`),
fetch(`http://${tenderdashHost}:${port}/net_info`),
fetch(`http://${tenderdashHost}:${port}/abci_info`),
]);

const [tenderdashStatus, tenderdashNetInfo] = await Promise.all([
const [tenderdashStatus, tenderdashNetInfo, tenderdashAbciInfo] = await Promise.all([
tenderdashStatusResponse.json(),
tenderdashNetInfoResponse.json(),
tenderdashAbciInfoResponse.json(),
]);

const { version, network, moniker } = tenderdashStatus.node_info;
Expand All @@ -133,6 +141,8 @@ export default function getPlatformScopeFactory(
}

info.version = version;
info.protocolVersion = parseInt(tenderdashStatus.node_info.protocol_version.app, 10);
info.desiredProtocolVersion = tenderdashAbciInfo.response.app_version;
shumkov marked this conversation as resolved.
Show resolved Hide resolved
info.listening = listening;
info.latestBlockHeight = latestBlockHeight;
info.latestBlockTime = latestBlockTime;
Expand Down Expand Up @@ -245,6 +255,8 @@ export default function getPlatformScopeFactory(
dockerStatus: null,
serviceStatus: null,
version: null,
protocolVersion: null,
desiredProtocolVersion: null,
listening: null,
catchingUp: null,
latestBlockHash: null,
Expand All @@ -258,6 +270,7 @@ export default function getPlatformScopeFactory(
drive: {
dockerStatus: null,
serviceStatus: null,
version: null,
},
};

Expand Down
69 changes: 66 additions & 3 deletions packages/dashmate/test/unit/status/scopes/platform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ describe('getPlatformScopeFactory', () => {

const mockStatus = {
node_info: {
protocol_version: {
p2p: '10',
block: '14',
app: '3',
},
version: '0',
network: 'test',
moniker: 'test',
Expand All @@ -94,6 +99,15 @@ describe('getPlatformScopeFactory', () => {
};
const mockNetInfo = { n_peers: 6, listening: true };

const mockAbciInfo = {
response: {
version: '1.4.1',
app_version: 4,
last_block_height: 90,
last_block_app_hash: 's0CySQxgRg96DrnJ7HCsql+k/Sk4JiT3y0psCaUI3TI=',
},
};

const expectedScope = {
platformActivation: 'Activated (at height 1337)',
coreIsSynced: true,
Expand All @@ -109,6 +123,8 @@ describe('getPlatformScopeFactory', () => {
p2pPortState: PortStateEnum.OPEN,
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
protocolVersion: 3,
desiredProtocolVersion: 4,
version: '0',
listening: true,
catchingUp: false,
Expand All @@ -131,7 +147,9 @@ describe('getPlatformScopeFactory', () => {
.onFirstCall()
.returns(Promise.resolve({ json: () => Promise.resolve(mockStatus) }))
.onSecondCall()
.returns(Promise.resolve({ json: () => Promise.resolve(mockNetInfo) }));
.returns(Promise.resolve({ json: () => Promise.resolve(mockNetInfo) }))
.onThirdCall()
.resolves({ json: () => Promise.resolve(mockAbciInfo) });
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));

const scope = await getPlatformScope(config);
Expand All @@ -155,6 +173,11 @@ describe('getPlatformScopeFactory', () => {

const mockStatus = {
node_info: {
protocol_version: {
p2p: '10',
block: '14',
app: '3',
},
version: '0',
network: 'test',
moniker: 'test',
Expand All @@ -169,6 +192,15 @@ describe('getPlatformScopeFactory', () => {
};
const mockNetInfo = { n_peers: 6, listening: true };

const mockAbciInfo = {
response: {
version: '1.4.1',
app_version: 4,
last_block_height: 90,
last_block_app_hash: 's0CySQxgRg96DrnJ7HCsql+k/Sk4JiT3y0psCaUI3TI=',
},
};

const expectedScope = {
platformActivation: 'Activated (at height 1337)',
coreIsSynced: true,
Expand All @@ -185,6 +217,8 @@ describe('getPlatformScopeFactory', () => {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.syncing,
version: '0',
protocolVersion: 3,
desiredProtocolVersion: 4,
listening: true,
catchingUp: true,
latestBlockHash: 'DEADBEEF',
Expand All @@ -206,7 +240,9 @@ describe('getPlatformScopeFactory', () => {
.onFirstCall()
.returns(Promise.resolve({ json: () => Promise.resolve(mockStatus) }))
.onSecondCall()
.returns(Promise.resolve({ json: () => Promise.resolve(mockNetInfo) }));
.returns(Promise.resolve({ json: () => Promise.resolve(mockNetInfo) }))
.onThirdCall()
.resolves({ json: () => Promise.resolve(mockAbciInfo) });
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));

const scope = await getPlatformScope(config);
Expand Down Expand Up @@ -238,6 +274,8 @@ describe('getPlatformScopeFactory', () => {
dockerStatus: null,
serviceStatus: null,
version: null,
protocolVersion: null,
desiredProtocolVersion: null,
listening: null,
catchingUp: null,
latestBlockHash: null,
Expand All @@ -251,6 +289,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: null,
serviceStatus: null,
version: null,
},
};

Expand Down Expand Up @@ -290,6 +329,8 @@ describe('getPlatformScopeFactory', () => {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.wait_for_core,
version: null,
protocolVersion: null,
desiredProtocolVersion: null,
listening: null,
catchingUp: null,
latestBlockHash: null,
Expand Down Expand Up @@ -347,6 +388,8 @@ describe('getPlatformScopeFactory', () => {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.error,
version: null,
protocolVersion: null,
desiredProtocolVersion: null,
listening: null,
catchingUp: null,
latestBlockHash: null,
Expand Down Expand Up @@ -393,6 +436,11 @@ describe('getPlatformScopeFactory', () => {

const mockStatus = {
node_info: {
protocol_version: {
p2p: '10',
block: '14',
app: '3',
},
version: '0',
network: 'test',
moniker: 'test',
Expand All @@ -407,11 +455,22 @@ describe('getPlatformScopeFactory', () => {
};
const mockNetInfo = { n_peers: 6, listening: true };

const mockAbciInfo = {
response: {
version: '1.4.1',
app_version: 4,
last_block_height: 90,
last_block_app_hash: 's0CySQxgRg96DrnJ7HCsql+k/Sk4JiT3y0psCaUI3TI=',
},
};

mockFetch
.onFirstCall()
.returns(Promise.resolve({ json: () => Promise.resolve(mockStatus) }))
.onSecondCall()
.returns(Promise.resolve({ json: () => Promise.resolve(mockNetInfo) }));
.returns(Promise.resolve({ json: () => Promise.resolve(mockNetInfo) }))
.onThirdCall()
.resolves({ json: () => Promise.resolve(mockAbciInfo) });

const expectedScope = {
platformActivation: 'Activated (at height 1337)',
Expand All @@ -429,6 +488,8 @@ describe('getPlatformScopeFactory', () => {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '0',
protocolVersion: 3,
desiredProtocolVersion: 4,
listening: true,
catchingUp: false,
latestBlockHash: 'DEADBEEF',
Expand Down Expand Up @@ -485,6 +546,8 @@ describe('getPlatformScopeFactory', () => {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.error,
version: null,
protocolVersion: null,
desiredProtocolVersion: null,
listening: null,
catchingUp: null,
latestBlockHash: null,
Expand Down
Loading