From e8c6079559946df1dfb4822164abb6d60e108b21 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Thu, 22 Aug 2024 11:40:44 +0530 Subject: [PATCH 01/19] Add test to send multiple txs --- src/index.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/index.test.ts b/src/index.test.ts index 0d846fc..7a3c1bf 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -43,6 +43,37 @@ const registryTests = () => { expect(type).toBe(DENOM); expect(quantity).toBe('10000'); }); + + test('Get transaction info.', async () => { + const bondAmount = '100000'; + + const accounts = await createAccounts(10); + + for (let i = 0; i < 10; i++) { + const amount = (10 ** (15 - i)).toString(); + const fromAccount = i === 0 ? privateKey : accounts[i - 1].getPrivateKey(); + + await registry.sendCoins({ denom: DENOM, amount, destinationAddress: accounts[i].address }, fromAccount, fee); + } + const bondPromises = accounts.map((account) => + registry.createBond({ denom: DENOM, amount: bondAmount }, account.getPrivateKey(), fee) + ); + + await Promise.all(bondPromises); + }); + + const createAccounts = async (numAccounts: number): Promise => { + const accounts: Account[] = []; + + for (let i = 0; i < numAccounts; i++) { + const mnemonic = Account.generateMnemonic(); + const account = await Account.generateFromMnemonic(mnemonic); + await account.init(); + accounts.push(account); + } + + return accounts; + }; }; describe('Registry', registryTests); -- 2.45.2 From b7795b83275b1cc4d65e0dca10c2005aaae36185 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Thu, 22 Aug 2024 12:07:21 +0530 Subject: [PATCH 02/19] Add test to check block height for all txs --- src/index.test.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 7a3c1bf..eeffcdc 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -44,9 +44,7 @@ const registryTests = () => { expect(quantity).toBe('10000'); }); - test('Get transaction info.', async () => { - const bondAmount = '100000'; - + test('Send batch txs.', async () => { const accounts = await createAccounts(10); for (let i = 0; i < 10; i++) { @@ -55,11 +53,16 @@ const registryTests = () => { await registry.sendCoins({ denom: DENOM, amount, destinationAddress: accounts[i].address }, fromAccount, fee); } - const bondPromises = accounts.map((account) => - registry.createBond({ denom: DENOM, amount: bondAmount }, account.getPrivateKey(), fee) - ); - await Promise.all(bondPromises); + await Promise.all(accounts.map((account) => + registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee) + )); + + const laconicClient = await registry.getLaconicClient(accounts[0]); + const bondTx = await laconicClient.searchTx('message.action="/cerc.bond.v1.MsgCreateBond"'); + + const expectedBlockHeight = bondTx[0].height; + expect(bondTx.every(tx => tx.height === expectedBlockHeight)).toBe(true); }); const createAccounts = async (numAccounts: number): Promise => { -- 2.45.2 From d979b2c1c000aa2c4c14930f2cce8f6818545327 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Thu, 22 Aug 2024 12:31:04 +0530 Subject: [PATCH 03/19] Refactor Batch txs test --- src/index.test.ts | 48 ++++++++++++++++++------------------------- src/testing/helper.ts | 15 +++++++++++++- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index eeffcdc..c8d006a 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,7 +1,7 @@ import { Account } from './account'; import { DENOM } from './constants'; import { Registry } from './index'; -import { getConfig } from './testing/helper'; +import { createTestAccounts, getConfig } from './testing/helper'; const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig(); @@ -44,39 +44,31 @@ const registryTests = () => { expect(quantity).toBe('10000'); }); - test('Send batch txs.', async () => { - const accounts = await createAccounts(10); + describe('Batch txs', () => { + let accounts: Account[]; - for (let i = 0; i < 10; i++) { - const amount = (10 ** (15 - i)).toString(); - const fromAccount = i === 0 ? privateKey : accounts[i - 1].getPrivateKey(); + beforeAll(async () => { + accounts = await createTestAccounts(10); + for (let i = 0; i < 10; i++) { + const amount = (10 ** (15 - i)).toString(); + const fromAccount = i === 0 ? privateKey : accounts[i - 1].getPrivateKey(); - await registry.sendCoins({ denom: DENOM, amount, destinationAddress: accounts[i].address }, fromAccount, fee); - } + await registry.sendCoins({ denom: DENOM, amount, destinationAddress: accounts[i].address }, fromAccount, fee); + } + }); - await Promise.all(accounts.map((account) => - registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee) - )); + test('All txs get included in a single block.', async () => { + await Promise.all(accounts.map((account) => + registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee) + )); - const laconicClient = await registry.getLaconicClient(accounts[0]); - const bondTx = await laconicClient.searchTx('message.action="/cerc.bond.v1.MsgCreateBond"'); + const laconicClient = await registry.getLaconicClient(accounts[0]); + const bondTx = await laconicClient.searchTx("message.action='/cerc.bond.v1.MsgCreateBond'"); - const expectedBlockHeight = bondTx[0].height; - expect(bondTx.every(tx => tx.height === expectedBlockHeight)).toBe(true); + const expectedBlockHeight = bondTx[0].height; + expect(bondTx.every(tx => tx.height === expectedBlockHeight)).toBe(true); + }); }); - - const createAccounts = async (numAccounts: number): Promise => { - const accounts: Account[] = []; - - for (let i = 0; i < numAccounts; i++) { - const mnemonic = Account.generateMnemonic(); - const account = await Account.generateFromMnemonic(mnemonic); - await account.init(); - accounts.push(account); - } - - return accounts; - }; }; describe('Registry', registryTests); diff --git a/src/testing/helper.ts b/src/testing/helper.ts index c431146..8c85652 100644 --- a/src/testing/helper.ts +++ b/src/testing/helper.ts @@ -2,7 +2,7 @@ import assert from 'assert'; import yaml from 'node-yaml'; import semver from 'semver'; -import { DEFAULT_CHAIN_ID } from '../index'; +import { Account, DEFAULT_CHAIN_ID } from '../index'; export const ensureUpdatedConfig = async (path: string) => { const conf = await yaml.read(path); @@ -33,3 +33,16 @@ export const getConfig = () => { } }; }; + +export const createTestAccounts = async (numAccounts: number): Promise => { + const accounts: Account[] = []; + + for (let i = 0; i < numAccounts; i++) { + const mnemonic = Account.generateMnemonic(); + const account = await Account.generateFromMnemonic(mnemonic); + await account.init(); + accounts.push(account); + } + + return accounts; +}; -- 2.45.2 From 96f27d4c76b8a07eebe4cc8ff8f22d410dd59bae Mon Sep 17 00:00:00 2001 From: Nabarun Date: Fri, 23 Aug 2024 08:08:32 +0530 Subject: [PATCH 04/19] Add option for setting gas price --- src/auction.test.ts | 2 +- src/bond.test.ts | 2 +- src/index.test.ts | 2 +- src/index.ts | 21 +++++++++++++++++---- src/nameservice-expiry.test.ts | 2 +- src/naming.test.ts | 2 +- src/onboarding.test.ts | 4 ++-- src/sdk.test.ts | 2 +- src/util.test.ts | 2 +- 9 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/auction.test.ts b/src/auction.test.ts index 62bd654..4bec436 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -16,7 +16,7 @@ const auctionTests = (numBidders = 3) => { beforeAll(async () => { console.log('Running auction tests with num bidders', numBidders); - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); }); test('Setup bidder accounts', async () => { diff --git a/src/bond.test.ts b/src/bond.test.ts index 6bbeb7f..06df38b 100644 --- a/src/bond.test.ts +++ b/src/bond.test.ts @@ -21,7 +21,7 @@ const bondTests = () => { }; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); }); test('Create bond.', async () => { diff --git a/src/index.test.ts b/src/index.test.ts index c8d006a..e91ae88 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -11,7 +11,7 @@ const registryTests = () => { let registry: Registry; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); }); test('Get account info.', async () => { diff --git a/src/index.ts b/src/index.ts index 09c5e1a..9ed43c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { sha256 } from 'js-sha256'; -import { DeliverTxResponse, StdFee } from '@cosmjs/stargate'; +import { DeliverTxResponse, StdFee, GasPrice } from '@cosmjs/stargate'; import { RegistryClient } from './registry-client'; import { Account } from './account'; @@ -60,19 +60,26 @@ export const createBid = async (chainId: string, auctionId: string, bidderAddres }; }; +interface RegistryOptions { + chainId?: string + gasPrice?: GasPrice +} + export class Registry { _endpoints: { [key: string]: string }; _chainID: string; _client: RegistryClient; + _gasPrice?: GasPrice; - constructor (gqlUrl: string, rpcUrl = '', chainId: string = DEFAULT_CHAIN_ID) { + constructor (gqlUrl: string, rpcUrl = '', options?: RegistryOptions) { this._endpoints = { rpc: rpcUrl, gql: gqlUrl }; this._client = new RegistryClient(gqlUrl, rpcUrl); - this._chainID = chainId; + this._chainID = options?.chainId ?? DEFAULT_CHAIN_ID; + this._gasPrice = options?.gasPrice; } /** @@ -448,7 +455,13 @@ export class Registry { } async getLaconicClient (account: Account) { - return LaconicClient.connectWithSigner(this._endpoints.rpc, account.wallet); + return LaconicClient.connectWithSigner( + this._endpoints.rpc, + account.wallet, + { + gasPrice: this._gasPrice + } + ); } /** diff --git a/src/nameservice-expiry.test.ts b/src/nameservice-expiry.test.ts index c19de2a..1724cce 100644 --- a/src/nameservice-expiry.test.ts +++ b/src/nameservice-expiry.test.ts @@ -21,7 +21,7 @@ const nameserviceExpiryTests = () => { let recordExpiryTime: Date; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); // Create bond. bondId = await registry.getNextBondId(privateKey); diff --git a/src/naming.test.ts b/src/naming.test.ts index 1bac15b..4d90228 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -34,7 +34,7 @@ const namingTests = () => { let account: CosmosAccount; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); // Create bond. bondId = await registry.getNextBondId(privateKey); diff --git a/src/onboarding.test.ts b/src/onboarding.test.ts index ff51ca6..28e92fe 100644 --- a/src/onboarding.test.ts +++ b/src/onboarding.test.ts @@ -20,7 +20,7 @@ const onboardingEnabledTests = () => { let expectedParticipants: Participant[] = []; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); const mnemonic = Account.generateMnemonic(); ethWallet = Wallet.fromMnemonic(mnemonic); @@ -76,7 +76,7 @@ const onboardingDisabledTests = () => { let ethWallet: Wallet; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); }); test('Error on onboarding attempt.', async () => { diff --git a/src/sdk.test.ts b/src/sdk.test.ts index f3217f5..9b13c7f 100644 --- a/src/sdk.test.ts +++ b/src/sdk.test.ts @@ -16,7 +16,7 @@ describe('Querying', () => { let bondId: string; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); bondId = await registry.getNextBondId(privateKey); await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, fee); diff --git a/src/util.test.ts b/src/util.test.ts index 4e198a9..7815e4e 100644 --- a/src/util.test.ts +++ b/src/util.test.ts @@ -19,7 +19,7 @@ const utilTests = () => { let watcherId: string; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); // Create bond. bondId = await registry.getNextBondId(privateKey); -- 2.45.2 From fa64e725c021c25456976b07ef15ec8ac13a6c98 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 23 Aug 2024 12:31:40 +0530 Subject: [PATCH 05/19] Accept fees optionally as gas estimation multiplier --- src/constants.ts | 3 +++ src/index.ts | 56 +++++++++++++++++++++---------------------- src/testing/helper.ts | 3 ++- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 7371e32..2206b01 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1 +1,4 @@ export const DENOM = 'alnt'; +export const DEFAULT_CHAIN_ID = 'laconic_9000-1'; + +export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 1.5; diff --git a/src/index.ts b/src/index.ts index 9ed43c9..0efd22f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,8 +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'; - -export const DEFAULT_CHAIN_ID = 'laconic_9000-1'; +import { DEFAULT_CHAIN_ID, DEFAULT_GAS_ESTIMATION_MULTIPLIER } from './constants'; /** * Create an auction bid. @@ -132,7 +131,7 @@ export class Registry { async setRecord ( { privateKey, record, bondId }: { privateKey: string, record: any, bondId: string }, transactionPrivateKey: string, - fee: StdFee + fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER ) { const account = new Account(Buffer.from(transactionPrivateKey, 'hex')); await account.init(); @@ -147,7 +146,7 @@ export class Registry { /** * Send coins. */ - async sendCoins ({ amount, denom, destinationAddress }: MessageMsgSendCoins, privateKey: string, fee: StdFee) { + async sendCoins ({ amount, denom, destinationAddress }: MessageMsgSendCoins, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -209,7 +208,7 @@ export class Registry { /** * Create bond. */ - async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee): Promise { + async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -225,7 +224,7 @@ export class Registry { /** * Refill bond. */ - async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee): Promise { + async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -242,7 +241,7 @@ export class Registry { /** * Withdraw (from) bond. */ - async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee): Promise { + async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -259,7 +258,7 @@ export class Registry { /** * Cancel bond. */ - async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee): Promise { + async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -274,7 +273,7 @@ export class Registry { /** * Associate record with bond. */ - async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, privateKey: string, fee: StdFee) { + async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -290,7 +289,7 @@ export class Registry { /** * Dissociate record from bond. */ - async dissociateBond ({ recordId }: MessageMsgDissociateBond, privateKey: string, fee: StdFee) { + async dissociateBond ({ recordId }: MessageMsgDissociateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -305,7 +304,7 @@ export class Registry { /** * Dissociate all records from bond. */ - async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee) { + async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -320,7 +319,7 @@ export class Registry { /** * Reassociate records (switch bond). */ - async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee) { + async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -336,7 +335,7 @@ export class Registry { /** * Reserve authority. */ - async reserveAuthority ({ name, owner }: { name: string, owner?: string }, privateKey: string, fee: StdFee) { + async reserveAuthority ({ name, owner }: { name: string, owner?: string }, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -352,7 +351,7 @@ export class Registry { /** * Set authority bond. */ - async setAuthorityBond ({ bondId, name }: MessageMsgSetAuthorityBond, privateKey: string, fee: StdFee) { + async setAuthorityBond ({ bondId, name }: MessageMsgSetAuthorityBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -368,7 +367,7 @@ export class Registry { /** * Commit auction bid. */ - async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, privateKey: string, fee: StdFee) { + async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -384,7 +383,7 @@ export class Registry { /** * Reveal auction bid. */ - async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, privateKey: string, fee: StdFee) { + async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -420,7 +419,7 @@ export class Registry { /** * Set name (LRN) to record ID (CID). */ - async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee) { + async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -443,7 +442,7 @@ export class Registry { /** * Delete name (LRN) mapping. */ - async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee) { + async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -454,20 +453,10 @@ export class Registry { ); } - async getLaconicClient (account: Account) { - return LaconicClient.connectWithSigner( - this._endpoints.rpc, - account.wallet, - { - gasPrice: this._gasPrice - } - ); - } - /** * Onboard participant. */ - async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee): Promise { + async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -502,9 +491,18 @@ export class Registry { async getParticipantByNitroAddress (nitroAddress: string) { return this._client.getParticipantByNitroAddress(nitroAddress); } + + async getLaconicClient (account: Account) { + return LaconicClient.connectWithSigner( + this._endpoints.rpc, + account.wallet, + { gasPrice: this._gasPrice } + ); + } } export { Account }; export { LaconicClient }; +export * from './constants'; export * from './types/cerc/bond/message'; export * from './types/cerc/onboarding/message'; diff --git a/src/testing/helper.ts b/src/testing/helper.ts index 8c85652..ed8a1e5 100644 --- a/src/testing/helper.ts +++ b/src/testing/helper.ts @@ -2,7 +2,8 @@ import assert from 'assert'; import yaml from 'node-yaml'; import semver from 'semver'; -import { Account, DEFAULT_CHAIN_ID } from '../index'; +import { Account } from '../index'; +import { DEFAULT_CHAIN_ID } from '../constants'; export const ensureUpdatedConfig = async (path: string) => { const conf = await yaml.read(path); -- 2.45.2 From 871d7a48210b3c11a5414c6406e37afaea72fdcf Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 26 Aug 2024 17:33:50 +0530 Subject: [PATCH 06/19] Set default gas estimation multiplier to 2 --- src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index 2206b01..f0c5654 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,4 @@ export const DENOM = 'alnt'; export const DEFAULT_CHAIN_ID = 'laconic_9000-1'; -export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 1.5; +export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 2; -- 2.45.2 From 84bbdf9a9627cd8bc334a8edaff8e4e9142ffcc0 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 27 Aug 2024 11:39:13 +0530 Subject: [PATCH 07/19] Fix test for batched txs --- src/index.test.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index e91ae88..e9268a4 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -48,25 +48,29 @@ const registryTests = () => { let accounts: Account[]; beforeAll(async () => { + // Fund 10 new accounts for the test accounts = await createTestAccounts(10); - for (let i = 0; i < 10; i++) { - const amount = (10 ** (15 - i)).toString(); - const fromAccount = i === 0 ? privateKey : accounts[i - 1].getPrivateKey(); - - await registry.sendCoins({ denom: DENOM, amount, destinationAddress: accounts[i].address }, fromAccount, fee); + for (let i = 0; i < accounts.length; i++) { + await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee); } }); test('All txs get included in a single block.', async () => { + // Send a bond creation tx from each account await Promise.all(accounts.map((account) => registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee) )); const laconicClient = await registry.getLaconicClient(accounts[0]); - const bondTx = await laconicClient.searchTx("message.action='/cerc.bond.v1.MsgCreateBond'"); + const bondCreationTxs = await Promise.all(accounts.map(async (account) => { + // Get the bond creation tx for each account + const [tx] = await laconicClient.searchTx(`message.sender='${account.address}' AND message.action='/cerc.bond.v1.MsgCreateBond'`); + return tx; + })); - const expectedBlockHeight = bondTx[0].height; - expect(bondTx.every(tx => tx.height === expectedBlockHeight)).toBe(true); + // Check that all txs are in the same block + const expectedBlockHeight = bondCreationTxs[0].height; + expect(bondCreationTxs.every(tx => tx.height === expectedBlockHeight)).toBe(true); }); }); }; -- 2.45.2 From 6809639b95fdd18ee25c1d176db0328d12ca17f3 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 27 Aug 2024 15:10:41 +0530 Subject: [PATCH 08/19] Add config tests --- src/config.test.ts | 111 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/config.test.ts diff --git a/src/config.test.ts b/src/config.test.ts new file mode 100644 index 0000000..b18d500 --- /dev/null +++ b/src/config.test.ts @@ -0,0 +1,111 @@ +import { GasPrice } from '@cosmjs/stargate'; + +import { Account } from './account'; +import { DENOM } from './constants'; +import { Registry } from './index'; +import { createTestAccounts, getConfig } from './testing/helper'; + +const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig(); + +jest.setTimeout(90 * 1000); + +const configTests = () => { + let registry: Registry; + let accounts: Account[]; + + beforeAll(async () => { + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); + + // Fund 4 new accounts for the test + accounts = await createTestAccounts(4); + for (let i = 0; i < accounts.length; i++) { + await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee); + } + }); + + test('StdFee fees with gas price not set', async () => { + const testAccount = accounts[0]; + const testFees = { + amount: [{ denom: 'alnt', amount: '400000' }], + gas: '400000' + }; + + // Send a bond creation tx + await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees); + + // Check that bond gets created + const [result] = await registry.queryBondsByOwner([testAccount.address]); + expect(result.bonds).toHaveLength(1); + }); + + test('StdFee fees with gas price set', async () => { + const testAccount = accounts[0]; + const testFees = { + amount: [{ denom: 'alnt', amount: '400000' }], + gas: '400000' + }; + + // Set gas price lower than min gas price + const testGasPrice = GasPrice.fromString(String('0.00001alnt')); + const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice }); + + // Send a bond creation tx + await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees); + + // Check that bond gets created (gas price ignored) + const [result] = await registry.queryBondsByOwner([testAccount.address]); + expect(result.bonds).toHaveLength(2); + }); + + test('Gas price with fees not set (default gas estimation multiplier)', async () => { + const testAccount = accounts[1]; + + // Set gas price + const testGasPrice = GasPrice.fromString('1alnt'); + const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice }); + + // Send a bond creation tx + await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey()); + + // Check that bond gets created (gas price ignored) + const [result] = await registry.queryBondsByOwner([testAccount.address]); + expect(result.bonds).toHaveLength(1); + }); + + test('Gas price with fees set (fees as the gas estimation multiplier)', async () => { + const testAccount = accounts[2]; + const testFees = 2.1; + + // Set gas price + const testGasPrice = GasPrice.fromString('1alnt'); + const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice }); + + // Send a bond creation tx + await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees); + + // Check that bond gets created (gas price ignored) + const [result] = await registry.queryBondsByOwner([testAccount.address]); + expect(result.bonds).toHaveLength(1); + }); + + test('Fees and gas price both not set', async () => { + const testAccount = accounts[3]; + const errorMsg = 'Gas price must be set in the client options when auto gas is used'; + + // Create registry without gasPrice + const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); + + // Send a bond creation tx + try { + await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey()); + } catch (error: any) { + expect(error.toString()).toContain(errorMsg); + } + + // Check that bond doesn't get created + const [result] = await registry.queryBondsByOwner([testAccount.address]); + expect(result.bonds).toHaveLength(0); + }); +}; + +describe('Config', configTests); -- 2.45.2 From e85ac9e3ac2198fff1768d02ba663b4ca37d263a Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 27 Aug 2024 15:18:32 +0530 Subject: [PATCH 09/19] Update test message --- src/config.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.test.ts b/src/config.test.ts index b18d500..4956ae2 100644 --- a/src/config.test.ts +++ b/src/config.test.ts @@ -88,7 +88,7 @@ const configTests = () => { expect(result.bonds).toHaveLength(1); }); - test('Fees and gas price both not set', async () => { + test('Error on fees and gas price both not set', async () => { const testAccount = accounts[3]; const errorMsg = 'Gas price must be set in the client options when auto gas is used'; -- 2.45.2 From cc3e1faa1df5a7a77932d05e755c802f9247634e Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 27 Aug 2024 16:16:17 +0530 Subject: [PATCH 10/19] Reduce number of txs in batched txs test --- src/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.test.ts b/src/index.test.ts index e9268a4..8a86914 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -49,7 +49,7 @@ const registryTests = () => { beforeAll(async () => { // Fund 10 new accounts for the test - accounts = await createTestAccounts(10); + accounts = await createTestAccounts(5); for (let i = 0; i < accounts.length; i++) { await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee); } -- 2.45.2 From adf33a5c3904e0c4b1cb8a7a478b227252d17984 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 27 Aug 2024 18:21:39 +0530 Subject: [PATCH 11/19] Debug logs --- src/index.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/index.test.ts b/src/index.test.ts index 8a86914..85902d2 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -53,6 +53,8 @@ const registryTests = () => { for (let i = 0; i < accounts.length; i++) { await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee); } + + console.log('accounts', accounts); }); test('All txs get included in a single block.', async () => { @@ -68,6 +70,10 @@ const registryTests = () => { return tx; })); + bondCreationTxs.forEach((tx, i) => { + console.log('tx', accounts[i].address, tx.height); + }); + // Check that all txs are in the same block const expectedBlockHeight = bondCreationTxs[0].height; expect(bondCreationTxs.every(tx => tx.height === expectedBlockHeight)).toBe(true); -- 2.45.2 From 14dd316976cd52f164092a4d49eb3a121ac714d0 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 27 Aug 2024 18:35:58 +0530 Subject: [PATCH 12/19] Use gitea laconicd URL --- .gitea/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 032359e..b2a481c 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -21,6 +21,7 @@ jobs: with: path: "./laconicd/" repository: cerc-io/laconicd + github-server-url: 'https://git.vdb.to' fetch-depth: 0 ref: main - name: Environment -- 2.45.2 From 6ed0be38ed15f7f6b6de324129c7ddaa3ebfe23c Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 27 Aug 2024 19:27:30 +0530 Subject: [PATCH 13/19] Check all txs are within two blocks in batched txs test --- .gitea/workflows/test.yml | 1 - src/index.test.ts | 18 ++++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index b2a481c..032359e 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -21,7 +21,6 @@ jobs: with: path: "./laconicd/" repository: cerc-io/laconicd - github-server-url: 'https://git.vdb.to' fetch-depth: 0 ref: main - name: Environment diff --git a/src/index.test.ts b/src/index.test.ts index 85902d2..9625147 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -53,30 +53,28 @@ const registryTests = () => { for (let i = 0; i < accounts.length; i++) { await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee); } - - console.log('accounts', accounts); }); - test('All txs get included in a single block.', async () => { + test('Multiple txs get included in a block.', async () => { // Send a bond creation tx from each account await Promise.all(accounts.map((account) => registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee) )); const laconicClient = await registry.getLaconicClient(accounts[0]); - const bondCreationTxs = await Promise.all(accounts.map(async (account) => { + const bondCreationTxHeights = await Promise.all(accounts.map(async (account) => { // Get the bond creation tx for each account const [tx] = await laconicClient.searchTx(`message.sender='${account.address}' AND message.action='/cerc.bond.v1.MsgCreateBond'`); - return tx; + return tx.height; })); - bondCreationTxs.forEach((tx, i) => { - console.log('tx', accounts[i].address, tx.height); + bondCreationTxHeights.forEach((txHeight, i) => { + console.log('tx', accounts[i].address, txHeight); }); - // Check that all txs are in the same block - const expectedBlockHeight = bondCreationTxs[0].height; - expect(bondCreationTxs.every(tx => tx.height === expectedBlockHeight)).toBe(true); + // Check that all txs are within two blocks + const expectedBlockHeight = bondCreationTxHeights.sort()[0]; + expect(bondCreationTxHeights.every(txHeight => txHeight === expectedBlockHeight || txHeight === expectedBlockHeight + 1)).toBe(true); }); }); }; -- 2.45.2 From 19374935b585c5948b510a3913a0c92cc1f169da Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 5 Sep 2024 11:20:50 +0530 Subject: [PATCH 14/19] Update config tests to use a single account --- src/config.test.ts | 22 +++++++--------------- src/index.test.ts | 4 ++-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/config.test.ts b/src/config.test.ts index 4956ae2..be0df9f 100644 --- a/src/config.test.ts +++ b/src/config.test.ts @@ -11,20 +11,17 @@ jest.setTimeout(90 * 1000); const configTests = () => { let registry: Registry; - let accounts: Account[]; + let testAccount: Account; beforeAll(async () => { registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); - // Fund 4 new accounts for the test - accounts = await createTestAccounts(4); - for (let i = 0; i < accounts.length; i++) { - await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee); - } + // Fund a new account for the test + [testAccount] = await createTestAccounts(1); + await registry.sendCoins({ denom: DENOM, amount: '10000000', destinationAddress: testAccount.address }, privateKey, fee); }); test('StdFee fees with gas price not set', async () => { - const testAccount = accounts[0]; const testFees = { amount: [{ denom: 'alnt', amount: '400000' }], gas: '400000' @@ -39,7 +36,6 @@ const configTests = () => { }); test('StdFee fees with gas price set', async () => { - const testAccount = accounts[0]; const testFees = { amount: [{ denom: 'alnt', amount: '400000' }], gas: '400000' @@ -58,8 +54,6 @@ const configTests = () => { }); test('Gas price with fees not set (default gas estimation multiplier)', async () => { - const testAccount = accounts[1]; - // Set gas price const testGasPrice = GasPrice.fromString('1alnt'); const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice }); @@ -69,11 +63,10 @@ const configTests = () => { // Check that bond gets created (gas price ignored) const [result] = await registry.queryBondsByOwner([testAccount.address]); - expect(result.bonds).toHaveLength(1); + expect(result.bonds).toHaveLength(3); }); test('Gas price with fees set (fees as the gas estimation multiplier)', async () => { - const testAccount = accounts[2]; const testFees = 2.1; // Set gas price @@ -85,11 +78,10 @@ const configTests = () => { // Check that bond gets created (gas price ignored) const [result] = await registry.queryBondsByOwner([testAccount.address]); - expect(result.bonds).toHaveLength(1); + expect(result.bonds).toHaveLength(4); }); test('Error on fees and gas price both not set', async () => { - const testAccount = accounts[3]; const errorMsg = 'Gas price must be set in the client options when auto gas is used'; // Create registry without gasPrice @@ -104,7 +96,7 @@ const configTests = () => { // Check that bond doesn't get created const [result] = await registry.queryBondsByOwner([testAccount.address]); - expect(result.bonds).toHaveLength(0); + expect(result.bonds).toHaveLength(4); }); }; diff --git a/src/index.test.ts b/src/index.test.ts index 9625147..d9906af 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -48,7 +48,7 @@ const registryTests = () => { let accounts: Account[]; beforeAll(async () => { - // Fund 10 new accounts for the test + // Fund 5 new accounts for the test accounts = await createTestAccounts(5); for (let i = 0; i < accounts.length; i++) { await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee); @@ -56,7 +56,7 @@ const registryTests = () => { }); test('Multiple txs get included in a block.', async () => { - // Send a bond creation tx from each account + // Send a bond creation tx from each account (send from different accounts to avoid sequence errors) await Promise.all(accounts.map((account) => registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee) )); -- 2.45.2 From 91a4792346a7f3cde44f27c4decfb3f59d03377b Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Thu, 5 Sep 2024 17:30:54 +0530 Subject: [PATCH 15/19] Update test to query bonds by owner --- src/bond.test.ts | 24 +++++++++++++++++------- src/index.ts | 10 +++++----- 2 files changed, 22 insertions(+), 12 deletions(-) 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; } /** -- 2.45.2 From adf39a40895712a37f6811a548ac8e5c03c9139c Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 6 Sep 2024 09:35:58 +0530 Subject: [PATCH 16/19] Update bonds test --- src/bond.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bond.test.ts b/src/bond.test.ts index b64e35e..2eb2898 100644 --- a/src/bond.test.ts +++ b/src/bond.test.ts @@ -13,6 +13,7 @@ jest.setTimeout(90 * 1000); const bondTests = () => { let registry: Registry; + let bond: any; const publishNewWatcherVersion = async (bondId: string) => { let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH); @@ -28,6 +29,8 @@ const bondTests = () => { let bondId = await registry.getNextBondId(privateKey); expect(bondId).toBeDefined(); await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, privateKey, fee); + + [bond] = await registry.getBondsByIds([bondId]); }); describe('With bond created', () => { @@ -68,15 +71,16 @@ const bondTests = () => { 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 [owner1Bonds] = await registry.queryBondsByOwner(bond.owner); + const owner1Bond1 = owner1Bonds.bonds.filter((b: any) => b.id === bond.id); + const owner1Bond2 = owner1Bonds.bonds.filter((b: any) => b.id === bond1.id); + expect(owner1Bond1).toBeDefined(); + expect(owner1Bond2).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); + const owner2Bond = owner2Bonds.bonds.filter((b: any) => b.id === bondId2); expect(owner2Bond).toBeDefined(); }); -- 2.45.2 From b56cb09b3b6870685de6ac32541cabdfa84c2f58 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 6 Sep 2024 11:42:49 +0530 Subject: [PATCH 17/19] Increment package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 09ee73a..d74b0ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/registry-sdk", - "version": "0.2.8", + "version": "0.2.9", "main": "dist/index.js", "types": "dist/index.d.ts", "repository": "git@github.com:cerc-io/registry-sdk.git", -- 2.45.2 From 7717b11fb2ad8b2f9b8886504a3704df5edfd0bc Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 6 Sep 2024 12:17:25 +0530 Subject: [PATCH 18/19] Move chain id constant to test helpers --- src/constants.ts | 2 -- src/testing/helper.ts | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index f0c5654..a54157d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,2 @@ export const DENOM = 'alnt'; -export const DEFAULT_CHAIN_ID = 'laconic_9000-1'; - export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 2; diff --git a/src/testing/helper.ts b/src/testing/helper.ts index ed8a1e5..8324402 100644 --- a/src/testing/helper.ts +++ b/src/testing/helper.ts @@ -3,7 +3,8 @@ import yaml from 'node-yaml'; import semver from 'semver'; import { Account } from '../index'; -import { DEFAULT_CHAIN_ID } from '../constants'; + +const DEFAULT_CHAIN_ID = 'laconic_9000-1'; export const ensureUpdatedConfig = async (path: string) => { const conf = await yaml.read(path); -- 2.45.2 From e88105f67b3ef902ebd932ca4951e9ae7353cf55 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 6 Sep 2024 12:24:46 +0530 Subject: [PATCH 19/19] Rename method to query bonds by owners --- src/bond.test.ts | 12 ++++++------ src/config.test.ts | 10 +++++----- src/index.ts | 4 ++-- src/registry-client.ts | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/bond.test.ts b/src/bond.test.ts index 2eb2898..9d5400a 100644 --- a/src/bond.test.ts +++ b/src/bond.test.ts @@ -13,7 +13,7 @@ jest.setTimeout(90 * 1000); const bondTests = () => { let registry: Registry; - let bond: any; + let bond0: { id: string, owner: string }; const publishNewWatcherVersion = async (bondId: string) => { let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH); @@ -30,11 +30,11 @@ const bondTests = () => { expect(bondId).toBeDefined(); await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, privateKey, fee); - [bond] = await registry.getBondsByIds([bondId]); + [bond0] = await registry.getBondsByIds([bondId]); }); describe('With bond created', () => { - let bond1: any; + let bond1: { id: string, owner: string }; beforeAll(async () => { let bondId1 = await registry.getNextBondId(privateKey); @@ -71,14 +71,14 @@ const bondTests = () => { const { id: bondId2 } = await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, otherAccount.getPrivateKey(), fee); - const [owner1Bonds] = await registry.queryBondsByOwner(bond.owner); - const owner1Bond1 = owner1Bonds.bonds.filter((b: any) => b.id === bond.id); + const [owner1Bonds] = await registry.queryBondsByOwners([bond0.owner]); + const owner1Bond1 = owner1Bonds.bonds.filter((b: any) => b.id === bond0.id); const owner1Bond2 = owner1Bonds.bonds.filter((b: any) => b.id === bond1.id); expect(owner1Bond1).toBeDefined(); expect(owner1Bond2).toBeDefined(); const [bond2] = await registry.getBondsByIds([bondId2]); - const [owner2Bonds] = await registry.queryBondsByOwner(bond2.owner); + const [owner2Bonds] = await registry.queryBondsByOwners([bond2.owner]); expect(owner2Bonds.bonds).toHaveLength(1); const owner2Bond = owner2Bonds.bonds.filter((b: any) => b.id === bondId2); expect(owner2Bond).toBeDefined(); diff --git a/src/config.test.ts b/src/config.test.ts index be0df9f..6516889 100644 --- a/src/config.test.ts +++ b/src/config.test.ts @@ -31,7 +31,7 @@ const configTests = () => { await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees); // Check that bond gets created - const [result] = await registry.queryBondsByOwner([testAccount.address]); + const [result] = await registry.queryBondsByOwners([testAccount.address]); expect(result.bonds).toHaveLength(1); }); @@ -49,7 +49,7 @@ const configTests = () => { await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees); // Check that bond gets created (gas price ignored) - const [result] = await registry.queryBondsByOwner([testAccount.address]); + const [result] = await registry.queryBondsByOwners([testAccount.address]); expect(result.bonds).toHaveLength(2); }); @@ -62,7 +62,7 @@ const configTests = () => { await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey()); // Check that bond gets created (gas price ignored) - const [result] = await registry.queryBondsByOwner([testAccount.address]); + const [result] = await registry.queryBondsByOwners([testAccount.address]); expect(result.bonds).toHaveLength(3); }); @@ -77,7 +77,7 @@ const configTests = () => { await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees); // Check that bond gets created (gas price ignored) - const [result] = await registry.queryBondsByOwner([testAccount.address]); + const [result] = await registry.queryBondsByOwners([testAccount.address]); expect(result.bonds).toHaveLength(4); }); @@ -95,7 +95,7 @@ const configTests = () => { } // Check that bond doesn't get created - const [result] = await registry.queryBondsByOwner([testAccount.address]); + const [result] = await registry.queryBondsByOwners([testAccount.address]); expect(result.bonds).toHaveLength(4); }); }; diff --git a/src/index.ts b/src/index.ts index 298dc65..4ea8b7d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -201,8 +201,8 @@ export class Registry { /** * Query bonds by owner(s). */ - async queryBondsByOwner (owners: string[]) { - return this._client.queryBondsByOwner(owners); + async queryBondsByOwners (owners: string[]) { + return this._client.queryBondsByOwners(owners); } /** diff --git a/src/registry-client.ts b/src/registry-client.ts index 08ebefa..a1cdde1 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -447,7 +447,7 @@ export class RegistryClient { /** * Get bonds by owner(s). */ - async queryBondsByOwner (ownerAddresses: string[]) { + async queryBondsByOwners (ownerAddresses: string[]) { const query = `query ($ownerAddresses: [String!]) { queryBondsByOwner(ownerAddresses: $ownerAddresses) { owner -- 2.45.2