Add CLI tests and setup CI #53

Merged
ashwin merged 23 commits from deep-stack/laconic-registry-cli:pm-add-tests into main 2024-01-29 04:46:32 +00:00
3 changed files with 179 additions and 125 deletions
Showing only changes of commit 4036d33d7a - Show all commits

View File

@ -34,8 +34,6 @@ jobs:
run: yarn && yarn build run: yarn && yarn build
- name: Install registry-cli - name: Install registry-cli
run: yarn global add file:$PWD run: yarn global add file:$PWD
- name: Log CLI version
run: laconic --version
- name: Checkout laconicd - name: Checkout laconicd
uses: actions/checkout@v3 uses: actions/checkout@v3

View File

@ -1,6 +1,8 @@
import assert from 'assert'; import assert from 'assert';
import { spawnSync } from 'child_process'; import { spawnSync } from 'child_process';
const TOKEN_TYPE = 'aphoton';
describe('Test laconic CLI commands', () => { describe('Test laconic CLI commands', () => {
test('laconic', async () => { test('laconic', async () => {
const result = spawnSync('laconic'); const result = spawnSync('laconic');
@ -14,8 +16,6 @@ describe('Test laconic CLI commands', () => {
expect(result.status).toBe(1); expect(result.status).toBe(1);
}); });
// TODO: Test subcommands
describe('laconic <command>', () => {
test('laconic cns', async () => { test('laconic cns', async () => {
const result = spawnSync('laconic', ['cns']); const result = spawnSync('laconic', ['cns']);
@ -30,11 +30,15 @@ describe('Test laconic CLI commands', () => {
expect(result.status).toBe(1); expect(result.status).toBe(1);
}); });
describe('laconic cns <command>', () => { describe('laconic CNS commands', () => {
const initialAccountBalance = Number('100000000000000000000000000'); const initialAccountBalance = Number('100000000000000000000000000');
// let accountSequence = 0;
const existingAccount = process.env.EXISTING_ACCOUNT; const existingAccount = process.env.EXISTING_ACCOUNT;
assert(existingAccount, 'EXISTING_ACCOUNT not set in env'); assert(existingAccount, 'EXISTING_ACCOUNT not set in env');
const secondAccount = 'ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu';
test('laconic cns status', async () => { test('laconic cns status', async () => {
const result = spawnSync('laconic', ['cns', 'status']); const result = spawnSync('laconic', ['cns', 'status']);
@ -58,13 +62,15 @@ describe('Test laconic CLI commands', () => {
expect(result.status).toBe(0); expect(result.status).toBe(0);
}); });
describe('laconic cns bond <command>', () => { describe('Bond operations', () => {
const bondBalance = 1000000000; const bondBalance = 1000000000;
const bondOwner = existingAccount; const bondOwner = existingAccount;
let bondId: string; let bondId = 'de88ffab68af143da5d3ba2cf86f468ac4ac2efaa005e4d2fbce5fde85cbaa3e';
// let bondId: string;
test('laconic cns bond create', async () => { test('laconic cns bond create', async () => {
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', 'aphoton', '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', '200000aphoton']); const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
// accountSequence++;
const output = result.stdout.toString().trim(); const output = result.stdout.toString().trim();
const errorOutput = result.stderr.toString().trim(); const errorOutput = result.stderr.toString().trim();
@ -139,7 +145,9 @@ describe('Test laconic CLI commands', () => {
}); });
}); });
describe('laconic cns account <command>', () => { describe('Account and tokens operations', () => {
let balanceBeforeSend: number;
test('laconic cns account get --address <account_address>', async () => { test('laconic cns account get --address <account_address>', async () => {
const result = spawnSync('laconic', ['cns', 'account', 'get', '--address', existingAccount]); const result = spawnSync('laconic', ['cns', 'account', 'get', '--address', existingAccount]);
@ -159,16 +167,62 @@ describe('Test laconic CLI commands', () => {
sequence: 2, sequence: 2,
balance: [ balance: [
{ {
type: "aphoton" type: TOKEN_TYPE
} }
] ]
}; };
balanceBeforeSend = Number(outputObj[0].balance[0].quantity);
expect(outputObj.length).toEqual(1); expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedAccount); expect(outputObj[0]).toMatchObject(expectedAccount);
expect(Number(outputObj[0].balance[0].quantity)).toBeGreaterThan(0); expect(balanceBeforeSend).toBeGreaterThan(0);
expect(Number(outputObj[0].balance[0].quantity)).toBeLessThan(initialAccountBalance); expect(balanceBeforeSend).toBeLessThan(initialAccountBalance);
}); });
test('laconic cns tokens send --address <account_address> --type <token_type> --quantity <quantity>', async () => {
const sendAmount = 1000000000;
const balanceAfterSend = balanceBeforeSend - sendAmount;
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();
expect(errorOutput).toBe('');
expect(result.status).toBe(0);
expect(output.length).toBeGreaterThan(0);
const outputObj = Array.from<any>(JSON.parse(output));
// Expected acconts
const expectedAccounts = [
{
address: existingAccount,
number: 0,
sequence: 3,
balance: [
{
type: TOKEN_TYPE,
quantity: balanceAfterSend
}
]
},
{
address: secondAccount,
pubKey: null,
sequence: 0,
balance: [
{
type: TOKEN_TYPE,
quantity: sendAmount
}
]
},
];
expect(outputObj.length).toEqual(2);
expect(outputObj).toMatchObject(expectedAccounts);
}); });
}); });
}); });
@ -182,7 +236,7 @@ function getExpectedBond(params: { id: string, owner: string, balance: number}):
owner: params.owner, owner: params.owner,
balance: [ balance: [
{ {
type: "aphoton", type: TOKEN_TYPE,
quantity: params.balance quantity: params.balance
} }
] ]

View File

@ -21,6 +21,8 @@ services:
userKey: $laconicd_key userKey: $laconicd_key
bondId: bondId:
chainId: $cosmos_chain_id chainId: $cosmos_chain_id
gas: 200000
fees: 200000aphoton
EOL EOL
) )
echo "$config" > "$config_file" echo "$config" > "$config_file"