forked from cerc-io/laconic-sdk
Add tests for record and authority expiry
This commit is contained in:
parent
6ca9f4041a
commit
e563cfe6b1
20
README.md
20
README.md
@ -50,6 +50,26 @@ Follow these steps to run the tests:
|
||||
yarn test:auctions
|
||||
```
|
||||
|
||||
- Run the tests for record and authority expiry
|
||||
|
||||
- In chiba-clonk repo run:
|
||||
|
||||
```bash
|
||||
TEST_NAMESERVICE_EXPIRY=true ./init.sh
|
||||
```
|
||||
|
||||
- Export the private key and change it in `.env` file again using:
|
||||
|
||||
```bash
|
||||
chibaclonkd keys export mykey --unarmored-hex --unsafe
|
||||
```
|
||||
|
||||
- Run tests:
|
||||
|
||||
```bash
|
||||
yarn test:expiry
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
[README](./DEVELOPMENT.md)
|
||||
|
@ -41,7 +41,8 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest --runInBand --verbose",
|
||||
"test:auctions": "AUCTIONS_ENABLED=1 jest --runInBand --verbose",
|
||||
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
|
||||
"test:expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
|
||||
"build": "tsc"
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ const auctionTests = (numBidders = 3) => {
|
||||
|
||||
const withNumBidders = (numBidders: number) => () => auctionTests(numBidders);
|
||||
|
||||
if (!process.env.AUCTIONS_ENABLED) {
|
||||
if (!process.env.TEST_AUCTIONS_ENABLED) {
|
||||
// Required as jest complains if file has no tests.
|
||||
test('skipping auction tests', () => {});
|
||||
} else {
|
||||
|
@ -95,7 +95,6 @@ export class Registry {
|
||||
_client: RegistryClient
|
||||
|
||||
static processWriteError(error: string) {
|
||||
console.log("error", error)
|
||||
// error string a stacktrace containing the message.
|
||||
// https://gist.github.com/nikugogoi/de55d390574ded3466abad8bffd81952#file-txresponse-js-L7
|
||||
const errorMessage = NAMESERVICE_ERRORS.find(message => error.includes(message))
|
||||
|
116
src/nameservice-expiry.test.ts
Normal file
116
src/nameservice-expiry.test.ts
Normal file
@ -0,0 +1,116 @@
|
||||
import path from 'path';
|
||||
|
||||
import { Registry } from './index';
|
||||
import { ensureUpdatedConfig, getConfig } from './testing/helper';
|
||||
|
||||
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
|
||||
|
||||
jest.setTimeout(120 * 1000);
|
||||
|
||||
const { chainId, restEndpoint, 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(restEndpoint, gqlEndpoint, chainId);
|
||||
|
||||
// Create bond.
|
||||
bondId = await registry.getNextBondId(privateKey);
|
||||
await registry.createBond({ denom: 'aphoton', amount: '3000000' }, privateKey, fee);
|
||||
});
|
||||
|
||||
test('Set record and check bond balance', async () => {
|
||||
// Create watcher.
|
||||
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||
await registry.setRecord(
|
||||
{
|
||||
privateKey,
|
||||
bondId,
|
||||
record: watcher.record
|
||||
},
|
||||
privateKey,
|
||||
fee
|
||||
)
|
||||
|
||||
const [record] = await registry.queryRecords({ type: 'watcher', 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 = `dxos-${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) => {
|
||||
setTimeout(done, 60 * 1000);
|
||||
});
|
||||
|
||||
test('Check record expiry time', async() => {
|
||||
const [record] = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true);
|
||||
const updatedExpiryTime = new Date(record.expiryTime);
|
||||
expect(updatedExpiryTime.getTime()).toBeGreaterThan(recordExpiryTime.getTime());
|
||||
recordExpiryTime = updatedExpiryTime;
|
||||
})
|
||||
|
||||
test('Check authority expiry time', async() => {
|
||||
const [authority] = await registry.lookupAuthorities([authorityName]);
|
||||
const updatedExpiryTime = new Date(authority.expiryTime);
|
||||
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) => {
|
||||
setTimeout(done, 60 * 1000);
|
||||
});
|
||||
|
||||
test('Check record deleted without balance', async() => {
|
||||
const records = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true);
|
||||
expect(records).toHaveLength(0);
|
||||
})
|
||||
|
||||
test('Check authority expired without 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 chiba-clonk repo run:
|
||||
|
||||
TEST_NAMESERVICE_EXPIRY=true ./init.sh
|
||||
|
||||
|
||||
Run tests:
|
||||
|
||||
yarn test:expiry
|
||||
*/
|
||||
|
||||
describe('Nameservice Expiry', nameserviceExpiryTests)
|
||||
}
|
@ -31,7 +31,7 @@ const namingTests = () => {
|
||||
bondId = await registry.getNextBondId(privateKey);
|
||||
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||
|
||||
// Create bot.
|
||||
// Create watcher.
|
||||
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||
await registry.setRecord(
|
||||
{
|
||||
@ -267,7 +267,7 @@ const namingTests = () => {
|
||||
});
|
||||
};
|
||||
|
||||
if (process.env.AUCTIONS_ENABLED) {
|
||||
if (process.env.TEST_AUCTIONS_ENABLED) {
|
||||
// Required as jest complains if file has no tests.
|
||||
test('skipping naming tests', () => {});
|
||||
} else {
|
||||
|
@ -24,7 +24,7 @@ const utilTests = () => {
|
||||
bondId = await registry.getNextBondId(privateKey);
|
||||
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||
|
||||
// Create bot.
|
||||
// Create watcher.
|
||||
watcher = await getBaseConfig(WATCHER_YML_PATH);
|
||||
await registry.setRecord(
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user