Add CLI tests and setup CI #53

Merged
ashwin merged 23 commits from deep-stack/laconic-registry-cli:pm-add-tests into main 2024-01-29 04:46:32 +00:00
2 changed files with 41 additions and 15 deletions
Showing only changes of commit ad91dfa4bf - Show all commits

View File

@ -55,6 +55,8 @@ describe('Test laconic CLI commands', () => {
const testAuthorityName = 'laconic'; const testAuthorityName = 'laconic';
let testAuctionId: string; let testAuctionId: string;
const testRecordFilePath = 'test/data/watcher-record.yml';
let testRecordId: string, testRecordBondId: string;
test('laconic cns status', async () => { test('laconic cns status', async () => {
const result = spawnSync('laconic', ['cns', 'status']); const result = spawnSync('laconic', ['cns', 'status']);
@ -173,23 +175,20 @@ describe('Test laconic CLI commands', () => {
}); });
describe('Record operations', () => { describe('Record operations', () => {
const recordFilePath = 'test/data/watcher-record.yml';
const gas = 250000; const gas = 250000;
const bondBalance = 1000000000; const bondBalance = 1000000000;
let bondId: string;
let recordId: string;
test('laconic cns record publish --filename <record_file> --bond-id <bond_id> --gas <gas>', async () => { 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 // 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); const outputObj = checkResultAndRetrieveOutput(result);
// Expect output object to resultant bond id // Expect output object to resultant bond id
expect(outputObj.id).toBeDefined(); expect(outputObj.id).toBeDefined();
recordId = outputObj.id; testRecordId = outputObj.id;
}); });
test('laconic cns record list', async () => { test('laconic cns record list', async () => {
@ -197,7 +196,7 @@ describe('Test laconic CLI commands', () => {
const outputObj = checkResultAndRetrieveOutput(result); const outputObj = checkResultAndRetrieveOutput(result);
// Expected record // 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.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedRecord); expect(outputObj[0]).toMatchObject(expectedRecord);
@ -208,11 +207,11 @@ describe('Test laconic CLI commands', () => {
}); });
test('laconic cns record get --id <record_id>', async () => { 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); const outputObj = checkResultAndRetrieveOutput(result);
// Expected record // 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.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedRecord); expect(outputObj[0]).toMatchObject(expectedRecord);
@ -391,20 +390,47 @@ describe('Test laconic CLI commands', () => {
}); });
describe('Name operations', () => { describe('Name operations', () => {
const testName = 'crn://laconic/watcher/erc20';
test('laconic cns name set <name> <record_id>', async () => { 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 () => { 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 () => { 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 () => { 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);
}); });
}); });
}); });

View File

@ -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; const recordContent = yaml.load(fs.readFileSync(recordFilePath, 'utf8')) as any;
return { return {
id: params.recordId, id: params.recordId,
names: null, names: params.names,
bondId: params.bondId, bondId: params.bondId,
attributes: recordContent.record attributes: recordContent.record
}; };