Prathamesh Musale
75493f05e3
All checks were successful
Tests / cli_tests (18.x) (pull_request) Successful in 3m49s
191 lines
6.6 KiB
TypeScript
191 lines
6.6 KiB
TypeScript
import assert from 'assert';
|
|
import { spawnSync } from 'child_process';
|
|
|
|
describe('Test laconic CLI commands', () => {
|
|
test('laconic', async () => {
|
|
const result = spawnSync('laconic');
|
|
|
|
const output = result.stdout.toString().trim();
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
// Expect error with usage string
|
|
expect(output).toBe('');
|
|
expect(errorOutput).toContain('laconic <command>');
|
|
expect(result.status).toBe(1);
|
|
});
|
|
|
|
// TODO: Test subcommands
|
|
describe('laconic <command>', () => {
|
|
test('laconic cns', async () => {
|
|
const result = spawnSync('laconic', ['cns']);
|
|
|
|
const output = result.stdout.toString().trim();
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
// Expect error with usage string
|
|
expect(output).toBe('');
|
|
expect(errorOutput).toContain('laconic cns');
|
|
expect(errorOutput).toContain('CNS tools');
|
|
expect(errorOutput).toContain('Commands:');
|
|
expect(result.status).toBe(1);
|
|
});
|
|
|
|
describe('laconic cns <command>', () => {
|
|
const initialAccountBalance = Number('100000000000000000000000000');
|
|
const existingAccount = process.env.EXISTING_ACCOUNT;
|
|
assert(existingAccount, 'EXISTING_ACCOUNT not set in env');
|
|
|
|
test('laconic cns status', async () => {
|
|
const result = spawnSync('laconic', ['cns', 'status']);
|
|
|
|
const output = result.stdout.toString().trim();
|
|
const outputObj = JSON.parse(output);
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
// Expect output object to have CNS status props
|
|
expect(outputObj).toHaveProperty('version');
|
|
expect(outputObj).toHaveProperty('node');
|
|
expect(outputObj).toHaveProperty('node.network', 'laconic_9000-1');
|
|
expect(outputObj).toHaveProperty('sync');
|
|
expect(Number(outputObj.sync.latest_block_height)).toBeGreaterThan(0);
|
|
expect(outputObj).toHaveProperty('validator');
|
|
expect(outputObj).toHaveProperty('validators');
|
|
expect(outputObj).toHaveProperty('num_peers');
|
|
expect(outputObj).toHaveProperty('peers');
|
|
expect(outputObj).toHaveProperty('disk_usage');
|
|
|
|
expect(errorOutput).toBe('');
|
|
expect(result.status).toBe(0);
|
|
});
|
|
|
|
describe('laconic cns bond <command>', () => {
|
|
const bondBalance = 1000000000;
|
|
const bondOwner = existingAccount;
|
|
let bondId: string;
|
|
|
|
test('laconic cns bond create', async () => {
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', 'aphoton', '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', '200000aphoton']);
|
|
|
|
const output = result.stdout.toString().trim();
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
expect(errorOutput).toBe('');
|
|
expect(result.status).toBe(0);
|
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
const outputObj = JSON.parse(output);
|
|
|
|
// Expect output object to resultant bond id
|
|
expect(outputObj).toHaveProperty('bondId');
|
|
|
|
bondId = outputObj.bondId;
|
|
});
|
|
|
|
test('laconic cns bond list', async () => {
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'list']);
|
|
|
|
const output = result.stdout.toString().trim();
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
expect(errorOutput).toBe('');
|
|
expect(result.status).toBe(0);
|
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
const outputObj = Array.from<any>(JSON.parse(output));
|
|
|
|
// Expected bond
|
|
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
});
|
|
|
|
test('laconic cns bond list --owner <owner_address>', async () => {
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'list', '--owner', bondOwner]);
|
|
|
|
const output = result.stdout.toString().trim();
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
expect(errorOutput).toBe('');
|
|
expect(result.status).toBe(0);
|
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
const outputObj = Array.from<any>(JSON.parse(output));
|
|
|
|
// Expected bond
|
|
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
});
|
|
|
|
test('laconic cns bond get --id <bond_id>', async () => {
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
|
|
|
|
const output = result.stdout.toString().trim();
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
expect(errorOutput).toBe('');
|
|
expect(result.status).toBe(0);
|
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
const outputObj = Array.from<any>(JSON.parse(output));
|
|
|
|
// Expected bond
|
|
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
});
|
|
});
|
|
|
|
describe('laconic cns account <command>', () => {
|
|
test('laconic cns account get --address <account_address>', async () => {
|
|
const result = spawnSync('laconic', ['cns', 'account', 'get', '--address', existingAccount]);
|
|
|
|
const output = result.stdout.toString().trim();
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
expect(errorOutput).toBe('');
|
|
expect(result.status).toBe(0);
|
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
const outputObj = Array.from<any>(JSON.parse(output));
|
|
|
|
// Expected account
|
|
const expectedAccount = {
|
|
address: existingAccount,
|
|
number: 0,
|
|
sequence: 2,
|
|
balance: [
|
|
{
|
|
type: "aphoton"
|
|
}
|
|
]
|
|
};
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
expect(outputObj[0]).toMatchObject(expectedAccount);
|
|
expect(Number(outputObj[0].balance[0].quantity)).toBeGreaterThan(0);
|
|
expect(Number(outputObj[0].balance[0].quantity)).toBeLessThan(initialAccountBalance);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
// Helper methods
|
|
|
|
function getExpectedBond(params: { id: string, owner: string, balance: number}): any {
|
|
return {
|
|
id: params.id,
|
|
owner: params.owner,
|
|
balance: [
|
|
{
|
|
type: "aphoton",
|
|
quantity: params.balance
|
|
}
|
|
]
|
|
};
|
|
}
|