forked from cerc-io/registry-sdk
Part of https://www.notion.so/Rename-laconic2d-to-laconicd-9028d0c020d24d1288e92ebcb773d7a7 Co-authored-by: neeraj <neeraj.rtly@gmail.com> Reviewed-on: cerc-io/registry-sdk#10 Co-authored-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to> Co-committed-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { Account } from './account';
|
|
import { DENOM } from './constants';
|
|
import { Registry } from './index';
|
|
import { getConfig } from './testing/helper';
|
|
|
|
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
|
|
|
jest.setTimeout(90 * 1000);
|
|
|
|
const registryTests = () => {
|
|
let registry: Registry;
|
|
|
|
beforeAll(async () => {
|
|
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
|
});
|
|
|
|
test('Get account info.', async () => {
|
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
|
await account.init();
|
|
const accounts = await registry.getAccounts([account.address]);
|
|
expect(accounts).toHaveLength(1);
|
|
const [accountObj] = accounts;
|
|
expect(accountObj.address).toBe(account.address);
|
|
expect(accountObj.pubKey).toBe(account.encodedPubkey);
|
|
expect(accountObj.number).toBe('0');
|
|
expect(accountObj.sequence).toBeDefined();
|
|
expect(accountObj.balance).toHaveLength(1);
|
|
const [{ type, quantity }] = accountObj.balance;
|
|
expect(type).toBe(DENOM);
|
|
expect(quantity).toBeDefined();
|
|
});
|
|
|
|
test('Get account balance.', async () => {
|
|
const mnenonic1 = Account.generateMnemonic();
|
|
const otherAccount = await Account.generateFromMnemonic(mnenonic1);
|
|
await otherAccount.init();
|
|
await registry.sendCoins({ denom: DENOM, amount: '10000', destinationAddress: otherAccount.address }, privateKey, fee);
|
|
|
|
const [accountObj] = await registry.getAccounts([otherAccount.address]);
|
|
expect(accountObj).toBeDefined();
|
|
expect(accountObj.address).toBe(otherAccount.address);
|
|
const [{ type, quantity }] = accountObj.balance;
|
|
expect(type).toBe(DENOM);
|
|
expect(quantity).toBe('10000');
|
|
});
|
|
};
|
|
|
|
describe('Registry', registryTests);
|