Compare commits

...

6 Commits

Author SHA1 Message Date
IshaVenikar
5fe6c432de Fix authority expiry timeout 2024-08-05 09:57:11 +05:30
IshaVenikar
37c2f5897f Check for properties in returned authorities list 2024-08-02 16:06:37 +05:30
IshaVenikar
225aa2a6aa Check name and owner address for authorities 2024-08-02 15:15:05 +05:30
IshaVenikar
81dbf57fc2 Update check for list authorities by owner 2024-08-02 11:52:49 +05:30
IshaVenikar
a3b78fd363 Check owner address for returned authorities 2024-08-02 10:04:14 +05:30
IshaVenikar
52cab23c70 Add method for get authorities 2024-08-01 16:44:21 +05:30
6 changed files with 134 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@cerc-io/registry-sdk", "name": "@cerc-io/registry-sdk",
"version": "0.2.5", "version": "0.2.6",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"repository": "git@github.com:cerc-io/registry-sdk.git", "repository": "git@github.com:cerc-io/registry-sdk.git",

View File

@ -389,6 +389,13 @@ export class Registry {
return this._client.getAuctionsByIds(ids); return this._client.getAuctionsByIds(ids);
} }
/**
* List authorities by owner.
*/
async getAuthorities (owner?: string, auction = false) {
return this._client.getAuthorities(owner, auction);
}
/** /**
* Lookup authorities by names. * Lookup authorities by names.
*/ */

View File

