2022-04-25 09:42:46 +00:00
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
import { Registry } from './index';
|
2024-03-11 11:27:27 +00:00
|
|
|
import { getConfig, ensureUpdatedConfig } from './testing/helper';
|
2024-03-11 08:51:00 +00:00
|
|
|
import { DENOM } from './constants';
|
2022-04-25 09:42:46 +00:00
|
|
|
|
2023-03-06 21:54:02 +00:00
|
|
|
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
|
2022-04-25 09:42:46 +00:00
|
|
|
|
|
|
|
jest.setTimeout(40 * 1000);
|
|
|
|
|
2024-04-01 14:23:34 +00:00
|
|
|
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
2022-04-25 09:42:46 +00:00
|
|
|
|
|
|
|
describe('Querying', () => {
|
|
|
|
let watcher: any;
|
|
|
|
let registry: Registry;
|
|
|
|
let bondId: string;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2024-08-23 02:38:32 +00:00
|
|
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
2024-03-06 14:18:45 +00:00
|
|
|
|
|
|
|
bondId = await registry.getNextBondId(privateKey);
|
2024-03-11 11:27:27 +00:00
|
|
|
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, fee);
|
2022-04-25 09:42:46 +00:00
|
|
|
|
|
|
|
const publishNewWatcherVersion = async () => {
|
|
|
|
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
2024-03-11 11:27:27 +00:00
|
|
|
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee);
|
2022-04-25 09:42:46 +00:00
|
|
|
return watcher.record.version;
|
|
|
|
};
|
|
|
|
|
|
|
|
await publishNewWatcherVersion();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Endpoint and chain ID.', async () => {
|
2024-04-01 14:23:34 +00:00
|
|
|
expect(registry.endpoints.rpc).toBe(rpcEndpoint);
|
2022-04-25 09:42:46 +00:00
|
|
|
expect(registry.endpoints.gql).toBe(gqlEndpoint);
|
|
|
|
expect(registry.chainID).toBe(chainId);
|
|
|
|
});
|
|
|
|
|
2024-03-13 10:29:46 +00:00
|
|
|
test('Get status.', async () => {
|
2022-04-25 09:42:46 +00:00
|
|
|
const status = await registry.getStatus();
|
|
|
|
expect(status).toBeDefined();
|
|
|
|
expect(status.version).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('List records.', async () => {
|
|
|
|
const records = await registry.queryRecords({}, true);
|
|
|
|
expect(records.length).toBeGreaterThanOrEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Query records by reference.', async () => {
|
2023-03-06 21:54:02 +00:00
|
|
|
const { repo_registration_record_cid } = watcher.record;
|
|
|
|
const records = await registry.queryRecords({ repo_registration_record_cid }, true);
|
2022-04-25 09:42:46 +00:00
|
|
|
expect(records.length).toBeGreaterThanOrEqual(1);
|
|
|
|
|
2023-03-06 21:54:02 +00:00
|
|
|
const { attributes: { repo_registration_record_cid: record_repo_registration_record_cid } } = records[0];
|
2024-01-15 04:58:55 +00:00
|
|
|
expect(repo_registration_record_cid).toStrictEqual(record_repo_registration_record_cid);
|
2022-04-25 09:42:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Query records by attributes.', async () => {
|
2024-01-15 04:58:55 +00:00
|
|
|
const { version, url } = watcher.record;
|
|
|
|
const records = await registry.queryRecords({ version, url, type: undefined }, true);
|
2022-04-25 09:42:46 +00:00
|
|
|
expect(records.length).toBe(1);
|
|
|
|
|
2024-03-07 04:17:05 +00:00
|
|
|
[watcher] = records;
|
2024-01-15 04:58:55 +00:00
|
|
|
const { attributes: { version: recordVersion, url: recordName } } = watcher;
|
2022-04-25 09:42:46 +00:00
|
|
|
expect(recordVersion).toBe(version);
|
2024-01-15 04:58:55 +00:00
|
|
|
expect(recordName).toBe(url);
|
2022-04-25 09:42:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Query records by id.', async () => {
|
|
|
|
const records = await registry.getRecordsByIds([watcher.id]);
|
|
|
|
expect(records.length).toBe(1);
|
|
|
|
expect(records[0].id).toBe(watcher.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Query records passing refs true.', async () => {
|
|
|
|
const [record] = await registry.getRecordsByIds([watcher.id], true);
|
|
|
|
expect(record.id).toBe(watcher.id);
|
2023-01-03 09:20:38 +00:00
|
|
|
// temp fix
|
2023-03-06 21:54:02 +00:00
|
|
|
expect(record.attributes.repo_registration_record_cid).toBeDefined();
|
2024-03-07 04:17:05 +00:00
|
|
|
expect(record.attributes.repo_registration_record_cid).toHaveProperty('/');
|
|
|
|
expect(record.attributes.repo_registration_record_cid['/']).toHaveLength(46);
|
2022-04-25 09:42:46 +00:00
|
|
|
});
|
|
|
|
});
|