@aastar/sdk 0.16.22 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +1 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +2 -0
  4. package/dist/utils/userOp.d.ts +11 -0
  5. package/dist/utils/userOp.js +43 -2
  6. package/package.json +11 -10
  7. package/dist/clients/ExperimentClient.test.d.ts +0 -1
  8. package/dist/clients/ExperimentClient.test.js +0 -53
  9. package/dist/clients/admin.test.d.ts +0 -1
  10. package/dist/clients/admin.test.js +0 -79
  11. package/dist/clients/clients.test.d.ts +0 -1
  12. package/dist/clients/clients.test.js +0 -91
  13. package/dist/clients/community.test.d.ts +0 -1
  14. package/dist/clients/community.test.js +0 -99
  15. package/dist/clients/endUser.test.d.ts +0 -1
  16. package/dist/clients/endUser.test.js +0 -188
  17. package/dist/clients/operator.test.d.ts +0 -1
  18. package/dist/clients/operator.test.js +0 -139
  19. package/dist/core/src/abis/BLSAggregator.json +0 -686
  20. package/dist/core/src/abis/BLSValidator.json +0 -42
  21. package/dist/core/src/abis/DVTValidator.json +0 -368
  22. package/dist/core/src/abis/EntryPoint.json +0 -1382
  23. package/dist/core/src/abis/GToken.json +0 -513
  24. package/dist/core/src/abis/GTokenStaking.json +0 -949
  25. package/dist/core/src/abis/MySBT.json +0 -1518
  26. package/dist/core/src/abis/Paymaster.json +0 -1143
  27. package/dist/core/src/abis/PaymasterFactory.json +0 -640
  28. package/dist/core/src/abis/Registry.json +0 -1942
  29. package/dist/core/src/abis/ReputationSystem.json +0 -699
  30. package/dist/core/src/abis/SimpleAccount.json +0 -560
  31. package/dist/core/src/abis/SimpleAccountFactory.json +0 -111
  32. package/dist/core/src/abis/SuperPaymaster.json +0 -1781
  33. package/dist/core/src/abis/xPNTsFactory.json +0 -718
  34. package/dist/core/src/abis/xPNTsToken.json +0 -1280
  35. package/dist/errors/AAStarError.d.ts +0 -26
  36. package/dist/errors/AAStarError.js +0 -32
  37. package/dist/errors/AAStarError.test.d.ts +0 -1
  38. package/dist/errors/AAStarError.test.js +0 -74
  39. package/dist/errors/decoder.test.d.ts +0 -1
  40. package/dist/errors/decoder.test.js +0 -90
  41. package/dist/node/index.d.ts +0 -7
  42. package/dist/node/index.js +0 -7
  43. package/dist/types/result.d.ts +0 -15
  44. package/dist/types/result.js +0 -23
  45. package/dist/utils/errorHandler.test.d.ts +0 -1
  46. package/dist/utils/errorHandler.test.js +0 -89
  47. package/dist/utils/eventDecoder.d.ts +0 -7
  48. package/dist/utils/eventDecoder.js +0 -54
  49. package/dist/utils/eventDecoder.test.d.ts +0 -1
  50. package/dist/utils/eventDecoder.test.js +0 -48
  51. package/dist/utils/funding.test.d.ts +0 -1
  52. package/dist/utils/funding.test.js +0 -105
  53. package/dist/utils/keys.test.d.ts +0 -1
  54. package/dist/utils/keys.test.js +0 -81
  55. package/dist/utils/roleData.test.d.ts +0 -1
  56. package/dist/utils/roleData.test.js +0 -74
  57. package/dist/utils/testScenarios.test.d.ts +0 -1
  58. package/dist/utils/testScenarios.test.js +0 -68
  59. package/dist/utils/userOp.test.d.ts +0 -1
  60. package/dist/utils/userOp.test.js +0 -152
package/README.md CHANGED
@@ -48,6 +48,7 @@ npm install @aastar/sdk viem
48
48
  - **Configuration Sync**: https://docs.aastar.io/guide/docs/Configuration_Sync
49
49
  - **Regression Testing**: https://docs.aastar.io/guide/docs/Regression_Testing_Guide
50
50
  - **Gasless Tester Guide**: https://docs.aastar.io/guide/docs/TESTER_GUIDE_GASLESS
51
+ - **Price Keeper Guide**: [docs/guide/keeper.md](../../docs/guide/keeper.md)
51
52
 
52
53
  ---
