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 1m48s
Tests / sdk_tests (pull_request) Successful in 20m57s

This commit is contained in:
Prathamesh Musale 2024-08-27 14:30:34 +05:30
parent 1c16b64752
commit 5744e2a08f
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

@ -186,10 +186,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

@ -427,11 +427,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 {
@ -441,11 +441,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');
}
/**