2022-04-22 10:15:47 +00:00
|
|
|
import { Account } from './account';
|
|
|
|
import { Registry } from './index';
|
|
|
|
import { getConfig } from './testing/helper';
|
|
|
|
|
|
|
|
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
|
|
|
|
|
|
|
jest.setTimeout(90 * 1000);
|
|
|
|
|
|
|
|
const registryTests = () => {
|
|
|
|
let registry: Registry;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2022-12-09 08:55:13 +00:00
|
|
|
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
2022-04-22 10:15:47 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Get account info.', async() => {
|
|
|
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
|
|
|
const accounts = await registry.getAccounts([account.formattedCosmosAddress]);
|
|
|
|
expect(accounts).toHaveLength(1)
|
|
|
|
const [accountObj] = accounts;
|
|
|
|
expect(accountObj.address).toBe(account.formattedCosmosAddress);
|
|
|
|
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('aphoton');
|
|
|
|
expect(quantity).toBeDefined();
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Get account balance.', async() => {
|
|
|
|
const mnenonic1 = Account.generateMnemonic();
|
|
|
|
const otherAccount = await Account.generateFromMnemonic(mnenonic1);
|
2022-11-01 10:10:34 +00:00
|
|
|
await registry.sendCoins({ denom: 'aphoton', amount: '100000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
|
2022-04-22 10:15:47 +00:00
|
|
|
|
|
|
|
const [accountObj] = await registry.getAccounts([otherAccount.formattedCosmosAddress]);
|
|
|
|
expect(accountObj).toBeDefined();
|
|
|
|
expect(accountObj.address).toBe(otherAccount.formattedCosmosAddress);
|
|
|
|
const [{ type, quantity }] = accountObj.balance
|
|
|
|
expect(type).toBe('aphoton');
|
2022-11-01 10:10:34 +00:00
|
|
|
expect(quantity).toBe('100000000');
|
2022-04-22 10:15:47 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Registry', registryTests);
|