Update authorities list command and add tests
All checks were successful
Lint / lint (18.x) (pull_request) Successful in 1m13s
Tests / cli_tests (18.x) (pull_request) Successful in 9m23s

This commit is contained in:
Prathamesh Musale 2024-08-05 14:35:48 +05:30
parent edd345b96c
commit e52878cdbd
3 changed files with 51 additions and 6 deletions

View File

@ -354,13 +354,13 @@ $ laconic registry authority reserve kube.laconic --owner laconic15za32wly5exgcr
Get all the authorities:
```bash
$ laconic registry authority get
$ laconic registry authority list
```
Get all the authorities by owner:
```bash
$ laconic registry authority get --owner laconic1zayjut6pd4xy9dguut56v55hktzmeq6r777hmd
$ laconic registry authority list --owner laconic1zayjut6pd4xy9dguut56v55hktzmeq6r777hmd
```
Set name:

View File

@ -5,13 +5,17 @@ import { Registry } from '@cerc-io/registry-sdk';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'list [owner]';
export const command = 'list';
export const desc = 'List authorities (optionally by owner).';
export const handler = async (argv: Arguments) => {
const owner = argv.owner as string || '';
export const builder = {
owner: {
type: 'string'
}
};
export const handler = async (argv: Arguments) => {
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
@ -19,7 +23,7 @@ export const handler = async (argv: Arguments) => {
assert(chainId, 'Invalid registry Chain ID.');
const registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
const result = await registry.getAuthorities(owner);
const result = await registry.getAuthorities(argv.owner as string);
queryOutput(result, argv.output);
};

View File

@ -478,6 +478,47 @@ describe('Test laconic CLI commands', () => {
expect(authorityOutputObj.length).toEqual(1);
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
});
test('laconic registry authority list', async () => {
const result = spawnSync('laconic', ['registry', 'authority', 'list']);
const authoritiesOutputObj = checkResultAndRetrieveOutput(result);
// Expected authorities
const expectedAuthorities = [
{ name: 'echo.laconic', entry: { ownerAddress: testAccount, status: 'active' } },
{ name: 'kube.laconic', entry: { ownerAddress: testAccount2, status: 'active' } },
{ name: 'laconic', entry: { ownerAddress: testAccount, status: 'active' } }
];
// Expected output
expect(authoritiesOutputObj.length).toEqual(3);
expect(authoritiesOutputObj).toMatchObject(expectedAuthorities);
});
test('laconic registry authority list --owner <owner_address>', async () => {
let result = spawnSync('laconic', ['registry', 'authority', 'list', '--owner', testAccount]);
const authoritiesByOwner1 = checkResultAndRetrieveOutput(result);
// Expected output
const expectedAuthoritiesByOwner1 = [
{ name: 'echo.laconic', entry: { ownerAddress: testAccount, status: 'active' } },
{ name: 'laconic', entry: { ownerAddress: testAccount, status: 'active' } }
];
expect(authoritiesByOwner1.length).toEqual(2);
expect(authoritiesByOwner1).toMatchObject(expectedAuthoritiesByOwner1);
result = spawnSync('laconic', ['registry', 'authority', 'list', '--owner', testAccount2]);
const authoritiesByOwner2 = checkResultAndRetrieveOutput(result);
// Expected output
const expectedAuthoritiesByOwner2 = [
{ name: 'kube.laconic', entry: { ownerAddress: testAccount2, status: 'active' } }
];
expect(authoritiesByOwner2.length).toEqual(1);
expect(authoritiesByOwner2).toMatchObject(expectedAuthoritiesByOwner2);
});
});
describe('Name operations', () => {