From 52cab23c70e97487a9fbe6ef0418d2209d2d3929 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Thu, 1 Aug 2024 15:55:21 +0530 Subject: [PATCH 1/7] Add method for get authorities --- src/index.ts | 7 +++++++ src/naming.test.ts | 33 ++++++++++++++++++++++++++------- src/registry-client.ts | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 692ebc5..fbe952f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -389,6 +389,13 @@ export class Registry { return this._client.getAuctionsByIds(ids); } + /** + * List authorities by owner. + */ + async getAuthorities (owner?: string) { + return this._client.getAuthorities(owner); + } + /** * Lookup authorities by names. */ diff --git a/src/naming.test.ts b/src/naming.test.ts index 4c40225..ec04a4a 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -19,6 +19,12 @@ const namingTests = () => { let watcher: any; let watcherId: string; + const mnenonic1 = Account.generateMnemonic(); + let otherAccount1: Account; + + const mnenonic2 = Account.generateMnemonic(); + let otherAccount2: Account; + beforeAll(async () => { registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); @@ -39,6 +45,12 @@ const namingTests = () => { ); watcherId = result.id; + + otherAccount1 = await Account.generateFromMnemonic(mnenonic1); + await otherAccount1.init(); + + otherAccount2 = await Account.generateFromMnemonic(mnenonic2); + await otherAccount2.init(); }); describe('Authority tests', () => { @@ -90,14 +102,7 @@ const namingTests = () => { test('Reserve sub-authority with different owner.', async () => { // Create another account, send tx to set public key on the account. - const mnenonic1 = Account.generateMnemonic(); - const otherAccount1 = await Account.generateFromMnemonic(mnenonic1); - await otherAccount1.init(); await registry.sendCoins({ denom: DENOM, amount: '1000000000', destinationAddress: otherAccount1.address }, privateKey, fee); - - const mnenonic2 = Account.generateMnemonic(); - const otherAccount2 = await Account.generateFromMnemonic(mnenonic2); - await otherAccount2.init(); await registry.sendCoins({ denom: DENOM, amount: '1000', destinationAddress: otherAccount2.address }, otherAccount1.getPrivateKey(), fee); const subAuthority = `halo.${authorityName}`; @@ -120,6 +125,20 @@ const namingTests = () => { test('Set authority bond', async () => { await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee); }); + + test('List authorities.', async () => { + const authorities = await registry.getAuthorities(); + + expect(authorities.length).toBeDefined(); + }); + + test('List authorities by owner.', async () => { + const authority1 = await registry.getAuthorities(otherAccount1._address); + const authority2 = await registry.getAuthorities(otherAccount2._address); + + expect(authority1).toBeDefined(); + expect(authority2).toBeDefined(); + }); }); }); diff --git a/src/registry-client.ts b/src/registry-client.ts index 31d8073..4658872 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -270,6 +270,41 @@ export class RegistryClient { return result; } + /** + * List authorities by owner. + */ + async getAuthorities (owner?: string) { + const query = `query ($owner: String) { + getAuthorities(owner: $owner) { + name + entry { + ownerAddress + ownerPublicKey + height + status + bondId + expiryTime + auction { + id + status + ownerAddress + createTime + commitsEndTime + revealsEndTime + } + } + } + }`; + + const variables = { + owner + }; + + const result = await this._graph(query)(variables); + + return result.getAuthorities; + } + /** * Lookup authorities by names. */ -- 2.45.2 From a3b78fd363c5ddae7492da5418b21c89e9a76acd Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 2 Aug 2024 09:49:57 +0530 Subject: [PATCH 2/7] Check owner address for returned authorities --- src/naming.test.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/naming.test.ts b/src/naming.test.ts index ec04a4a..19832e4 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -22,9 +22,6 @@ const namingTests = () => { const mnenonic1 = Account.generateMnemonic(); let otherAccount1: Account; - const mnenonic2 = Account.generateMnemonic(); - let otherAccount2: Account; - beforeAll(async () => { registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); @@ -48,9 +45,6 @@ const namingTests = () => { otherAccount1 = await Account.generateFromMnemonic(mnenonic1); await otherAccount1.init(); - - otherAccount2 = await Account.generateFromMnemonic(mnenonic2); - await otherAccount2.init(); }); describe('Authority tests', () => { @@ -102,6 +96,10 @@ const namingTests = () => { test('Reserve sub-authority with different owner.', async () => { // Create another account, send tx to set public key on the account. + const mnenonic2 = Account.generateMnemonic(); + const otherAccount2 = await Account.generateFromMnemonic(mnenonic2); + await otherAccount2.init(); + await registry.sendCoins({ denom: DENOM, amount: '1000000000', destinationAddress: otherAccount1.address }, privateKey, fee); await registry.sendCoins({ denom: DENOM, amount: '1000', destinationAddress: otherAccount2.address }, otherAccount1.getPrivateKey(), fee); @@ -133,11 +131,9 @@ const namingTests = () => { }); test('List authorities by owner.', async () => { - const authority1 = await registry.getAuthorities(otherAccount1._address); - const authority2 = await registry.getAuthorities(otherAccount2._address); + const authorities = await registry.getAuthorities(otherAccount1.address); - expect(authority1).toBeDefined(); - expect(authority2).toBeDefined(); + expect(authorities[0].entry.ownerAddress).toBe(otherAccount1.address); }); }); }); -- 2.45.2 From 81dbf57fc2e3a1939845d50001a08c2908a1fd08 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 2 Aug 2024 11:52:49 +0530 Subject: [PATCH 3/7] Update check for list authorities by owner --- src/index.ts | 4 ++-- src/naming.test.ts | 4 +++- src/registry-client.ts | 11 ++--------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index fbe952f..17047ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -392,8 +392,8 @@ export class Registry { /** * List authorities by owner. */ - async getAuthorities (owner?: string) { - return this._client.getAuthorities(owner); + async getAuthorities (owner?: string, auction = false) { + return this._client.getAuthorities(owner, auction); } /** diff --git a/src/naming.test.ts b/src/naming.test.ts index 19832e4..58ad295 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -127,13 +127,15 @@ const namingTests = () => { test('List authorities.', async () => { const authorities = await registry.getAuthorities(); - expect(authorities.length).toBeDefined(); + expect(authorities.length).toEqual(4); }); test('List authorities by owner.', async () => { const authorities = await registry.getAuthorities(otherAccount1.address); + expect(authorities.length).toEqual(1); expect(authorities[0].entry.ownerAddress).toBe(otherAccount1.address); + expect(authorities[0].entry.ownerPublicKey).toBe(otherAccount1.encodedPubkey); }); }); }); diff --git a/src/registry-client.ts b/src/registry-client.ts index 4658872..23c7776 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -273,7 +273,7 @@ export class RegistryClient { /** * List authorities by owner. */ - async getAuthorities (owner?: string) { + async getAuthorities (owner?: string, auction = false) { const query = `query ($owner: String) { getAuthorities(owner: $owner) { name @@ -284,14 +284,7 @@ export class RegistryClient { status bondId expiryTime - auction { - id - status - ownerAddress - createTime - commitsEndTime - revealsEndTime - } + ${auction ? ('auction { ' + auctionFields + ' }') : ''} } } }`; -- 2.45.2 From 225aa2a6aaea75ab0de6c06f7865165716cdd338 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 2 Aug 2024 15:15:05 +0530 Subject: [PATCH 4/7] Check name and owner address for authorities --- package.json | 2 +- src/naming.test.ts | 56 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1b454b8..8308526 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/registry-sdk", - "version": "0.2.5", + "version": "0.2.6", "main": "dist/index.js", "types": "dist/index.d.ts", "repository": "git@github.com:cerc-io/registry-sdk.git", diff --git a/src/naming.test.ts b/src/naming.test.ts index 58ad295..2edf69f 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -1,6 +1,8 @@ import assert from 'assert'; import path from 'path'; +import { DirectSecp256k1Wallet, AccountData as CosmosAccount } from '@cosmjs/proto-signing'; + import { Account } from './account'; import { Registry } from './index'; import { ensureUpdatedConfig, getConfig } from './testing/helper'; @@ -19,9 +21,18 @@ const namingTests = () => { let watcher: any; let watcherId: string; - const mnenonic1 = Account.generateMnemonic(); let otherAccount1: Account; + let reservedAuthorities: { + name: string; + entry: { + ownerAddress: string; + status: string; + }; + }[] = []; + + let cosmosWallet: CosmosAccount; + beforeAll(async () => { registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); @@ -43,6 +54,11 @@ const namingTests = () => { watcherId = result.id; + const account_pk = new Account(Buffer.from(privateKey, 'hex')); + const account = await DirectSecp256k1Wallet.fromKey(account_pk._privateKey, 'laconic'); + [cosmosWallet] = await account.getAccounts(); + + const mnenonic1 = Account.generateMnemonic(); otherAccount1 = await Account.generateFromMnemonic(mnenonic1); await otherAccount1.init(); }); @@ -51,6 +67,13 @@ const namingTests = () => { test('Reserve authority.', async () => { const authorityName = `laconic-${Date.now()}`; await registry.reserveAuthority({ name: authorityName }, privateKey, fee); + reservedAuthorities.push({ + name: authorityName, + entry: { + ownerAddress: cosmosWallet.address, + status: 'active' + } + }); }); describe('With authority reserved', () => { @@ -62,6 +85,13 @@ const namingTests = () => { lrn = `lrn://${authorityName}/app/test`; await registry.reserveAuthority({ name: authorityName }, privateKey, fee); + reservedAuthorities.push({ + name: authorityName, + entry: { + ownerAddress: cosmosWallet.address, + status: 'active' + } + }); }); test('Lookup authority.', async () => { @@ -86,6 +116,13 @@ const namingTests = () => { test('Reserve sub-authority.', async () => { const subAuthority = `echo.${authorityName}`; await registry.reserveAuthority({ name: subAuthority }, privateKey, fee); + reservedAuthorities.push({ + name: subAuthority, + entry: { + ownerAddress: cosmosWallet.address, + status: 'active' + } + }); const [record] = await registry.lookupAuthorities([subAuthority]); expect(record).toBeDefined(); @@ -105,6 +142,13 @@ const namingTests = () => { const subAuthority = `halo.${authorityName}`; await registry.reserveAuthority({ name: subAuthority, owner: otherAccount1.address }, privateKey, fee); + reservedAuthorities.push({ + name: subAuthority, + entry: { + ownerAddress: otherAccount1.address, + status: 'active' + } + }); const [record] = await registry.lookupAuthorities([subAuthority]); expect(record).toBeDefined(); @@ -127,7 +171,17 @@ const namingTests = () => { test('List authorities.', async () => { const authorities = await registry.getAuthorities(); + reservedAuthorities.sort((a, b) => a.name.localeCompare(b.name)); + expect(authorities.length).toEqual(4); + authorities.forEach((authority: any, index: number) => { + authorities.forEach((authority: any) => { + expect(authority).toHaveProperty('name'); + expect(authority.entry).toHaveProperty('ownerAddress'); + expect(authority.entry).toHaveProperty('status'); + }); + expect(authority).toMatchObject(reservedAuthorities[index]); + }); }); test('List authorities by owner.', async () => { -- 2.45.2 From 37c2f5897fba848d2a0ebf55856e9935347b9bdf Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 2 Aug 2024 15:40:27 +0530 Subject: [PATCH 5/7] Check for properties in returned authorities list --- src/nameservice-expiry.test.ts | 6 ++++++ src/naming.test.ts | 36 ++++++++++++++++++++++------------ src/onboarding.test.ts | 5 ++--- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/nameservice-expiry.test.ts b/src/nameservice-expiry.test.ts index a8627e7..184c13a 100644 --- a/src/nameservice-expiry.test.ts +++ b/src/nameservice-expiry.test.ts @@ -61,6 +61,9 @@ const nameserviceExpiryTests = () => { test('Wait for expiry duration', (done) => { setTimeout(done, 60 * 1000); + + // Wait some more time for block to be executed + setTimeout(done, 3 * 1000); }); test('Check record expiry time', async () => { @@ -85,6 +88,9 @@ const nameserviceExpiryTests = () => { test('Wait for expiry duration', (done) => { setTimeout(done, 60 * 1000); + + // Wait some more time for block to be executed + setTimeout(done, 3 * 1000); }); test('Check record deleted without bond balance', async () => { diff --git a/src/naming.test.ts b/src/naming.test.ts index 2edf69f..0711091 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -31,7 +31,7 @@ const namingTests = () => { }; }[] = []; - let cosmosWallet: CosmosAccount; + let account: CosmosAccount; beforeAll(async () => { registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); @@ -54,9 +54,8 @@ const namingTests = () => { watcherId = result.id; - const account_pk = new Account(Buffer.from(privateKey, 'hex')); - const account = await DirectSecp256k1Wallet.fromKey(account_pk._privateKey, 'laconic'); - [cosmosWallet] = await account.getAccounts(); + const accountWallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(privateKey, 'hex'), 'laconic'); + [account] = await accountWallet.getAccounts(); const mnenonic1 = Account.generateMnemonic(); otherAccount1 = await Account.generateFromMnemonic(mnenonic1); @@ -70,7 +69,7 @@ const namingTests = () => { reservedAuthorities.push({ name: authorityName, entry: { - ownerAddress: cosmosWallet.address, + ownerAddress: account.address, status: 'active' } }); @@ -88,7 +87,7 @@ const namingTests = () => { reservedAuthorities.push({ name: authorityName, entry: { - ownerAddress: cosmosWallet.address, + ownerAddress: account.address, status: 'active' } }); @@ -119,7 +118,7 @@ const namingTests = () => { reservedAuthorities.push({ name: subAuthority, entry: { - ownerAddress: cosmosWallet.address, + ownerAddress: account.address, status: 'active' } }); @@ -169,17 +168,28 @@ const namingTests = () => { }); test('List authorities.', async () => { - const authorities = await registry.getAuthorities(); - + const authorities = await registry.getAuthorities(undefined, true); reservedAuthorities.sort((a, b) => a.name.localeCompare(b.name)); + const expectedEntryKeys = [ + 'ownerAddress', + 'ownerPublicKey', + 'height', + 'status', + 'bondId', + 'expiryTime', + 'auction' + ]; expect(authorities.length).toEqual(4); - authorities.forEach((authority: any, index: number) => { + expectedEntryKeys.forEach(key => { authorities.forEach((authority: any) => { - expect(authority).toHaveProperty('name'); - expect(authority.entry).toHaveProperty('ownerAddress'); - expect(authority.entry).toHaveProperty('status'); + expect(authority.entry).toHaveProperty(key); }); + }); + authorities.forEach((authority: any, index: number) => { + expect(authority).toHaveProperty('name'); + expect(authority.entry).toHaveProperty('ownerAddress'); + expect(authority.entry).toHaveProperty('status'); expect(authority).toMatchObject(reservedAuthorities[index]); }); }); diff --git a/src/onboarding.test.ts b/src/onboarding.test.ts index ca51fd9..25e6f51 100644 --- a/src/onboarding.test.ts +++ b/src/onboarding.test.ts @@ -25,9 +25,8 @@ const onboardingEnabledTests = () => { const mnemonic = Account.generateMnemonic(); ethWallet = Wallet.fromMnemonic(mnemonic); - const account = new Account(Buffer.from(privateKey, 'hex')); - const cosmosAccount = await DirectSecp256k1Wallet.fromKey(account._privateKey, 'laconic'); - [cosmosWallet] = await cosmosAccount.getAccounts(); + const accountWallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(privateKey, 'hex'), 'laconic'); + [cosmosWallet] = await accountWallet.getAccounts(); expectedParticipants = [ { -- 2.45.2 From a190e517fdf97d2f6aeed7ffa889763f72de3660 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Mon, 5 Aug 2024 09:57:11 +0530 Subject: [PATCH 6/7] Fix authority expiry timeout --- src/nameservice-expiry.test.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/nameservice-expiry.test.ts b/src/nameservice-expiry.test.ts index 184c13a..262d327 100644 --- a/src/nameservice-expiry.test.ts +++ b/src/nameservice-expiry.test.ts @@ -60,10 +60,11 @@ const nameserviceExpiryTests = () => { }); test('Wait for expiry duration', (done) => { - setTimeout(done, 60 * 1000); + // Wait expirty time + time for a block to be executed + const expiryTime = 60 * 1000; + const waitTime = expiryTime + (3 * 1000); - // Wait some more time for block to be executed - setTimeout(done, 3 * 1000); + setTimeout(done, waitTime); }); test('Check record expiry time', async () => { @@ -87,10 +88,11 @@ const nameserviceExpiryTests = () => { }); test('Wait for expiry duration', (done) => { - setTimeout(done, 60 * 1000); + // Wait expirty time + time for a block to be executed + const expiryTime = 60 * 1000; + const waitTime = expiryTime + (3 * 1000); - // Wait some more time for block to be executed - setTimeout(done, 3 * 1000); + setTimeout(done, waitTime); }); test('Check record deleted without bond balance', async () => { -- 2.45.2 From 06344cce509cfa071996df8758b0850f72b69b23 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 5 Aug 2024 12:02:34 +0530 Subject: [PATCH 7/7] Fix typos --- src/nameservice-expiry.test.ts | 4 ++-- src/naming.test.ts | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/nameservice-expiry.test.ts b/src/nameservice-expiry.test.ts index 262d327..c19de2a 100644 --- a/src/nameservice-expiry.test.ts +++ b/src/nameservice-expiry.test.ts @@ -60,7 +60,7 @@ const nameserviceExpiryTests = () => { }); test('Wait for expiry duration', (done) => { - // Wait expirty time + time for a block to be executed + // Wait for expiry time + time for a block to be executed const expiryTime = 60 * 1000; const waitTime = expiryTime + (3 * 1000); @@ -88,7 +88,7 @@ const nameserviceExpiryTests = () => { }); test('Wait for expiry duration', (done) => { - // Wait expirty time + time for a block to be executed + // Wait for expiry time + time for a block to be executed const expiryTime = 60 * 1000; const waitTime = expiryTime + (3 * 1000); diff --git a/src/naming.test.ts b/src/naming.test.ts index 0711091..1bac15b 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -183,13 +183,11 @@ const namingTests = () => { expect(authorities.length).toEqual(4); expectedEntryKeys.forEach(key => { authorities.forEach((authority: any) => { + expect(authority).toHaveProperty('name'); expect(authority.entry).toHaveProperty(key); }); }); authorities.forEach((authority: any, index: number) => { - expect(authority).toHaveProperty('name'); - expect(authority.entry).toHaveProperty('ownerAddress'); - expect(authority.entry).toHaveProperty('status'); expect(authority).toMatchObject(reservedAuthorities[index]); }); }); -- 2.45.2