Update account info and balance test

This commit is contained in:
neeraj 2024-03-07 18:11:23 +05:30
parent e5109f8635
commit b183cfe9ee

View File

@ -1,8 +1,10 @@
import { Account } from './account'; import { Account } from './account';
import { DENOM } from './constants';
import { Registry } from './index'; import { Registry } from './index';
import { getConfig } from './testing/helper'; import { getConfig, getLaconic2Config } from './testing/helper';
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig(); const { chainId, restEndpoint, gqlEndpoint, privateKey } = getConfig();
const { fee } = getLaconic2Config();
jest.setTimeout(90 * 1000); jest.setTimeout(90 * 1000);
@ -15,30 +17,32 @@ const registryTests = () => {
test('Get account info.', async () => { test('Get account info.', async () => {
const account = new Account(Buffer.from(privateKey, 'hex')); const account = new Account(Buffer.from(privateKey, 'hex'));
const accounts = await registry.getAccounts([account.formattedCosmosAddress]); await account.init();
const accounts = await registry.getAccounts([account.address]);
expect(accounts).toHaveLength(1); expect(accounts).toHaveLength(1);
const [accountObj] = accounts; const [accountObj] = accounts;
expect(accountObj.address).toBe(account.formattedCosmosAddress); expect(accountObj.address).toBe(account.address);
expect(accountObj.pubKey).toBe(account.encodedPubkey); expect(accountObj.pubKey).toBe(account.encodedPubkey);
expect(accountObj.number).toBe('0'); expect(accountObj.number).toBe('0');
expect(accountObj.sequence).toBeDefined(); expect(accountObj.sequence).toBeDefined();
expect(accountObj.balance).toHaveLength(1); expect(accountObj.balance).toHaveLength(1);
const [{ type, quantity }] = accountObj.balance; const [{ type, quantity }] = accountObj.balance;
expect(type).toBe('aphoton'); expect(type).toBe(DENOM);
expect(quantity).toBeDefined(); expect(quantity).toBeDefined();
}); });
test('Get account balance.', async () => { test('Get account balance.', async () => {
const mnenonic1 = Account.generateMnemonic(); const mnenonic1 = Account.generateMnemonic();
const otherAccount = await Account.generateFromMnemonic(mnenonic1); const otherAccount = await Account.generateFromMnemonic(mnenonic1);
await registry.sendCoins({ denom: 'aphoton', amount: '100000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee); await otherAccount.init();
await registry.sendCoins({ denom: DENOM, amount: '10000', destinationAddress: otherAccount.address }, privateKey, fee);
const [accountObj] = await registry.getAccounts([otherAccount.formattedCosmosAddress]); const [accountObj] = await registry.getAccounts([otherAccount.address]);
expect(accountObj).toBeDefined(); expect(accountObj).toBeDefined();
expect(accountObj.address).toBe(otherAccount.formattedCosmosAddress); expect(accountObj.address).toBe(otherAccount.address);
const [{ type, quantity }] = accountObj.balance; const [{ type, quantity }] = accountObj.balance;
expect(type).toBe('aphoton'); expect(type).toBe(DENOM);
expect(quantity).toBe('100000000'); expect(quantity).toBe('10000');
}); });
}; };