Add tests for post auction name authority operations
All checks were successful
Tests / cli_tests (18.x) (pull_request) Successful in 6m23s

This commit is contained in:
Prathamesh Musale 2024-01-25 15:47:24 +05:30
parent d8a5b93a23
commit 74a5183ad8
2 changed files with 74 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import {
CHAIN_ID,
TOKEN_TYPE,
COMMIT_DURATION,
REVEAL_DURATION,
delay,
checkResultAndRetrieveOutput,
createBond,
@ -246,7 +247,7 @@ describe('Test laconic CLI commands', () => {
const outputObj = checkResultAndRetrieveOutput(result);
// Expected authority (still in auction)
const expectedAuthority = getAuthorityObj({ status: 'auction', auction: getAuctionObj({ owner: testAccount }) });
const expectedAuthority = getAuthorityObj({ owner: '', status: 'auction', auction: getAuctionObj({ owner: testAccount }) });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedAuthority);
@ -283,7 +284,7 @@ describe('Test laconic CLI commands', () => {
});
test('laconic cns auction bid reveal <auction_id> <file_path>', async () => {
// Wait for commits duration (60s)
// Wait for auction commits duration (60s)
await delay(COMMIT_DURATION * 1000);
const auctionResult = spawnSync('laconic', ['cns', 'auction', 'get', testAuctionId]);
@ -313,16 +314,79 @@ describe('Test laconic CLI commands', () => {
});
describe('Name authority operations (post auction)', () => {
const testSubAuthorityName = 'echo.laconic';
const testSubAuthorityName2 = 'kube.laconic';
test('laconic cns authority whois <authority_name>', async () => {
// Wait for auction reveals duration (60s)
await delay(REVEAL_DURATION * 1000);
const result = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected authority (active)
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedAuthority);
}, (REVEAL_DURATION + 5) * 1000);
test('laconic cns authority bond set laconic <bond_id>', async () => {
// TODO
// Create a new bond to be set on the authority
const bondBalance = 1000000000;
const { bondId } = createBond(bondBalance);
const result = spawnSync('laconic', ['cns', 'authority', 'bond', 'set', testAuthorityName, bondId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated authority
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]);
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
// Expected authority (active with bond)
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null, bondId: bondId });
expect(authorityOutputObj.length).toEqual(1);
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
});
test('laconic cns authority reserve <sub_authority> (same owner)', async () => {
// TODO
const result = spawnSync('laconic', ['cns', 'authority', 'reserve', testSubAuthorityName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated authority
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testSubAuthorityName]);
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
// Expected authority (active with bond)
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null });
expect(authorityOutputObj.length).toEqual(1);
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
});
test('laconic cns authority reserve <sub_authority> --owner <owner_address> (different owner)', async () => {
// TODO
const result = spawnSync('laconic', ['cns', 'authority', 'reserve', testSubAuthorityName2, '--owner', testAccount2]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated authority
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testSubAuthorityName2]);
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
// Expected authority (active with bond)
const expectedAuthority = getAuthorityObj({ owner: testAccount2, status: 'active', auction: null });
expect(authorityOutputObj.length).toEqual(1);
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
});
});

View File

@ -10,6 +10,7 @@ export const AUCTION_FEES = {
minimumBid: 5000000
};
export const COMMIT_DURATION = 60; // 60s
export const REVEAL_DURATION = 60; // 60s
export function checkResultAndRetrieveOutput(result: SpawnSyncReturns<Buffer>): any {
expect(result.status).toBe(0);
@ -66,13 +67,12 @@ export function getRecordObj(recordFilePath: string, params: { bondId: string, r
};
}
export function getAuthorityObj(params: { status: string, auction: any }): any {
export function getAuthorityObj(params: { owner: string, status: string, auction: any, bondId?: string }): any {
return {
ownerAddress: '',
ownerPublicKey: '',
ownerAddress: params.owner,
status: params.status,
bondId: '',
auction: params.auction || null
bondId: params.bondId || '',
auction: params.auction
};
}