Add tests for name operations
All checks were successful
Tests / cli_tests (18.x) (pull_request) Successful in 8m10s
All checks were successful
Tests / cli_tests (18.x) (pull_request) Successful in 8m10s
This commit is contained in:
parent
74a5183ad8
commit
ad91dfa4bf
@ -55,6 +55,8 @@ describe('Test laconic CLI commands', () => {
|
||||
|
||||
const testAuthorityName = 'laconic';
|
||||
let testAuctionId: string;
|
||||
const testRecordFilePath = 'test/data/watcher-record.yml';
|
||||
let testRecordId: string, testRecordBondId: string;
|
||||
|
||||
test('laconic cns status', async () => {
|
||||
const result = spawnSync('laconic', ['cns', 'status']);
|
||||
@ -173,23 +175,20 @@ describe('Test laconic CLI commands', () => {
|
||||
});
|
||||
|
||||
describe('Record operations', () => {
|
||||
const recordFilePath = 'test/data/watcher-record.yml';
|
||||
const gas = 250000;
|
||||
const bondBalance = 1000000000;
|
||||
let bondId: string;
|
||||
let recordId: string;
|
||||
|
||||
test('laconic cns record publish --filename <record_file> --bond-id <bond_id> --gas <gas>', async () => {
|
||||
// Create a new bond to be associated with the record
|
||||
({ bondId } = createBond(bondBalance));
|
||||
({ bondId: testRecordBondId } = createBond(bondBalance));
|
||||
|
||||
const result = spawnSync('laconic', ['cns', 'record', 'publish', '--filename', recordFilePath, '--bond-id', bondId, '--gas', gas.toString()]);
|
||||
const result = spawnSync('laconic', ['cns', 'record', 'publish', '--filename', testRecordFilePath, '--bond-id', testRecordBondId, '--gas', gas.toString()]);
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
|
||||
// Expect output object to resultant bond id
|
||||
expect(outputObj.id).toBeDefined();
|
||||
|
||||
recordId = outputObj.id;
|
||||
testRecordId = outputObj.id;
|
||||
});
|
||||
|
||||
test('laconic cns record list', async () => {
|
||||
@ -197,7 +196,7 @@ describe('Test laconic CLI commands', () => {
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
|
||||
// Expected record
|
||||
const expectedRecord = getRecordObj(recordFilePath, { bondId, recordId });
|
||||
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
||||
|
||||
expect(outputObj.length).toEqual(1);
|
||||
expect(outputObj[0]).toMatchObject(expectedRecord);
|
||||
@ -208,11 +207,11 @@ describe('Test laconic CLI commands', () => {
|
||||
});
|
||||
|
||||
test('laconic cns record get --id <record_id>', async () => {
|
||||
const result = spawnSync('laconic', ['cns', 'record', 'get', '--id', recordId]);
|
||||
const result = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
|
||||
// Expected record
|
||||
const expectedRecord = getRecordObj(recordFilePath, { bondId, recordId });
|
||||
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
||||
|
||||
expect(outputObj.length).toEqual(1);
|
||||
expect(outputObj[0]).toMatchObject(expectedRecord);
|
||||
@ -391,20 +390,47 @@ describe('Test laconic CLI commands', () => {
|
||||
});
|
||||
|
||||
describe('Name operations', () => {
|
||||
const testName = 'crn://laconic/watcher/erc20';
|
||||
|
||||
test('laconic cns name set <name> <record_id>', async () => {
|
||||
// TODO
|
||||
const result = spawnSync('laconic', ['cns', 'name', 'set', testName, testRecordId]);
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
|
||||
// Expected output
|
||||
expect(outputObj).toEqual({ success: true });
|
||||
});
|
||||
|
||||
test('laconic cns name lookup <name>', async () => {
|
||||
// TODO
|
||||
const result = spawnSync('laconic', ['cns', 'name', 'lookup', testName]);
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
|
||||
// Expected output
|
||||
expect(outputObj.length).toEqual(1);
|
||||
expect(outputObj[0]).toMatchObject({ latest: { id: testRecordId } });
|
||||
});
|
||||
|
||||
test('laconic cns name resolve <name>', async () => {
|
||||
// TODO
|
||||
const result = spawnSync('laconic', ['cns', 'name', 'resolve', testName]);
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
|
||||
// Expected resolved record
|
||||
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: [testName] });
|
||||
|
||||
expect(outputObj.length).toEqual(1);
|
||||
expect(outputObj[0]).toMatchObject(expectedRecord);
|
||||
});
|
||||
|
||||
test('laconic cns name delete <name>', async () => {
|
||||
// TODO
|
||||
const result = spawnSync('laconic', ['cns', 'name', 'delete', testName]);
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
|
||||
// Expected output
|
||||
expect(outputObj).toEqual({ success: true });
|
||||
|
||||
// Check that name doesn't resolve
|
||||
const resolveResult = spawnSync('laconic', ['cns', 'name', 'resolve', testName]);
|
||||
const resolveOutputObj = checkResultAndRetrieveOutput(resolveResult);
|
||||
expect(resolveOutputObj.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -56,12 +56,12 @@ export function getAccountObj(params: { address: string, balance?: number }): an
|
||||
};
|
||||
}
|
||||
|
||||
export function getRecordObj(recordFilePath: string, params: { bondId: string, recordId: string }): any {
|
||||
export function getRecordObj(recordFilePath: string, params: { bondId: string, recordId: string, names: any }): any {
|
||||
const recordContent = yaml.load(fs.readFileSync(recordFilePath, 'utf8')) as any;
|
||||
|
||||
return {
|
||||
id: params.recordId,
|
||||
names: null,
|
||||
names: params.names,
|
||||
bondId: params.bondId,
|
||||
attributes: recordContent.record
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user