diff --git a/test/cli.test.ts b/test/cli.test.ts index c04dba8..cd9706e 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -76,7 +76,7 @@ describe('Test laconic CLI commands', () => { }); describe('Bond operations', () => { - const bondBalance = 1000000000; + let bondBalance = 1000000000; const bondOwner = testAccount; let bondId: string; @@ -123,16 +123,63 @@ describe('Test laconic CLI commands', () => { expect(outputObj[0]).toEqual(expectedBond); }); - test('laconic cns bond refill --id --type --quantity ', async () => { - // TODO + test('laconic cns bond refill --id --type --quantity ', async () => { + const bondRefillAmount = 1000; + bondBalance += bondRefillAmount; + + const result = spawnSync('laconic', ['cns', 'bond', 'refill', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondRefillAmount.toString()]); + const outputObj = checkResultAndRetrieveOutput(result); + + // Expected output + expect(outputObj).toEqual({ success: true }); + + // Check updated bond + const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]); + const bondOutputObj = checkResultAndRetrieveOutput(bondResult); + + // Expected bond + const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance }); + + expect(bondOutputObj.length).toEqual(1); + expect(bondOutputObj[0]).toEqual(expectedBond); }); test('laconic cns bond withdraw --id --type --quantity ', async () => { - // TODO + const bondWithdrawAmount = 500; + bondBalance -= bondWithdrawAmount; + + const result = spawnSync('laconic', ['cns', 'bond', 'withdraw', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondWithdrawAmount.toString()]); + const outputObj = checkResultAndRetrieveOutput(result); + + // Expected output + expect(outputObj).toEqual({ success: true }); + + // Check updated bond + const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]); + const bondOutputObj = checkResultAndRetrieveOutput(bondResult); + + // Expected bond + const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance }); + + // Expect balance to be deducted (also deducts gas) + expect(bondOutputObj.length).toEqual(1); + expect(bondOutputObj[0]).toEqual(expectedBond); }); test('laconic cns bond cancel --id ', async () => { - // TODO + const result = spawnSync('laconic', ['cns', 'bond', 'cancel', '--id', bondId]); + const outputObj = checkResultAndRetrieveOutput(result); + + // Expected output + expect(outputObj).toEqual({ success: true }); + + // Check updated bond + const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]); + const bondOutputObj = checkResultAndRetrieveOutput(bondResult); + + // Expect empty object + expect(bondOutputObj.length).toEqual(1); + expect(bondOutputObj[0]).toEqual({ id: '', owner: '', balance: [] }); }); });