Skip to content

Commit

Permalink
Add a command to list authorities (#74)
Browse files Browse the repository at this point in the history
Part of [Create a public laconicd testnet](https://www.notion.so/Create-a-public-laconicd-testnet-896a11bdd8094eff8f1b49c0be0ca3b8)

Co-authored-by: IshaVenikar <ishavenikar7@gmail.com>
Reviewed-on: https://git.vdb.to/cerc-io/laconic-registry-cli/pulls/74
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
  • Loading branch information
2 people authored and nabarun committed Aug 5, 2024
1 parent 70e63c7 commit 30654bb
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 6 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,18 @@ Create sub-authority (custom owner for sub-authority):
$ laconic registry authority reserve kube.laconic --owner laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k
```
Get all the authorities:
```bash
$ laconic registry authority list
```
Get all the authorities by owner:
```bash
$ laconic registry authority list --owner laconic1zayjut6pd4xy9dguut56v55hktzmeq6r777hmd
```
Set name:
```bash
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/laconic-registry-cli",
"version": "0.2.2",
"version": "0.2.3",
"main": "index.js",
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
"author": "",
Expand Down Expand Up @@ -29,7 +29,7 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@cerc-io/registry-sdk": "^0.2.5",
"@cerc-io/registry-sdk": "^0.2.6",
"fs-extra": "^10.1.0",
"js-yaml": "^3.14.1",
"lodash": "^4.17.21",
Expand Down
29 changes: 29 additions & 0 deletions src/cmds/registry-cmds/authority-cmds/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Arguments } from 'yargs';
import assert from 'assert';

import { Registry } from '@cerc-io/registry-sdk';

import { getConfig, getConnectionInfo, queryOutput } from '../../../util';

export const command = 'list';

export const desc = 'List authorities (optionally by owner).';

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.');
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
assert(chainId, 'Invalid registry Chain ID.');

const registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
const result = await registry.getAuthorities(argv.owner as string);

queryOutput(result, argv.output);
};
41 changes: 41 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@cerc-io/registry-sdk@^0.2.5":
version "0.2.5"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.5/registry-sdk-0.2.5.tgz#9ca19fecb2923520dd6a19946c309ecb2ec780a2"
integrity sha512-/KXAYf9gStaX/rRBMCEeDCexEIpTOFHeHzMK9B3xfCT+SyYZE9WC9GpX299LzBYJKKPsb0/JvnDfip9S1igJtA==
"@cerc-io/registry-sdk@^0.2.6":
version "0.2.6"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.6/registry-sdk-0.2.6.tgz#af8a5844bdb742a01d322a9d93ace90d35aad37e"
integrity sha512-Z2rneeoPLTJk9aBTqMrR9WPKfPQZhNWShI4IYOb7kzoIorp3eD8mEals0I5bVjzStjapw/5RKf8lVnDCX9I4iA==
dependencies:
"@cosmjs/amino" "^0.28.1"
"@cosmjs/crypto" "^0.28.1"
Expand Down

0 comments on commit 30654bb

Please sign in to comment.