diff --git a/test/cli.test.ts b/test/cli.test.ts index 971298a..f299a81 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -82,7 +82,7 @@ describe('Test laconic CLI commands', () => { expect(output.length).toBeGreaterThan(0); const outputObj = JSON.parse(output); - // Expect output object to resultant bond id + // Expect output object to have resultant bond id expect(outputObj).toHaveProperty('bondId'); bondId = outputObj.bondId; @@ -294,6 +294,47 @@ describe('Test laconic CLI commands', () => { expect(outputObj[0]).toMatchObject(expectedRecord); }); }); + + describe('Name authority operations', () => { + const authorityName = 'laconic'; + + test('laconic cns authority reserve ', async () => { + const result = spawnSync('laconic', ['cns', 'authority', 'reserve', authorityName]); + + 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 result + expect(outputObj).toEqual({ success: true }); + }); + + test('laconic cns authority whois ', async () => { + const result = spawnSync('laconic', ['cns', 'authority', 'whois', authorityName]); + + 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(JSON.parse(output)); + + // Expected authority (still in auction) + const expectedAuthority = getAuthority({ status: 'auction', auction: getAuction({ owner: existingAccount }) }); + + expect(outputObj.length).toEqual(1); + expect(outputObj[0]).toMatchObject(expectedAuthority); + expect(outputObj[0]).toHaveProperty('expiryTime'); + expect(outputObj[0].height).toBeGreaterThan(0); + }); + }); }); }); @@ -329,3 +370,40 @@ function getRecord(recordFilePath: string, params: { bondId: string, recordId: s attributes: recordContent.record }; } + +function getAuthority(params: { status: string, auction: any }): any { + return { + ownerAddress: '', + ownerPublicKey: '', + status: params.status, + bondId: '', + auction: params.auction || null + }; +} + +function getAuction(params: { owner: string, status?: string, bids?: any[] }): any { + const auctionFees = { + commit: 1000000, + reveal: 1000000, + minimumBid: 5000000 + }; + + return { + status: params.status || 'commit', + ownerAddress: params.owner, + commitFee: { + type: TOKEN_TYPE, + quantity: auctionFees.commit + }, + revealFee: { + type: TOKEN_TYPE, + quantity: auctionFees.reveal + }, + minimumBid: { + type: TOKEN_TYPE, + quantity: auctionFees.minimumBid + }, + winnerAddress: '', + bids: params.bids || [] + }; +}