Skip to content

Commit 9a2b8cb

Browse files
committed
feat: adjust handler naming, fix unit tests and docs
Signed-off-by: rozekmichal <michal.rozek@blockydevs.com>
1 parent e7a100f commit 9a2b8cb

File tree

206 files changed

+833
-875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+833
-875
lines changed

docs/adr/ADR-007-structured-error-handling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class ErrorBoundaryServiceImpl {
326326
Before (current):
327327

328328
```typescript
329-
export async function getAccountBalance(args: CommandHandlerArgs): Promise<CommandExecutionResult> {
329+
export async function accountBalance(args: CommandHandlerArgs): Promise<CommandExecutionResult> {
330330
const validArgs = AccountBalanceInputSchema.parse(args.args);
331331

332332
try {
@@ -352,7 +352,7 @@ After (new approach):
352352

353353
```typescript
354354
// Handler returns result data - no status boilerplate, no stringify
355-
export async function getAccountBalance(args: CommandHandlerArgs): Promise<CommandExecutionResult<AccountBalanceOutput>> {
355+
export async function accountBalance(args: CommandHandlerArgs): Promise<CommandExecutionResult<AccountBalanceOutput>> {
356356
const validArgs = AccountBalanceInputSchema.parse(args.args);
357357

358358
const account = api.alias.resolve(validArgs.account, ALIAS_TYPE.Account, network);

docs/adr/ADR-008-smart-contract-plugin-implementation-strategy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Contract plugin will consist of two commands:
108108
'Key manager to use: local or local_encrypted (defaults to config setting)',
109109
},
110110
],
111-
handler: createContract,
111+
handler: contractCreate,
112112
output: {
113113
schema: ContractCreateOutputSchema,
114114
humanTemplate: CONTRACT_CREATE_TEMPLATE,
@@ -152,7 +152,7 @@ hcli contract create --name my-token --default erc20 -c "CustomToken" -c "CTK" -
152152
summary: 'List all contracts',
153153
description: 'List all smart contracts stored in the state',
154154
options: [],
155-
handler: listContracts,
155+
handler: contractList,
156156
output: {
157157
schema: ContractListOutputSchema,
158158
humanTemplate: CONTRACT_LIST_TEMPLATE,

docs/adr/ADR-010-batch-transaction-plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ hooks: [
260260
options: [ /* ... token-specific options ... */ ],
261261
registeredHooks: ['batchify'],
262262
command: new MintNftCommand(),
263-
handler: mintNft,
263+
handler: tokenMintNft,
264264
output: { schema: MintNftOutputSchema, humanTemplate: MINT_NFT_TEMPLATE },
265265
}
266266

@@ -385,7 +385,7 @@ hooks: [
385385
options: [ /* ... */ ],
386386
registeredHooks: ['token-batch-state', 'topic-batch-state', 'account-batch-state'],
387387
command: new ExecuteBatchCommand(),
388-
handler: executeBatch,
388+
handler: batchExecute,
389389
output: { schema: ExecuteBatchOutputSchema, humanTemplate: EXECUTE_BATCH_TEMPLATE },
390390
}
391391
```

src/__tests__/integration/config/config.integration.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import '@/core/utils/json-serialize';
88
import { STATE_STORAGE_FILE_PATH } from '@/__tests__/test-constants';
99
import { setDefaultOperatorForNetwork } from '@/__tests__/utils/network-and-operator-setup';
1010
import { createCoreApi } from '@/core';
11-
import { getConfigOption } from '@/plugins/config/commands/get/handler';
12-
import { listConfigOptions } from '@/plugins/config/commands/list/handler';
13-
import { setConfigOption } from '@/plugins/config/commands/set/handler';
11+
import { configGet } from '@/plugins/config/commands/get/handler';
12+
import { configList } from '@/plugins/config/commands/list/handler';
13+
import { configSet } from '@/plugins/config/commands/set/handler';
1414

1515
describe('Config Integration Tests', () => {
1616
let coreApi: CoreApi;
@@ -21,7 +21,7 @@ describe('Config Integration Tests', () => {
2121
});
2222

2323
it('should list config options', async () => {
24-
const listConfigResult = await listConfigOptions({
24+
const listConfigResult = await configList({
2525
args: {},
2626
api: coreApi,
2727
state: coreApi.state,
@@ -46,7 +46,7 @@ describe('Config Integration Tests', () => {
4646
option: 'ed25519_support_enabled',
4747
value: 'true',
4848
};
49-
const setConfigResult = await setConfigOption({
49+
const setConfigResult = await configSet({
5050
args: setConfigArgs,
5151
api: coreApi,
5252
state: coreApi.state,
@@ -60,7 +60,7 @@ describe('Config Integration Tests', () => {
6060
const getConfigArgs: Record<string, unknown> = {
6161
option: 'ed25519_support_enabled',
6262
};
63-
const getConfigResult = await getConfigOption({
63+
const getConfigResult = await configGet({
6464
args: getConfigArgs,
6565
api: coreApi,
6666
state: coreApi.state,

src/plugins/account/__tests__/unit/balance.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { assertOutput } from '@/__tests__/utils/assert-output';
1414
import { InternalError, NotFoundError, StateError } from '@/core/errors';
1515
import { AliasType } from '@/core/services/alias/alias-service.interface';
1616
import { AccountBalanceOutputSchema } from '@/plugins/account/commands/balance';
17-
import { getAccountBalance } from '@/plugins/account/commands/balance/handler';
17+
import { accountBalance } from '@/plugins/account/commands/balance/handler';
1818
import { ZustandAccountStateHelper } from '@/plugins/account/zustand-state-helper';
1919

2020
jest.mock('../../zustand-state-helper', () => ({
@@ -53,7 +53,7 @@ describe('account plugin - balance command (ADR-003)', () => {
5353
token: '0.0.7777',
5454
});
5555

56-
const result = await getAccountBalance(args);
56+
const result = await accountBalance(args);
5757
const output = assertOutput(result.result, AccountBalanceOutputSchema);
5858

5959
expect(mirrorMock.getAccountHBarBalance).not.toHaveBeenCalled();
@@ -108,7 +108,7 @@ describe('account plugin - balance command (ADR-003)', () => {
108108
token: 'token-alias',
109109
});
110110

111-
const result = await getAccountBalance(args);
111+
const result = await accountBalance(args);
112112

113113
expect(mirrorMock.getAccountHBarBalance).not.toHaveBeenCalled();
114114
expect(mirrorMock.getAccountTokenBalances).toHaveBeenCalledWith(
@@ -151,7 +151,7 @@ describe('account plugin - balance command (ADR-003)', () => {
151151
hbarOnly: true,
152152
});
153153

154-
const result = await getAccountBalance(args);
154+
const result = await accountBalance(args);
155155

156156
expect(mirrorMock.getAccountHBarBalance).toHaveBeenCalledWith('0.0.1001');
157157
const output = assertOutput(result.result, AccountBalanceOutputSchema);
@@ -187,7 +187,7 @@ describe('account plugin - balance command (ADR-003)', () => {
187187
};
188188
const args = makeArgs(api, logger, { account: 'acc2' });
189189

190-
const result = await getAccountBalance(args);
190+
const result = await accountBalance(args);
191191

192192
expect(mirrorMock.getAccountHBarBalance).toHaveBeenCalledWith('0.0.2002');
193193
expect(mirrorMock.getAccountTokenBalances).toHaveBeenCalledWith(
@@ -239,7 +239,7 @@ describe('account plugin - balance command (ADR-003)', () => {
239239
};
240240
const args = makeArgs(api, logger, { account: 'acc777' });
241241

242-
const result = await getAccountBalance(args);
242+
const result = await accountBalance(args);
243243

244244
expect(mirrorMock.getAccountHBarBalance).toHaveBeenCalledWith('0.0.7777');
245245
const output = assertOutput(result.result, AccountBalanceOutputSchema);
@@ -268,7 +268,7 @@ describe('account plugin - balance command (ADR-003)', () => {
268268
};
269269
const args = makeArgs(api, logger, { account: 'acc3' });
270270

271-
const result = await getAccountBalance(args);
271+
const result = await accountBalance(args);
272272

273273
const output = assertOutput(result.result, AccountBalanceOutputSchema);
274274
expect(output.accountId).toBe('0.0.5005');
@@ -299,7 +299,7 @@ describe('account plugin - balance command (ADR-003)', () => {
299299
};
300300
const args = makeArgs(api, logger, { account: 'acc4' });
301301

302-
await expect(getAccountBalance(args)).rejects.toThrow();
302+
await expect(accountBalance(args)).rejects.toThrow();
303303
});
304304

305305
test('throws NotFoundError when account not found', async () => {
@@ -322,7 +322,7 @@ describe('account plugin - balance command (ADR-003)', () => {
322322
const account = 'broken';
323323
const args = makeArgs(api, logger, { account });
324324

325-
await expect(getAccountBalance(args)).rejects.toThrow(NotFoundError);
325+
await expect(accountBalance(args)).rejects.toThrow(NotFoundError);
326326
});
327327

328328
test('throws error when mirror service fails', async () => {
@@ -350,7 +350,7 @@ describe('account plugin - balance command (ADR-003)', () => {
350350
hbarOnly: true,
351351
});
352352

353-
await expect(getAccountBalance(args)).rejects.toThrow();
353+
await expect(accountBalance(args)).rejects.toThrow();
354354
});
355355

356356
test('returns display units by default', async () => {
@@ -384,7 +384,7 @@ describe('account plugin - balance command (ADR-003)', () => {
384384
account: 'test-acc',
385385
});
386386

387-
const result = await getAccountBalance(args);
387+
const result = await accountBalance(args);
388388

389389
const output = assertOutput(result.result, AccountBalanceOutputSchema);
390390
expect(output.accountId).toBe('0.0.2002');
@@ -433,7 +433,7 @@ describe('account plugin - balance command (ADR-003)', () => {
433433
raw: true,
434434
});
435435

436-
const result = await getAccountBalance(args);
436+
const result = await accountBalance(args);
437437

438438
const output = assertOutput(result.result, AccountBalanceOutputSchema);
439439
expect(output.accountId).toBe('0.0.2002');

src/plugins/account/__tests__/unit/clear.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { makeLogger, makeStateMock } from '@/__tests__/mocks/mocks';
55
import { assertOutput } from '@/__tests__/utils/assert-output';
66
import { InternalError } from '@/core';
77
import { ClearAccountsOutputSchema } from '@/plugins/account/commands/clear';
8-
import { clearAccounts } from '@/plugins/account/commands/clear/handler';
8+
import { accountClear } from '@/plugins/account/commands/clear/handler';
99
import { ZustandAccountStateHelper } from '@/plugins/account/zustand-state-helper';
1010

1111
jest.mock('../../zustand-state-helper', () => ({
@@ -44,7 +44,7 @@ describe('account plugin - clear command (ADR-003)', () => {
4444
args: {},
4545
};
4646

47-
const result = await clearAccounts(args as CommandHandlerArgs);
47+
const result = await accountClear(args as CommandHandlerArgs);
4848

4949
expect(MockedHelper).toHaveBeenCalledWith(args.api!.state, logger);
5050
expect(listAccountsMock).toHaveBeenCalledTimes(1);
@@ -78,6 +78,6 @@ describe('account plugin - clear command (ADR-003)', () => {
7878
args: {},
7979
};
8080

81-
await expect(clearAccounts(args as CommandHandlerArgs)).rejects.toThrow();
81+
await expect(accountClear(args as CommandHandlerArgs)).rejects.toThrow();
8282
});
8383
});

src/plugins/account/__tests__/unit/create.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { NetworkError, SupportedNetwork } from '@/core';
1818
import { AliasType } from '@/core/services/alias/alias-service.interface';
1919
import { KeyAlgorithm } from '@/core/shared/constants';
2020
import { CreateAccountOutputSchema } from '@/plugins/account/commands/create';
21-
import { createAccount } from '@/plugins/account/commands/create/handler';
21+
import { accountCreate } from '@/plugins/account/commands/create/handler';
2222
import { ZustandAccountStateHelper } from '@/plugins/account/zustand-state-helper';
2323

2424
import { makeApiMocksForAccountCreate } from './helpers/mocks';
@@ -70,7 +70,7 @@ describe('account plugin - create command (ADR-003)', () => {
7070
name: 'myAccount',
7171
});
7272

73-
const result = await createAccount(args);
73+
const result = await accountCreate(args);
7474

7575
expect(kms.createLocalPrivateKey).toHaveBeenCalledWith(
7676
KeyAlgorithm.ECDSA,
@@ -146,10 +146,10 @@ describe('account plugin - create command (ADR-003)', () => {
146146

147147
const args = makeArgs(api, logger, { name: 'failAccount', balance: '100' });
148148

149-
await expect(createAccount(args)).rejects.toThrow();
149+
await expect(accountCreate(args)).rejects.toThrow();
150150
});
151151

152-
test('throws error when createAccount fails', async () => {
152+
test('throws error when accountCreate fails', async () => {
153153
const logger = makeLogger();
154154
MockedHelper.mockImplementation(() => ({ saveAccount: jest.fn() }));
155155

@@ -176,7 +176,7 @@ describe('account plugin - create command (ADR-003)', () => {
176176
balance: '100',
177177
});
178178

179-
await expect(createAccount(args)).rejects.toThrow();
179+
await expect(accountCreate(args)).rejects.toThrow();
180180
});
181181

182182
test('creates account with ECDSA key type', async () => {
@@ -215,7 +215,7 @@ describe('account plugin - create command (ADR-003)', () => {
215215
name: 'ecdsaAccount',
216216
});
217217

218-
const result = await createAccount(args);
218+
const result = await accountCreate(args);
219219

220220
expect(kms.createLocalPrivateKey).toHaveBeenCalledWith(
221221
KeyAlgorithm.ECDSA,
@@ -292,7 +292,7 @@ describe('account plugin - create command (ADR-003)', () => {
292292
key: `ecdsa:private:${ECDSA_HEX_PRIVATE_KEY}`,
293293
});
294294

295-
const result = await createAccount(args);
295+
const result = await accountCreate(args);
296296

297297
expect(kms.createLocalPrivateKey).not.toHaveBeenCalled();
298298
expect(keyResolver.getPublicKey).toHaveBeenCalled();
@@ -366,7 +366,7 @@ describe('account plugin - create command (ADR-003)', () => {
366366
key: 'kr_test123',
367367
});
368368

369-
const result = await createAccount(args);
369+
const result = await accountCreate(args);
370370

371371
expect(kms.createLocalPrivateKey).not.toHaveBeenCalled();
372372
expect(keyResolver.getPublicKey).toHaveBeenCalled();
@@ -413,7 +413,7 @@ describe('account plugin - create command (ADR-003)', () => {
413413
keyType: KeyAlgorithm.ECDSA,
414414
});
415415

416-
await expect(createAccount(args)).rejects.toThrow();
416+
await expect(accountCreate(args)).rejects.toThrow();
417417
});
418418

419419
test('creates account with ED25519 key type', async () => {
@@ -452,7 +452,7 @@ describe('account plugin - create command (ADR-003)', () => {
452452
name: 'ed25519Account',
453453
});
454454

455-
const result = await createAccount(args);
455+
const result = await accountCreate(args);
456456

457457
expect(kms.createLocalPrivateKey).toHaveBeenCalledWith(
458458
KeyAlgorithm.ED25519,

0 commit comments

Comments
 (0)