Rename crn to lrn

This commit is contained in:
neeraj 2024-03-11 10:52:06 +05:30
parent 562fa4c235
commit 70717d2c67
6 changed files with 73 additions and 70 deletions

View File

@ -17,7 +17,7 @@ const bondTests = () => {
const publishNewWatcherVersion = async (bondId: string) => { const publishNewWatcherVersion = async (bondId: string) => {
let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH); let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee); await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, laconic2Fee);
return watcher; return watcher;
}; };

View File

@ -472,16 +472,16 @@ export class Registry {
} }
/** /**
* Set name (CRN) to record ID (CID). * Set name (LRN) to record ID (CID).
*/ */
async setName ({ cid, crn }: MessageMsgSetName, privateKey: string, fee: StdFee) { async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee) {
const account = new Account(Buffer.from(privateKey, 'hex')); const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init(); await account.init();
const laconicClient = await this.getLaconicClient(account); const laconicClient = await this.getLaconicClient(account);
const response: DeliverTxResponse = await laconicClient.setName( const response: DeliverTxResponse = await laconicClient.setName(
account.address, account.address,
crn, lrn,
cid, cid,
fee fee
); );
@ -498,15 +498,15 @@ export class Registry {
} }
/** /**
* Delete name (CRN) mapping. * Delete name (LRN) mapping.
*/ */
async deleteName ({ crn }: MessageMsgDeleteName, privateKey: string, fee: StdFee) { async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee) {
const account = new Account(Buffer.from(privateKey, 'hex')); const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init(); await account.init();
const laconicClient = await this.getLaconicClient(account); const laconicClient = await this.getLaconicClient(account);
const response: DeliverTxResponse = await laconicClient.deleteName( const response: DeliverTxResponse = await laconicClient.deleteName(
account.address, account.address,
crn, lrn,
fee fee
); );

View File

@ -93,7 +93,7 @@ export interface MessageMsgReserveAuthority {
} }
export interface MessageMsgSetName { export interface MessageMsgSetName {
crn: string lrn: string
cid: string cid: string
} }
@ -108,7 +108,7 @@ export interface MessageMsgSetAuthorityBond {
} }
export interface MessageMsgDeleteName { export interface MessageMsgDeleteName {
crn: string lrn: string
} }
export function createTxMsgReserveAuthority ( export function createTxMsgReserveAuthority (
@ -145,13 +145,13 @@ export function createTxMsgSetName (
const types = generateTypes(MSG_SET_NAME_TYPES); const types = generateTypes(MSG_SET_NAME_TYPES);
const msg = createMsgSetName( const msg = createMsgSetName(
params.crn, params.lrn,
params.cid, params.cid,
sender.accountAddress sender.accountAddress
); );
const msgCosmos = protoCreateMsgSetName( const msgCosmos = protoCreateMsgSetName(
params.crn, params.lrn,
params.cid, params.cid,
sender.accountAddress sender.accountAddress
); );
@ -217,12 +217,12 @@ export function createTxMsgDeleteName (
const types = generateTypes(MSG_DELETE_NAME_TYPES); const types = generateTypes(MSG_DELETE_NAME_TYPES);
const msg = createMsgDeleteName( const msg = createMsgDeleteName(
params.crn, params.lrn,
sender.accountAddress sender.accountAddress
); );
const msgCosmos = protoCreateMsgDeleteName( const msgCosmos = protoCreateMsgDeleteName(
params.crn, params.lrn,
sender.accountAddress sender.accountAddress
); );

View File

@ -39,9 +39,9 @@ const nameserviceExpiryTests = () => {
record: watcher.record record: watcher.record
}, },
privateKey, privateKey,
fee laconic2Fee
); );
console.log('SetRecordResult: ' + result.data.id); console.log('SetRecordResult: ' + result.id);
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true); const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
recordExpiryTime = new Date(record.expiryTime); recordExpiryTime = new Date(record.expiryTime);

View File