@ -60,7 +60,11 @@ const nameserviceExpiryTests = () => {
}); });
test('Wait for expiry duration', (done) => { test('Wait for expiry duration', (done) => {
setTimeout(done, 60 * 1000); const expiryTime = 60 * 1000;
// Wait some more time for block to be executed
const waitTime = expiryTime + (3 * 1000);
setTimeout(done, waitTime);
}); });
test('Check record expiry time', async () => { test('Check record expiry time', async () => {
@ -84,7 +88,11 @@ const nameserviceExpiryTests = () => {
}); });
test('Wait for expiry duration', (done) => { test('Wait for expiry duration', (done) => {
setTimeout(done, 60 * 1000); const expiryTime = 60 * 1000;
// Wait some more time for block to be executed
const waitTime = expiryTime + (3 * 1000);
setTimeout(done, waitTime);
}); });
test('Check record deleted without bond balance', async () => { test('Check record deleted without bond balance', async () => {

View File

@ -1,6 +1,8 @@
import assert from 'assert'; import assert from 'assert';
import path from 'path'; import path from 'path';
import { DirectSecp256k1Wallet, AccountData as CosmosAccount } from '@cosmjs/proto-signing';
import { Account } from './account'; import { Account } from './account';
import { Registry } from './index'; import { Registry } from './index';
import { ensureUpdatedConfig, getConfig } from './testing/helper'; import { ensureUpdatedConfig, getConfig } from './testing/helper';
@ -19,6 +21,18 @@ const namingTests = () => {
let watcher: any; let watcher: any;
let watcherId: string; let watcherId: string;
let otherAccount1: Account;
let reservedAuthorities: {
name: string;
entry: {
ownerAddress: string;
status: string;
};
}[] = [];
let account: CosmosAccount;
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
@ -39,12 +53,26 @@ const namingTests = () => {
); );
watcherId = result.id; watcherId = result.id;
const accountWallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(privateKey, 'hex'), 'laconic');
[account] = await accountWallet.getAccounts();
const mnenonic1 = Account.generateMnemonic();
otherAccount1 = await Account.generateFromMnemonic(mnenonic1);
await otherAccount1.init();
}); });
describe('Authority tests', () => { describe('Authority tests', () => {
test('Reserve authority.', async () => { test('Reserve authority.', async () => {
const authorityName = `laconic-${Date.now()}`; const authorityName = `laconic-${Date.now()}`;
await registry.reserveAuthority({ name: authorityName }, privateKey, fee); await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
reservedAuthorities.push({
name: authorityName,
entry: {
ownerAddress: account.address,
status: 'active'
}
});
}); });
describe('With authority reserved', () => { describe('With authority reserved', () => {
@ -56,6 +84,13 @@ const namingTests = () => {
lrn = `lrn://${authorityName}/app/test`; lrn = `lrn://${authorityName}/app/test`;
await registry.reserveAuthority({ name: authorityName }, privateKey, fee); await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
reservedAuthorities.push({
name: authorityName,
entry: {
ownerAddress: account.address,
status: 'active'
}
});
}); });
test('Lookup authority.', async () => { test('Lookup authority.', async () => {
@ -80,6 +115,13 @@ const namingTests = () => {
test('Reserve sub-authority.', async () => { test('Reserve sub-authority.', async () => {
const subAuthority = `echo.${authorityName}`; const subAuthority = `echo.${authorityName}`;
await registry.reserveAuthority({ name: subAuthority }, privateKey, fee); await registry.reserveAuthority({ name: subAuthority }, privateKey, fee);
reservedAuthorities.push({
name: subAuthority,
entry: {
ownerAddress: account.address,
status: 'active'
}
});
const [record] = await registry.lookupAuthorities([subAuthority]); const [record] = await registry.lookupAuthorities([subAuthority]);
expect(record).toBeDefined(); expect(record).toBeDefined();
@ -90,18 +132,22 @@ const namingTests = () => {
test('Reserve sub-authority with different owner.', async () => { test('Reserve sub-authority with different owner.', async () => {
// Create another account, send tx to set public key on the account. // 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 mnenonic2 = Account.generateMnemonic();
const otherAccount2 = await Account.generateFromMnemonic(mnenonic2); const otherAccount2 = await Account.generateFromMnemonic(mnenonic2);
await otherAccount2.init(); 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); await registry.sendCoins({ denom: DENOM, amount: '1000', destinationAddress: otherAccount2.address }, otherAccount1.getPrivateKey(), fee);
const subAuthority = `halo.${authorityName}`; const subAuthority = `halo.${authorityName}`;
await registry.reserveAuthority({ name: subAuthority, owner: otherAccount1.address }, privateKey, fee); 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]); const [record] = await registry.lookupAuthorities([subAuthority]);
expect(record).toBeDefined(); expect(record).toBeDefined();
@ -120,6 +166,41 @@ const namingTests = () => {
test('Set authority bond', async () => { test('Set authority bond', async () => {
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee); await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
}); });
test('List authorities.', async () => {
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);
expectedEntryKeys.forEach(key => {
authorities.forEach((authority: any) => {
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]);
});
});
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);
});
}); });
}); });

View File

@ -25,9 +25,8 @@ const onboardingEnabledTests = () => {
const mnemonic = Account.generateMnemonic(); const mnemonic = Account.generateMnemonic();
ethWallet = Wallet.fromMnemonic(mnemonic); ethWallet = Wallet.fromMnemonic(mnemonic);
const account = new Account(Buffer.from(privateKey, 'hex')); const accountWallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(privateKey, 'hex'), 'laconic');
const cosmosAccount = await DirectSecp256k1Wallet.fromKey(account._privateKey, 'laconic'); [cosmosWallet] = await accountWallet.getAccounts();
[cosmosWallet] = await cosmosAccount.getAccounts();
expectedParticipants = [ expectedParticipants = [
{ {

View File

@ -270,6 +270,34 @@ export class RegistryClient {
return result; return result;
} }
/**
* List authorities by owner.
*/
async getAuthorities (owner?: string, auction = false) {
const query = `query ($owner: String) {
getAuthorities(owner: $owner) {
name
entry {
ownerAddress
ownerPublicKey
height
status
bondId
expiryTime
${auction ? ('auction { ' + auctionFields + ' }') : ''}
}
}
}`;
const variables = {
owner
};
const result = await this._graph(query)(variables);
return result.getAuthorities;
}
/** /**
* Lookup authorities by names. * Lookup authorities by names.
*/ */