Refactor Batch txs test

This commit is contained in:
IshaVenikar 2024-08-22 12:31:04 +05:30
parent 0880185a4b
commit 6aad0e2506
2 changed files with 34 additions and 29 deletions

View File

@ -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[];
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);
}
});
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 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<Account[]> => {
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);

View File

@ -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<Account[]> => {
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;
};