Update config tests to use a single account

This commit is contained in:
Prathamesh Musale 2024-09-05 11:20:50 +05:30
parent f802e1d31c
commit 8828b5388d
2 changed files with 9 additions and 17 deletions

View File

@ -11,20 +11,17 @@ jest.setTimeout(90 * 1000);
const configTests = () => { const configTests = () => {
let registry: Registry; let registry: Registry;
let accounts: Account[]; let testAccount: Account;
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
// Fund 4 new accounts for the test // Fund a new account for the test
accounts = await createTestAccounts(4); [testAccount] = await createTestAccounts(1);
for (let i = 0; i < accounts.length; i++) { await registry.sendCoins({ denom: DENOM, amount: '10000000', destinationAddress: testAccount.address }, privateKey, fee);
await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee);
}
}); });
test('StdFee fees with gas price not set', async () => { test('StdFee fees with gas price not set', async () => {
const testAccount = accounts[0];
const testFees = { const testFees = {
amount: [{ denom: 'alnt', amount: '400000' }], amount: [{ denom: 'alnt', amount: '400000' }],
gas: '400000' gas: '400000'
@ -39,7 +36,6 @@ const configTests = () => {
}); });
test('StdFee fees with gas price set', async () => { test('StdFee fees with gas price set', async () => {
const testAccount = accounts[0];
const testFees = { const testFees = {
amount: [{ denom: 'alnt', amount: '400000' }], amount: [{ denom: 'alnt', amount: '400000' }],
gas: '400000' gas: '400000'
@ -58,8 +54,6 @@ const configTests = () => {
}); });
test('Gas price with fees not set (default gas estimation multiplier)', async () => { test('Gas price with fees not set (default gas estimation multiplier)', async () => {
const testAccount = accounts[1];
// Set gas price // Set gas price
const testGasPrice = GasPrice.fromString('1alnt'); const testGasPrice = GasPrice.fromString('1alnt');
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice }); const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice });
@ -69,11 +63,10 @@ const configTests = () => {
// Check that bond gets created (gas price ignored) // Check that bond gets created (gas price ignored)
const [result] = await registry.queryBondsByOwner([testAccount.address]); 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 () => { test('Gas price with fees set (fees as the gas estimation multiplier)', async () => {
const testAccount = accounts[2];
const testFees = 2.1; const testFees = 2.1;
// Set gas price // Set gas price
@ -85,11 +78,10 @@ const configTests = () => {
// Check that bond gets created (gas price ignored) // Check that bond gets created (gas price ignored)
const [result] = await registry.queryBondsByOwner([testAccount.address]); 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 () => { 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'; const errorMsg = 'Gas price must be set in the client options when auto gas is used';
// Create registry without gasPrice // Create registry without gasPrice
@ -104,7 +96,7 @@ const configTests = () => {
// Check that bond doesn't get created // Check that bond doesn't get created
const [result] = await registry.queryBondsByOwner([testAccount.address]); const [result] = await registry.queryBondsByOwner([testAccount.address]);
expect(result.bonds).toHaveLength(0); expect(result.bonds).toHaveLength(4);
}); });
}; };

View File

@ -48,7 +48,7 @@ const registryTests = () => {
let accounts: Account[]; let accounts: Account[];
beforeAll(async () => { beforeAll(async () => {
// Fund 10 new accounts for the test // Fund 5 new accounts for the test
accounts = await createTestAccounts(5); accounts = await createTestAccounts(5);
for (let i = 0; i < accounts.length; i++) { for (let i = 0; i < accounts.length; i++) {
await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee); 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 () => { 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) => await Promise.all(accounts.map((account) =>
registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee) registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee)
)); ));