diff --git a/CHANGELOG.md b/CHANGELOG.md index 42db34f1..1dca917d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,19 @@ Version header format: `[version] Name - year-month-day (entropy-core compatibil ## [UNRELEASED] +### Added +- new: 'src/flows/user-program-management/view.ts' - service file for pure functions of viewing user programs +- new: 'src/flows/user-program-management/helpers/utils.ts' - utility helper file for user program management specific methods +### Fixed + +### Changed + +### Broke + +### Meta/Dev + +## [0.0.2] AntMan - 2024-07-12 (entropy-core compatibility: 0.2.0) + ### Added - new: './src/flows/balance/balance.ts' - service file separated out of main flow containing the pure functions to perform balance requests for one or multiple addresses - new: './tests/balance.test.ts' - new unit tests file for balance pure functions diff --git a/package.json b/package.json index 6d480658..37e6dd40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@entropyxyz/cli", - "version": "0.0.1", + "version": "0.0.2", "description": "cli and tui for interacting with the entropy protocol", "type": "module", "scripts": { diff --git a/src/flows/index.ts b/src/flows/index.ts index af41e7bf..d86504ca 100644 --- a/src/flows/index.ts +++ b/src/flows/index.ts @@ -1,7 +1,7 @@ export { entropyFaucet } from './entropyFaucet' export { checkBalance } from './balance' export { register } from './register' -export { userPrograms } from './UserPrograms' +export { userPrograms } from './user-program-management' export { devPrograms } from './DeployPrograms' export { sign } from './sign' export { entropyTransfer } from './entropyTransfer' diff --git a/src/flows/user-program-management/helpers/questions.ts b/src/flows/user-program-management/helpers/questions.ts new file mode 100644 index 00000000..bda7afe9 --- /dev/null +++ b/src/flows/user-program-management/helpers/questions.ts @@ -0,0 +1,9 @@ +import Entropy from "@entropyxyz/sdk"; + +export const verifyingKeyQuestion = (entropy: Entropy) => [{ + type: 'list', + name: 'verifyingKey', + message: 'Select the key to proceeed', + choices: entropy.keyring.accounts.registration.verifyingKeys, + default: entropy.keyring.accounts.registration.verifyingKeys[0] +}] \ No newline at end of file diff --git a/src/flows/user-program-management/helpers/utils.ts b/src/flows/user-program-management/helpers/utils.ts new file mode 100644 index 00000000..ff0a3fe6 --- /dev/null +++ b/src/flows/user-program-management/helpers/utils.ts @@ -0,0 +1,11 @@ +import { print } from "src/common/utils" + +export function displayPrograms (programs): void { + programs.forEach((program, index) => { + print( + `${index + 1}. Pointer: ${ + program.program_pointer + }, Config: ${JSON.stringify(program.program_config)}` + ) + }) +} \ No newline at end of file diff --git a/src/flows/UserPrograms/index.ts b/src/flows/user-program-management/index.ts similarity index 87% rename from src/flows/UserPrograms/index.ts rename to src/flows/user-program-management/index.ts index da4e7c4f..106317d4 100644 --- a/src/flows/UserPrograms/index.ts +++ b/src/flows/user-program-management/index.ts @@ -3,6 +3,9 @@ import * as util from "@polkadot/util" import { initializeEntropy } from "../../common/initializeEntropy" import { getSelectedAccount, print } from "../../common/utils" import { EntropyLogger } from "src/common/logger"; +import { verifyingKeyQuestion } from "./helpers/questions"; +import { viewPrograms } from "./view"; +import { displayPrograms } from "./helpers/utils"; let verifyingKey: string; @@ -35,35 +38,21 @@ export async function userPrograms ({ accounts, selectedAccount: selectedAccount throw new Error("Keys are undefined") } - const verifyingKeyQuestion = [{ - type: 'list', - name: 'verifyingKey', - message: 'Select the key to proceeed', - choices: entropy.keyring.accounts.registration.verifyingKeys, - default: entropy.keyring.accounts.registration.verifyingKeys[0] - }] - switch (actionChoice.action) { case "View My Programs": { try { if (!verifyingKey && entropy.keyring.accounts.registration.verifyingKeys.length) { - ({ verifyingKey } = await inquirer.prompt(verifyingKeyQuestion)) + ({ verifyingKey } = await inquirer.prompt(verifyingKeyQuestion(entropy))) } else { print('You currently have no verifying keys, please register this account to generate the keys') break } - const programs = await entropy.programs.get(verifyingKey) + const programs = await viewPrograms(entropy, { verifyingKey }) if (programs.length === 0) { print("You currently have no programs set.") } else { print("Your Programs:") - programs.forEach((program, index) => { - print( - `${index + 1}. Pointer: ${ - program.program_pointer - }, Config: ${JSON.stringify(program.program_config)}` - ) - }) + displayPrograms(programs) } } catch (error) { console.error(error.message) @@ -132,7 +121,7 @@ export async function userPrograms ({ accounts, selectedAccount: selectedAccount case "Remove a Program from My List": { try { if (!verifyingKey) { - ({ verifyingKey } = await inquirer.prompt(verifyingKeyQuestion)) + ({ verifyingKey } = await inquirer.prompt(verifyingKeyQuestion(entropy))) } const { programPointerToRemove } = await inquirer.prompt([ { diff --git a/src/flows/user-program-management/types.ts b/src/flows/user-program-management/types.ts new file mode 100644 index 00000000..2559d036 --- /dev/null +++ b/src/flows/user-program-management/types.ts @@ -0,0 +1,3 @@ +export interface ViewProgramsParams { + verifyingKey: string +} \ No newline at end of file diff --git a/src/flows/user-program-management/view.ts b/src/flows/user-program-management/view.ts new file mode 100644 index 00000000..6cff1e9f --- /dev/null +++ b/src/flows/user-program-management/view.ts @@ -0,0 +1,6 @@ +import Entropy from "@entropyxyz/sdk"; +import { ViewProgramsParams } from "./types"; + +export async function viewPrograms (entropy: Entropy, { verifyingKey }: ViewProgramsParams): Promise { + return entropy.programs.get(verifyingKey) +} \ No newline at end of file diff --git a/tests/user-program-management.test.ts b/tests/user-program-management.test.ts new file mode 100644 index 00000000..6dc580f0 --- /dev/null +++ b/tests/user-program-management.test.ts @@ -0,0 +1,15 @@ +import test from 'tape' +import { viewPrograms } from 'src/flows/user-program-management/view' +import { charlieStashSeed, setupTest } from './testing-utils' + +const networkType = 'two-nodes' + +test('User Program Management::View Programs', async t => { + const { run, entropy } = await setupTest(t, { seed: charlieStashSeed, networkType }) + + await run('charlie register', entropy.register()) + const programs = await run('get charlie programs', viewPrograms(entropy, { verifyingKey: entropy.programs.verifyingKey })) + + t.equal(programs.length, 1, 'charlie has 1 program') + t.end() +}) \ No newline at end of file