2024-01-24 13:26:35 +00:00
|
|
|
import assert from 'assert';
|
2024-01-24 06:51:43 +00:00
|
|
|
import { spawnSync } from 'child_process';
|
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
const TOKEN_TYPE = 'aphoton';
|
|
|
|
|
2024-01-24 06:51:43 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
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 commands', () => {
|
|
|
|
const initialAccountBalance = Number('100000000000000000000000000');
|
|
|
|
// let accountSequence = 0;
|
|
|
|
const existingAccount = process.env.EXISTING_ACCOUNT;
|
|
|
|
assert(existingAccount, 'EXISTING_ACCOUNT not set in env');
|
|
|
|
|
|
|
|
const secondAccount = 'ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu';
|
|
|
|
|
|
|
|
|
|
|
|
test('laconic cns status', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'status']);
|
2024-01-24 07:17:38 +00:00
|
|
|
|
|
|
|
const output = result.stdout.toString().trim();
|
2024-01-25 04:26:33 +00:00
|
|
|
const outputObj = JSON.parse(output);
|
2024-01-24 07:17:38 +00:00
|
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// 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);
|
2024-01-24 07:17:38 +00:00
|
|
|
});
|
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
describe('Bond operations', () => {
|
|
|
|
const bondBalance = 1000000000;
|
|
|
|
const bondOwner = existingAccount;
|
|
|
|
let bondId = 'de88ffab68af143da5d3ba2cf86f468ac4ac2efaa005e4d2fbce5fde85cbaa3e';
|
|
|
|
// let bondId: string;
|
2024-01-24 13:26:35 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns bond create', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
|
|
|
|
// accountSequence++;
|
2024-01-24 07:17:38 +00:00
|
|
|
|
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
|
|
|
|
expect(errorOutput).toBe('');
|
|
|
|
expect(result.status).toBe(0);
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
|
|
const outputObj = JSON.parse(output);
|
|
|
|
|
|
|
|
// Expect output object to resultant bond id
|
|
|
|
expect(outputObj).toHaveProperty('bondId');
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
bondId = outputObj.bondId;
|
|
|
|
});
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns bond list', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'list']);
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(errorOutput).toBe('');
|
|
|
|
expect(result.status).toBe(0);
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
|
|
const outputObj = Array.from<any>(JSON.parse(output));
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns bond list --owner <owner_address>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'list', '--owner', bondOwner]);
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(errorOutput).toBe('');
|
|
|
|
expect(result.status).toBe(0);
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
|
|
const outputObj = Array.from<any>(JSON.parse(output));
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns bond get --id <bond_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(errorOutput).toBe('');
|
|
|
|
expect(result.status).toBe(0);
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
|
|
const outputObj = Array.from<any>(JSON.parse(output));
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
|
|
|
});
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
describe('Account and tokens operations', () => {
|
|
|
|
let balanceBeforeSend: number;
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns account get --address <account_address>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'account', 'get', '--address', existingAccount]);
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(errorOutput).toBe('');
|
|
|
|
expect(result.status).toBe(0);
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
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: TOKEN_TYPE
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
balanceBeforeSend = Number(outputObj[0].balance[0].quantity);
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedAccount);
|
|
|
|
expect(balanceBeforeSend).toBeGreaterThan(0);
|
|
|
|
expect(balanceBeforeSend).toBeLessThan(initialAccountBalance);
|
2024-01-24 09:02:12 +00:00
|
|
|
});
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns tokens send --address <account_address> --type <token_type> --quantity <quantity>', async () => {
|
|
|
|
const sendAmount = 1000000000;
|
|
|
|
const balanceAfterSend = balanceBeforeSend - sendAmount;
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'tokens', 'send', '--address', secondAccount, '--type', TOKEN_TYPE, '--quantity', sendAmount.toString()]);
|
|
|
|
// accountSequence++;
|
|
|
|
|
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(errorOutput).toBe('');
|
|
|
|
expect(result.status).toBe(0);
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(output.length).toBeGreaterThan(0);
|
|
|
|
const outputObj = Array.from<any>(JSON.parse(output));
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expected acconts
|
|
|
|
const expectedAccounts = [
|
|
|
|
{
|
2024-01-24 13:40:49 +00:00
|
|
|
address: existingAccount,
|
|
|
|
number: 0,
|
2024-01-25 04:26:33 +00:00
|
|
|
sequence: 3,
|
|
|
|
balance: [
|
|
|
|
{
|
|
|
|
type: TOKEN_TYPE,
|
|
|
|
quantity: balanceAfterSend
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
address: secondAccount,
|
|
|
|
pubKey: null,
|
|
|
|
sequence: 0,
|
2024-01-24 13:40:49 +00:00
|
|
|
balance: [
|
|
|
|
{
|
2024-01-25 04:26:33 +00:00
|
|
|
type: TOKEN_TYPE,
|
|
|
|
quantity: sendAmount
|
2024-01-24 13:40:49 +00:00
|
|
|
}
|
|
|
|
]
|
2024-01-25 04:26:33 +00:00
|
|
|
},
|
|
|
|
];
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj.length).toEqual(2);
|
|
|
|
expect(outputObj).toMatchObject(expectedAccounts);
|
2024-01-24 13:40:49 +00:00
|
|
|
});
|
2024-01-24 07:17:38 +00:00
|
|
|
});
|
2024-01-24 06:51:43 +00:00
|
|
|
});
|
|
|
|
});
|
2024-01-24 12:52:03 +00:00
|
|
|
|
|
|
|
// Helper methods
|
|
|
|
|
2024-01-24 13:26:35 +00:00
|
|
|
function getExpectedBond(params: { id: string, owner: string, balance: number}): any {
|
|
|
|
return {
|
2024-01-24 12:52:03 +00:00
|
|
|
id: params.id,
|
2024-01-24 13:26:35 +00:00
|
|
|
owner: params.owner,
|
2024-01-24 12:52:03 +00:00
|
|
|
balance: [
|
|
|
|
{
|
2024-01-25 04:26:33 +00:00
|
|
|
type: TOKEN_TYPE,
|
2024-01-24 12:52:03 +00:00
|
|
|
quantity: params.balance
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|