53
54
 
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from './clients/ExperimentClient.js';
12
12
  export * from '@aastar/enduser';
13
13
  export * from '@aastar/operator';
14
14
  export * from '@aastar/admin';
15
+ export * as AirAccount from '@aastar/airaccount';
15
16
  export * from './utils/roleData.js';
16
17
  export * from './utils/keys.js';
17
18
  export * from './utils/funding.js';
package/dist/index.js CHANGED
@@ -15,6 +15,8 @@ export * from './clients/ExperimentClient.js';
15
15
  export * from '@aastar/enduser';
16
16
  export * from '@aastar/operator';
17
17
  export * from '@aastar/admin';
18
+ // Export AirAccount SDK (ERC-4337 + KMS + BLS)
19
+ export * as AirAccount from '@aastar/airaccount';
18
20
  // Export Utils & Errors
19
21
  export * from './utils/roleData.js';
20
22
  export * from './utils/keys.js';
@@ -33,6 +33,17 @@ export declare class UserOperationBuilder {
33
33
  * Packs maxPriorityFeePerGas and maxFeePerGas into a bytes32 Hex string.
34
34
  */
35
35
  static packGasFees(maxPriorityFeePerGas: bigint, maxFeePerGas: bigint): Hex;
36
+ static estimatePreVerificationGasV07(userOp: {
37
+ sender: Address;
38
+ nonce: bigint | Hex | number | string;
39
+ initCode: Hex;
40
+ callData: Hex;
41
+ accountGasLimits: Hex;
42
+ preVerificationGas: bigint | Hex | number | string;
43
+ gasFees: Hex;
44
+ paymasterAndData: Hex;
45
+ signature: Hex;
46
+ }): bigint;
36
47
  /**
37
48
  * Packs Paymaster parameters into the v0.7 paymasterAndData format.
38
49
  */
@@ -1,4 +1,4 @@
1
- import { concat, pad } from 'viem';
1
+ import { concat, pad, encodeAbiParameters, parseAbiParameters, toBytes } from 'viem';
2
2
  export class UserOperationBuilder {
3
3
  /**
4
4
  * Packs verificationGasLimit and callGasLimit into a bytes32 Hex string.
@@ -18,6 +18,36 @@ export class UserOperationBuilder {
18
18
  pad(`0x${maxFeePerGas.toString(16)}`, { dir: 'left', size: 16 })
19
19
  ]);
20
20
  }
21
+ static estimatePreVerificationGasV07(userOp) {
22
+ const nonce = typeof userOp.nonce === 'bigint'
23
+ ? userOp.nonce
24
+ : typeof userOp.nonce === 'number'
25
+ ? BigInt(userOp.nonce)
26
+ : BigInt(userOp.nonce);
27
+ const preVerificationGas = typeof userOp.preVerificationGas === 'bigint'
28
+ ? userOp.preVerificationGas
29
+ : typeof userOp.preVerificationGas === 'number'
30
+ ? BigInt(userOp.preVerificationGas)
31
+ : BigInt(userOp.preVerificationGas);
32
+ const encoded = encodeAbiParameters(parseAbiParameters('(address,uint256,bytes,bytes,bytes32,uint256,bytes32,bytes,bytes)'), [
33
+ [
34
+ userOp.sender,
35
+ nonce,
36
+ userOp.initCode,
37
+ userOp.callData,
38
+ userOp.accountGasLimits,
39
+ preVerificationGas,
40
+ userOp.gasFees,
41
+ userOp.paymasterAndData,
42
+ userOp.signature
43
+ ]
44
+ ]);
45
+ const bytes = toBytes(encoded);
46
+ let calldataCost = 0n;
47
+ for (const b of bytes)
48
+ calldataCost += b === 0 ? 4n : 16n;
49
+ return calldataCost + 26000n;
50
+ }
21
51
  /**
22
52
  * Packs Paymaster parameters into the v0.7 paymasterAndData format.
23
53
  */
@@ -127,9 +157,20 @@ export class UserOperationBuilder {
127
157
  * @param options.paymasterPostOpGasLimit - Gas limit for paymaster postOp (default: 200000)
128
158
  */
129
159
  static toAlchemyUserOperation(userOp, options) {
160
+ const toHexStr = (val) => {
161
+ if (val === undefined || val === null)
162
+ return undefined;
163
+ if (typeof val === 'bigint')
164
+ return `0x${val.toString(16)}`;
165
+ if (typeof val === 'number')
166
+ return `0x${val.toString(16)}`;
167
+ if (typeof val === 'string' && !val.startsWith('0x'))
168
+ return `0x${val}`;
169
+ return val;
170
+ };
130
171
  const result = {
131
172
  sender: userOp.sender,
132
- nonce: userOp.nonce,
173
+ nonce: toHexStr(userOp.nonce),
133
174
  callData: userOp.callData,
134
175
  signature: userOp.signature
135
176
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aastar/sdk",
3
- "version": "0.16.22",
3
+ "version": "0.17.0",
4
4
  "description": "AAStar SDK - The all-in-one package for Mycelium Network",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -14,15 +14,16 @@
14
14
  ],
15
15
  "dependencies": {
16
16
  "viem": "2.43.3",
17
- "@aastar/core": "0.16.22",
18
- "@aastar/dapp": "0.16.22",
19
- "@aastar/identity": "0.16.22",
20
- "@aastar/account": "0.16.22",
21
- "@aastar/enduser": "0.16.22",
22
- "@aastar/paymaster": "0.16.22",
23
- "@aastar/tokens": "0.16.22",
24
- "@aastar/admin": "0.16.22",
25
- "@aastar/operator": "0.16.22"
17
+ "@aastar/enduser": "0.17.0",
18
+ "@aastar/core": "0.17.0",
19
+ "@aastar/account": "0.17.0",
20
+ "@aastar/dapp": "0.17.0",
21
+ "@aastar/tokens": "0.17.0",
22
+ "@aastar/identity": "0.17.0",
23
+ "@aastar/airaccount": "0.17.0",
24
+ "@aastar/paymaster": "0.17.0",
25
+ "@aastar/admin": "0.17.0",
26
+ "@aastar/operator": "0.17.0"
26
27
  },
27
28
  "devDependencies": {
28
29
  "typescript": "5.7.2"
@@ -1 +0,0 @@
1
- export {};
@@ -1,53 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { ExperimentClient } from './ExperimentClient.js';
3
- describe('ExperimentClient', () => {
4
- it('should record transaction result', () => {
5
- const client = new ExperimentClient('test-scenario', 'AA');
6
- const receipt = { gasUsed: 21000n, effectiveGasPrice: 1000000000n };
7
- const record = client.recordTx('0xhash', receipt, 'Success');
8
- expect(record.txHash).toBe('0xhash');
9
- expect(record.group).toBe('AA');
10
- expect(record.status).toBe('Success');
11
- expect(record.costETH).toBe('0.000021');
12
- expect(client.getRecords()).toHaveLength(1);
13
- });
14
- it('should measure transaction automatically', async () => {
15
- const client = new ExperimentClient('test-scenario', 'SuperPaymaster');
16
- const mockPublicClient = {
17
- waitForTransactionReceipt: vi.fn().mockResolvedValue({
18
- gasUsed: 50000n,
19
- effectiveGasPrice: 2000000000n
20
- })
21
- };
22
- const txPromise = Promise.resolve('0xhash');
23
- const hash = await client.measureTx('test-task', txPromise, mockPublicClient);
24
- expect(hash).toBe('0xhash');
25
- expect(client.getRecords()).toHaveLength(1);
26
- expect(client.getRecords()[0].status).toBe('Success');
27
- });
28
- it('should handle failed measureTx', async () => {
29
- const client = new ExperimentClient('test-scenario', 'EOA');
30
- const txPromise = Promise.reject(new Error('tx failed'));
31
- await expect(client.measureTx('test-task', txPromise, {})).rejects.toThrow('tx failed');
32
- });
33
- it('should handle missing gas fields in receipt', () => {
34
- const client = new ExperimentClient('test-scenario', 'AA');
35
- const record = client.recordTx('0xhash', {}, 'Success');
36
- expect(record.gasUsed).toBe(0n);
37
- expect(record.gasPrice).toBe(0n);
38
- expect(record.costETH).toBe('0');
39
- });
40
- it('should record latency in measureTx', async () => {
41
- const client = new ExperimentClient('test-scenario', 'AA');
42
- const mockPublicClient = {
43
- waitForTransactionReceipt: vi.fn().mockResolvedValue({
44
- gasUsed: 21000n,
45
- effectiveGasPrice: 1000000000n
46
- })
47
- };
48
- await client.measureTx('test', Promise.resolve('0xhash'), mockPublicClient);
49
- const record = client.getRecords()[0];
50
- expect(record.meta?.latency).toBeDefined();
51
- expect(typeof record.meta.latency).toBe('number');
52
- });
53
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,79 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { createAdminClient } from './admin.js';
3
- import { mainnet } from 'viem/chains';
4
- import { http } from 'viem';
5
- describe('AdminClient', () => {
6
- const MOCK_ADDR = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
7
- it('should create admin client and access modules', () => {
8
- const client = createAdminClient({ chain: mainnet, transport: http() });
9
- expect(client.system).toBeDefined();
10
- expect(client.finance).toBeDefined();
11
- expect(client.operators).toBeDefined();
12
- });
13
- describe('SystemModule', () => {
14
- it('should grant role', async () => {
15
- const client = createAdminClient({ chain: mainnet, transport: http() });
16
- const spy = vi.fn().mockResolvedValue('0xhash');
17
- client.registryRegisterRole = spy;
18
- const hash = await client.system.grantRole({ roleId: '0x1', user: MOCK_ADDR, data: '0x' });
19
- expect(hash).toBe('0xhash');
20
- expect(spy).toHaveBeenCalled();
21
- });
22
- it('should revoke role', async () => {
23
- const client = createAdminClient({ chain: mainnet, transport: http() });
24
- const spy = vi.fn().mockResolvedValue('0xhash');
25
- client.registryUnRegisterRole = spy;
26
- const hash = await client.system.revokeRole({ roleId: '0x1', user: MOCK_ADDR });
27
- expect(hash).toBe('0xhash');
28
- expect(spy).toHaveBeenCalled();
29
- });
30
- it('should set super paymaster', async () => {
31
- const client = createAdminClient({ chain: mainnet, transport: http() });
32
- const spy = vi.fn().mockResolvedValue('0xhash');
33
- client.registrySetSuperPaymaster = spy;
34
- const hash = await client.system.setSuperPaymaster(MOCK_ADDR);
35
- expect(hash).toBe('0xhash');
36
- });
37
- });
38
- describe('FinanceModule', () => {
39
- it('should deposit', async () => {
40
- const client = createAdminClient({ chain: mainnet, transport: http() });
41
- const spy = vi.fn().mockResolvedValue('0xhash');
42
- client.superPaymasterDeposit = spy;
43
- const hash = await client.finance.deposit({ amount: 100n });
44
- expect(hash).toBe('0xhash');
45
- });
46
- it('should depositForOperator', async () => {
47
- const client = createAdminClient({ chain: mainnet, transport: http() });
48
- const spy = vi.fn().mockResolvedValue('0xhash');
49
- client.superPaymasterDepositFor = spy;
50
- const hash = await client.finance.depositForOperator({ operator: MOCK_ADDR, amount: 100n });
51
- expect(hash).toBe('0xhash');
52
- });
53
- it('should withdrawTo', async () => {
54
- const client = createAdminClient({ chain: mainnet, transport: http() });
55
- const spy = vi.fn().mockResolvedValue('0xhash');
56
- client.superPaymasterWithdrawTo = spy;
57
- const hash = await client.finance.withdrawTo({ to: MOCK_ADDR, amount: 100n });
58
- expect(hash).toBe('0xhash');
59
- });
60
- });
61
- describe('OperatorsModule', () => {
62
- it('should ban/unban operator', async () => {
63
- const client = createAdminClient({ chain: mainnet, transport: http() });
64
- const spy = vi.fn().mockResolvedValue('0xhash');
65
- client.registryUpdateOperatorBlacklist = spy;
66
- await client.operators.ban(MOCK_ADDR);
67
- expect(spy).toHaveBeenCalledWith(expect.objectContaining({ statuses: [true] }));
68
- await client.operators.unban(MOCK_ADDR);
69
- expect(spy).toHaveBeenCalledWith(expect.objectContaining({ statuses: [false] }));
70
- });
71
- it('should setPaused', async () => {
72
- const client = createAdminClient({ chain: mainnet, transport: http() });
73
- const spy = vi.fn().mockResolvedValue('0xhash');
74
- client.superPaymasterSetOperatorPaused = spy;
75
- await client.operators.setPaused(MOCK_ADDR, true);
76
- expect(spy).toHaveBeenCalledWith(expect.objectContaining({ paused: true }));
77
- });
78
- });
79
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,91 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { createEndUserClient } from './endUser.js';
3
- import { createCommunityClient } from './community.js';
4
- import { createOperatorClient } from './operator.js';
5
- import { createAdminClient } from './admin.js';
6
- import { http } from 'viem';
7
- import { mainnet } from 'viem/chains';
8
- describe('SDK L2 Clients', () => {
9
- let mockTransport;
10
- let mockChain;
11
- let mockAccount;
12
- const MOCK_ADDR = '0x1111111111111111111111111111111111111111';
13
- beforeEach(() => {
14
- mockTransport = http('http://localhost:8545');
15
- mockChain = mainnet;
16
- mockAccount = {
17
- address: MOCK_ADDR,
18
- type: 'json-rpc',
19
- signMessage: vi.fn().mockResolvedValue('0xsignature')
20
- };
21
- });
22
- describe('EndUserClient', () => {
23
- let client;
24
- beforeEach(() => {
25
- client = createEndUserClient({ chain: mockChain, transport: mockTransport, account: mockAccount });
26
- client.readContract = vi.fn();
27
- client.writeContract = vi.fn().mockResolvedValue('0xhash');
28
- client.waitForTransactionReceipt = vi.fn().mockResolvedValue({ logs: [] });
29
- client.getBytecode = vi.fn().mockResolvedValue('0x123');
30
- });
31
- it('should create EndUserClient', () => {
32
- expect(client.onboard).toBeDefined();
33
- });
34
- it('should create smart account', async () => {
35
- client.readContract.mockResolvedValue(MOCK_ADDR);
36
- const result = await client.createSmartAccount({ owner: MOCK_ADDR });
37
- expect(result.accountAddress).toBe(MOCK_ADDR);
38
- expect(result.initCode).toBeDefined();
39
- });
40
- it('should execute gasless transaction', async () => {
41
- client.readContract.mockResolvedValue(0n); // nonce
42
- client.readContract.mockResolvedValueOnce(0n).mockResolvedValueOnce('0xhash'); // nonce, userOpHash
43
- client.createSmartAccount = vi.fn().mockResolvedValue({ accountAddress: MOCK_ADDR, initCode: '0x' });
44
- const result = await client.executeGasless({
45
- target: MOCK_ADDR,
46
- data: '0x',
47
- operator: MOCK_ADDR
48
- });
49
- expect(result.hash).toBe('0xhash');
50
- });
51
- });
52
- describe('CommunityClient', () => {
53
- it('should launch community', async () => {
54
- const client = createCommunityClient({ chain: mockChain, transport: mockTransport, account: mockAccount });
55
- client.writeContract = vi.fn().mockResolvedValue('0xhash');
56
- client.simulateContract = vi.fn().mockResolvedValue({ request: {} });
57
- client.waitForTransactionReceipt = vi.fn().mockResolvedValue({ logs: [] });
58
- client.readContract = vi.fn().mockResolvedValue(MOCK_ADDR);
59
- const result = await client.launch({
60
- name: 'Test',
61
- tokenName: 'TT',
62
- tokenSymbol: 'TT'
63
- });
64
- expect(result.tokenAddress).toBe(MOCK_ADDR);
65
- expect(result.results.length).toBeGreaterThan(0);
66
- });
67
- });
68
- describe('OperatorClient', () => {
69
- it('should setup operator', async () => {
70
- const client = createOperatorClient({ chain: mockChain, transport: mockTransport, account: mockAccount });
71
- client.readContract = vi.fn().mockResolvedValue(['', 0n]); // roleConfig
72
- client.writeContract = vi.fn().mockResolvedValue('0xhash');
73
- client.waitForTransactionReceipt = vi.fn().mockResolvedValue({ logs: [] });
74
- client.registryHasRole = vi.fn().mockResolvedValue(false);
75
- const result = await client.setup({
76
- stakeAmount: 100n,
77
- depositAmount: 100n,
78
- roleId: '0x1'
79
- });
80
- expect(result.txs.length).toBeGreaterThan(0);
81
- });
82
- });
83
- describe('AdminClient', () => {
84
- it('should have namespaces', () => {
85
- const client = createAdminClient({ chain: mockChain, transport: mockTransport, account: mockAccount });
86
- expect(client.system).toBeDefined();
87
- expect(client.finance).toBeDefined();
88
- expect(client.operators).toBeDefined();
89
- });
90
- });
91
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,99 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { createCommunityClient } from './community.js';
3
- import { mainnet } from 'viem/chains';
4
- import { http } from 'viem';
5
- vi.mock('@aastar/core', async () => {
6
- const actual = await vi.importActual('@aastar/core');
7
- return {
8
- ...actual,
9
- registryActions: vi.fn(() => vi.fn(() => ({
10
- registerRoleSelf: vi.fn().mockResolvedValue('0xhash'),
11
- hasRole: vi.fn(),
12
- roleMetadata: vi.fn()
13
- }))),
14
- sbtActions: vi.fn(() => vi.fn(() => ({
15
- getUserSBT: vi.fn().mockResolvedValue(123n)
16
- }))),
17
- reputationActions: vi.fn(() => vi.fn(() => ({
18
- setReputationRule: vi.fn().mockResolvedValue('0xhash')
19
- }))),
20
- };
21
- });
22
- describe('CommunityClient', () => {
23
- const MOCK_ADDR = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
24
- it('should create community client', () => {
25
- const client = createCommunityClient({ chain: mainnet, transport: http() });
26
- expect(client.launch).toBeDefined();
27
- });
28
- describe('launch', () => {
29
- it('should launch community with token and governance', async () => {
30
- const client = createCommunityClient({
31
- chain: mainnet,
32
- transport: http(),
33
- account: { address: MOCK_ADDR }
34
- });
35
- // Mock base client methods
36
- client.readContract = vi.fn().mockResolvedValue('0x0000000000000000000000000000000000000000');
37
- client.simulateContract = vi.fn().mockResolvedValue({ request: {} });
38
- client.writeContract = vi.fn().mockResolvedValue('0xhash');
39
- client.waitForTransactionReceipt = vi.fn().mockResolvedValue({ logs: [] });
40
- const result = await client.launch({
41
- name: 'Test',
42
- tokenName: 'T',
43
- tokenSymbol: 'T',
44
- governance: { initialReputationRule: true }
45
- });
46
- expect(result.results.length).toBeGreaterThanOrEqual(2);
47
- expect(client.writeContract).toHaveBeenCalled();
48
- });
49
- });
50
- describe('getCommunityInfo', () => {
51
- it('should return info for registered community', async () => {
52
- const client = createCommunityClient({ chain: mainnet, transport: http() });
53
- client.readContract = vi.fn()
54
- .mockResolvedValueOnce(true) // hasRole
55
- .mockResolvedValueOnce('0xtoken') // getTokenAddress
56
- .mockResolvedValueOnce('0x'); // roleMetadata
57
- const info = await client.getCommunityInfo(MOCK_ADDR);
58
- expect(info.hasRole).toBe(true);
59
- expect(info.tokenAddress).toBe('0xtoken');
60
- });
61
- });
62
- describe('Launch', () => {
63
- it('should validate launch inputs', async () => {
64
- const communityClient = createCommunityClient({ chain: mainnet, transport: http(), account: { address: MOCK_ADDR } });
65
- await expect(communityClient.launch({
66
- name: '',
67
- tokenName: 'T',
68
- tokenSymbol: 'T'
69
- })).rejects.toThrow('Community Name is required');
70
- await expect(communityClient.launch({
71
- name: 'Test',
72
- tokenName: '',
73
- tokenSymbol: 'T'
74
- })).rejects.toThrow('Token Name is required');
75
- await expect(communityClient.launch({
76
- name: 'Test',
77
- tokenName: 'Test',
78
- tokenSymbol: ''
79
- })).rejects.toThrow('Token Symbol is required');
80
- });
81
- it('should handle registration failure gracefully in launch', async () => {
82
- const communityClient = createCommunityClient({ chain: mainnet, transport: http(), account: { address: MOCK_ADDR } });
83
- // Mock writeContract failure (Already registered)
84
- communityClient.writeContract = vi.fn().mockRejectedValueOnce(new Error('Already registered'));
85
- // Mock deployToken to succeed
86
- communityClient.readContract = vi.fn().mockResolvedValue('0x0000000000000000000000000000000000000000');
87
- communityClient.deployToken = vi.fn().mockResolvedValue('0xtoken');
88
- // Mock setGovernance
89
- communityClient.setReputationRule = vi.fn().mockResolvedValue('0xrule');
90
- communityClient.waitForTransactionReceipt = vi.fn().mockResolvedValue({ logs: [] });
91
- await communityClient.launch({
92
- name: 'Test',
93
- tokenName: 'Test',
94
- tokenSymbol: 'TST'
95
- });
96
- expect(true).toBe(true);
97
- });
98
- });
99
- });
@@ -1 +0,0 @@
1
- export {};