Update authorities list command and add tests
This commit is contained in:
parent
edd345b96c
commit
e52878cdbd
@ -354,13 +354,13 @@ $ laconic registry authority reserve kube.laconic --owner laconic15za32wly5exgcr
|
|||||||
Get all the authorities:
|
Get all the authorities:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic registry authority get
|
$ laconic registry authority list
|
||||||
```
|
```
|
||||||
|
|
||||||
Get all the authorities by owner:
|
Get all the authorities by owner:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic registry authority get --owner laconic1zayjut6pd4xy9dguut56v55hktzmeq6r777hmd
|
$ laconic registry authority list --owner laconic1zayjut6pd4xy9dguut56v55hktzmeq6r777hmd
|
||||||
```
|
```
|
||||||
|
|
||||||
Set name:
|
Set name:
|
||||||
|
@ -5,13 +5,17 @@ import { Registry } from '@cerc-io/registry-sdk';
|
|||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
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 desc = 'List authorities (optionally by owner).';
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const builder = {
|
||||||
const owner = argv.owner as string || '';
|
owner: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
@ -19,7 +23,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(chainId, 'Invalid registry Chain ID.');
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
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);
|
queryOutput(result, argv.output);
|
||||||
};
|
};
|
||||||
|
@ -478,6 +478,47 @@ describe('Test laconic CLI commands', () => {
|
|||||||
expect(authorityOutputObj.length).toEqual(1);
|
expect(authorityOutputObj.length).toEqual(1);
|
||||||
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
|
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', () => {
|
describe('Name operations', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user