forked from cerc-io/registry-sdk
Refactor Batch txs test
This commit is contained in:
parent
ae787decb9
commit
1eb1cf0e76
@ -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<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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user