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'); }); test('Get transaction info.', async () => { const bondAmount = '100000'; const accounts = await createAccounts(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); } const bondPromises = accounts.map((account) => registry.createBond({ denom: DENOM, amount: bondAmount }, account.getPrivateKey(), fee) ); await Promise.all(bondPromises); }); const createAccounts = async (numAccounts: number): Promise => { 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);