forked from cerc-io/registry-sdk
Prathamesh Musale
6a17b1b175
Part of [Create a public laconicd testnet](https://www.notion.so/Create-a-public-laconicd-testnet-896a11bdd8094eff8f1b49c0be0ca3b8) - Add an option for setting gas price - Use fees as gas estimation multiplier when `gasPrice` is provided (following `cosmjs` pattern) - Default gas estimation multiplier: `2` - Add a method to query bonds by owners and fix tests - Add a test for inclusion of batch of txs sent at once in the same block Co-authored-by: IshaVenikar <ishavenikar7@gmail.com> Co-authored-by: Nabarun <nabarun@deepstacksoft.com> Reviewed-on: cerc-io/registry-sdk#22 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
104 lines
3.7 KiB
TypeScript
104 lines
3.7 KiB
TypeScript
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 testAccount: Account;
|
|
|
|
beforeAll(async () => {
|
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
|
|
|
// 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 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.queryBondsByOwners([testAccount.address]);
|
|
expect(result.bonds).toHaveLength(1);
|
|
});
|
|
|
|
test('StdFee fees with gas price set', async () => {
|
|
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.queryBondsByOwners([testAccount.address]);
|
|
expect(result.bonds).toHaveLength(2);
|
|
});
|
|
|
|
test('Gas price with fees not set (default gas estimation multiplier)', async () => {
|
|
// 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.queryBondsByOwners([testAccount.address]);
|
|
expect(result.bonds).toHaveLength(3);
|
|
});
|
|
|
|
test('Gas price with fees set (fees as the gas estimation multiplier)', async () => {
|
|
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.queryBondsByOwners([testAccount.address]);
|
|
expect(result.bonds).toHaveLength(4);
|
|
});
|
|
|
|
test('Error on fees and gas price both not set', async () => {
|
|
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.queryBondsByOwners([testAccount.address]);
|
|
expect(result.bonds).toHaveLength(4);
|
|
});
|
|
};
|
|
|
|
describe('Config', configTests);
|