diff --git a/src/bond.test.ts b/src/bond.test.ts index 06df38b..b64e35e 100644 --- a/src/bond.test.ts +++ b/src/bond.test.ts @@ -1,6 +1,6 @@ import path from 'path'; -import { Registry } from './index'; +import { Account, Registry } from './index'; import { ensureUpdatedConfig, getConfig } from './testing/helper'; import { DENOM } from './constants'; @@ -61,13 +61,23 @@ const bondTests = () => { }); test('Query bonds by owner.', async () => { - const [result] = await registry.queryBondsByOwner([bond1.owner]); - expect(result).toBeDefined(); - expect(result.bonds).toBeDefined(); + const mnenonic = Account.generateMnemonic(); + const otherAccount = await Account.generateFromMnemonic(mnenonic); + 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); - expect(filteredBonds).toHaveLength(1); - expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner }); + const { id: bondId2 } = await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, otherAccount.getPrivateKey(), fee); + + 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 () => { diff --git a/src/index.ts b/src/index.ts index 0efd22f..298dc65 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,7 @@ import { Coin } from './proto/cosmos/base/v1beta1/coin'; import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx'; import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/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. @@ -60,7 +60,7 @@ export const createBid = async (chainId: string, auctionId: string, bidderAddres }; interface RegistryOptions { - chainId?: string + chainId: string gasPrice?: GasPrice } @@ -70,15 +70,15 @@ export class Registry { _client: RegistryClient; _gasPrice?: GasPrice; - constructor (gqlUrl: string, rpcUrl = '', options?: RegistryOptions) { + constructor (gqlUrl: string, rpcUrl = '', options: RegistryOptions) { this._endpoints = { rpc: rpcUrl, gql: gqlUrl }; this._client = new RegistryClient(gqlUrl, rpcUrl); - this._chainID = options?.chainId ?? DEFAULT_CHAIN_ID; - this._gasPrice = options?.gasPrice; + this._chainID = options.chainId; + this._gasPrice = options.gasPrice; } /**