Update test to query bonds by owner
Some checks failed
Lint & Build / lint_and_build (20.x) (pull_request) Successful in 1m57s
Tests / sdk_tests (pull_request) Failing after 9m34s

This commit is contained in:
IshaVenikar 2024-09-05 17:30:54 +05:30
parent cb1d74614c
commit d30245c6df
2 changed files with 22 additions and 12 deletions

View File

@ -1,6 +1,6 @@
import path from 'path'; import path from 'path';
import { Registry } from './index'; import { Account, Registry } from './index';
import { ensureUpdatedConfig, getConfig } from './testing/helper'; import { ensureUpdatedConfig, getConfig } from './testing/helper';
import { DENOM } from './constants'; import { DENOM } from './constants';
@ -61,13 +61,23 @@ const bondTests = () => {
}); });
test('Query bonds by owner.', async () => { test('Query bonds by owner.', async () => {
const [result] = await registry.queryBondsByOwner([bond1.owner]); const mnenonic = Account.generateMnemonic();
expect(result).toBeDefined(); const otherAccount = await Account.generateFromMnemonic(mnenonic);
expect(result.bonds).toBeDefined(); await otherAccount.init();
await registry.sendCoins({ denom: DENOM, amount: '1000000000000', destinationAddress: otherAccount.address }, privateKey, fee);
const filteredBonds = result.bonds.filter((bond: any) => bond.id === bond1.id); const { id: bondId2 } = await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, otherAccount.getPrivateKey(), fee);
expect(filteredBonds).toHaveLength(1);
expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner }); const [owner1Bonds] = await registry.queryBondsByOwner(bond1.owner);
expect(owner1Bonds.bonds).toHaveLength(2);
const owner1Bond = owner1Bonds.bonds.filter((bond: any) => bond.id === bond1.id);
expect(owner1Bond).toBeDefined();
const [bond2] = await registry.getBondsByIds([bondId2]);
const [owner2Bonds] = await registry.queryBondsByOwner(bond2.owner);
expect(owner2Bonds.bonds).toHaveLength(1);
const owner2Bond = owner2Bonds.bonds.filter((bond: any) => bond.id === bond2.id);
expect(owner2Bond).toBeDefined();
}); });
test('Refill bond.', async () => { test('Refill bond.', async () => {

View File

@ -31,7 +31,7 @@ import { Coin } from './proto/cosmos/base/v1beta1/coin';
import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx'; import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx';
import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx'; import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx';
import { MsgSendResponse } from './proto/cosmos/bank/v1beta1/tx'; import { MsgSendResponse } from './proto/cosmos/bank/v1beta1/tx';
import { DEFAULT_CHAIN_ID, DEFAULT_GAS_ESTIMATION_MULTIPLIER } from './constants'; import { DEFAULT_GAS_ESTIMATION_MULTIPLIER } from './constants';
/** /**
* Create an auction bid. * Create an auction bid.
@ -60,7 +60,7 @@ export const createBid = async (chainId: string, auctionId: string, bidderAddres
}; };
interface RegistryOptions { interface RegistryOptions {
chainId?: string chainId: string
gasPrice?: GasPrice gasPrice?: GasPrice
} }
@ -70,15 +70,15 @@ export class Registry {
_client: RegistryClient; _client: RegistryClient;
_gasPrice?: GasPrice; _gasPrice?: GasPrice;
constructor (gqlUrl: string, rpcUrl = '', options?: RegistryOptions) { constructor (gqlUrl: string, rpcUrl = '', options: RegistryOptions) {
this._endpoints = { this._endpoints = {
rpc: rpcUrl, rpc: rpcUrl,
gql: gqlUrl gql: gqlUrl
}; };
this._client = new RegistryClient(gqlUrl, rpcUrl); this._client = new RegistryClient(gqlUrl, rpcUrl);
this._chainID = options?.chainId ?? DEFAULT_CHAIN_ID; this._chainID = options.chainId;
this._gasPrice = options?.gasPrice; this._gasPrice = options.gasPrice;
} }
/** /**