2022-04-14 04:34:52 +00:00
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
import { Registry } from './index';
|
2024-03-11 08:51:00 +00:00
|
|
|
import { getBaseConfig, getConfig, getLaconic2Config } from './testing/helper';
|
2022-04-14 04:34:52 +00:00
|
|
|
import { Util } from './util';
|
2024-03-11 08:51:00 +00:00
|
|
|
import { DENOM } from './constants';
|
2022-04-14 04:34:52 +00:00
|
|
|
|
2023-03-06 21:54:02 +00:00
|
|
|
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
|
2022-04-14 04:34:52 +00:00
|
|
|
|
|
|
|
jest.setTimeout(90 * 1000);
|
|
|
|
|
|
|
|
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
2024-03-11 08:51:00 +00:00
|
|
|
const { fee: laconic2Fee } = getLaconic2Config();
|
2022-04-14 04:34:52 +00:00
|
|
|
|
|
|
|
const utilTests = () => {
|
|
|
|
let registry: Registry;
|
|
|
|
|
|
|
|
let bondId: string;
|
|
|
|
let watcher: any;
|
|
|
|
let watcherId: string;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2022-12-09 08:55:13 +00:00
|
|
|
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
2022-04-14 04:34:52 +00:00
|
|
|
|
|
|
|
// Create bond.
|
|
|
|
bondId = await registry.getNextBondId(privateKey);
|
2024-03-11 08:51:00 +00:00
|
|
|
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, laconic2Fee);
|
2022-04-14 04:34:52 +00:00
|
|
|
|
2022-04-19 10:24:41 +00:00
|
|
|
// Create watcher.
|
2022-04-14 04:34:52 +00:00
|
|
|
watcher = await getBaseConfig(WATCHER_YML_PATH);
|
2022-04-20 11:54:37 +00:00
|
|
|
const result = await registry.setRecord(
|
2022-04-14 04:34:52 +00:00
|
|
|
{
|
|
|
|
privateKey,
|
|
|
|
bondId,
|
|
|
|
record: watcher.record
|
|
|
|
},
|
|
|
|
privateKey,
|
2024-03-11 08:51:00 +00:00
|
|
|
laconic2Fee
|
2024-03-07 04:17:05 +00:00
|
|
|
);
|
2022-04-14 04:34:52 +00:00
|
|
|
|
2024-03-11 08:51:00 +00:00
|
|
|
watcherId = result.id;
|
2022-04-14 04:34:52 +00:00
|
|
|
});
|
|
|
|
|
2022-04-22 06:02:55 +00:00
|
|
|
test('Generate content id.', async () => {
|
2022-04-14 04:34:52 +00:00
|
|
|
const cid = await Util.getContentId(watcher.record);
|
2024-03-07 04:17:05 +00:00
|
|
|
expect(cid).toBe(watcherId);
|
2022-04-14 04:34:52 +00:00
|
|
|
});
|
2024-03-07 04:17:05 +00:00
|
|
|
};
|
2022-04-14 04:34:52 +00:00
|
|
|
|
|
|
|
describe('Util', utilTests);
|