@ -25,22 +25,21 @@ const namingTests = () => {
// Create bond. // Create bond.
bondId = await registry.getNextBondId(privateKey); bondId = await registry.getNextBondId(privateKey);
await registry.createBond({ denom: DENOM, amount: '20000' }, privateKey, laconic2Fee); await registry.createBond({ denom: DENOM, amount: '2000000' }, privateKey, laconic2Fee);
// TODO: Implement set record
// Create watcher. // Create watcher.
// watcher = await ensureUpdatedConfig(WATCHER_YML_PATH); watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
// const result = await registry.setRecord( const result = await registry.setRecord(
// { {
// privateKey, privateKey,
// bondId, bondId,
// record: watcher.record record: watcher.record
// }, },
// privateKey, privateKey,
// fee laconic2Fee
// ); );
// watcherId = result.data.id; watcherId = result.id;
}); });
describe('Authority tests', () => { describe('Authority tests', () => {
@ -51,11 +50,11 @@ const namingTests = () => {
describe('With authority reserved', () => { describe('With authority reserved', () => {
let authorityName: string; let authorityName: string;
let crn: string; let lrn: string;
beforeAll(async () => { beforeAll(async () => {
authorityName = `laconic-${Date.now()}`; authorityName = `laconic-${Date.now()}`;
crn = `crn://${authorityName}/app/test`; lrn = `lrn://${authorityName}/app/test`;
await registry.reserveAuthority({ name: authorityName }, privateKey, laconic2Fee); await registry.reserveAuthority({ name: authorityName }, privateKey, laconic2Fee);
}); });
@ -117,10 +116,10 @@ const namingTests = () => {
expect(Number(record.height)).toBeGreaterThan(0); expect(Number(record.height)).toBeGreaterThan(0);
}); });
// TODO: Implement set record // TODO: Parse error response from set name
xtest('Set name for unbonded authority', async () => { xtest('Set name for unbonded authority', async () => {
assert(watcherId); assert(watcherId);
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)) await expect(registry.setName({ lrn, cid: watcherId }, privateKey, laconic2Fee))
.rejects.toThrow('Authority bond not found.'); .rejects.toThrow('Authority bond not found.');
}); });
@ -130,8 +129,7 @@ const namingTests = () => {
}); });
}); });
// TODO: Implement set record describe('Naming tests', () => {
xdescribe('Naming tests', () => {
let authorityName: string; let authorityName: string;
let otherAuthorityName: string; let otherAuthorityName: string;
let otherPrivateKey: string; let otherPrivateKey: string;
@ -145,39 +143,40 @@ const namingTests = () => {
// Create another account. // Create another account.
const mnenonic = Account.generateMnemonic(); const mnenonic = Account.generateMnemonic();
otherAccount = await Account.generateFromMnemonic(mnenonic); otherAccount = await Account.generateFromMnemonic(mnenonic);
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, laconic2Fee); await otherAccount.init();
await registry.sendCoins({ denom: DENOM, amount: '1000000000', destinationAddress: otherAccount.address }, privateKey, laconic2Fee);
otherAuthorityName = `other-${Date.now()}`; otherAuthorityName = `other-${Date.now()}`;
otherPrivateKey = otherAccount.privateKey.toString('hex'); otherPrivateKey = otherAccount.privateKey.toString('hex');
}); });
test('Set name', async () => { test('Set name', async () => {
const crn = `crn://${authorityName}/app/test1`; const lrn = `lrn://${authorityName}/app/test1`;
await registry.setName({ crn, cid: watcherId }, privateKey, fee); await registry.setName({ lrn, cid: watcherId }, privateKey, laconic2Fee);
// Query records should return it (some CRN points to it). // Query records should return it (some lrn points to it).
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }); const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
expect(record).toBeDefined(); expect(record).toBeDefined();
expect(record.names).toHaveLength(1); expect(record.names).toHaveLength(1);
await registry.deleteName({ crn }, privateKey, fee); await registry.deleteName({ lrn }, privateKey, laconic2Fee);
}); });
describe('With name set', () => { describe('With name set', () => {
let crn: string; let lrn: string;
beforeAll(async () => { beforeAll(async () => {
crn = `crn://${authorityName}/app/test2`; lrn = `lrn://${authorityName}/app/test2`;
await registry.setName({ crn, cid: watcherId }, privateKey, fee); await registry.setName({ lrn, cid: watcherId }, privateKey, laconic2Fee);
}); });
afterAll(async () => { afterAll(async () => {
await registry.deleteName({ crn }, privateKey, fee); await registry.deleteName({ lrn }, privateKey, laconic2Fee);
}); });
test('Lookup name', async () => { test('Lookup name', async () => {
const records = await registry.lookupNames([crn]); const records = await registry.lookupNames([lrn]);
expect(records).toBeDefined(); expect(records).toBeDefined();
expect(records).toHaveLength(1); expect(records).toHaveLength(1);
@ -190,7 +189,7 @@ const namingTests = () => {
}); });
test('Resolve name', async () => { test('Resolve name', async () => {
const records = await registry.resolveNames([crn]); const records = await registry.resolveNames([lrn]);
expect(records).toBeDefined(); expect(records).toBeDefined();
expect(records).toHaveLength(1); expect(records).toHaveLength(1);
@ -207,13 +206,13 @@ const namingTests = () => {
record: updatedWatcher.record record: updatedWatcher.record
}, },
privateKey, privateKey,
fee laconic2Fee
); );
const updatedWatcherId = result.data.id; const updatedWatcherId = result.id;
await registry.setName({ crn, cid: updatedWatcherId }, privateKey, fee); await registry.setName({ lrn, cid: updatedWatcherId }, privateKey, laconic2Fee);
const records = await registry.lookupNames([crn], true); const records = await registry.lookupNames([lrn], true);
expect(records).toHaveLength(1); expect(records).toHaveLength(1);
const [{ latest, history }] = records; const [{ latest, history }] = records;
@ -232,9 +231,9 @@ const namingTests = () => {
}); });
test('Delete name', async () => { test('Delete name', async () => {
await registry.deleteName({ crn }, privateKey, fee); await registry.deleteName({ lrn }, privateKey, laconic2Fee);
let records = await registry.lookupNames([crn], true); let records = await registry.lookupNames([lrn], true);
expect(records).toBeDefined(); expect(records).toBeDefined();
expect(records).toHaveLength(1); expect(records).toHaveLength(1);
@ -244,7 +243,7 @@ const namingTests = () => {
expect(latest.id).toBe(''); expect(latest.id).toBe('');
expect(latest.height).toBeDefined(); expect(latest.height).toBeDefined();
// Query records should NOT return it (no CRN points to it). // Query records should NOT return it (no LRN points to it).
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }); records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
expect(records).toBeDefined(); expect(records).toBeDefined();
expect(records).toHaveLength(0); expect(records).toHaveLength(0);
@ -256,10 +255,10 @@ const namingTests = () => {
}); });
test('Delete already deleted name', async () => { test('Delete already deleted name', async () => {
await registry.deleteName({ crn }, privateKey, fee); await registry.deleteName({ lrn }, privateKey, laconic2Fee);
await registry.deleteName({ crn }, privateKey, fee); await registry.deleteName({ lrn }, privateKey, laconic2Fee);
const records = await registry.lookupNames([crn], true); const records = await registry.lookupNames([lrn], true);
expect(records).toBeDefined(); expect(records).toBeDefined();
expect(records).toHaveLength(1); expect(records).toHaveLength(1);
@ -271,34 +270,37 @@ const namingTests = () => {
}); });
}); });
test('Set name without reserving authority', async () => { // TODO: Parse error response form set name
await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee)) xtest('Set name without reserving authority', async () => {
await expect(registry.setName({ lrn: 'lrn://not-reserved/app/test', cid: watcherId }, privateKey, laconic2Fee))
.rejects.toThrow('Name authority not found.'); .rejects.toThrow('Name authority not found.');
}); });
test('Set name for non-owned authority', async () => { // TODO: Parse error response form set name
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, laconic2Fee); xtest('Set name for non-owned authority', async () => {
await registry.sendCoins({ denom: DENOM, amount: '1000000000', destinationAddress: otherAccount.address }, privateKey, laconic2Fee);
// Other account reserves an authority. // Other account reserves an authority.
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, laconic2Fee); await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, laconic2Fee);
// Try setting name under other authority. // Try setting name under other authority.
await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.'); await expect(registry.setName({ lrn: `lrn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, laconic2Fee)).rejects.toThrow('Access denied.');
}); });
test('Delete name for non-owned authority.', async () => { // TODO: Parse error response form set name
xtest('Delete name for non-owned authority.', async () => {
const otherBondId = await registry.getNextBondId(otherPrivateKey); const otherBondId = await registry.getNextBondId(otherPrivateKey);
await registry.createBond({ denom: 'aphoton', amount: '10000' }, otherPrivateKey, laconic2Fee); await registry.createBond({ denom: DENOM, amount: '1000000' }, otherPrivateKey, laconic2Fee);
await registry.setAuthorityBond({ name: otherAuthorityName, bondId: otherBondId }, otherPrivateKey, laconic2Fee); await registry.setAuthorityBond({ name: otherAuthorityName, bondId: otherBondId }, otherPrivateKey, laconic2Fee);
await registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, otherPrivateKey, fee); await registry.setName({ lrn: `lrn://${otherAuthorityName}/app/test`, cid: watcherId }, otherPrivateKey, laconic2Fee);
// Try deleting name under other authority. // Try deleting name under other authority.
await expect(registry.deleteName({ crn: `crn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.'); await expect(registry.deleteName({ lrn: `lrn://${otherAuthorityName}/app/test` }, privateKey, laconic2Fee)).rejects.toThrow('Access denied.');
}); });
// TODO: Check later for empty records // TODO: Check later for empty records
test('Lookup non existing name', async () => { test('Lookup non existing name', async () => {
const records = await registry.lookupNames(['crn://not-reserved/app/test']); const records = await registry.lookupNames(['lrn://not-reserved/app/test']);
expect(records).toBeDefined(); expect(records).toBeDefined();
expect(records).toHaveLength(1); expect(records).toHaveLength(1);
const [record] = records; const [record] = records;
@ -306,7 +308,7 @@ const namingTests = () => {
}); });
test('Resolve non existing name', async () => { test('Resolve non existing name', async () => {
const records = await registry.resolveNames(['crn://not-reserved/app/test']); const records = await registry.resolveNames(['lrn://not-reserved/app/test']);
expect(records).toBeDefined(); expect(records).toBeDefined();
expect(records).toHaveLength(1); expect(records).toHaveLength(1);
const [record] = records; const [record] = records;

View File

@ -3,6 +3,7 @@ import path from 'path';
import { Registry } from './index'; import { Registry } from './index';
import { getBaseConfig, getConfig, getLaconic2Config } from './testing/helper'; import { getBaseConfig, getConfig, getLaconic2Config } from './testing/helper';
import { Util } from './util'; import { Util } from './util';
import { DENOM } from './constants';
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml'); const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
@ -23,7 +24,7 @@ const utilTests = () => {
// Create bond. // Create bond.
bondId = await registry.getNextBondId(privateKey); bondId = await registry.getNextBondId(privateKey);
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, laconic2Fee); await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, laconic2Fee);
// Create watcher. // Create watcher.
watcher = await getBaseConfig(WATCHER_YML_PATH); watcher = await getBaseConfig(WATCHER_YML_PATH);
@ -34,10 +35,10 @@ const utilTests = () => {
record: watcher.record record: watcher.record
}, },
privateKey, privateKey,
fee laconic2Fee
); );
watcherId = result.data.id; watcherId = result.id;
}); });
test('Generate content id.', async () => { test('Generate content id.', async () => {
@ -46,4 +47,4 @@ const utilTests = () => {
}); });
}; };
xdescribe('Util', utilTests); describe('Util', utilTests);