Add a method to query bonds by owner and update tests
All checks were successful
Lint & Build / lint_and_build (20.x) (pull_request) Successful in 1m53s
Tests / sdk_tests (pull_request) Successful in 21m26s

This commit is contained in:
Prathamesh Musale 2024-08-27 14:30:34 +05:30
parent 06adca6e81
commit 9a1abc18ca
3 changed files with 48 additions and 15 deletions

View File

@ -54,15 +54,20 @@ const bondTests = () => {
test('Query bonds.', async () => {
const bonds = await registry.queryBonds();
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
expect(bond).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 });
});
test('Query bonds by owner.', async () => {
const bonds = await registry.queryBonds({ owner: bond1.owner });
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
expect(bond).toBeDefined();
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 });
});
test('Refill bond.', async () => {

View File

@ -192,10 +192,17 @@ export class Registry {
}
/**
* Query bonds by attributes.
* Query bonds.
*/
async queryBonds (attributes = {}) {
return this._client.queryBonds(attributes);
async queryBonds () {
return this._client.queryBonds();
}
/**
* Query bonds by owner(s).
*/
async queryBondsByOwner (owners: string[]) {
return this._client.queryBondsByOwner(owners);
}
/**

View File

@ -425,11 +425,11 @@ export class RegistryClient {
}
/**
* Get bonds by attributes.
* Get bonds.
*/
async queryBonds (attributes = {}) {
const query = `query ($attributes: [KeyValueInput!]) {
queryBonds(attributes: $attributes) {
async queryBonds () {
const query = `query {
queryBonds {
id
owner
balance {
@ -439,11 +439,32 @@ 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 = {
attributes: Util.toGQLAttributes(attributes)
ownerAddresses
};
return RegistryClient.getResult(this._graph(query)(variables), 'queryBonds');
return RegistryClient.getResult(this._graph(query)(variables), 'queryBondsByOwner');
}
/**