forked from cerc-io/registry-sdk
Prathamesh Musale
6a17b1b175
Part of [Create a public laconicd testnet](https://www.notion.so/Create-a-public-laconicd-testnet-896a11bdd8094eff8f1b49c0be0ca3b8) - Add an option for setting gas price - Use fees as gas estimation multiplier when `gasPrice` is provided (following `cosmjs` pattern) - Default gas estimation multiplier: `2` - Add a method to query bonds by owners and fix tests - Add a test for inclusion of batch of txs sent at once in the same block Co-authored-by: IshaVenikar <ishavenikar7@gmail.com> Co-authored-by: Nabarun <nabarun@deepstacksoft.com> Reviewed-on: cerc-io/registry-sdk#22 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
125 lines
4.0 KiB
TypeScript
125 lines
4.0 KiB
TypeScript
import path from 'path';
|
|
|
|
import { Registry } from './index';
|
|
import { ensureUpdatedConfig, getConfig } from './testing/helper';
|
|
import { DENOM } from './constants';
|
|
|
|
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
|
|
|
|
jest.setTimeout(120 * 1000);
|
|
|
|
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
|
|
|
const nameserviceExpiryTests = () => {
|
|
let registry: Registry;
|
|
|
|
let bondId: string;
|
|
let watcher: any;
|
|
|
|
let authorityName: string;
|
|
let authorityExpiryTime: Date;
|
|
let recordExpiryTime: Date;
|
|
|
|
beforeAll(async () => {
|
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
|
|
|
// Create bond.
|
|
bondId = await registry.getNextBondId(privateKey);
|
|
await registry.createBond({ denom: DENOM, amount: '3000000' }, privateKey, fee);
|
|
});
|
|
|
|
test('Set record and check bond balance', async () => {
|
|
// Create watcher.
|
|
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
|
const result = await registry.setRecord(
|
|
{
|
|
privateKey,
|
|
bondId,
|
|
record: watcher.record
|
|
},
|
|
privateKey,
|
|
fee
|
|
);
|
|
expect(result.id).toBeDefined();
|
|
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
|
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');
|
|
});
|
|
|
|
test('Reserve authority and set bond', async () => {
|
|
authorityName = `laconic-${Date.now()}`;
|
|
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
|
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
|
|
const [authority] = await registry.lookupAuthorities([authorityName]);
|
|
expect(authority.status).toBe('active');
|
|
authorityExpiryTime = new Date(authority.expiryTime);
|
|
});
|
|
|
|
test('Wait for expiry duration', (done) => {
|
|
// Wait for expiry time + time for a block to be executed
|
|
const expiryTime = 60 * 1000;
|
|
const waitTime = expiryTime + (3 * 1000);
|
|
|
|
setTimeout(done, waitTime);
|
|
});
|
|
|
|
test('Check record expiry time', async () => {
|
|
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
|
const updatedExpiryTime = new Date();
|
|
expect(updatedExpiryTime.getTime()).toBeGreaterThan(recordExpiryTime.getTime());
|
|
recordExpiryTime = updatedExpiryTime;
|
|
});
|
|
|
|
test('Check authority expiry time', async () => {
|
|
const [authority] = await registry.lookupAuthorities([authorityName]);
|
|
const updatedExpiryTime = new Date();
|
|
expect(updatedExpiryTime.getTime()).toBeGreaterThan(authorityExpiryTime.getTime());
|
|
authorityExpiryTime = updatedExpiryTime;
|
|
});
|
|
|
|
test('Check bond balance', async () => {
|
|
const [bond] = await registry.getBondsByIds([bondId]);
|
|
expect(bond).toBeDefined();
|
|
expect(bond.balance).toHaveLength(0);
|
|
});
|
|
|
|
test('Wait for expiry duration', (done) => {
|
|
// Wait for expiry time + time for a block to be executed
|
|
const expiryTime = 60 * 1000;
|
|
const waitTime = expiryTime + (3 * 1000);
|
|
|
|
setTimeout(done, waitTime);
|
|
});
|
|
|
|
test('Check record deleted without bond balance', async () => {
|
|
const records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
|
expect(records).toHaveLength(0);
|
|
});
|
|
|
|
test('Check authority expired without bond balance', async () => {
|
|
const [authority] = await registry.lookupAuthorities([authorityName]);
|
|
expect(authority.status).toBe('expired');
|
|
});
|
|
};
|
|
|
|
if (!process.env.TEST_NAMESERVICE_EXPIRY) {
|
|
// Required as jest complains if file has no tests.
|
|
test('skipping nameservice expiry tests', () => {});
|
|
} else {
|
|
/**
|
|
Running these tests requires timers to be set. In laconicd repo run:
|
|
|
|
TEST_REGISTRY_EXPIRY=true ./init.sh
|
|
|
|
Run tests:
|
|
|
|
yarn test:nameservice-expiry
|
|
*/
|
|
|
|
describe('Nameservice Expiry', nameserviceExpiryTests);
|
|
}
|