diff --git a/README.md b/README.md index b8dbdf4..a5c6825 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index b066699..10d149d 100644 --- a/package.json +++ b/package.json @@ -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": "", @@ -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", diff --git a/src/cmds/registry-cmds/authority-cmds/list.ts b/src/cmds/registry-cmds/authority-cmds/list.ts new file mode 100644 index 0000000..b92b59d --- /dev/null +++ b/src/cmds/registry-cmds/authority-cmds/list.ts @@ -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); +}; diff --git a/test/cli.test.ts b/test/cli.test.ts index 8ab2e7e..8718bb2 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -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 ', 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', () => { diff --git a/yarn.lock b/yarn.lock index ace5fad..62ac42b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"