Add tests for record operations commands
Some checks failed
Tests / cli_tests (18.x) (pull_request) Failing after 3m38s
Some checks failed
Tests / cli_tests (18.x) (pull_request) Failing after 3m38s
This commit is contained in:
parent
4036d33d7a
commit
f8dee0d8d4
@ -1,3 +1,5 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { spawnSync } from 'child_process';
|
import { spawnSync } from 'child_process';
|
||||||
|
|
||||||
@ -65,8 +67,7 @@ describe('Test laconic CLI commands', () => {
|
|||||||
describe('Bond operations', () => {
|
describe('Bond operations', () => {
|
||||||
const bondBalance = 1000000000;
|
const bondBalance = 1000000000;
|
||||||
const bondOwner = existingAccount;
|
const bondOwner = existingAccount;
|
||||||
let bondId = 'de88ffab68af143da5d3ba2cf86f468ac4ac2efaa005e4d2fbce5fde85cbaa3e';
|
let bondId: string;
|
||||||
// let bondId: string;
|
|
||||||
|
|
||||||
test('laconic cns bond create', async () => {
|
test('laconic cns bond create', async () => {
|
||||||
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
|
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
|
||||||
@ -100,7 +101,7 @@ describe('Test laconic CLI commands', () => {
|
|||||||
const outputObj = Array.from<any>(JSON.parse(output));
|
const outputObj = Array.from<any>(JSON.parse(output));
|
||||||
|
|
||||||
// Expected bond
|
// Expected bond
|
||||||
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
const expectedBond = getBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
expect(outputObj.length).toEqual(1);
|
expect(outputObj.length).toEqual(1);
|
||||||
expect(outputObj[0]).toEqual(expectedBond);
|
expect(outputObj[0]).toEqual(expectedBond);
|
||||||
@ -119,7 +120,7 @@ describe('Test laconic CLI commands', () => {
|
|||||||
const outputObj = Array.from<any>(JSON.parse(output));
|
const outputObj = Array.from<any>(JSON.parse(output));
|
||||||
|
|
||||||
// Expected bond
|
// Expected bond
|
||||||
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
const expectedBond = getBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
expect(outputObj.length).toEqual(1);
|
expect(outputObj.length).toEqual(1);
|
||||||
expect(outputObj[0]).toEqual(expectedBond);
|
expect(outputObj[0]).toEqual(expectedBond);
|
||||||
@ -138,7 +139,7 @@ describe('Test laconic CLI commands', () => {
|
|||||||
const outputObj = Array.from<any>(JSON.parse(output));
|
const outputObj = Array.from<any>(JSON.parse(output));
|
||||||
|
|
||||||
// Expected bond
|
// Expected bond
|
||||||
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
const expectedBond = getBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
expect(outputObj.length).toEqual(1);
|
expect(outputObj.length).toEqual(1);
|
||||||
expect(outputObj[0]).toEqual(expectedBond);
|
expect(outputObj[0]).toEqual(expectedBond);
|
||||||
@ -225,12 +226,80 @@ describe('Test laconic CLI commands', () => {
|
|||||||
expect(outputObj).toMatchObject(expectedAccounts);
|
expect(outputObj).toMatchObject(expectedAccounts);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Record operations', () => {
|
||||||
|
const recordFilePath = 'test/data/watcher-record.yml';
|
||||||
|
const gas = 250000;
|
||||||
|
const bondBalance = 1000000000;
|
||||||
|
const { bondId } = createBond(bondBalance);
|
||||||
|
let recordId: string;
|
||||||
|
|
||||||
|
test('laconic cns record publish --filename <record_file> --bond-id <bond_id> --gas <gas>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['cns', 'record', 'publish', '--filename', recordFilePath, '--bond-id', bondId, '--gas', gas.toString()]);
|
||||||
|
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
const errorOutput = result.stderr.toString().trim();
|
||||||
|
|
||||||
|
expect(errorOutput).toBe('');
|
||||||
|
expect(result.status).toBe(0);
|
||||||
|
|
||||||
|
expect(output.length).toBeGreaterThan(0);
|
||||||
|
const outputObj = JSON.parse(output);
|
||||||
|
|
||||||
|
// Expect output object to resultant bond id
|
||||||
|
expect(outputObj).toHaveProperty('id');
|
||||||
|
|
||||||
|
recordId = outputObj.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic cns record list', async () => {
|
||||||
|
const result = spawnSync('laconic', ['cns', 'record', 'list']);
|
||||||
|
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
const errorOutput = result.stderr.toString().trim();
|
||||||
|
|
||||||
|
expect(errorOutput).toBe('');
|
||||||
|
expect(result.status).toBe(0);
|
||||||
|
|
||||||
|
expect(output.length).toBeGreaterThan(0);
|
||||||
|
const outputObj = Array.from<any>(JSON.parse(output));
|
||||||
|
|
||||||
|
// Expected record
|
||||||
|
const expectedRecord = getRecord(recordFilePath, { bondId, recordId });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
||||||
|
expect(outputObj[0]).toHaveProperty('createTime');
|
||||||
|
expect(outputObj[0]).toHaveProperty('expiryTime');
|
||||||
|
expect(outputObj[0]).toHaveProperty('owners');
|
||||||
|
expect(outputObj[0].owners.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic cns record get --id <record_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['cns', 'record', 'get', '--id', recordId]);
|
||||||
|
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
const errorOutput = result.stderr.toString().trim();
|
||||||
|
|
||||||
|
expect(errorOutput).toBe('');
|
||||||
|
expect(result.status).toBe(0);
|
||||||
|
|
||||||
|
expect(output.length).toBeGreaterThan(0);
|
||||||
|
const outputObj = Array.from<any>(JSON.parse(output));
|
||||||
|
|
||||||
|
// Expected record
|
||||||
|
const expectedRecord = getRecord(recordFilePath, { bondId, recordId });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
|
|
||||||
function getExpectedBond(params: { id: string, owner: string, balance: number}): any {
|
function getBond(params: { id: string, owner: string, balance: number}): any {
|
||||||
return {
|
return {
|
||||||
id: params.id,
|
id: params.id,
|
||||||
owner: params.owner,
|
owner: params.owner,
|
||||||
@ -242,3 +311,21 @@ function getExpectedBond(params: { id: string, owner: string, balance: number}):
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createBond(quantity: number): { bondId: string } {
|
||||||
|
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', quantity.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
|
||||||
|
return JSON.parse(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRecord(recordFilePath: string, params: { bondId: string, recordId: string }): any {
|
||||||
|
const recordContent = yaml.load(fs.readFileSync(recordFilePath, 'utf8')) as any;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: params.recordId,
|
||||||
|
names: null,
|
||||||
|
bondId: params.bondId,
|
||||||
|
attributes: recordContent.record
|
||||||
|
};
|
||||||
|
}
|
||||||
|
7
test/data/watcher-record.yml
Normal file
7
test/data/watcher-record.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
record:
|
||||||
|
type: WebsiteRegistrationRecord
|
||||||
|
url: 'https://cerc.io'
|
||||||
|
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
|
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
|
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
||||||
|
version: 1.0.23
|
Loading…
Reference in New Issue
Block a user