From a0cd3443c52215883696d56d400529268f2b371e Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 29 Jan 2024 09:58:58 +0530 Subject: [PATCH] Rename constants and helper methods --- .github/workflows/test.yml | 1 - test/cli.test.ts | 28 ++++++++++++++-------------- test/helpers.ts | 7 ++++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd07de6..e238e86 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,3 @@ -# TODO: Remove name: Tests on: pull_request: diff --git a/test/cli.test.ts b/test/cli.test.ts index 90689b4..5fa5198 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -5,8 +5,8 @@ import { spawnSync } from 'child_process'; import { CHAIN_ID, TOKEN_TYPE, - COMMIT_DURATION, - REVEAL_DURATION, + AUCTION_COMMIT_DURATION, + AUCTION_REVEAL_DURATION, delay, checkResultAndRetrieveOutput, createBond, @@ -15,7 +15,7 @@ import { getRecordObj, getAuthorityObj, getAuctionObj, - getBidObject + getBidObj } from './helpers'; describe('Test laconic CLI commands', () => { @@ -45,18 +45,18 @@ describe('Test laconic CLI commands', () => { expect(errorOutput).toContain('Commands:'); }); + // TODO: Break up tests into separate files // TODO: Add tests for CNS commands with all available flags describe('laconic CNS commands', () => { - const initialAccountBalance = Number('100000000000000000000000000'); const testAccount = process.env.TEST_ACCOUNT; - const testAccount2 = 'ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu'; assert(testAccount, 'TEST_ACCOUNT not set in env'); + const testAccount2 = 'ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu'; + const initialAccountBalance = Number('100000000000000000000000000'); const testAuthorityName = 'laconic'; - let testAuctionId: string; const testRecordFilePath = 'test/data/watcher-record.yml'; - let testRecordId: string, testRecordBondId: string; + let testAuctionId: string, testRecordId: string, testRecordBondId: string; test('laconic cns status', async () => { const result = spawnSync('laconic', ['cns', 'status']); @@ -76,8 +76,8 @@ describe('Test laconic CLI commands', () => { }); describe('Bond operations', () => { - let bondBalance = 1000000000; const bondOwner = testAccount; + let bondBalance = 1000000000; let bondId: string; test('laconic cns bond create --type --quantity --gas --fees ', async () => { @@ -161,7 +161,7 @@ describe('Test laconic CLI commands', () => { // Expected bond const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance }); - // Expect balance to be deducted (also deducts gas) + // Expect balance to be deducted expect(bondOutputObj.length).toEqual(1); expect(bondOutputObj[0]).toEqual(expectedBond); }); @@ -376,13 +376,13 @@ describe('Test laconic CLI commands', () => { test('laconic cns auction bid reveal ', async () => { // Wait for auction commits duration (60s) - await delay(COMMIT_DURATION * 1000); + await delay(AUCTION_COMMIT_DURATION * 1000); const auctionResult = spawnSync('laconic', ['cns', 'auction', 'get', testAuctionId]); const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult); const expectedAuction = getAuctionObj({ owner: testAccount, status: 'reveal' }); - const expectedBid = getBidObject({ bidder: testAccount }); + const expectedBid = getBidObj({ bidder: testAccount }); expect(auctionOutputObj[0]).toMatchObject(expectedAuction); expect(auctionOutputObj[0].bids[0]).toMatchObject(expectedBid); @@ -401,7 +401,7 @@ describe('Test laconic CLI commands', () => { bidderAddress: testAccount, bidAmount: `${bidAmount}aphoton` }); - }, (COMMIT_DURATION + 5) * 1000); + }, (AUCTION_COMMIT_DURATION + 5) * 1000); }); describe('Name authority operations (post auction)', () => { @@ -410,7 +410,7 @@ describe('Test laconic CLI commands', () => { test('laconic cns authority whois ', async () => { // Wait for auction reveals duration (60s) - await delay(REVEAL_DURATION * 1000); + await delay(AUCTION_REVEAL_DURATION * 1000); const result = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]); const outputObj = checkResultAndRetrieveOutput(result); @@ -420,7 +420,7 @@ describe('Test laconic CLI commands', () => { expect(outputObj.length).toEqual(1); expect(outputObj[0]).toMatchObject(expectedAuthority); - }, (REVEAL_DURATION + 5) * 1000); + }, (AUCTION_REVEAL_DURATION + 5) * 1000); test('laconic cns authority bond set laconic ', async () => { // Create a new bond to be set on the authority diff --git a/test/helpers.ts b/test/helpers.ts index 66e0938..cc2a335 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -4,13 +4,14 @@ import { SpawnSyncReturns, spawnSync } from 'child_process'; export const CHAIN_ID = 'laconic_9000-1'; export const TOKEN_TYPE = 'aphoton'; + export const AUCTION_FEES = { commit: 1000000, reveal: 1000000, minimumBid: 5000000 }; -export const COMMIT_DURATION = 60; // 60s -export const REVEAL_DURATION = 60; // 60s +export const AUCTION_COMMIT_DURATION = 60; // 60s +export const AUCTION_REVEAL_DURATION = 60; // 60s export function checkResultAndRetrieveOutput(result: SpawnSyncReturns): any { expect(result.status).toBe(0); @@ -96,7 +97,7 @@ export function getAuctionObj(params: { owner: string, status?: string }): any { }; } -export function getBidObject(params: { bidder: string, status?: string }): any { +export function getBidObj(params: { bidder: string, status?: string }): any { return { bidderAddress: params.bidder, status: params.status || 'commit',