From 85827c8466b68bc9c01741bc54f7be35e49ffd90 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 25 Jan 2024 17:05:21 +0530 Subject: [PATCH] Add tests for bonds-records association commands --- test/cli.test.ts | 57 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/test/cli.test.ts b/test/cli.test.ts index cd9706e..90689b4 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -80,7 +80,7 @@ describe('Test laconic CLI commands', () => { const bondOwner = testAccount; let bondId: string; - test('laconic cns bond create --type --quantity ', async () => { + test('laconic cns bond create --type --quantity --gas --fees ', async () => { const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]); const outputObj = checkResultAndRetrieveOutput(result); @@ -265,16 +265,61 @@ describe('Test laconic CLI commands', () => { }); describe('Bond records operations', () => { - test('laconic cns bond associate --id --bond-id ', async () => { - // TODO - }); + let testRecordBondId2: string; test('laconic cns bond dissociate --id ', async () => { - // TODO + const result = spawnSync('laconic', ['cns', 'bond', 'dissociate', '--id', testRecordId]); + const outputObj = checkResultAndRetrieveOutput(result); + + // Expected output + expect(outputObj).toEqual({ success: true }); + + const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]); + const recordOutputObj = checkResultAndRetrieveOutput(recordResult); + + // Expected record + const expectedRecord = getRecordObj(testRecordFilePath, { bondId: '', recordId: testRecordId, names: null }); + + expect(recordOutputObj.length).toEqual(1); + expect(recordOutputObj[0]).toMatchObject(expectedRecord); + + }); + + test('laconic cns bond associate --id --bond-id ', async () => { + // Create a new bond to be associated with the record + ({ bondId: testRecordBondId2 } = createBond(bondBalance)); + + const result = spawnSync('laconic', ['cns', 'bond', 'associate', '--id', testRecordId, '--bond-id', testRecordBondId2]); + const outputObj = checkResultAndRetrieveOutput(result); + + // Expected output + expect(outputObj).toEqual({ success: true }); + + const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]); + const recordOutputObj = checkResultAndRetrieveOutput(recordResult); + + // Expected record + const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId2, recordId: testRecordId, names: null }); + + expect(recordOutputObj.length).toEqual(1); + expect(recordOutputObj[0]).toMatchObject(expectedRecord); }); test('laconic cns bond records reassociate --old-bond-id --new-bond-id ', async () => { - // TODO + const result = spawnSync('laconic', ['cns', 'bond', 'records', 'reassociate', '--old-bond-id', testRecordBondId2, '--new-bond-id', testRecordBondId]); + const outputObj = checkResultAndRetrieveOutput(result); + + // Expected output + expect(outputObj).toEqual({ success: true }); + + const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]); + const recordOutputObj = checkResultAndRetrieveOutput(recordResult); + + // Expected record + const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null }); + + expect(recordOutputObj.length).toEqual(1); + expect(recordOutputObj[0]).toMatchObject(expectedRecord); }); }); });