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
Lint & Build / lint_and_build (20.x) (pull_request) Successful in 2m28s
Tests / sdk_tests (pull_request) Failing after 18m33s
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
12 changed files with 55 additions and 89 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/registry-sdk",
"version": "0.2.8",
"version": "0.2.6",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "git@github.com:cerc-io/registry-sdk.git",
+6 -11
View File
@@ -54,20 +54,15 @@ const bondTests = () => {
test('Query bonds.', async () => {
const bonds = await registry.queryBonds();
expect(bonds).toBeDefined();
const filteredBonds = bonds.filter((bond: any) => bond.id === bond1.id);
expect(filteredBonds).toHaveLength(1);
expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner });
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
expect(bond).toBeDefined();
});
test('Query bonds by owner.', async () => {
const [result] = await registry.queryBondsByOwner([bond1.owner]);
expect(result).toBeDefined();
expect(result.bonds).toBeDefined();
const filteredBonds = result.bonds.filter((bond: any) => bond.id === bond1.id);
expect(filteredBonds).toHaveLength(1);
expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner });
const bonds = await registry.queryBonds({ owner: bond1.owner });
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
expect(bond).toBeDefined();
});
test('Refill bond.', async () => {
+5 -12
View File
@@ -107,8 +107,8 @@ export class Registry {
/**
* Get records by attributes.
*/
async queryRecords (attributes: { [key: string]: any }, all = false, refs = false, limit?: number, offset?: number) {
return this._client.queryRecords(attributes, all, refs, limit, offset);
async queryRecords (attributes: { [key: string]: any }, all = false, refs = false) {
return this._client.queryRecords(attributes, all, refs);
}
/**
@@ -186,17 +186,10 @@ export class Registry {
}
/**
* Query bonds.
* Query bonds by attributes.
*/
async queryBonds () {
return this._client.queryBonds();
}
/**
* Query bonds by owner(s).
*/
async queryBondsByOwner (owners: string[]) {
return this._client.queryBondsByOwner(owners);
async queryBonds (attributes = {}) {
return this._client.queryBonds(attributes);
}
/**
+2 -2
View File
@@ -13,7 +13,7 @@ import { MsgCancelBondEncodeObject, MsgCreateBondEncodeObject, MsgRefillBondEnco
import { Coin } from './proto/cosmos/base/v1beta1/coin';
import { MsgAssociateBondEncodeObject, MsgDeleteNameEncodeObject, MsgDissociateBondEncodeObject, MsgDissociateRecordsEncodeObject, MsgReassociateRecordsEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgAssociateBond, typeUrlMsgDeleteName, typeUrlMsgDissociateBond, typeUrlMsgDissociateRecords, typeUrlMsgReassociateRecords, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetName, typeUrlMsgSetRecord, NAMESERVICE_ERRORS } from './types/cerc/registry/message';
import { MsgCommitBidEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgRevealBid } from './types/cerc/auction/message';
import { MsgOnboardParticipantEncodeObject, ONBOARDING_DISABLED_ERROR, onboardingTypes, typeUrlMsgOnboardParticipant } from './types/cerc/onboarding/message';
import { MsgOnboardParticipantEncodeObject, onboardingTypes, typeUrlMsgOnboardParticipant } from './types/cerc/onboarding/message';
import { MsgAssociateBondResponse, MsgDeleteNameResponse, MsgDissociateBondResponse, MsgDissociateRecordsResponse, MsgReassociateRecordsResponse, MsgReserveAuthorityResponse, MsgSetAuthorityBondResponse, MsgSetNameResponse, MsgSetRecordResponse, Payload } from './proto/cerc/registry/v1/tx';
import { Record, Signature } from './proto/cerc/registry/v1/registry';
import { Account } from './account';
@@ -381,7 +381,7 @@ export class LaconicClient extends SigningStargateClient {
}
processWriteError (error: string) {
const errorMessage = [...NAMESERVICE_ERRORS, ONBOARDING_DISABLED_ERROR].find(message => error.includes(message));
const errorMessage = NAMESERVICE_ERRORS.find(message => error.includes(message));
if (!errorMessage) {
console.error(error);
+4 -4
View File
@@ -60,10 +60,10 @@ const nameserviceExpiryTests = () => {
});
test('Wait for expiry duration', (done) => {
// Wait for expiry 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
const waitTime = expiryTime + (3 * 1000);
setTimeout(done, waitTime);
});
@@ -88,10 +88,10 @@ const nameserviceExpiryTests = () => {
});
test('Wait for expiry duration', (done) => {
// Wait for expiry 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
const waitTime = expiryTime + (3 * 1000);
setTimeout(done, waitTime);
});
+3 -1
View File
@@ -183,11 +183,13 @@ 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]);
});
});
+3 -2
View File
@@ -2,7 +2,7 @@ import { Wallet } from 'ethers';
import { DirectSecp256k1Wallet, AccountData as CosmosAccount } from '@cosmjs/proto-signing';
import { Registry, Account, ONBOARDING_DISABLED_ERROR } from './index';
import { Registry, Account } from './index';
import { getConfig } from './testing/helper';
import { Participant } from './proto/cerc/onboarding/v1/onboarding';
@@ -80,6 +80,7 @@ const onboardingDisabledTests = () => {
});
test('Error on onboarding attempt.', async () => {
const errorMsg = 'Validator onboarding is disabled: invalid request';
const mnemonic = Account.generateMnemonic();
ethWallet = Wallet.fromMnemonic(mnemonic);
@@ -99,7 +100,7 @@ const onboardingDisabledTests = () => {
kycId: DUMMY_KYC_ID
}, privateKey, fee);
} catch (error: any) {
expect(error.toString()).toContain(ONBOARDING_DISABLED_ERROR);
expect(error.toString()).toContain(errorMsg);
}
});
+7 -7
View File
@@ -1162,7 +1162,7 @@ export const RecordsList = {
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var _globalThis: any = (() => {
var globalThis: any = (() => {
if (typeof globalThis !== "undefined") return globalThis;
if (typeof self !== "undefined") return self;
if (typeof window !== "undefined") return window;
@@ -1171,10 +1171,10 @@ var _globalThis: any = (() => {
})();
function bytesFromBase64(b64: string): Uint8Array {
if (_globalThis.Buffer) {
return Uint8Array.from(_globalThis.Buffer.from(b64, "base64"));
if (globalThis.Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = _globalThis.atob(b64);
const bin = globalThis.atob(b64);
const arr = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; ++i) {
arr[i] = bin.charCodeAt(i);
@@ -1184,14 +1184,14 @@ function bytesFromBase64(b64: string): Uint8Array {
}
function base64FromBytes(arr: Uint8Array): string {
if (_globalThis.Buffer) {
return _globalThis.Buffer.from(arr).toString("base64");
if (globalThis.Buffer) {
return globalThis.Buffer.from(arr).toString("base64");
} else {
const bin: string[] = [];
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
});
return _globalThis.btoa(bin.join(""));
return globalThis.btoa(bin.join(""));
}
}
@@ -251,7 +251,7 @@ export const PageResponse = {
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var _globalThis: any = (() => {
var globalThis: any = (() => {
if (typeof globalThis !== "undefined") return globalThis;
if (typeof self !== "undefined") return self;
if (typeof window !== "undefined") return window;
@@ -260,10 +260,10 @@ var _globalThis: any = (() => {
})();
function bytesFromBase64(b64: string): Uint8Array {
if (_globalThis.Buffer) {
return Uint8Array.from(_globalThis.Buffer.from(b64, "base64"));
if (globalThis.Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = _globalThis.atob(b64);
const bin = globalThis.atob(b64);
const arr = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; ++i) {
arr[i] = bin.charCodeAt(i);
@@ -273,14 +273,14 @@ function bytesFromBase64(b64: string): Uint8Array {
}
function base64FromBytes(arr: Uint8Array): string {
if (_globalThis.Buffer) {
return _globalThis.Buffer.from(arr).toString("base64");
if (globalThis.Buffer) {
return globalThis.Buffer.from(arr).toString("base64");
} else {
const bin: string[] = [];
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
});
return _globalThis.btoa(bin.join(""));
return globalThis.btoa(bin.join(""));
}
}
+7 -7
View File
@@ -4324,7 +4324,7 @@ export const GeneratedCodeInfo_Annotation = {
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var _globalThis: any = (() => {
var globalThis: any = (() => {
if (typeof globalThis !== "undefined") return globalThis;
if (typeof self !== "undefined") return self;
if (typeof window !== "undefined") return window;
@@ -4333,10 +4333,10 @@ var _globalThis: any = (() => {
})();
function bytesFromBase64(b64: string): Uint8Array {
if (_globalThis.Buffer) {
return Uint8Array.from(_globalThis.Buffer.from(b64, "base64"));
if (globalThis.Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = _globalThis.atob(b64);
const bin = globalThis.atob(b64);
const arr = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; ++i) {
arr[i] = bin.charCodeAt(i);
@@ -4346,14 +4346,14 @@ function bytesFromBase64(b64: string): Uint8Array {
}
function base64FromBytes(arr: Uint8Array): string {
if (_globalThis.Buffer) {
return _globalThis.Buffer.from(arr).toString("base64");
if (globalThis.Buffer) {
return globalThis.Buffer.from(arr).toString("base64");
} else {
const bin: string[] = [];
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
});
return _globalThis.btoa(bin.join(""));
return globalThis.btoa(bin.join(""));
}
}
+10 -33
View File
@@ -241,13 +241,13 @@ export class RegistryClient {
/**
* Get records by attributes.
*/
async queryRecords (attributes: { [key: string]: any }, all = false, refs = false, limit?: number, offset?: number) {
async queryRecords (attributes: { [key: string]: any }, all = false, refs = false) {
if (!attributes) {
attributes = {};
}
const query = `query ($attributes: [KeyValueInput!], $all: Boolean, $limit: Int, $offset: Int) {
queryRecords(attributes: $attributes, all: $all, limit: $limit, offset: $offset) {
const query = `query ($attributes: [KeyValueInput!], $all: Boolean) {
queryRecords(attributes: $attributes, all: $all) {
id
names
owners
@@ -261,9 +261,7 @@ export class RegistryClient {
const variables = {
attributes: Util.toGQLAttributes(attributes),
all,
limit,
offset
all
};
let result = (await this._graph(query)(variables)).queryRecords;
@@ -427,11 +425,11 @@ export class RegistryClient {
}
/**
* Get bonds.
* Get bonds by attributes.
*/
async queryBonds () {
const query = `query {
queryBonds {
async queryBonds (attributes = {}) {
const query = `query ($attributes: [KeyValueInput!]) {
queryBonds(attributes: $attributes) {
id
owner
balance {
@@ -441,32 +439,11 @@ export class RegistryClient {
}
}`;
return RegistryClient.getResult(this._graph(query)({}), 'queryBonds');
}
/**
* Get bonds by owner(s).
*/
async queryBondsByOwner (ownerAddresses: string[]) {
const query = `query ($ownerAddresses: [String!]) {
queryBondsByOwner(ownerAddresses: $ownerAddresses) {
owner
bonds {
id
owner
balance {
type
quantity
}
}
}
}`;
const variables = {
ownerAddresses
attributes: Util.toGQLAttributes(attributes)
};
return RegistryClient.getResult(this._graph(query)(variables), 'queryBondsByOwner');
return RegistryClient.getResult(this._graph(query)(variables), 'queryBonds');
}
/**
-2
View File
@@ -15,8 +15,6 @@ export interface MsgOnboardParticipantEncodeObject extends EncodeObject {
readonly value: MsgOnboardParticipant;
}
export const ONBOARDING_DISABLED_ERROR = 'Onboarding is disabled';
interface ethPayload {
address: string
msg: string