Skip to content

Commit

Permalink
fix(chain): show correctly consensus protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Apr 17, 2023
1 parent ced97ac commit a5fa358
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
12 changes: 4 additions & 8 deletions src/actions/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

import { verifyTransaction } from '@aeternity/aepp-sdk';
import { verifyTransaction, ConsensusProtocolVersion } from '@aeternity/aepp-sdk';
import { initSdk } from '../utils/cli';
import {
printBlock, print, printUnderscored, printTransaction, printValidation,
Expand All @@ -33,19 +33,14 @@ export async function version(options) {
const sdk = initSdk(options);
// Call `getStatus` API and print it
const status = await sdk.api.getStatus();
const { consensusProtocolVersion } = sdk.getNodeInfo();
const { consensusProtocolVersion } = await sdk.getNodeInfo();
if (json) {
print(status);
return;
}
const FORKS = {
3: 'Fortuna',
4: 'Lima',
5: 'Iris',
};
printUnderscored('Difficulty', status.difficulty);
printUnderscored('Node version', status.nodeVersion);
printUnderscored('Consensus protocol version', `${consensusProtocolVersion} (${FORKS[consensusProtocolVersion]})`);
printUnderscored('Consensus protocol version', `${consensusProtocolVersion} (${ConsensusProtocolVersion[consensusProtocolVersion]})`);
printUnderscored('Node revision', status.nodeRevision);
printUnderscored('Genesis hash', status.genesisKeyBlockHash);
printUnderscored('Network ID', status.networkId);
Expand Down Expand Up @@ -87,6 +82,7 @@ export async function top(options) {
// Initialize `Ae`
const sdk = initSdk(options);
// Call `getTopBlock` API and print it
// TODO: shouldn't be padded
printBlock(await sdk.api.getTopHeader(), json);
}

Expand Down
47 changes: 40 additions & 7 deletions test/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import { before, describe, it } from 'mocha';
import { expect } from 'chai';
import { executeProgram, parseBlock, getSdk } from './index';
import chainProgram from '../src/commands/chain';

Expand All @@ -28,19 +29,51 @@ describe('Chain Module', () => {
sdk = await getSdk();
});

it('TOP', async () => {
it('prints top', async () => {
const res = await executeChain(['top', '--json']);
res.should.be.a('object');
res.hash.should.be.a('string');
res.height.should.be.a('number');
});

it('STATUS', async () => {
const res = await executeChain(['status', '--json']);
res.nodeVersion.should.equal((await sdk.api.getStatus()).nodeVersion);
it('prints status', async () => {
const resJson = await executeChain(['status', '--json']);
expect(resJson).to.eql({
difficulty: resJson.difficulty,
genesisKeyBlockHash: resJson.genesisKeyBlockHash,
listening: true,
networkId: 'ae_devnet',
nodeRevision: 'a42c1b1e84dabdad350005213a2a9334113a6832',
nodeVersion: '6.8.1',
peerConnections: { inbound: 0, outbound: 0 },
peerCount: 0,
peerPubkey: resJson.peerPubkey,
pendingTransactionsCount: 0,
protocols: [{ effectiveAtHeight: 1, version: 5 }, { effectiveAtHeight: 0, version: 1 }],
solutions: 0,
syncProgress: 100,
syncing: false,
topBlockHeight: resJson.topBlockHeight,
topKeyBlockHash: resJson.topKeyBlockHash,
});

const res = await executeChain(['status']);
expect(res).to.equal(`
Difficulty ______________________________ ${resJson.difficulty}
Node version ____________________________ 6.8.1
Consensus protocol version ______________ 5 (Iris)
Node revision ___________________________ a42c1b1e84dabdad350005213a2a9334113a6832
Genesis hash ____________________________ ${resJson.genesisKeyBlockHash}
Network ID ______________________________ ae_devnet
Listening _______________________________ true
Peer count ______________________________ 0
Pending transactions count ______________ 0
Solutions _______________________________ 0
Syncing _________________________________ false
`.trim());
});

it('PLAY', async () => {
it('plays', async () => {
const res = await executeChain(['play', '--limit', '4']);
res.split('<<------------------------------------->>').length.should.equal(5);

Expand All @@ -50,14 +83,14 @@ describe('Chain Module', () => {
parsed[2].previousBlockHash.should.equal(parsed[3].blockHash);
}).timeout(10000);

it('TTL', async () => {
it('calculates ttl', async () => {
const { relativeTtl } = await executeChain(['ttl', 10, '--json']);
const height = await sdk.getHeight();
const isValid = [relativeTtl + 1, relativeTtl, relativeTtl - 1].includes(height + 10);
isValid.should.equal(true);
});

it('NETWORK ID', async () => {
it('prints network id', async () => {
const nodeNetworkId = await sdk.api.getNetworkId();
const { networkId } = await executeChain(['network_id', '--json']);
nodeNetworkId.should.equal(networkId);
Expand Down

0 comments on commit a5fa358

Please sign in to comment.