2022-04-19 10:24:41 +00:00
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
import { Registry } from './index';
|
2024-03-11 11:27:27 +00:00
|
|
|
import { ensureUpdatedConfig, getConfig } from './testing/helper';
|
2024-03-11 08:51:00 +00:00
|
|
|
import { DENOM } from './constants';
|
2022-04-19 10:24:41 +00:00
|
|
|
|
2023-03-06 21:54:02 +00:00
|
|
|
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
|
2022-04-19 10:24:41 +00:00
|
|
|
|
|
|
|
jest.setTimeout(120 * 1000);
|
|
|
|
|
2024-04-01 14:23:34 +00:00
|
|
|
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
2022-04-19 10:24:41 +00:00
|
|
|
|
|
|
|
const nameserviceExpiryTests = () => {
|
|
|
|
let registry: Registry;
|
|
|
|
|
|
|
|
let bondId: string;
|
|
|
|
let watcher: any;
|
|
|
|
|
|
|
|
let authorityName: string;
|
|
|
|
let authorityExpiryTime: Date;
|
|
|
|
let recordExpiryTime: Date;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2024-04-01 14:23:34 +00:00
|
|
|
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
2022-04-19 10:24:41 +00:00
|
|
|
|
|
|
|
// Create bond.
|
|
|
|
bondId = await registry.getNextBondId(privateKey);
|
2024-03-11 11:27:27 +00:00
|
|
|
await registry.createBond({ denom: DENOM, amount: '3000000' }, privateKey, fee);
|
2022-04-19 10:24:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Set record and check bond balance', async () => {
|
|
|
|
// Create watcher.
|
|
|
|
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
2023-02-10 19:44:23 +00:00
|
|
|
const result = await registry.setRecord(
|
2022-04-19 10:24:41 +00:00
|
|
|
{
|
|
|
|
privateKey,
|
|
|
|
bondId,
|
|
|
|
record: watcher.record
|
|
|
|
},
|
|
|
|
privateKey,
|
2024-03-11 11:27:27 +00:00
|
|
|
fee
|
2024-03-07 04:17:05 +00:00
|
|
|
);
|
2024-03-13 05:23:13 +00:00
|
|
|
expect(result.id).toBeDefined();
|
2023-03-06 21:54:02 +00:00
|
|
|
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
2022-04-19 10:24:41 +00:00
|
|
|
recordExpiryTime = new Date(record.expiryTime);
|
|
|
|
|
|
|
|
const [bond] = await registry.getBondsByIds([bondId]);
|
|
|
|
expect(bond).toBeDefined();
|
|
|
|
expect(bond.balance).toHaveLength(1);
|
|
|
|
expect(bond.balance[0].quantity).toBe('2000000');
|
2024-03-07 04:17:05 +00:00
|
|
|
});
|
2022-04-19 10:24:41 +00:00
|
|
|
|
|
|
|
test('Reserve authority and set bond', async () => {
|
2022-09-28 19:20:15 +00:00
|
|
|
authorityName = `laconic-${Date.now()}`;
|
2024-03-11 11:27:27 +00:00
|
|
|
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
|
|
|
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
|
2022-04-19 10:24:41 +00:00
|
|
|
const [authority] = await registry.lookupAuthorities([authorityName]);
|
|
|
|
expect(authority.status).toBe('active');
|
|
|
|
authorityExpiryTime = new Date(authority.expiryTime);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Wait for expiry duration', (done) => {
|
2024-08-05 07:53:13 +00:00
|
|
|
// Wait for expiry time + time for a block to be executed
|
|
|
|
const expiryTime = 60 * 1000;
|
|
|
|
const waitTime = expiryTime + (3 * 1000);
|
|
|
|
|
|
|
|
setTimeout(done, waitTime);
|
2022-04-19 10:24:41 +00:00
|
|
|
});
|
|
|
|
|
2024-03-07 04:17:05 +00:00
|
|
|
test('Check record expiry time', async () => {
|
2023-03-06 21:54:02 +00:00
|
|
|
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
2023-02-10 19:44:23 +00:00
|
|
|
const updatedExpiryTime = new Date();
|
2022-04-19 10:24:41 +00:00
|
|
|
expect(updatedExpiryTime.getTime()).toBeGreaterThan(recordExpiryTime.getTime());
|
|
|
|
recordExpiryTime = updatedExpiryTime;
|
2024-03-07 04:17:05 +00:00
|
|
|
});
|
2022-04-19 10:24:41 +00:00
|
|
|
|
2024-03-07 04:17:05 +00:00
|
|
|
test('Check authority expiry time', async () => {
|
2022-04-19 10:24:41 +00:00
|
|
|
const [authority] = await registry.lookupAuthorities([authorityName]);
|
2023-02-10 19:44:23 +00:00
|
|
|
const updatedExpiryTime = new Date();
|
2022-04-19 10:24:41 +00:00
|
|
|
expect(updatedExpiryTime.getTime()).toBeGreaterThan(authorityExpiryTime.getTime());
|
|
|
|
authorityExpiryTime = updatedExpiryTime;
|
2024-03-07 04:17:05 +00:00
|
|
|
});
|
2022-04-19 10:24:41 +00:00
|
|
|
|
|
|
|
test('Check bond balance', async () => {
|
|
|
|
const [bond] = await registry.getBondsByIds([bondId]);
|
|
|
|
expect(bond).toBeDefined();
|
|
|
|
expect(bond.balance).toHaveLength(0);
|
2024-03-07 04:17:05 +00:00
|
|
|
});
|
2022-04-19 10:24:41 +00:00
|
|
|
|
|
|
|
test('Wait for expiry duration', (done) => {
|
2024-08-05 07:53:13 +00:00
|
|
|
// Wait for expiry time + time for a block to be executed
|
|
|
|
const expiryTime = 60 * 1000;
|
|
|
|
const waitTime = expiryTime + (3 * 1000);
|
|
|
|
|
|
|
|
setTimeout(done, waitTime);
|
2022-04-19 10:24:41 +00:00
|
|
|
});
|
|
|
|
|
2024-03-07 04:17:05 +00:00
|
|
|
test('Check record deleted without bond balance', async () => {
|
2023-03-06 21:54:02 +00:00
|
|
|
const records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
2022-04-19 10:24:41 +00:00
|
|
|
expect(records).toHaveLength(0);
|
2024-03-07 04:17:05 +00:00
|
|
|
});
|
2022-04-19 10:24:41 +00:00
|
|
|
|
2024-03-07 04:17:05 +00:00
|
|
|
test('Check authority expired without bond balance', async () => {
|
2022-04-19 10:24:41 +00:00
|
|
|
const [authority] = await registry.lookupAuthorities([authorityName]);
|
|
|
|
expect(authority.status).toBe('expired');
|
2024-03-07 04:17:05 +00:00
|
|
|
});
|
|
|
|
};
|
2022-04-19 10:24:41 +00:00
|
|
|
|
|
|
|
if (!process.env.TEST_NAMESERVICE_EXPIRY) {
|
|
|
|
// Required as jest complains if file has no tests.
|
|
|
|
test('skipping nameservice expiry tests', () => {});
|
|
|
|
} else {
|
|
|
|
/**
|
2024-07-23 04:52:49 +00:00
|
|
|
Running these tests requires timers to be set. In laconicd repo run:
|
2022-04-19 10:24:41 +00:00
|
|
|
|
2023-02-10 19:44:23 +00:00
|
|
|
TEST_REGISTRY_EXPIRY=true ./init.sh
|
2022-04-19 10:24:41 +00:00
|
|
|
|
|
|
|
Run tests:
|
|
|
|
|
2022-04-22 10:15:47 +00:00
|
|
|
yarn test:nameservice-expiry
|
2022-04-19 10:24:41 +00:00
|
|
|
*/
|
|
|
|
|
2024-03-07 04:17:05 +00:00
|
|
|
describe('Nameservice Expiry', nameserviceExpiryTests);
|
2022-04-19 10:24:41 +00:00
|
|
|
}
|