2022-04-01 12:32:56 +00:00
|
|
|
import { Registry } from './index';
|
2022-04-05 14:11:06 +00:00
|
|
|
import { getConfig } from './testing/helper';
|
2022-04-01 12:32:56 +00:00
|
|
|
|
2022-04-12 10:54:26 +00:00
|
|
|
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
2022-04-01 12:32:56 +00:00
|
|
|
|
|
|
|
jest.setTimeout(90 * 1000);
|
|
|
|
|
|
|
|
const bondTests = () => {
|
|
|
|
let registry: Registry;
|
|
|
|
let bondId1: string;
|
|
|
|
|
2022-04-04 07:05:16 +00:00
|
|
|
let bondOwner: string;
|
|
|
|
|
2022-04-01 12:32:56 +00:00
|
|
|
beforeAll(async () => {
|
2022-04-04 07:05:16 +00:00
|
|
|
registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
2022-04-01 12:32:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create bond.', async () => {
|
2022-04-12 10:54:26 +00:00
|
|
|
bondId1 = await registry.getNextBondId(privateKey);
|
2022-04-01 12:32:56 +00:00
|
|
|
expect(bondId1).toBeDefined();
|
2022-04-12 10:54:26 +00:00
|
|
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
2022-04-01 12:32:56 +00:00
|
|
|
})
|
2022-04-04 07:05:16 +00:00
|
|
|
|
|
|
|
test('Get bond by ID.', async () => {
|
|
|
|
const [bond] = await registry.getBondsByIds([bondId1]);
|
|
|
|
expect(bond).toBeDefined();
|
|
|
|
expect(bond.id).toBe(bondId1);
|
|
|
|
expect(bond.balance).toHaveLength(1);
|
2022-04-04 10:20:20 +00:00
|
|
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
2022-04-04 07:05:16 +00:00
|
|
|
bondOwner = bond.owner;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Query bonds.', async () => {
|
|
|
|
const bonds = await registry.queryBonds();
|
|
|
|
expect(bonds).toBeDefined();
|
|
|
|
const bond = bonds.filter((bond: any) => bond.id === bondId1);
|
|
|
|
expect(bond).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Query bonds by owner.', async () => {
|
|
|
|
const bonds = await registry.queryBonds({ owner: bondOwner });
|
|
|
|
expect(bonds).toBeDefined();
|
|
|
|
const bond = bonds.filter((bond: any) => bond.id === bondId1);
|
|
|
|
expect(bond).toBeDefined();
|
|
|
|
});
|
2022-04-04 10:20:20 +00:00
|
|
|
|
|
|
|
test('Refill bond.', async () => {
|
2022-04-12 10:54:26 +00:00
|
|
|
await registry.refillBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
2022-04-04 10:20:20 +00:00
|
|
|
|
|
|
|
const [bond] = await registry.getBondsByIds([bondId1]);
|
|
|
|
expect(bond).toBeDefined();
|
|
|
|
expect(bond.id).toBe(bondId1);
|
|
|
|
expect(bond.balance).toHaveLength(1);
|
|
|
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000500' });
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Withdraw bond.', async () => {
|
2022-04-12 10:54:26 +00:00
|
|
|
await registry.withdrawBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
2022-04-04 10:20:20 +00:00
|
|
|
|
|
|
|
const [bond] = await registry.getBondsByIds([bondId1]);
|
|
|
|
expect(bond).toBeDefined();
|
|
|
|
expect(bond.id).toBe(bondId1);
|
|
|
|
expect(bond.balance).toHaveLength(1);
|
|
|
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Cancel bond.', async () => {
|
2022-04-12 10:54:26 +00:00
|
|
|
await registry.cancelBond({ id: bondId1 }, privateKey, fee);
|
2022-04-04 10:20:20 +00:00
|
|
|
|
|
|
|
const [bond] = await registry.getBondsByIds([bondId1]);
|
|
|
|
expect(bond.id).toBe("");
|
|
|
|
expect(bond.owner).toBe("");
|
|
|
|
expect(bond.balance).toHaveLength(0);
|
|
|
|
});
|
2022-04-01 12:32:56 +00:00
|
|
|
};
|
|
|
|
|
2022-04-05 14:11:06 +00:00
|
|
|
describe('Bonds', bondTests);
|